Java Developer

1500+ Java Developer Interview Questions and Answers

Updated 23 Feb 2025
search-icon

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

Q52. Where I implemented Executor service in my project?

Ans.

Implemented Executor service in the backend for parallel processing.

  • Implemented ExecutorService in the backend to handle multiple requests concurrently.

  • Used ExecutorService to execute multiple tasks in parallel.

  • Implemented ExecutorService to improve the performance of the application.

  • Used ExecutorService to manage thread pools and execute tasks asynchronously.

Q53. What is tha difference between object and object reference and 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

Q54. Can you explain the difference between setMaxResults() and setFetchSize() in a Query?
Are these interview questions helpful?
Q55. What are collections in Java?
Q56. What are some standard Java pre-defined functional interfaces?

Share interview questions and help millions of jobseekers 🌟

man-with-laptop
Q57. What is Inversion of Control?
Q58. Why do we need to override the equals and hashCode methods in Java?

Java Developer Jobs

Java Developer 6-8 years
SAP Labs India Pvt. Ltd.
4.2
Bangalore / Bengaluru
Lead- Java Developer, SQL 5-9 years
S&P Global Inc.
4.2
Hyderabad / Secunderabad
Lead - Java Developer, AWS 6-10 years
S&P Global Inc.
4.2
Hyderabad / Secunderabad

Q59. How to change a div background colour?

Ans.

Use CSS to change the background color of a div element.

  • Use the 'background-color' property in CSS to specify the color.

  • You can use color names, hex codes, RGB values, or HSL values to set the background color.

  • Example: div { background-color: blue; }

Q60. 1. How 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.

Q61. 13. Other than inheritance what you will use to connect two classes?

Ans.

We can use composition, aggregation, or association to connect two classes.

  • Composition is a strong form of aggregation where the lifetime of the contained object is controlled by the container object.

  • Aggregation is a weaker form of composition where the contained object has an independent lifecycle.

  • Association is a relationship between two classes where one class uses the functionality of another class.

  • Examples of association are dependency, inheritance, and realization.

  • Examp...read more

Q62. 9. When is memory allocated, when class is created or instance is created or when it is?

Ans.

Memory is allocated when an instance of a class is created.

  • Memory allocation happens when an object is created using the 'new' keyword.

  • Static variables are allocated memory when the class is loaded.

  • Memory is released when the object is no longer referenced or when the program terminates.

Q63. What is Dependency Injection in Spring?

Q64. //design patterns //markers interface // example of functional interface . can you override Default method. Can you directly or do you need object. give some examples of functional interface //one try catch fin...

read more
Ans.

The interview questions cover a wide range of topics including design patterns, exception handling, Hibernate, MongoDB, Java collections, Spring framework, and microservices.

  • Design patterns like markers interface, functional interface, and Singleton pattern are important in Java development.

  • Understanding exception handling with try-catch-finally blocks is crucial for handling errors in Java applications.

  • Knowing the differences between load and get in Hibernate, as well as the...read more

Q65. What is the difference between Local Variable, static variable, and instance variable?

Ans.

Local, static, and instance variables differ in their scope and lifetime.

  • Local variables are declared inside a method and have a limited scope.

  • Static variables belong to the class and are shared among all instances.

  • Instance variables are unique to each object and can be accessed using the object reference.

Q66. Write a program for different types of books( Paperbook,E-book,Audiobook) using Inheritance Concept.

Ans.

Program for different types of books using Inheritance Concept

  • Create a Book class as the parent class

  • Create Paperbook, E-book, and Audiobook classes as child classes

  • Inherit properties and methods from the Book class

  • Add unique properties and methods to each child class

  • Example: Paperbook class can have a property for number of pages

  • Example: E-book class can have a property for file format

Q67. What are the advantages of multithreading in Java?
Q68. What is dependency injection?
Frequently asked in,

Q69. What is the difference between Hashmap and Hashtable?

Ans.

Hashtable is synchronized and does not allow null keys or values, while HashMap is not synchronized and allows null keys and values.

  • Hashtable is thread-safe, while HashMap is not.

  • Hashtable does not allow null keys or values, while HashMap allows null keys and values.

  • Hashtable is slower than HashMap due to synchronization.

  • Hashtable is a legacy class, while HashMap is part of the Java Collections Framework.

  • Hashtable is recommended to be used in multi-threaded environments, whil...read more

Q70. How do we call stored procedures in java ?

Ans.

Stored procedures can be called in Java using JDBC API.

  • Create a CallableStatement object using Connection.prepareCall() method.

  • Set the input parameters using setXXX() methods.

  • Execute the stored procedure using execute() or executeUpdate() method.

  • Retrieve the output parameters using getXXX() methods.

  • Close the CallableStatement object using close() method.

Q71. What are the different properties of MVC routes?
Q72. What are the features of a lambda expression?

Q73. 4. How to make a class immutable?

Ans.

To make a class immutable, we need to ensure that its state cannot be modified after creation.

  • Make all fields private and final

  • Do not provide any setters

  • Ensure that mutable objects are not returned from methods

  • Make the class final or use a private constructor

  • Consider using defensive copying

Q74. What are the different states of entity instances?
Q75. What is the difference between MongoDB and MySQL?

Q76. What is daemon thread? How it help in multithreading?

Ans.

Daemon thread is a low priority thread that runs in the background and provides services to other threads.

  • Daemon threads are used for tasks that don't require user interaction or input.

  • They are automatically terminated when all non-daemon threads have completed.

  • Examples include garbage collection, logging, and monitoring.

  • They can be created using setDaemon() method.

  • Daemon threads should not be used for tasks that require data consistency or integrity.

  • They can help in improvin...read more

Q77. What is session in java?

Ans.

Session in Java is a way to store information about a user across multiple requests.

  • Session is used to maintain stateful information about a user.

  • It is created when a user first accesses a web application and remains active until the user logs out or the session times out.

  • Session data is stored on the server and can be accessed by multiple requests from the same user.

  • It is commonly used for user authentication, shopping carts, and personalization.

  • The HttpSession interface in ...read more

Q78. 1. Write a program to sort the characters of a string in descending order? 2. Write a lambda expression of addition? 3. How to write custom exceptions? 4. What is indexing?

Ans.

This program sorts the characters of a string in descending order.

  • Convert the string to a character array

  • Sort the character array in descending order

  • Convert the sorted character array back to a string

Q79. What are oops concepts, What are java8 features, functional interface, spring boot annotations, microservice.

Ans.

Answering questions related to OOPs concepts, Java8 features, functional interface, Spring Boot annotations, and microservices.

  • OOPs concepts include encapsulation, inheritance, abstraction, and polymorphism.

  • Java8 features include lambda expressions, streams, default methods, and functional interfaces.

  • Functional interface is an interface with only one abstract method and can be used with lambda expressions.

  • Spring Boot annotations include @RestController, @RequestMapping, @Auto...read more

Q80. What are the concurrency strategies available in Hibernate?

Q81. What are the internal partitions of the java virtual machine .

Ans.

Internal partitions of Java Virtual Machine

  • Java Virtual Machine has three internal partitions: Heap, Stack, and Method Area

  • Heap is used for dynamic memory allocation of objects and arrays

  • Stack is used for storing method frames and local variables

  • Method Area is used for storing class-level data such as method code and static variables

Q82. What issues are generally addressed by Spring Cloud?

Q83. what are the implicit objects in Jsp servlets ?

Ans.

Implicit objects in JSP servlets are pre-defined objects that can be accessed without any declaration.

  • Implicit objects are created by the container and are available to the JSP page.

  • Some of the implicit objects are request, response, session, application, out, pageContext, config, exception, etc.

  • These objects can be used to perform various operations like accessing request parameters, setting attributes, forwarding requests, etc.

Q84. What is Exception and what is Exception Handling in java ?

Ans.

Exception is an event that occurs during the execution of a program and disrupts the normal flow of instructions.

  • Exception is a subclass of Throwable class.

  • Exception Handling is a mechanism to handle runtime errors and prevent program termination.

  • try-catch block is used to handle exceptions.

  • Multiple catch blocks can be used to handle different types of exceptions.

  • finally block is used to execute code after try-catch block.

  • Example: int a = 10/0; will throw ArithmeticException....read more

Q85. What is the garbage collector in Java?
Frequently asked in, ,

Q86. find sum of all odd numbers in a list using stream?

Ans.

Using Java stream, find the sum of all odd numbers in a list.

  • Use the filter() method to filter out the odd numbers from the list.

  • Use the mapToInt() method to convert the filtered numbers to integers.

  • Use the sum() method to calculate the sum of the filtered odd numbers.

Q87. Can you explain what lazy loading is in Hibernate?

Q88. Explain public static void main (String args []) in Java.

Ans.

Entry point for Java programs.

  • public: Access modifier that allows the method to be called from anywhere.

  • static: Method belongs to the class and not to any instance of the class.

  • void: Method does not return any value.

  • main: Method name that is recognized by JVM as the entry point for the program.

  • String args[]: Command line arguments passed to the program as an array of strings.

Q89. What is the difference between an Abstract Class and an Interface in Java 8?
Q90. How does ConcurrentHashMap work in Java?
Q91. What are the advantages of design patterns in Java?

Q92. What is java? What is oops? Difference between hashmap and hashset

Ans.

Java is a high-level programming language known for its portability and object-oriented programming support. OOPs stands for Object-Oriented Programming. HashMap and HashSet are both data structures in Java, but HashMap is used to store key-value pairs while HashSet is used to store unique elements.

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

  • OOPs (Object-Oriented Programming) is a programming paradigm based on the concept of objects...read more

Q93. What is dependency injection and how to achieve that? and what is Inversion of control?

Ans.

Dependency injection is a design pattern that allows objects to receive dependencies rather than creating them.

  • Dependency injection is a way to achieve loose coupling between objects.

  • It allows for easier testing and maintenance of code.

  • There are three types of dependency injection: constructor injection, setter injection, and interface injection.

  • Inversion of control is a principle that states that the control of object creation and lifecycle should be handed over to a contain...read more

Q94. 1. What are the advantages of Microservices?

Ans.

Microservices offer advantages such as scalability, flexibility, and easier maintenance.

  • Scalability: Microservices allow for individual components to be scaled independently, making it easier to handle high traffic.

  • Flexibility: Microservices can be developed and deployed independently, allowing for faster development and deployment cycles.

  • Easier maintenance: Microservices are smaller and more focused, making it easier to identify and fix issues.

  • Example: Netflix uses microserv...read more

Q95. 1.Difference between HashMap and Hashtable ?

Ans.

HashMap is not synchronized and allows null values, while Hashtable is synchronized and does not allow null values.

  • HashMap is faster than Hashtable due to lack of synchronization.

  • Hashtable is thread-safe while HashMap is not.

  • HashMap allows null values for both key and value, while Hashtable does not.

  • HashMap is part of the Java Collections Framework while Hashtable is a legacy class.

  • HashMap uses Iterator while Hashtable uses Enumeration.

  • Example: HashMap map = new HashMap<>(); ...read more

Q96. How is routing carried out in MVC?
Q97. How do you create an immutable class in Java?

Q98. How to create Thread in Java and What are the ways?

Ans.

Threads in Java allow concurrent execution of multiple tasks. They can be created in multiple ways.

  • Using the Thread class

  • Implementing the Runnable interface

  • Using the Executor framework

  • Using the Callable interface with ExecutorService

Q99. In Tr what is exception handling.oops, difference between abstraction and encapsulation about project.

Ans.

The question is about exception handling, OOPs, and the difference between abstraction and encapsulation in a project.

  • Exception handling is a mechanism to handle runtime errors and prevent program termination.

  • Abstraction is the process of hiding implementation details and showing only necessary information to the user.

  • Encapsulation is the process of binding data and methods together in a single unit.

  • In a project, abstraction can be achieved by using interfaces and abstract cl...read more

Q100. What is Hibernate caching?
Previous
1
2
3
4
5
6
7
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.5k Interviews
3.8
 • 8.2k Interviews
3.6
 • 7.6k Interviews
3.7
 • 5.7k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.8k Interviews
3.5
 • 3.9k Interviews
3.5
 • 3.8k Interviews
3.8
 • 3k Interviews
4.0
 • 2.4k Interviews
View all

Calculate your in-hand salary

Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary

Java Developer 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
65 L+

Reviews

4 L+

Interviews

4 Cr+

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