Java Developer
1500+ Java Developer Interview Questions and Answers
Popular Companies
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
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?
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.
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.
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 moreBasic 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 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.
Share interview questions and help millions of jobseekers 🌟
Q57. 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.
Q58. 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
Java Developer Jobs
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
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.
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?
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?
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?
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?
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 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
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?
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.
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
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
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?
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 ?
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.
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();
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?
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
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?
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
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?
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?
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
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
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
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.
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
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 .
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
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 ?
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 ?
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?
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.
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.
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
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;
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
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?
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?
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 ?
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
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.
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