Top 250 Java Interview Questions and Answers

Updated 26 Feb 2025

Q101. Java vs other language

Ans.

Java is a popular language with strong community support and cross-platform compatibility.

  • Java is object-oriented and has automatic memory management

  • Other languages like C++ require manual memory management

  • Java has a large standard library and is used for web development, mobile apps, and enterprise software

  • Other languages like Python are popular for data science and machine learning

  • Java is compiled to bytecode and runs on a virtual machine, making it cross-platform compatibl...read more

Add your answer

Q102. Drawback of java api stream

Ans.

One drawback of Java API Stream is that it can be less efficient for small collections.

  • Stream operations can be slower for small collections compared to traditional loops.

  • Stream operations can be harder to debug and understand for some developers.

  • Stream operations can lead to increased memory usage due to intermediate objects created during processing.

Add your answer

Q103. Different technologies available in java

Ans.

Some technologies available in Java include Java EE, Spring Framework, Hibernate, Apache Struts, and JavaFX.

  • Java EE (Enterprise Edition) for building enterprise applications

  • Spring Framework for dependency injection and aspect-oriented programming

  • Hibernate for object-relational mapping

  • Apache Struts for developing web applications

  • JavaFX for creating rich internet applications

Add your answer
Frequently asked in

Q104. public static void getsum(int a,int b){System.out.println("a b method");}public static void getsum(int a,int b,int c){System.out.println("a b c method");}public static void getsum(int a,int ...b){System.out.pri...

read more
Ans.

The question is about method overloading in Java.

  • Method overloading allows multiple methods with the same name but different parameters.

  • The method to be called is determined at compile-time based on the arguments passed.

  • In the given code, there are three overloaded methods with the same name 'getsum'.

  • The first method takes two integers as arguments.

  • The second method takes three integers as arguments.

  • The third method takes one integer followed by a variable number of integers ...read more

Add your answer
Are these interview questions helpful?

Q105. Hopq to deploy java aps

Ans.

Java applications can be deployed using various methods such as manual deployment, using build tools like Maven or Gradle, or using containerization platforms like Docker.

  • Use build tools like Maven or Gradle to package the application into a JAR or WAR file

  • Deploy the packaged application to a server or cloud platform

  • Utilize containerization platforms like Docker to create a container image of the application and deploy it

  • Automate deployment process using CI/CD tools like Jenk...read more

Add your answer

Q106. What happens in the backend when we cret an object in Java? What should be done before creating the method body in Java?

Ans.

When an object is created in Java, memory is allocated in the heap for the object and its instance variables.

  • Memory is allocated in the heap for the object and its instance variables

  • Constructor is called to initialize the object

  • Reference to the object is returned

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q107. Why do you use public static void main in java why can't you use private/final

Ans.

public static void main is used in Java as the entry point for the program. private/final cannot be used as they restrict access or prevent overriding.

  • public static void main is the standard entry point method in Java programs

  • Using private/final would restrict access or prevent overriding, which is not suitable for the entry point method

  • Example: public static void main(String[] args) { }

Add your answer

Q108. JPA vs Hibernate

Ans.

JPA is a specification while Hibernate is an implementation of JPA.

  • JPA is a Java specification for managing relational data in applications.

  • Hibernate is an ORM framework that implements the JPA specification.

  • Hibernate provides additional features beyond JPA, such as caching and lazy loading.

  • JPA is vendor-neutral, allowing developers to switch between different JPA implementations.

  • Hibernate is a popular choice for JPA implementation due to its extensive features and community ...read more

Add your answer
Frequently asked in

Java Jobs

Java Full Stack Developer 7-12 years
CBRE
4.2
Noida
Java Developer (Database) 5-8 years
A.P. Moller Maersk
4.2
₹ 20 L/yr - ₹ 28 L/yr
Bangalore / Bengaluru
Software Development Engineer 3-8 years
A.P. Moller Maersk
4.2
₹ 20 L/yr - ₹ 33 L/yr
Bangalore / Bengaluru

Q109. 1. Fundamental concepts in java

Ans.

Fundamental concepts in Java include object-oriented programming, platform independence, and automatic memory management.

  • Object-oriented programming: Java is an object-oriented language, which means it uses objects to represent data and behavior.

  • Platform independence: Java code can run on any platform that has a Java Virtual Machine (JVM) installed.

  • Automatic memory management: Java has a garbage collector that automatically frees up memory that is no longer being used.

  • Other c...read more

Add your answer

Q110. 1 Write a procedure using user defined exception 2 write a procedure to get error, if updating end of the month. Etc....

Ans.

Creating procedures with user defined exceptions and handling errors when updating at end of month.

  • Create a procedure with a user defined exception using 'RAISE_APPLICATION_ERROR' and 'EXCEPTION' keywords.

  • Use 'TO_CHAR(SYSDATE, 'DD')' to check if it is the end of the month before updating.

  • Handle the error by raising an exception if the update is attempted at the end of the month.

  • Example: CREATE OR REPLACE PROCEDURE update_data AS BEGIN IF TO_CHAR(SYSDATE, 'DD') = '31' THEN RAI...read more

Add your answer
Frequently asked in

Q111. All Java 8 new features

Ans.

Java 8 introduced several new features including lambda expressions, functional interfaces, streams, and default methods.

  • Lambda expressions allow you to pass functionality as an argument to a method.

  • Functional interfaces have a single abstract method and can be used with lambda expressions.

  • Streams provide a way to work with sequences of elements efficiently.

  • Default methods allow interfaces to have method implementations.

  • Some other features include the new Date and Time API, N...read more

Add your answer
Frequently asked in

Q112. 2) experience with vue.js and java?

Ans.

I have experience with Vue.js and Java, including building web applications and implementing front-end and back-end functionalities.

  • Developed a web application using Vue.js for the front-end and Java for the back-end

  • Implemented RESTful APIs in Java to communicate with the Vue.js front-end

  • Utilized Vue.js components to create dynamic and interactive user interfaces

Add your answer

Q113. AWT Token working

Ans.

AWT Token is a security token used for authentication and authorization in Java applications.

  • AWT stands for Abstract Window Toolkit

  • AWT Token is used for managing user authentication and authorization in Java applications

  • It provides a secure way to control access to resources based on user credentials

Add your answer

Q114. Spring JPA vs Hibernate

Ans.

Spring JPA is a part of the Spring Data project that makes it easier to work with JPA. Hibernate is a popular ORM framework.

  • Spring JPA is a higher level abstraction on top of JPA, providing more features and simplifying development.

  • Hibernate is a powerful ORM framework that provides mapping between Java objects and database tables.

  • Spring JPA can be used with Hibernate as the underlying ORM provider.

  • Hibernate offers more flexibility and control over the database interactions c...read more

Add your answer

Q115. Implementation of database connection pool in java

Ans.

Database connection pool in Java helps manage multiple database connections efficiently.

  • Use a connection pool library like HikariCP or Apache DBCP.

  • Set up the pool with a maximum number of connections, timeout settings, etc.

  • Acquire and release connections from the pool as needed in your Java code.

Add your answer
Frequently asked in

Q116. Java 8 streams - how they function internally

Ans.

Java 8 streams are functional programming constructs that allow for efficient processing of large data sets.

  • Streams are composed of a source, intermediate operations, and a terminal operation.

  • Intermediate operations include filter, map, and sorted, and are lazily evaluated.

  • Terminal operations trigger the evaluation of the stream and include forEach, reduce, and collect.

  • Streams can be parallelized for even greater performance.

  • Streams are designed to work with lambdas and funct...read more

Add your answer

Q117. Concurrent package: internal working of CopyOnWriteArrayList Diff between synchronized collection and concurrent collection

Ans.

Explaining CopyOnWriteArrayList and difference between synchronized and concurrent collections.

  • CopyOnWriteArrayList is a thread-safe variant of ArrayList where all mutative operations are implemented by making a new copy of the underlying array.

  • Synchronized collections use a single lock to synchronize access to the collection, while concurrent collections use multiple locks to allow concurrent access.

  • Concurrent collections are designed to handle high-concurrency scenarios, wh...read more

Add your answer
Frequently asked in

Q118. Classloaders in java

Ans.

Classloaders are responsible for loading classes into the JVM at runtime.

  • Java has three built-in classloaders: bootstrap, extension, and system.

  • Custom classloaders can be created to load classes from non-standard sources.

  • Classloaders follow a delegation model, where they first delegate to their parent classloader before attempting to load the class themselves.

  • Classloaders can be used for dynamic class loading and hot-swapping of code at runtime.

Add your answer
Frequently asked in

Q119. latest feature of java 8

Ans.

Java 8 introduced lambda expressions and functional interfaces.

  • Lambda expressions allow for more concise and readable code.

  • Functional interfaces enable the use of lambda expressions.

  • Stream API for processing collections of data.

  • Date and Time API for improved handling of date and time.

  • Default methods in interfaces for backward compatibility.

Add your answer
Frequently asked in

Q120. Stream and collection api usage

Ans.

Stream and collection api usage involves manipulating data using streams and collections in Java.

  • Stream API provides a way to process collections of objects in a functional way.

  • Collection API provides data structures to store and manipulate groups of objects.

  • Stream API can be used to filter, map, reduce, and collect data from collections.

  • Collection API includes interfaces like List, Set, and Map for different data structures.

Add your answer

Q121. Objects in java 8

Ans.

Java 8 introduced the concept of functional programming with the addition of lambda expressions and streams.

  • Lambda expressions allow for concise code and easier parallel programming.

  • Streams provide a way to work with collections of objects in a functional style.

  • Functional interfaces like Predicate, Function, and Consumer are commonly used with lambda expressions.

Add your answer

Q122. java 8 improvements

Ans.

Java 8 introduced several improvements including lambda expressions, functional interfaces, streams, and default methods.

  • Lambda expressions allow for more concise code and easier parallel programming.

  • Functional interfaces enable the use of lambda expressions.

  • Streams provide a way to work with sequences of elements efficiently.

  • Default methods allow interfaces to have concrete methods.

  • Optional class helps to handle null values more effectively.

Add your answer
Frequently asked in

Q123. What is build in Java ?

Ans.

Build in Java refers to the process of compiling source code into executable code.

  • Build process involves compiling, testing, and packaging the code

  • Java build tools like Maven and Gradle automate the build process

  • Build artifacts can be JAR, WAR, or EAR files

  • Build process can be customized using build scripts like Ant

Add your answer

Q124. Differnence between C and Java

Ans.

C is a procedural programming language while Java is an object-oriented programming language.

  • C is a low-level language while Java is a high-level language.

  • C requires manual memory management while Java has automatic memory management.

  • C supports pointers while Java does not.

  • C is platform-dependent while Java is platform-independent.

  • C has a simpler syntax compared to Java.

Add your answer
Frequently asked in

Q125. Differnece between C++ and Java

Ans.

C++ is a compiled language with pointers and memory management, while Java is an interpreted language with garbage collection.

  • C++ is faster than Java due to direct memory access and lack of garbage collection

  • Java is more secure than C++ due to its sandbox environment

  • C++ allows for low-level system programming, while Java is better suited for web applications

  • C++ has multiple inheritance, while Java only has single inheritance

  • C++ has operator overloading, while Java does not

Add your answer

Q126. what are spring bean scope ?

Ans.

Spring bean scope defines the lifecycle and visibility of a bean in the Spring container.

  • Singleton scope: Only one instance of the bean is created and shared across the application.

  • Prototype scope: A new instance of the bean is created every time it is requested.

  • Request scope: A new instance of the bean is created for each HTTP request.

  • Session scope: A new instance of the bean is created for each HTTP session.

  • Global session scope: Similar to session scope, but for global HTTP...read more

View 1 answer

Q127. Why python is popular in market and java popularity is decreasing?

Ans.

Python's simplicity, versatility, and ease of use make it popular. Java's complexity and verbosity make it less popular.

  • Python has a simpler syntax and is easier to learn than Java.

  • Python is versatile and can be used for a wide range of applications, including web development, data analysis, and artificial intelligence.

  • Java's verbosity and complexity make it less appealing to developers.

  • Python has a large and active community that contributes to its popularity.

  • Java's populari...read more

Add your answer
Frequently asked in

Q128. Explain about Java 8 features

Ans.

Java 8 introduced several new features including lambda expressions, functional interfaces, and streams.

  • Lambda expressions allow for functional programming and simplify code

  • Functional interfaces enable the use of lambda expressions

  • Streams provide a way to process collections of data in a functional style

  • Default methods allow for adding methods to interfaces without breaking existing implementations

  • Date and time API improvements

  • Nashorn JavaScript engine

Add your answer

Q129. What @SpringBootApplication will do

Ans.

@SpringBootApplication is a Spring Boot annotation that enables auto-configuration and component scanning.

  • Enables auto-configuration of the Spring application context

  • Enables component scanning for beans

  • Provides a convenient shortcut for @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations

  • Can be used as a single entry point for the Spring Boot application

Add your answer

Q130. What is java, html

Ans.

Java is a programming language used for developing applications, while HTML is a markup language used for creating web pages.

  • Java is an object-oriented programming language known for its portability and versatility.

  • HTML is a markup language used to create the structure of web pages.

  • Java is used for developing applications like mobile apps, web applications, and enterprise software.

  • HTML is used to define the structure of web pages, including headings, paragraphs, links, and im...read more

Add your answer
Frequently asked in

Q131. Explain Life cycle methods

Ans.

Life cycle methods are functions that are called at different stages of a component's life cycle.

  • There are three categories of life cycle methods: mounting, updating, and unmounting.

  • Mounting methods are called when a component is first created and added to the DOM.

  • Updating methods are called when a component's state or props change.

  • Unmounting methods are called when a component is removed from the DOM.

  • Examples of life cycle methods include componentDidMount, componentDidUpdat...read more

Add your answer
Frequently asked in

Q132. What are the features in java 8

Ans.

Java 8 introduced several new features including lambda expressions, streams, and default methods.

  • Lambda expressions for functional programming

  • Streams for efficient processing of large data sets

  • Default methods to add new functionality to interfaces

  • Date and Time API for improved handling of date and time

  • Nashorn JavaScript engine for improved performance

  • Parallel array sorting for faster sorting of large arrays

Add your answer

Q133. No Java is not 100 % Object Oriented, its datatypes are not objects

Ans.

Java is not 100% Object Oriented because its primitive data types are not objects.

  • Java has primitive data types like int, double, boolean which are not objects and do not inherit from a common class.

  • However, Java provides wrapper classes like Integer, Double, Boolean to treat primitives as objects.

  • Java also supports features like inheritance, encapsulation, and polymorphism which are key aspects of Object Oriented Programming.

Add your answer
Frequently asked in

Q134. What is the keyword used in interface if we want concreate method?

Ans.

The keyword used in interface for concrete method is 'default'.

  • The 'default' keyword is used in interfaces to provide a default implementation for a method.

  • It allows interfaces to have concrete methods without requiring implementing classes to override them.

  • Example: 'default void methodName() { // method implementation }'

Add your answer

Q135. What is the different technique to inject bean in application context

Ans.

Different techniques for injecting beans in application context

  • Constructor Injection

  • Setter Injection

  • Field Injection

  • Method Injection

Add your answer
Frequently asked in

Q136. Different between java and .net

Ans.

Java is a programming language while .NET is a framework that supports multiple programming languages.

  • Java is platform-independent, while .NET is primarily used on Windows.

  • Java uses a virtual machine for execution, while .NET uses a Common Language Runtime (CLR).

  • Java has a larger community and more open-source libraries, while .NET has better integration with Microsoft products.

  • Java is mainly used for web applications, while .NET is commonly used for enterprise applications.

  • E...read more

Add your answer

Q137. Name some methods in Executor framework?

Ans.

Some methods in Executor framework include execute(), submit(), shutdown(), awaitTermination(), and invokeAll().

  • execute() - Used to execute the given command at some time in the future.

  • submit() - Submits a Runnable or Callable task for execution and returns a Future representing the task.

  • shutdown() - Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

  • awaitTermination() - Blocks until all tasks have completed execu...read more

Add your answer

Q138. difference between streams and parallel streams

Ans.

Streams process elements sequentially, while parallel streams process elements concurrently.

  • Streams process elements one by one in a sequential manner.

  • Parallel streams process elements concurrently, potentially utilizing multiple threads for faster processing.

  • Streams are suitable for smaller datasets or when order matters.

  • Parallel streams are more efficient for larger datasets or when order is not important.

  • Example: Stream processing a list of numbers vs. parallel stream proc...read more

Add your answer
Frequently asked in

Q139. What is Java and explain the execution process

Ans.

Java is a high-level programming language used for developing applications and software.

  • Java is an object-oriented language

  • It is platform-independent

  • Java code is compiled into bytecode

  • The bytecode is executed by the Java Virtual Machine (JVM)

  • JVM converts bytecode into machine code

  • Java programs are executed in a sandbox environment for security

  • Java has automatic memory management

Add your answer

Q140. What is the use of Intent & Intent Filters?

Ans.

Intent is used to communicate between components of an app or between different apps. Intent Filters are used to specify the type of intent a component can handle.

  • Intent is used to start an activity, service or broadcast receiver.

  • Intent can also be used to pass data between components.

  • Intent Filters are used to specify the type of intent a component can handle.

  • Intent Filters are declared in the AndroidManifest.xml file.

  • Intent Filters can be used to launch an activity from ano...read more

Add your answer

Q141. Are u good at java or sql?

Ans.

I am proficient in both Java and SQL.

  • I have experience in developing Java applications using various frameworks like Spring, Hibernate, and Struts.

  • I am skilled in writing complex SQL queries and optimizing database performance.

  • I have worked on projects that involve integrating Java and SQL technologies.

  • I am constantly learning and keeping up with the latest updates in both Java and SQL.

Add your answer

Q142. What to choose nodejs or java.

Ans.

It depends on the specific project requirements and team expertise.

  • Consider the project requirements - Node.js is great for real-time applications, while Java is better for large-scale enterprise applications.

  • Evaluate team expertise - If your team is more familiar with JavaScript, Node.js may be the better choice.

  • Performance - Java is generally faster and more efficient than Node.js.

  • Scalability - Java is known for its scalability, making it a good choice for growing applicati...read more

Add your answer

Q143. What is java and pattern question?

Ans.

Java is a popular programming language used for developing software applications. Design patterns are reusable solutions to common problems in software design.

  • Java is an object-oriented programming language known for its platform independence and versatility.

  • Design patterns are best practices for solving common software design problems.

  • Examples of design patterns include Singleton, Factory, Observer, and Strategy patterns.

Add your answer

Q144. What is java and method

Ans.

Java is a popular programming language used for developing applications, while a method is a block of code that performs a specific task.

  • Java is an object-oriented programming language known for its portability and versatility.

  • Methods in Java are used to define behavior for objects and can be called to perform specific tasks.

  • Example: public void printMessage() { System.out.println("Hello, World!"); }

Add your answer

Q145. what is java & datatypes

Ans.

Java is a popular programming language used for developing applications. Data types in Java define the type of data that a variable can hold.

  • Java is an object-oriented programming language.

  • Data types in Java include int, double, boolean, and String.

  • Each data type has a specific range of values it can hold.

  • Variables in Java must be declared with a specific data type before use.

Add your answer
Frequently asked in

Q146. Difference between intermediate and terminal operations in stream

Ans.

Intermediate operations return a stream and do not produce a result, while terminal operations produce a result.

  • Intermediate operations are lazy and do not execute until a terminal operation is called

  • Examples of intermediate operations include filter(), map(), and sorted()

  • Examples of terminal operations include forEach(), reduce(), and collect()

  • Terminal operations are eager and execute immediately

View 1 answer
Frequently asked in

Q147. How is kotlin better than java?

Ans.

Kotlin is better than Java due to its concise syntax, null safety, extension functions, and interoperability with Java.

  • Kotlin has a more concise syntax compared to Java, reducing boilerplate code.

  • Kotlin has built-in null safety features, reducing the risk of null pointer exceptions.

  • Kotlin supports extension functions, allowing developers to add new functionality to existing classes.

  • Kotlin is fully interoperable with Java, making it easy to use both languages in the same proje...read more

Add your answer

Q148. Tell me about what is completable future

Ans.

CompletableFuture is a class introduced in Java 8 to represent a future result of an asynchronous computation.

  • CompletableFuture can be used to perform tasks asynchronously and then combine their results.

  • It supports chaining of multiple asynchronous operations.

  • It provides methods like thenApply, thenCompose, thenCombine, etc. for combining results.

  • Example: CompletableFuture future = CompletableFuture.supplyAsync(() -> 10);

View 1 answer
Frequently asked in

Q149. How to write name program in eclipse

Ans.

To write a name program in Eclipse, create a new Java project and class, then write the code to print the name.

  • Create a new Java project in Eclipse

  • Create a new class in the project

  • Write the code to print the name using System.out.println()

  • Run the program to see the output

Add your answer

Q150. What is @ peek annotation, @qualifier annotation

Ans.

The @Peek annotation is used in Java to mark a method as a peek operation in a stream. The @Qualifier annotation is used in Spring to specify which bean should be autowired when multiple beans of the same type are present.

  • The @Peek annotation is used in Java streams to perform a side-effect operation on each element without changing the elements themselves.

  • The @Qualifier annotation in Spring is used to disambiguate beans of the same type by specifying the bean name to be inje...read more

Add your answer

Q151. give the brief of spring annotations

Ans.

Spring annotations are used to provide metadata to Spring framework classes and methods.

  • Annotations like @Component, @Controller, @Service, and @Repository are used for component scanning and auto-wiring.

  • @Autowired is used for dependency injection.

  • @RequestMapping is used to map web requests to specific handler methods.

  • @Transactional is used for managing transactions.

  • Annotations like @Value, @Qualifier, and @Scope are used for configuring beans.

Add your answer
Frequently asked in

Q152. tell us bout the college project in java

Ans.

Developed a college project in Java to create a student management system.

  • Used Java programming language to develop the project

  • Implemented features such as student registration, course enrollment, and grade tracking

  • Utilized object-oriented programming concepts like classes and inheritance

  • Integrated a graphical user interface for user interaction

Add your answer
Frequently asked in

Q153. Types of wait, handle & handles, findElement & findElements

Ans.

Wait types include implicit, explicit, and fluent. Handles refer to browser windows or tabs. findElement(s) locate web elements.

  • Implicit wait waits for a certain amount of time before throwing an exception if the element is not found

  • Explicit wait waits for a certain condition to be met before proceeding

  • Fluent wait waits for a certain condition to be met and polls at regular intervals

  • Handles are used to switch between browser windows or tabs

  • findElement locates the first web el...read more

Add your answer
Frequently asked in

Q154. Frameworks in Java?

Ans.

Frameworks in Java

  • Java Spring Framework

  • Java Hibernate Framework

  • Java Struts Framework

  • Java Play Framework

  • Java JSF (JavaServer Faces) Framework

Add your answer

Q155. tell me about the basics of java and react

Ans.

Java is a popular programming language known for its platform independence, while React is a JavaScript library for building user interfaces.

  • Java is an object-oriented programming language used for developing various types of applications.

  • React is a JavaScript library developed by Facebook for building interactive user interfaces.

  • Java programs are compiled into bytecode that can run on any Java Virtual Machine (JVM).

  • React allows developers to create reusable UI components tha...read more

Add your answer

Q156. Can we keep the reference variable of a parent class in the object of a child class?

Ans.

Yes, we can keep the reference variable of a parent class in the object of a child class.

  • This is possible because a child class is a type of parent class and can inherit its properties and methods.

  • This allows for polymorphism, where a parent class reference variable can refer to an object of a child class.

  • For example, if we have a parent class Animal and a child class Dog, we can create an object of Dog and assign it to an Animal reference variable.

Add your answer

Q157. What is Meta space in Java 8 ?

Ans.

Meta space is a memory space in Java 8 used to store class metadata.

  • Meta space replaces the permanent generation (PermGen) space in Java 8.

  • It stores class metadata such as class name, access modifiers, and constant pool.

  • Meta space is dynamically sized and can expand or shrink based on the application's needs.

  • It can be configured using the -XX:MetaspaceSize and -XX:MaxMetaspaceSize JVM options.

Add your answer

Q158. What is Java concurrency?

Ans.

Java concurrency refers to the ability of multiple threads to execute simultaneously in a Java program.

  • Java concurrency allows for efficient utilization of resources by running multiple tasks concurrently.

  • It involves concepts like threads, synchronization, locks, and atomic variables.

  • Examples include using the 'synchronized' keyword to protect critical sections of code from concurrent access.

Add your answer

Q159. Why do we have @functionalInterface if we can make any interface as functional interface if it already has one abstract method?

Ans.

Functional interfaces provide clarity and enforce single abstract method constraint.

  • Functional interfaces provide clarity to developers by explicitly indicating that the interface is intended to be used as a functional interface.

  • Using @FunctionalInterface annotation helps enforce the single abstract method constraint, preventing accidental addition of more abstract methods.

  • It also allows the compiler to perform additional checks to ensure that the interface meets the requirem...read more

Add your answer

Q160. Explaing colletion framework

Ans.

Collection framework is a set of classes and interfaces that provide a way to store and manipulate groups of objects.

  • It provides interfaces like List, Set, Map, Queue, etc.

  • It allows easy manipulation of data structures like arrays, linked lists, trees, etc.

  • It provides algorithms like sorting, searching, etc.

  • It is a part of Java API and is widely used in Java programming.

  • Example: ArrayList is a class that implements the List interface and provides dynamic array functionality.

Add your answer

Q161. Difference between getwindowhandle and getwindowhandles

Ans.

getwindowhandle returns the handle of the current window, while getwindowhandles returns the handles of all open windows.

  • getwindowhandle returns a single window handle, while getwindowhandles returns multiple window handles

  • getwindowhandle is used to switch focus to a specific window, while getwindowhandles is used to handle multiple windows simultaneously

  • Example: driver.getwindowhandle() vs driver.getwindowhandles()

Add your answer
Frequently asked in

Q162. What is the purpose of using default methods in java8?

Ans.

Default methods in Java 8 allow interfaces to have method implementations, enabling backward compatibility and reducing code duplication.

  • Default methods were introduced in Java 8 to provide a way to add new methods to interfaces without breaking existing implementations.

  • They allow interfaces to have method implementations, which was not possible before Java 8.

  • Default methods can be overridden in implementing classes to provide specific implementations.

  • They help in reducing co...read more

Add your answer

Q163. What is your Prefer Coding language What is the java What is the piiler of the java

Ans.

Java is a popular object-oriented programming language used for developing various applications.

  • Java is platform-independent and can run on any operating system

  • It is used for developing web, mobile, and desktop applications

  • Java is known for its security features and is widely used in enterprise applications

  • The Java compiler is the piiler of the Java programming language

Add your answer

Q164. What are functional Interfaces?

Ans.

Functional interfaces are interfaces with only one abstract method, used for functional programming in Java.

  • Functional interfaces can have multiple default or static methods, but only one abstract method.

  • They are used in lambda expressions and method references for functional programming.

  • Examples include java.lang.Runnable, java.util.Comparator, and java.util.function.Function.

Add your answer
Frequently asked in

Q165. What is parallel stream

Ans.

Parallel stream is a feature in Java that allows processing elements of a stream concurrently.

  • Parallel stream can be created from a regular stream using parallel() method.

  • It utilizes multiple threads to process elements in parallel, improving performance for large datasets.

  • However, parallel stream may not always be faster than sequential stream due to overhead of managing multiple threads.

  • Example: List list = Arrays.asList("apple", "banana", "cherry"); list.parallelStream().f...read more

Add your answer
Frequently asked in

Q166. Difference between @requestbody and @responsebody

Ans.

Difference between @requestbody and @responsebody annotations in Spring MVC

  • The @RequestBody annotation is used to bind the HTTP request body to a method parameter in Spring MVC controller

  • The @ResponseBody annotation is used to bind the return value of a method to the HTTP response body in Spring MVC

  • Example: @RequestBody User user - binds the request body to a User object parameter

  • Example: @ResponseBody String hello() - binds the return value of hello() method to the response ...read more

Add your answer

Q167. The latest technology of java or angular.

Ans.

Both Java and Angular have recently released new versions with significant updates and improvements.

  • Java 16 was released in March 2021 with new features like Records, Pattern Matching, and Vector API.

  • Angular 12 was released in May 2021 with improvements in performance, accessibility, and developer experience.

  • Java and Angular are both widely used technologies in the software development industry.

  • It's important for technical recruiters to stay up-to-date with the latest technol...read more

Add your answer

Q168. various Springboot Annotations.

Ans.

Springboot annotations are used to simplify the development process and provide additional functionality.

  • Annotations like @RestController and @RequestMapping are used to create RESTful web services.

  • @Autowired is used for dependency injection.

  • @Transactional is used to manage transactions.

  • @Component is used to mark a class as a Spring component.

  • @Value is used to inject values from properties files or environment variables.

  • @Scheduled is used to schedule tasks to run at specific ...read more

Add your answer

Q169. Frame works in Java

Ans.

Frameworks in Java provide pre-written code to help developers build applications more efficiently.

  • Frameworks like Spring, Hibernate, and Struts provide structure and functionality to Java applications.

  • Frameworks help developers follow best practices and reduce the amount of code they need to write.

  • Frameworks often include features like dependency injection, ORM mapping, and MVC architecture.

  • Using frameworks can speed up development time and make applications more maintainabl...read more

Add your answer
Frequently asked in

Q170. Requestparam vs pathvariable and syntax of both

Ans.

Requestparam vs pathvariable and syntax

  • RequestParam is used to extract query parameters from the URL, while PathVariable is used to extract values from the URI template

  • RequestParam syntax: @RequestParam("paramName") String paramValue

  • PathVariable syntax: @PathVariable("varName") String varValue

  • Example: @RequestParam("id") String id

  • Example: @PathVariable("name") String name

Add your answer
Frequently asked in

Q171. Java program on data structures

Ans.

Java program on data structures

  • Use Java to implement common data structures like arrays, linked lists, stacks, queues, trees, and graphs

  • Practice implementing algorithms like sorting, searching, and traversal on these data structures

  • Understand the time and space complexity of different operations on data structures

Add your answer
Frequently asked in

Q172. Java 8 in depth

Ans.

Java 8 introduced several new features including lambda expressions, streams, and functional interfaces.

  • Lambda expressions allow for more concise code by enabling functional programming.

  • Streams provide a way to process collections of objects in a functional style.

  • Functional interfaces are interfaces with a single abstract method, which can be implemented using lambda expressions.

  • Java 8 also introduced the Optional class to handle null values more effectively.

Add your answer

Q173. Design principles in Java.

Ans.

Design principles in Java focus on creating modular, reusable, and maintainable code.

  • Single Responsibility Principle - Each class should have only one responsibility.

  • Open/Closed Principle - Classes should be open for extension but closed for modification.

  • Liskov Substitution Principle - Subtypes should be substitutable for their base types.

  • Interface Segregation Principle - Clients should not be forced to depend on interfaces they do not use.

  • Dependency Inversion Principle - Hig...read more

Add your answer

Q174. Spring is immutable or mutable

Ans.

Spring is immutable

  • Spring framework is immutable

  • Once a Spring bean is created, its state cannot be changed

  • Any modifications to a Spring bean result in a new instance being created

Add your answer

Q175. what is try with resources

Ans.

Try with resources is a feature introduced in Java 7 to automatically close resources after use.

  • It simplifies the code by eliminating the need for a finally block to close the resource

  • The resource must implement the AutoCloseable interface

  • Multiple resources can be declared in a single try-with-resources statement

  • Example: try(FileInputStream fis = new FileInputStream("file.txt")) { //code }

Add your answer

Q176. Diff between C and Java?

Ans.

C is a procedural language while Java is an object-oriented language.

  • C is compiled while Java is interpreted

  • C has pointers while Java does not

  • Java has automatic garbage collection while C does not

  • Java has platform independence while C does not

  • Java has built-in exception handling while C does not

Add your answer

Q177. can youdo coding in c++ or java?

Ans.

Yes, I can do coding in both C++ and Java.

  • I have experience in writing code in C++ and Java.

  • I am familiar with the syntax and features of both languages.

  • I have worked on projects using C++ and Java.

  • I can provide examples of my coding work in both languages if needed.

Add your answer

Q178. Whats the difference between @Service and @Component annotations?

Ans.

The @Service annotation is a specialization of the @Component annotation and is used to indicate that a class is a service.

  • Both @Service and @Component annotations are used to indicate that a class is a Spring-managed component.

  • @Service is a specialization of @Component and is used to indicate that a class is a service layer component.

  • The @Service annotation is used to add a layer of abstraction between the controller and the DAO layer.

  • The @Service annotation is used to provi...read more

Add your answer
Frequently asked in

Q179. Why not python instead of using Java?

Ans.

Java is preferred for its performance, scalability, and strong typing compared to Python.

  • Java is statically typed, which helps catch errors at compile time, while Python is dynamically typed.

  • Java is faster in terms of execution speed compared to Python.

  • Java is preferred for large-scale enterprise applications due to its scalability and performance.

  • Java has a strong ecosystem and support for multi-threading, making it suitable for high-performance applications.

Add your answer

Q180. Tell about Java 8 features

Ans.

Java 8 introduced several new features including lambda expressions, streams, and default methods.

  • Lambda expressions allow for functional programming and simplify code.

  • Streams provide a way to process collections of data in a functional way.

  • Default methods allow for adding new methods to interfaces without breaking existing implementations.

  • Other features include the Date and Time API, Nashorn JavaScript engine, and improved security.

  • Java 8 also introduced the concept of Optio...read more

Add your answer
Frequently asked in

Q181. name few annotations in springboot

Ans.

Some annotations in Spring Boot are @RestController, @Autowired, @Component, @RequestMapping, @Service.

  • @RestController - used to define RESTful web services.

  • @Autowired - used for automatic dependency injection.

  • @Component - marks a java class as a bean so that the component-scanning mechanism of Spring can pick it up and pull it into the application context.

  • @RequestMapping - used to map web requests to specific handler classes or methods.

  • @Service - used to indicate that a clas...read more

Add your answer

Q182. Difference between Java and Java. script

Ans.

Java is a programming language while JavaScript is a scripting language used for web development.

  • Java is a compiled language while JavaScript is an interpreted language.

  • Java is used for developing standalone applications, web applications, and Android apps while JavaScript is used for web development.

  • Java is statically typed while JavaScript is dynamically typed.

  • Java code is executed on the server-side while JavaScript code is executed on the client-side.

  • Java is more complex ...read more

Add your answer

Q183. Explain the Java new features in 1.8 version

Ans.

Java 1.8 introduced lambda expressions, default methods, and functional interfaces.

  • Lambda expressions allow functional programming in Java.

  • Default methods allow adding new methods to interfaces without breaking existing implementations.

  • Functional interfaces are interfaces with a single abstract method, used for lambda expressions.

  • Stream API for processing collections and arrays.

  • Date and Time API for easier handling of date and time.

  • Nashorn JavaScript engine for running JavaSc...read more

Add your answer

Q184. What is java opps

Ans.

Java OOPs (Object-Oriented Programming) is a programming paradigm based on the concept of objects, which can contain data in the form of fields and code in the form of procedures.

  • Java OOPs focuses on creating objects that interact with each other to solve a problem.

  • Key principles of Java OOPs include Inheritance, Encapsulation, Polymorphism, and Abstraction.

  • Example: Inheritance allows a class to inherit properties and behavior from another class, promoting code reusability.

Add your answer
Frequently asked in

Q185. How to call default method of interface if class implemented multiple interfaces.

Ans.

To call a default method of an interface when a class implements multiple interfaces, use the interface name followed by the method name.

  • Use InterfaceName.super.methodName() to call the default method of a specific interface.

  • If a class implements multiple interfaces with default methods of the same name, you must specify the interface name to call the desired method.

  • Example: Interface1.super.defaultMethod() to call the defaultMethod() of Interface1.

Add your answer

Q186. What are the basic role of JAVA in the development of software?

Ans.

JAVA is a versatile programming language used for developing various software applications.

  • JAVA is platform-independent and can run on any operating system

  • It is object-oriented and supports multithreading

  • JAVA is widely used for developing web applications, mobile applications, and enterprise software

  • It provides a vast library of pre-built classes and APIs for developers to use

  • JAVA is also used for developing games, scientific applications, and financial applications

Add your answer
Frequently asked in

Q187. what is java and .net

Ans.

Java and .NET are both popular programming languages used for developing software applications.

  • Java is a high-level programming language developed by Sun Microsystems, now owned by Oracle. It is platform-independent and object-oriented.

  • .NET is a framework developed by Microsoft for building Windows applications. It supports multiple programming languages like C#, VB.NET, and F#.

  • Java applications run on a Java Virtual Machine (JVM), while .NET applications run on the Common La...read more

Add your answer

Q188. multithreading in spring boot

Ans.

Multithreading in Spring Boot allows for concurrent execution of tasks, improving performance and responsiveness.

  • Spring Boot provides support for multithreading through the use of @Async annotation.

  • By annotating a method with @Async, it will be executed in a separate thread.

  • ThreadPoolTaskExecutor can be configured to control the number of threads used for executing async methods.

  • Example: @Async public void asyncMethod() { // method logic }

Add your answer

Q189. Difference between findFirst and findAny

Ans.

findFirst returns the first element in a stream, while findAny returns any element in a stream.

  • findFirst is deterministic and will always return the first element in a stream, while findAny is non-deterministic and can return any element.

  • findAny is useful for parallel processing as it can return any available element without the need to search for the first one.

  • findFirst is typically used when the order of elements matters, while findAny is used when any element can satisfy t...read more

Add your answer

Q190. What is service, fragment,

Ans.

A service is a component that performs operations in the background without a user interface. A fragment is a modular section of an activity that has its own lifecycle and UI.

  • Service is used for long-running operations such as network calls or playing music in the background.

  • Fragments are reusable UI components that can be added or removed from an activity dynamically.

  • Services and fragments are both important components in Android development.

Add your answer
Frequently asked in

Q191. Your score is good sql than java?

Ans.

I have a good understanding of both SQL and Java.

  • I have experience working with both SQL and Java in various projects.

  • I have a strong understanding of SQL syntax and can write complex queries.

  • I am proficient in Java and have worked with various frameworks and libraries.

  • I believe that having a good understanding of both SQL and Java is important for a Java Developer.

Add your answer

Q192. Why we use java rather then Node.js?

Ans.

Java is preferred for its strong typing, scalability, platform independence, and extensive libraries.

  • Java is statically typed, which helps catch errors at compile time.

  • Java is known for its scalability, making it suitable for large enterprise applications.

  • Java is platform independent, allowing it to run on any device with a Java Virtual Machine (JVM).

  • Java has a vast array of libraries and frameworks available for various functionalities.

  • Node.js, on the other hand, is single-t...read more

Add your answer

Q193. What is java design latterns

Ans.

Java design patterns are reusable solutions to common problems encountered in software design.

  • Java design patterns help in creating flexible, reusable, and maintainable code.

  • Examples of Java design patterns include Singleton, Factory, Observer, and Strategy.

  • Design patterns can be categorized into three groups: creational, structural, and behavioral.

Add your answer

Q194. Explain java datatypes in java

Ans.

Java datatypes are used to define the type of data that a variable can hold.

  • Java has two categories of datatypes: primitive and non-primitive

  • Primitive datatypes include int, double, char, boolean, etc.

  • Non-primitive datatypes include classes, interfaces, arrays, etc.

  • Each datatype has a specific size and range of values it can hold

Add your answer
Frequently asked in

Q195. Characters finding using Stream Api

Ans.

Using Stream API to find characters in a string

  • Use the chars() method to convert the string to an IntStream of characters

  • Use filter() method to filter out specific characters

  • Use collect() method to collect the characters into an array of strings

Add your answer
Frequently asked in

Q196. How Kotlin is better than Java.

Ans.

Kotlin is better than Java due to its concise syntax, null safety, interoperability, and improved performance.

  • Kotlin has concise syntax which reduces boilerplate code and makes code more readable.

  • Kotlin provides null safety features to prevent NullPointerExceptions at runtime.

  • Kotlin is fully interoperable with Java, allowing developers to use both languages in the same project.

  • Kotlin offers improved performance compared to Java in terms of compilation speed and runtime perfor...read more

Add your answer

Q197. Difference between @bean and @ component

Ans.

The @Bean annotation is used to define a method that returns an object to be registered as a bean in the Spring application context. The @Component annotation is used to indicate that a class is a Spring component.

  • The @Bean annotation is used on methods within a @Configuration class to define Spring beans.

  • The @Component annotation is used on classes to indicate that they are Spring components.

  • The @Bean annotation allows for more flexibility in defining bean creation logic com...read more

Add your answer
Frequently asked in

Q198. Tell me spring boot Annotation?

Ans.

Spring Boot annotations are used to simplify the development process by providing shortcuts for common tasks.

  • Annotations like @SpringBootApplication, @RestController, @Autowired, @GetMapping, @PostMapping are commonly used in Spring Boot applications.

  • These annotations help in configuring the application, defining REST endpoints, injecting dependencies, and mapping HTTP requests to controller methods.

  • For example, @SpringBootApplication is used to mark the main class of a Sprin...read more

Add your answer
Frequently asked in

Q199. Java project you worked previously

Ans.

Developed a Java project for a banking application

  • Used Java to create backend logic for customer transactions

  • Implemented security features to protect sensitive data

  • Integrated with external APIs for currency exchange rates

Add your answer

Q200. Functional interface in Java 8 and it's purpose.

Ans.

Functional interface is an interface with only one abstract method. It enables lambda expressions and method references.

  • Functional interface is used to enable lambda expressions and method references in Java 8.

  • It has only one abstract method and can have any number of default or static methods.

  • Examples of functional interfaces are Runnable, Consumer, Predicate, Function, etc.

Add your answer
Frequently asked in
1
2
3
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.8
 • 8.1k Interviews
3.6
 • 7.5k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.7k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
3.8
 • 2.9k Interviews
4.0
 • 2.3k Interviews
View all
Java Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter