Java Developer
2000+ Java Developer Interview Questions and Answers

Asked in Accenture

Q. What are the principles of object-oriented programming, such as OOP concepts in Java?
Object-oriented programming (OOP) principles in Java include encapsulation, inheritance, polymorphism, and abstraction.
Encapsulation: Bundling data and methods together into a single unit (class) to hide implementation details.
Inheritance: Creating new classes (subclasses) from existing classes (superclasses) to inherit properties and behaviors.
Polymorphism: The ability of an object to take on many forms, allowing objects of different classes to be treated as objects of a com...read more

Asked in Capita

Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.
Abstract class can have constructor, fields, and methods, while interface cannot have any implementation.
A class can implement multiple interfaces but can only extend one abstract class.
Abstract class is used to define common characteristics of subclasses, while interface is used to define a contract for classes to implement.
Example: Abstract class 'Animal' with abst...read more

Asked in Wunderman Thompson Commerce

Q. Swap Two Numbers Without Using a Third Variable
Your task is to swap two given numbers without utilizing an additional variable and print the swapped values.
Input:
The first line contains an integer 't', indic...read more
Swapping two numbers without using a third variable in Java.
Use bitwise XOR operation to swap the numbers without using a third variable.
a = a XOR b; b = a XOR b; a = a XOR b; will swap the values of a and b.
Ensure to handle edge cases like when a and b are the same number.

Asked in Capita

An interface in OOP is a blueprint of a class that defines a set of methods that a class must implement.
Interfaces in Java are used to achieve abstraction and multiple inheritance.
Interfaces contain only method signatures, not method bodies.
Classes can implement multiple interfaces but can only extend one class.
Example: interface Shape { void draw(); }
Example: class Circle implements Shape { public void draw() { // draw circle } }

Asked in Infosys

The starter dependency of the Spring Boot module is spring-boot-starter-parent.
The starter dependency provides a set of default configurations and dependencies to kickstart a Spring Boot project.
It includes commonly used dependencies like spring-boot-starter-web, spring-boot-starter-data-jpa, etc.
By including the spring-boot-starter-parent in your project, you inherit all the default configurations and dependencies managed by Spring Boot.

Asked in Wissen Technology

Q. Using Java 8, how would you find the sum of squares of all the odd numbers in an ArrayList?
Using Java 8, find the sum of squares of all the odd numbers in the arraylist.
Use the stream() method to convert the ArrayList to a stream
Use the filter() method to filter out the even numbers
Use the mapToInt() method to square each odd number
Use the sum() method to calculate the sum of the squared odd numbers
Java Developer Jobs




Asked in Wipro

Q. What are some Java keywords that can be used to create a thread-safe program?
Keywords for thread safe program in Java
Synchronization using synchronized keyword
Using volatile keyword for shared variables
Using atomic classes for thread safe operations
Using thread safe collections like ConcurrentHashMap
Using locks and semaphores for synchronization
Avoiding shared mutable state
Using immutable objects
Using thread local variables
Asked in VBRI Innovation

Q. Q1. What are the technologies you have worked on ? Q2. What are the corporate training you have attended ? Q3. How do you handle non-productive team members ? Q4. Tell us some of your extraordinary skills which...
read moreAnswers to interview questions for a Java Developer position
Q1. Mention the technologies you have worked on, such as Java, Spring, Hibernate, etc.
Q2. List any corporate training you have attended, like Java certification courses or workshops.
Q3. Explain how you handle non-productive team members, emphasizing communication and motivation strategies.
Q4. Highlight your extraordinary skills that set you apart from other technical associates, such as problem-solving abilities or l...read more
Share interview questions and help millions of jobseekers 🌟

Asked in Infosys

Q. Difference Between Comparator and Comparable. What is fully qualified domain name? What is the working principle for an ArrayList? How do you handle an exception? What is custom exception? What is the differenc...
read moreComparator is used to compare objects for sorting, while Comparable is implemented by objects to define their natural ordering.
Comparator is an external class, while Comparable is implemented by the object itself.
Comparator can compare objects of different classes, while Comparable can only compare objects of the same class.
Comparator uses the compare() method, while Comparable uses the compareTo() method.

Asked in TCS

Q. Explain the execution flow of static blocks, instance blocks, and methods in Java.
Static blocks run once at class loading; instance blocks run for each object; methods execute as called, following the order of execution.
Static blocks are executed when the class is loaded into memory.
Instance blocks are executed when an object of the class is created.
Static block example: static { System.out.println('Static block'); }
Instance block example: { System.out.println('Instance block'); }
Method execution follows the order of method calls in the code.

Asked in Hewlett Packard Enterprise

Q. Middle of a Linked List
You are given the head node of a singly linked list. Your task is to return a pointer pointing to the middle of the linked list.
If there is an odd number of elements, return the middle ...read more
Return the middle element of a singly linked list, or the one farther from the head if there are even elements.
Traverse the linked list with two pointers, one moving twice as fast as the other
When the fast pointer reaches the end, the slow pointer will be at the middle
If there are even elements, return the one that is farther from the head node

Asked in Intellect Design Arena

Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.
Abstract class can have constructors, fields, and methods, while interface cannot have any of these.
A class can extend only one abstract class, but can implement multiple interfaces.
Abstract classes are used to provide a common base for subclasses, while interfaces are used to define a contract for classes to implement.
Example: Abstract class - Animal with abstract m...read more

Asked in Wissen Technology

Q. Write a SQL query for a student table with columns Name, Subjects, and Marks. The table contains data like (abc, Eng, 19), (abc, Phy, 17), (abc, Chem, 20), (xyz, Eng, 16), (xyz, Phy, 18), (xyz, Chem, 12), etc....
read moreSQL query to sum student marks and display results in descending order.
Use the SUM() function to calculate total marks for each student.
Group results by student name using GROUP BY clause.
Order the results in descending order using ORDER BY clause.
Example SQL query: SELECT Name, SUM(Marks) AS TotalMarks FROM student GROUP BY Name ORDER BY TotalMarks DESC;

Asked in SutiSoft

Q. 2.differance between throw and throws, and difference between final,finally,finalize and difference between arraylist and linked list
throw is used to explicitly throw an exception, while throws is used to declare exceptions that a method may throw.
throw is used within a method to throw an exception explicitly
throws is used in the method signature to declare the exceptions that the method may throw
final is a keyword used to make a variable, method, or class unchangeable
finally is a block that is used to execute code regardless of whether an exception is thrown or not
finalize is a method that is called by th...read more

Asked in Morgan Stanley

Use two threads to print even and odd numbers in increasing order.
Create two threads, one for printing even numbers and one for printing odd numbers.
Use a shared variable to keep track of the current number to be printed.
Synchronize access to the shared variable to ensure correct ordering of numbers.
Use a loop in each thread to print the next number and update the shared variable.

Asked in Infosys

User threads are non-daemon threads that keep the program running until they complete, while Daemon threads are background threads that do not prevent the program from exiting.
User threads are non-daemon threads that keep the program running until they complete
Daemon threads are background threads that do not prevent the program from exiting
User threads are created using the Thread class, while Daemon threads are created by calling setDaemon(true) on a Thread object
Examples: ...read more

Asked in Happiest Minds Technologies

Q. 5. What are scope of beans? 6. Functional interfaces and examples 7. Can we make a class as private? 8. SQL query to find employees of particular department table. 9. Cascading 10. MapBy in hibernate 11. What i...
read moreJava Developer interview questions on beans, functional interfaces, SQL queries, hibernate, and more.
Scope of beans refers to the visibility of a bean within an application context.
Functional interfaces have only one abstract method and can be used as lambda expressions.
Classes cannot be private, but their constructors can be.
SQL query to find employees of a particular department table: SELECT * FROM employees WHERE department = 'department_name'
Cascading in Hibernate refers ...read more
Asked in Caspex Corp

Enable debugging logs in a Spring Boot application
Add 'logging.level.root=DEBUG' in application.properties file
Use '@Slf4j' annotation in the Java class to enable logging
Set logging level for specific packages or classes using 'logging.level.packageName=DEBUG'

Asked in Ernst & Young

The @SpringBootApplication annotation is used to mark a class as a Spring Boot application and enables auto-configuration and component scanning.
Enables auto-configuration by scanning the classpath for specific types and configuring beans based on their presence.
Enables component scanning to automatically discover and register Spring components such as @Component, @Service, @Repository, and @Controller.
Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan anno...read more

Asked in Xoriant

Q. If we have @Service, @Controller, @Configuration, and @Repository, why do we need @Component? Can we replace them with @Component?
The @Component annotation is a generic stereotype annotation that can be used in place of other annotations.
The @Component annotation is a general-purpose annotation that can be used in place of @Service, @Controller, @Configuration, and @Repository annotations.
However, using more specific annotations can help in better understanding the role of the annotated class.
For example, using @Service annotation on a class that provides a service makes it easier to understand the purp...read more

Asked in Capita

setMaxResults() limits the number of results returned by a query, while setFetchSize() determines the number of rows fetched at a time from the database.
setMaxResults() is used to limit the number of results returned by a query.
setFetchSize() determines the number of rows fetched at a time from the database.
setMaxResults() is typically used for pagination purposes, while setFetchSize() can improve performance by reducing the number of round trips to the database.
Example: setM...read more

Asked in Pace Wisdom

Q. what is interface, inheritance doesn't supported by java, where to use interface, what are the advantage of using program to reverse each word in a string (eg. input -> pace wisdom output ->ecap modsiw)
Answering questions related to Java interfaces and string manipulation
Interface is a collection of abstract methods that can be implemented by a class
Inheritance is supported by Java, but only single inheritance is allowed
Interfaces are used to achieve abstraction and provide a contract for implementing classes
Advantages of program to reverse each word in a string include improved readability and searchability
To reverse each word in a string, split the string into words, reve...read more

Asked in Morgan Stanley

HashMap in Java is a data structure that stores key-value pairs and uses hashing to efficiently retrieve values based on keys.
HashMap internally uses an array of linked lists to store key-value pairs.
When a key-value pair is added, the key is hashed to find the index in the array where it will be stored.
If multiple keys hash to the same index, a linked list is used to handle collisions.
Retrieving a value involves hashing the key to find the index and then traversing the linke...read more

Asked in Publicis Sapient

For loop is used when the number of iterations is known, while While loop is used when the condition is true.
For loop is used when the number of iterations is known beforehand.
While loop is used when the condition is true.
For loop has initialization, condition, and increment/decrement in one line.
While loop only has a condition to check before each iteration.
Example: for(int i=0; i<5; i++) { //code }
Example: int i = 0; while(i < 5) { //code i++; }

Asked in Capgemini

Q. What is the difference between an object, an object reference, and an object reference variable?
Object is an instance of a class while object reference is a variable that holds the memory address of the object.
Object is a real-world entity while object reference is a pointer to the memory location of the object.
Object reference variable is a variable that holds the reference of an object.
Object reference can be null while object cannot be null.
Multiple object references can refer to the same object.
Object reference can be reassigned to another object while object cannot...read more

Asked in Infosys

Runnable interface is used for running a task without returning a result, while Callable interface is used for running a task that returns a result and can throw an exception.
Runnable interface has a run() method that does not return a result.
Callable interface has a call() method that returns a result and can throw an exception.
Runnable tasks can be submitted to an ExecutorService for execution.
Callable tasks can be submitted to an ExecutorService as well, but they return a ...read more

Asked in Volkswagen Group Technology Solution

Q. How do microservices communicate with each other?
Microservices communicate with each other through APIs and messaging protocols.
Microservices use APIs to communicate with each other.
Messaging protocols like HTTP, AMQP, and MQTT are used for asynchronous communication.
Service discovery mechanisms like Eureka and Consul are used to locate services.
API gateways like Zuul and Kong are used to manage API traffic.
Event-driven architecture is used for real-time communication between services.

Asked in Wissen Technology

Q. What are the advantages and disadvantages of immutable classes?
Immutable classes have advantages like thread safety, security, and simplicity, but they also have disadvantages like memory consumption and limited flexibility.
Advantages of immutable classes:
- Thread safety: Immutable objects can be safely shared among multiple threads without the need for synchronization.
- Security: Immutable objects cannot be modified, which can prevent unauthorized changes to sensitive data.
- Simplicity: Immutable classes are easier to understand and rea...read more

Asked in Capita

MVC components include Model, View, and Controller. Model represents data, View displays data, and Controller handles user input.
Model: Represents data and business logic
View: Displays data to the user
Controller: Handles user input and updates the model and view accordingly

Asked in Cross Country Infotech

Q. Besides inheritance, what other mechanisms can you use to connect two classes?
Interfaces can be used to connect two classes in Java.
Interfaces define a contract that implementing classes must adhere to.
A class can implement multiple interfaces.
Interfaces can be used to achieve loose coupling and abstraction.
Example: Connecting a Car class with a Fuelable interface.
Interview Questions of Similar Designations
Interview Experiences of Popular Companies





Top Interview Questions for Java Developer Related Skills



Reviews
Interviews
Salaries
Users

