Java Developer
1500+ Java Developer Interview Questions and Answers
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 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.
Q52. Where I implemented Executor service in my project?
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
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
Share interview questions and help millions of jobseekers 🌟
Java Developer Jobs
Q59. How to change a div background colour?
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?
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?
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?
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.
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 moreThe 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?
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.
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
Q69. What is the difference between Hashmap and Hashtable?
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 ?
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.
Q73. 4. How to make a class immutable?
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
Q76. What is daemon thread? How it help in multithreading?
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?
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?
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.
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
Q81. What are the internal partitions of the java virtual machine .
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
Q83. what are the implicit objects in Jsp servlets ?
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 ?
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
Q86. find sum of all odd numbers in a list using stream?
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.
Q88. Explain public static void main (String args []) in Java.
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.
Q92. What is java? What is oops? Difference between hashmap and hashset
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?
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?
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 ?
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
Q98. How to create Thread in Java and What are the ways?
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.
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
Interview Questions of Similar Designations
Top Interview Questions for Java Developer Related Skills
Interview experiences of popular companies
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
Reviews
Interviews
Salaries
Users/Month