Java Developer

filter-iconFilter interviews by

1500+ Java Developer Interview Questions and Answers

Updated 25 Feb 2025

Popular Companies

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

Q52. What are the advantages of using Packages in Java?
Ans.

Packages in Java help organize code, prevent naming conflicts, and provide access control.

  • Organize code into logical groups for easier maintenance and readability

  • Prevent naming conflicts by using unique package names

  • Provide access control by using access modifiers like public, private, protected, and default

  • Facilitate reusability by allowing classes to be easily imported and used in other packages

Q53. 6. Advantages and Disadvantages of immutable class?

Ans.

Immutable classes have advantages like thread safety, security, and simplicity, but also have disadvantages like memory usage and performance overhead.

  • 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 objects are easier to reason about and debug since...read more

Q54. Do you have any Java certficate? If no then please leave you are rejected.

Ans.

Java certification is not mandatory for a Java Developer role.

  • Certification is not a measure of practical skills and experience.

  • Experience and skills are more important than certification.

  • Certification can be helpful in some cases, but not mandatory.

  • Certification can be expensive and time-consuming.

  • Employers may value certification differently.

  • Examples of Java certifications: Oracle Certified Professional Java SE 11 Developer, Java SE 8 Programmer, etc.

Are these interview questions helpful?

Q55. 1.why we go with oops concept? 2.what is polymorphism? 3.what is JVM? 4.what is the Database connection coding in JAVA? 5.what is JOIN(QUERY)? 6.what is TRIGGER? 7.what is PROCEDURE? 8.what is Hashmap? 9.what i...

read more
Ans.

Basic Java and Query questions for Java Developer position.

  • OOPs concept helps in creating modular, reusable and maintainable code.

  • Polymorphism is the ability of an object to take on many forms.

  • JVM stands for Java Virtual Machine, which executes Java bytecode.

  • Database connection coding in Java involves creating a connection object, setting connection properties, and executing SQL queries.

  • JOIN is used to combine rows from two or more tables based on a related column between the...read more

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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

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

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

Java Developer Jobs

Java Developer (Database) 5-8 years
A.P. Moller Maersk
4.2
₹ 20 L/yr - ₹ 28 L/yr
Bangalore / Bengaluru
Java Developer 9-14 years
Ericsson
4.1
₹ 19 L/yr - ₹ 23 L/yr
Noida
Lead - Full Stack Java Developer 8-13 years
S&P Global Inc.
4.2
Hyderabad / Secunderabad
Q59. What are some standard Java pre-defined functional interfaces?
Ans.

Some standard Java pre-defined functional interfaces include Function, Consumer, Predicate, and Supplier.

  • Function: Represents a function that accepts one argument and produces a result. Example: Function<Integer, String>

  • Consumer: Represents an operation that accepts a single input argument and returns no result. Example: Consumer<String>

  • Predicate: Represents a predicate (boolean-valued function) of one argument. Example: Predicate<Integer>

  • Supplier: Represents a supplier of re...read more

Q60. What are the basic annotations that Spring Boot offers?
Ans.

Spring Boot offers annotations like @SpringBootApplication, @RestController, @Autowired, @Component, @RequestMapping, etc.

  • @SpringBootApplication - Used to mark the main class of a Spring Boot application.

  • @RestController - Used to define a class as a controller in a RESTful web service.

  • @Autowired - Used for automatic dependency injection.

  • @Component - Used to indicate that a class is a Spring component.

  • @RequestMapping - Used to map web requests to specific handler methods.

Q61. Why do we need to override the equals and hashCode methods in Java?
Ans.

Overriding equals and hashCode methods in Java is important for proper object comparison and hashing.

  • Equals method is used to compare two objects for equality, while hashCode method is used to generate a unique integer value for an object.

  • By overriding equals and hashCode methods, we can ensure that objects are compared based on their actual content rather than memory address.

  • This is crucial for collections like HashMap and HashSet, where proper implementation of equals and h...read more

Q62. 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; }

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

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

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

Q66. //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

Q67. What are the new features in Java 8?
Ans.

Java 8 introduced several new features including lambda expressions, functional interfaces, streams, and the new Date and Time API.

  • Lambda expressions: Allow you to treat functionality as a method argument.

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

  • Streams: Provide a new abstraction to work with sequences of elements.

  • Date and Time API: Improved API for handling date and time operations.

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

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

Q70. What are the differences between Synchronized Collection and Concurrent Collection in Java?
Ans.

Synchronized Collection is thread-safe but may have performance issues, while Concurrent Collection is optimized for concurrent access.

  • Synchronized Collection uses synchronized keyword to achieve thread-safety, while Concurrent Collection uses non-blocking algorithms like CAS (Compare and Swap).

  • Synchronized Collection locks the entire collection during modification, leading to potential performance bottlenecks, while Concurrent Collection allows multiple threads to access and...read more

Q71. What is the difference between a View and a Partial View in MVC?
Ans.

A View is a complete page while a Partial View is a reusable component in MVC.

  • A View represents a complete page in MVC which can include layout, content, and other views.

  • A Partial View is a reusable component that can be rendered within a View or another Partial View.

  • Partial Views are useful for creating modular and reusable components in MVC applications.

  • Example: A View may contain the overall layout of a website, while a Partial View may represent a sidebar or a navigation ...read more

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

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

Q74. Can you explain briefly about the Session interface used in Hibernate?
Ans.

Session interface in Hibernate is used to create, read, update, and delete persistent objects.

  • Session interface is used to interact with the database in Hibernate.

  • It represents a single-threaded unit of work.

  • It provides methods for CRUD operations like save, update, delete, and get.

  • Session is created using SessionFactory object.

  • Example: Session session = sessionFactory.openSession();

Q75. What is the difference between Comparable and Comparator in Java?
Ans.

Comparable is an interface used for natural ordering, while Comparator is an interface used for custom ordering in Java.

  • Comparable interface is used to define the natural ordering of objects. It is implemented by the class whose objects are to be compared.

  • Comparator interface is used to define custom ordering of objects. It is implemented by a separate class.

  • Comparable interface has a single method, compareTo(), which compares the current object with another object.

  • Comparator...read more

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

Q77. What is the difference between static and final in Java?
Ans.

Static is used to define class-level variables and methods, while final is used to define constants that cannot be changed.

  • Static variables belong to the class itself, while final variables are constants that cannot be modified.

  • Static methods can be called without creating an instance of the class, while final methods cannot be overridden.

  • Static keyword is used for memory management, while final keyword is used for defining constants.

  • Example: static int count = 0; final doubl...read more

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

Q79. What is the comparison between Azure and AWS cloud service providers?
Ans.

Azure and AWS are two major cloud service providers offering similar services but with some differences in features and pricing.

  • AWS is the oldest and most widely used cloud service provider, while Azure is catching up quickly.

  • Azure is known for its strong integration with Microsoft products and services, while AWS has a wider range of third-party integrations.

  • AWS has a larger global presence with more data centers worldwide compared to Azure.

  • Pricing models differ between the ...read more

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

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

Q82. Can you explain the N+1 SELECT problem in Hibernate?
Ans.

N+1 SELECT problem in Hibernate occurs when a query results in N+1 additional queries being executed.

  • Occurs when a query fetches a collection of entities and then for each entity, an additional query is executed to fetch related entities

  • Can be resolved by using fetch joins or batch fetching to fetch all related entities in a single query

  • Example: Fetching a list of orders and then for each order, fetching the customer information separately

Q83. Can you explain the @RestController annotation in Spring Boot?
Ans.

The @RestController annotation in Spring Boot is used to define a class as a RESTful controller.

  • Used to create RESTful web services in Spring Boot

  • Combines @Controller and @ResponseBody annotations

  • Eliminates the need to annotate every method with @ResponseBody

Q84. Can you explain the working of Microservice Architecture?
Ans.

Microservice Architecture is an architectural style that structures an application as a collection of loosely coupled services.

  • Each service is self-contained and can be developed, deployed, and scaled independently.

  • Services communicate with each other over a network, typically using HTTP/REST or messaging protocols.

  • Microservices allow for better scalability, flexibility, and resilience compared to monolithic architectures.

  • Examples of companies using microservices include Netf...read more

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

Q86. What are the concurrency strategies available in Hibernate?
Ans.

Hibernate provides several concurrency strategies like optimistic locking, pessimistic locking, and versioning.

  • Optimistic locking: Allows multiple transactions to read and write to the database without locking the data. It checks for concurrent modifications before committing the transaction.

  • Pessimistic locking: Locks the data to prevent other transactions from accessing or modifying it until the lock is released.

  • Versioning: Uses a version number to track changes to an entity...read more

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

Q88. What issues are generally addressed by Spring Cloud?
Ans.

Spring Cloud addresses issues related to distributed systems and microservices architecture.

  • Service discovery and registration

  • Load balancing

  • Circuit breakers

  • Distributed configuration management

  • Routing and gateway

  • Monitoring and tracing

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

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

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

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

Q93. How does the MVC (Model-View-Controller) architecture work in Spring?
Ans.

MVC architecture in Spring separates the application into three main components: Model, View, and Controller.

  • Model represents the data and business logic of the application.

  • View is responsible for displaying the data to the user.

  • Controller acts as an intermediary between Model and View, handling user input and updating the Model accordingly.

  • Spring MVC framework provides support for implementing MVC architecture in web applications.

  • Annotations like @Controller, @RequestMapping...read more

Q94. What are the primitive data types in Java?
Ans.

Primitive data types in Java are basic data types that are not objects.

  • Primitive data types include int, double, float, char, boolean, byte, short, and long.

  • Examples: int num = 10; double price = 19.99; char letter = 'A'; boolean flag = true;

Q95. What is the difference between ArrayList and HashMap in Java?
Ans.

ArrayList is a dynamic array that can grow or shrink in size, while HashMap is a key-value pair collection where each element is accessed by a key.

  • ArrayList stores elements in an ordered sequence and allows duplicate values.

  • HashMap stores key-value pairs and does not allow duplicate keys.

  • Example: ArrayList<String> list = new ArrayList<>(); HashMap<String, Integer> map = new HashMap<>();

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

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

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

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

Q100. What is the internal working of a CopyOnWrite ArrayList?
Ans.

CopyOnWriteArrayList creates a new copy of the underlying array whenever an element is added, modified, or removed.

  • CopyOnWriteArrayList is thread-safe and suitable for scenarios where reads are more frequent than writes.

  • Adding, modifying, or removing elements in CopyOnWriteArrayList creates a new copy of the underlying array, ensuring thread safety.

  • Iterators on CopyOnWriteArrayList operate on the original array and do not throw ConcurrentModificationException.

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

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

Recently Viewed
JOBS
Browse jobs
Discover jobs you love
JOBS
Browse jobs
Discover jobs you love
SALARIES
Ernst & Young
DESIGNATION
DESIGNATION
DESIGNATION
SALARIES
KPMG India
LIST OF COMPANIES
Discover companies
Find best workplace
DESIGNATION
INTERVIEWS
Infosys
No Interviews
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