Java Developer

2000+ Java Developer Interview Questions and Answers

Updated 13 Jul 2025
search-icon

Asked in Accenture

1w ago

Q. What are the principles of object-oriented programming, such as OOP concepts in Java?

Ans.

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

1w ago
Q. What is the difference between an abstract class and an interface in OOP?
Ans.

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

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
Ans.

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

1w ago
Q. What is meant by an interface in Object-Oriented Programming?
Ans.

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 } }

Are these interview questions helpful?

Asked in Infosys

2w ago
Q. What is the starter dependency of the Spring Boot module?
Ans.

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.

1w ago

Q. Using Java 8, how would you find the sum of squares of all the odd numbers in an ArrayList?

Ans.

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

Atos Pvt Ltd logo
Java Developer 2-4 years
Atos Pvt Ltd
3.8
Bangalore / Bengaluru
Atos Pvt Ltd logo
Java Developer 6-12 years
Atos Pvt Ltd
3.8
Mumbai
UST logo
Java Developer 4-8 years
UST
3.8
₹ 18 L/yr - ₹ 25 L/yr
Kochi

Asked in Wipro

1w ago

Q. What are some Java keywords that can be used to create a thread-safe program?

Ans.

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

2w ago

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 more
Ans.

Answers 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 🌟

man-with-laptop

Asked in Infosys

1w ago

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 more
Ans.

Comparator 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

1w ago

Q. Explain the execution flow of static blocks, instance blocks, and methods in Java.

Ans.

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.

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

Ans.

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

Q. What is the difference between an Abstract Class and an Interface in Java 8?
Ans.

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

1w ago

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 more
Ans.

SQL 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

4d ago

Q. 2.differance between throw and throws, and difference between final,finally,finalize and difference between arraylist and linked list

Ans.

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

1w ago
Q. How can you print even and odd numbers in increasing order using two threads in Java?
Ans.

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

1w ago
Q. What is the difference between a User thread and a Daemon thread in Java?
Ans.

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

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 more
Ans.

Java 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

2w ago
Q. How do you enable debugging logs in a Spring Boot application?
Ans.

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'

1w ago
Q. What does the @SpringBootApplication annotation do internally?
Ans.

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

2w ago

Q. If we have @Service, @Controller, @Configuration, and @Repository, why do we need @Component? Can we replace them with @Component?

Ans.

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

6d ago
Q. Can you explain the difference between setMaxResults() and setFetchSize() in a Query?
Ans.

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

2w ago

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)

Ans.

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

4d ago
Q. Can you explain the internal working of a hash map in Java?
Ans.

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

2w ago
Q. What is the difference between a For loop and a While loop?
Ans.

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

1w ago

Q. What is the difference between an object, an object reference, and an object reference variable?

Ans.

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

1w ago
Q. What is the difference between the Runnable interface and the Callable interface in Java?
Ans.

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

Q. How do microservices communicate with each other?

Ans.

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.

3d ago

Q. What are the advantages and disadvantages of immutable classes?

Ans.

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

3d ago
Q. Can you explain in brief the role of different MVC components?
Ans.

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

Q. Besides inheritance, what other mechanisms can you use to connect two classes?

Ans.

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.

Previous
1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.7
 • 8.7k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
Cognizant Logo
3.7
 • 5.9k Interviews
View all
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Java Developer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits