Senior Java Developer
300+ Senior Java Developer Interview Questions and Answers
Popular Companies
Q51. If I have OS and JDK only How will you setup a Spring-Boot project in my laptop?
To set up a Spring-Boot project with only OS and JDK, you need to install Maven and then create a new project using Spring Initializr.
Install Apache Maven to manage dependencies and build the project
Use Spring Initializr to generate a new Spring Boot project with required dependencies
Import the project into your IDE and start coding
Q52. What is the use of Static and final when you will use Static methods
Static methods can be accessed without creating an instance of the class, while final keyword makes the method unchangeable.
Static methods belong to the class itself, not to any specific instance
Final keyword ensures that the method cannot be overridden in subclasses
Static methods are commonly used for utility methods that do not require access to instance variables
Example: Math class in Java has static methods like Math.max() and Math.min()
Q53. 1.Calculate age without without using any inbuilt function 2.Department wise highest salary 3.Factorial number
Answering interview questions for Senior Java Developer
To calculate age, subtract birth year from current year
To find department wise highest salary, group by department and find max salary
To find factorial number, use a loop to multiply numbers from 1 to n
Q54. What is one problem that interfaces solve that abstract classes do not?
Interfaces allow multiple inheritance, abstract classes do not.
Interfaces can be implemented by multiple classes, allowing for multiple inheritance.
Abstract classes can only be extended by one class, limiting inheritance.
Interfaces promote loose coupling and flexibility in design.
Abstract classes provide a common base implementation for subclasses.
Q55. Differnce between ArrayList and LinkedList
ArrayList is implemented as a resizable array while LinkedList is implemented as a doubly linked list.
ArrayList provides constant time for accessing elements while LinkedList provides constant time for adding or removing elements.
ArrayList is better for storing and accessing data while LinkedList is better for manipulating data.
ArrayList is faster for iterating through elements while LinkedList is faster for adding or removing elements in the middle of the list.
Q56. What is the different technique to inject bean in application context
Different techniques for injecting beans in application context
Constructor Injection
Setter Injection
Field Injection
Method Injection
Share interview questions and help millions of jobseekers 🌟
Q57. How do you accumulate heap to the jvm and what values do you pass?
To accumulate heap to the JVM, specify the initial and maximum heap size using -Xms and -Xmx flags respectively.
Use -Xms flag to specify the initial heap size, e.g. -Xms512m for 512 MB.
Use -Xmx flag to specify the maximum heap size, e.g. -Xmx1024m for 1 GB.
Example: java -Xms512m -Xmx1024m YourClassName
Q58. Draw low level design of implementation of notify me if item is back in stock in a ecommerce application
Implementation of 'notify me if item is back in stock' feature in an ecommerce application
Create a database table to store user notifications for out-of-stock items
Implement a service to check item availability and send notifications to subscribed users
Provide a user interface for users to subscribe to notifications for specific items
Senior Java Developer Jobs
Q59. what is equals and hashcode and does Object class implement equals method ?
equals and hashcode are methods in Java used for comparing objects and generating hash codes respectively. Object class does implement equals method.
equals method is used to compare two objects for equality. It is overridden in most classes to provide custom comparison logic.
hashcode method is used to generate a unique integer value for an object. It is used in hash-based collections like HashMap.
Object class does implement equals method, but it uses reference equality (==) f...read more
Q60. What is difference between get & load in hibernate
get() method returns null if object is not found in database, while load() method throws ObjectNotFoundException.
get() method is eager loading while load() method is lazy loading.
get() method returns a fully initialized object while load() method returns a proxy object.
get() method is slower than load() method as it hits the database immediately.
load() method is faster than get() method as it returns a proxy object and hits the database only when required.
Q61. Suppose your application experiences due to inefficient database queries and data access pattern. So analyze the database schema and query execution to identify performance borderline
Analyzing database schema and query execution to identify performance issues
Review database schema for normalization and indexing
Analyze query execution plans for inefficiencies
Consider optimizing data access patterns and query structure
Use database profiling tools to identify bottlenecks
Implement caching mechanisms for frequently accessed data
Q62. what is difference between springboot and spring
Spring is a framework for building Java applications, while Spring Boot is a tool that simplifies the setup and configuration of Spring applications.
Spring is a comprehensive framework that provides support for various functionalities like dependency injection, aspect-oriented programming, and more.
Spring Boot is an opinionated tool that simplifies the setup and configuration of Spring applications by providing defaults and auto-configuration.
Spring Boot includes embedded ser...read more
Q63. Using single API endpoint can you perform all 3 operations, 1- Get the data, 2- Supply the data, 3- delete the data?
Yes, by implementing a RESTful API with different HTTP methods for each operation.
Implement a RESTful API with different endpoints for each operation: GET for retrieving data, POST for supplying data, and DELETE for deleting data.
For example, GET /data to retrieve data, POST /data to supply data, and DELETE /data/{id} to delete data by ID.
Use proper HTTP methods and status codes to handle each operation effectively.
Q64. Java 8 features and stream api example of distinct element in a list
Example of using Java 8 features and stream api to get distinct elements in a list.
Use the distinct() method of the Stream interface to get distinct elements in a list.
The distinct() method returns a stream consisting of the distinct elements of the original stream.
Example: List
list = Arrays.asList("apple", "banana", "apple", "orange"); list.stream().distinct().forEach(System.out::println); Output: apple banana orange
Q65. What are the common issues faced while deploying a service to AWS?
Common issues faced while deploying a service to AWS
Configuration errors leading to service downtime
Security misconfigurations exposing sensitive data
Performance issues due to improper resource allocation
Network connectivity problems affecting service availability
Lack of monitoring and logging causing difficulties in troubleshooting
Incompatibility issues with other AWS services or third-party integrations
Q66. what about concurrent HashMap? spring framework IOC And DI
ConcurrentHashMap is a thread-safe implementation of the Map interface in Java.
ConcurrentHashMap allows multiple threads to read and write to the map concurrently without the need for external synchronization.
It is part of the java.util.concurrent package and provides better performance in multi-threaded environments compared to synchronized HashMap.
Spring framework supports the use of ConcurrentHashMap for managing beans in a concurrent environment.
Inversion of Control (IoC)...read more
Q67. How to enable debugging log in the spring boot application
Enable debugging log in 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.org.springframework=DEBUG' for Spring framework debugging
Q68. What is the difference between Monolithic SOE and Microservices architecture
Monolithic SOE is a single large application while Microservices architecture breaks down the application into smaller, independent services.
Monolithic SOE is a single, self-contained application where all components are tightly coupled.
Microservices architecture breaks down the application into smaller, independent services that communicate through APIs.
Monolithic SOE is easier to develop and test but can be harder to scale and maintain.
Microservices architecture allows for ...read more
Q69. Custom HashMap Implementation including some Efficient code to write to Search for a Key Value Pair of a Composite Object like Object within an Object within a Main Object.
Implement a custom HashMap to efficiently search for a key value pair of a composite object.
Create a custom HashMap class with methods for adding key value pairs and searching for a specific key.
Implement a hash function to calculate the index of the key in the HashMap array.
For composite objects, override the hashCode and equals methods to ensure proper comparison and retrieval.
Q70. What are the Spring boot annotations you use commonly?
Commonly used Spring Boot annotations include @RestController, @Autowired, @RequestMapping, @Service, @Component, @Repository.
@RestController - Used to define RESTful web services.
@Autowired - Used for automatic dependency injection.
@RequestMapping - Used to map web requests to specific handler methods.
@Service - Used to indicate that a class is a service component.
@Component - Used to indicate that a class is a Spring component.
@Repository - Used to indicate that a class is ...read more
Q71. write program in java to print even no by one thread and odd no by another thread
Program to print even and odd numbers using two threads in Java
Create two threads, one for even numbers and one for odd numbers
Use a loop to generate numbers and check if they are even or odd
Print the numbers using the respective threads
Use synchronization to ensure alternate printing of even and odd numbers
Q72. Write code for below: Removed number character before hash based on count of hash Case 1 I/P= abc#d O/P= abcd Case 2 I/P=abc##d O/p=ad
Write code to remove number character before hash based on count of hash
Count the number of hashes in the input string
Loop through the string and remove the character before the hash based on the count of hashes
Return the modified string
Q73. What are other principles apart from SOLID for best coding practices.
Other principles for best coding practices include DRY, KISS, YAGNI, and design patterns.
DRY (Don't Repeat Yourself) - Avoid duplicating code by creating reusable functions or classes.
KISS (Keep It Simple, Stupid) - Write simple and easy-to-understand code rather than overcomplicating it.
YAGNI (You Aren't Gonna Need It) - Only implement functionality that is needed at the present moment, avoiding unnecessary features.
Design Patterns - Follow established design patterns like S...read more
Q74. HOW TO CREATE OUR OWN IMMUTABLE CLASS? WHY IMMUTABLE CLASS
Immutable classes in Java are classes whose objects cannot be modified once they are created.
Make the class final to prevent inheritance
Make all fields private and final
Do not provide setter methods for fields
Ensure that any mutable objects within the class are also immutable
Q75. IN WHICH SITUATION WE USE @PRIMARY AND @ QUALIFIER ?
Use @Primary to specify a primary bean when multiple beans of the same type are present. Use @Qualifier to specify a specific bean when multiple beans of the same type are present.
Use @Primary to indicate the primary bean to be used when multiple beans of the same type are present in the Spring application context.
Use @Qualifier along with @Autowired to specify a specific bean to be injected when multiple beans of the same type are present.
Example: @Primary annotation can be ...read more
Q76. What is the difference between @restController and @controller Annotation
The @RestController annotation is used to define RESTful web services while @Controller annotation is used to define MVC controller.
RestController is a specialized version of Controller used for RESTful web services
RestController eliminates the need for @ResponseBody annotation
Controller is used for traditional MVC controller functionality
RestController returns data directly without needing to go through a view resolver
Controller typically returns a view name which is resolve...read more
Q77. Different exceptions in Spring Boot
Spring Boot has various exceptions for different scenarios.
DataAccessException - for database access errors
HttpMessageNotReadableException - for errors in HTTP message conversion
MethodArgumentNotValidException - for validation errors in request parameters
NoSuchBeanDefinitionException - for errors in bean configuration
UnauthorizedException - for authentication and authorization errors
Q78. what is oops, abstraction, ioc container, application context
OOPs is a programming paradigm based on the concept of objects. Abstraction is the process of hiding implementation details from the user.
OOPs stands for Object-Oriented Programming.
Abstraction is achieved through encapsulation and inheritance.
IOC container is a framework for implementing Inversion of Control.
Application context is a container for holding beans in Spring Framework.
Q79. Could you explain how the autowired annotation functions internally?
Autowired annotation in Spring framework injects dependencies automatically
Autowired annotation is used for automatic dependency injection in Spring framework
It eliminates the need for explicit bean wiring in XML configuration files
Autowired annotation can be used on fields, constructors, or methods
It searches for a bean of the same type and injects it into the annotated field
Q80. What can you explain about the qualifier annotation?
Qualifier annotation is used in Spring framework to distinguish between beans of the same type.
Qualifier annotation is used in Spring framework to resolve ambiguity when multiple beans of the same type are present.
It is used in conjunction with Autowired annotation to specify which bean should be injected.
For example, @Qualifier("myBean") can be used to specify a particular bean named 'myBean' to be injected.
Q81. with stream API, find employees with salary greater than 50000 and arrange it in descending order. using streams find average of numbers in a list
Use stream API to filter employees by salary and find average of numbers in a list.
Filter employees with salary > 50000 and sort in descending order using stream API
Calculate average of numbers in a list using stream API
Q82. What happens when the Liskov Substitution principle breaks?
Code becomes less maintainable and can lead to unexpected behavior.
Violates the principle of substitutability, leading to unexpected behavior in subclasses.
May result in code that is harder to understand and maintain.
Can lead to bugs and errors that are difficult to trace back to the violation of the principle.
Example: If a subclass overrides a method in a way that changes its behavior significantly, it can break the Liskov Substitution principle.
Q83. What are the advantages of spring boot over spring?
Spring Boot simplifies the development of Spring applications by providing out-of-the-box configurations and reducing boilerplate code.
Spring Boot provides a quick and easy way to set up a Spring application with minimal configuration.
It includes embedded servers like Tomcat, Jetty, or Undertow, eliminating the need for deploying WAR files.
Auto-configuration feature in Spring Boot automatically configures the application based on dependencies in the classpath.
Spring Boot Actu...read more
Q84. How to optimize your database when you have to handle large data ?
Optimizing database for handling large data involves indexing, partitioning, denormalization, and using appropriate data types.
Use indexing on frequently queried columns to improve search performance.
Partition large tables to distribute data across multiple storage devices for faster access.
Denormalize data by reducing the number of joins needed for queries.
Use appropriate data types to minimize storage space and improve query performance.
Q85. WHAT IS DIFFERENCE BETWEEN COMPOSITION AND AGGREGATION ?
Composition is a strong relationship where the child object cannot exist independently of the parent object, while aggregation is a weak relationship where the child object can exist independently.
Composition is a 'has-a' relationship, where the child object is a part of the parent object.
Aggregation is a 'has-a' relationship, where the child object is not a part of the parent object.
In composition, the child object is created and destroyed along with the parent object.
In agg...read more
Q86. Write a program that takes a string of words, including spaces and special symbols, and returns each occurrence of a specified character, excluding spaces and special symbols.
Program to find occurrences of a specified character in a string, excluding spaces and special symbols.
Iterate through each character in the string
Check if the character is the specified character and not a space or special symbol
Store the occurrences in an array of strings
Q87. How to create and consume end point with spring boot microservices
To create and consume endpoints with Spring Boot microservices, use Spring Web and RESTful APIs.
Create a Spring Boot application with Spring Web dependency
Define RESTful APIs using @RestController and @RequestMapping annotations
Use HTTP methods like GET, POST, PUT, DELETE to handle requests
Consume endpoints using RestTemplate or FeignClient
Handle exceptions using @ExceptionHandler annotation
Q88. apring annotations, how to exclude class configuration
Use @ComponentScan annotation with excludeFilters to exclude class configuration in Spring
Use @ComponentScan annotation with excludeFilters parameter to exclude specific classes from component scanning
Specify the classes to be excluded using TypeFilter implementations like AnnotationTypeFilter or AssignableTypeFilter
Example: @ComponentScan(basePackages = {"com.example"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {ExcludedClass.class})...read more
Q89. How to make an entity as composite key in spring boot
Use @Embeddable and @EmbeddedId annotations to create a composite key in Spring Boot
Create a new class for the composite key and annotate it with @Embeddable
Define the composite key fields within the new class
In the entity class, use @EmbeddedId annotation to reference the composite key class
Q90. Can we create own immutable class
Yes, we can create our own immutable class in Java.
Make the class final
Make all fields private and final
Do not provide any setter methods
Provide only getter methods
If any mutable object is used, return a copy of it instead of the original object
Q91. How ClassLoader work & what is JIT
ClassLoader loads classes at runtime. JIT compiles bytecode to native machine code.
ClassLoader loads classes dynamically at runtime
It searches for classes in classpath and loads them into JVM memory
JIT (Just-In-Time) compiler compiles bytecode to native machine code for faster execution
It optimizes frequently executed code by compiling it at runtime
JIT is enabled by default in most JVMs
Q92. Microservice architecture Difference between rest n graphql Java solid principles Pagination concept n implementation
Questions on microservice architecture, REST vs GraphQL, Java SOLID principles, and pagination.
Microservice architecture involves breaking down a monolithic application into smaller, independent services.
REST is an architectural style for building web services, while GraphQL is a query language for APIs.
Java SOLID principles are a set of design principles for writing maintainable and scalable code.
Pagination is the process of dividing large amounts of data into smaller, more ...read more
Q93. What is difference between JDK & JRE
JDK is a development kit that includes JRE, while JRE is a runtime environment for executing Java programs.
JDK stands for Java Development Kit and includes tools for developing, debugging, and monitoring Java applications.
JRE stands for Java Runtime Environment and includes the minimum set of tools required to run Java applications.
JDK includes JRE, so if you have JDK installed, you also have JRE.
JDK includes a compiler, while JRE does not.
JDK is required for developing Java ...read more
Q94. how do you use JPA in your project write it
I use JPA in my project by defining entity classes, annotating them with JPA annotations, creating repositories, and using JPQL queries.
Define entity classes with @Entity annotation
Annotate fields with @Column, @Id, @GeneratedValue, etc.
Create repositories by extending JpaRepository interface
Use JPQL queries for custom database operations
Q95. How microservices communicate in your project
Microservices communicate through REST APIs and messaging queues in our project.
Microservices communicate with each other using REST APIs for synchronous communication.
Messaging queues like Kafka or RabbitMQ are used for asynchronous communication between microservices.
Service discovery tools like Eureka or Consul are used to locate and communicate with other microservices.
Microservices may also use gRPC for communication in some cases.
Q96. How the communication is happening between the microservices ?
Communication between microservices is typically done through APIs, messaging queues, or service meshes.
Microservices communicate with each other through APIs, which allow them to send and receive data over the network.
Messaging queues like RabbitMQ or Kafka can be used for asynchronous communication between microservices.
Service meshes like Istio or Linkerd can handle communication between microservices by managing traffic, security, and monitoring.
RESTful APIs are commonly ...read more
Q97. What is the to begin a software ?
The first step to begin a software is to identify the problem and gather requirements.
Identify the problem that needs to be solved
Gather requirements from stakeholders
Analyze and prioritize requirements
Design a solution architecture
Choose appropriate technologies and tools
Develop and test the software
Deploy and maintain the software
Railway Reservation System for booking train tickets
Create a database to store train schedules, seat availability, and passenger information
Develop a user interface for customers to search for trains, select seats, and make payments
Implement a booking system to reserve seats and generate tickets
Include features like seat selection, cancellation, and ticket printing
Ensure security measures for payment processing and data protection
Q99. Principal of garbage collection
Garbage collection is an automatic memory management process that frees up memory occupied by objects that are no longer in use.
Garbage collection is performed by the JVM.
It helps prevent memory leaks and improves application performance.
There are different types of garbage collectors such as serial, parallel, CMS, and G1.
Garbage collection can cause pauses in the application, which can be minimized by tuning the JVM parameters.
It is important to write efficient and optimized...read more
Q100. What is N tier and 2 tier architecture?
N tier and 2 tier architecture are software architecture patterns used in designing applications.
2 tier architecture involves a client and a server, where the client directly communicates with the server.
N tier architecture involves multiple layers of servers, where each layer communicates with the layer above and below it.
2 tier architecture is simpler and faster, but less scalable and secure than N tier architecture.
N tier architecture is more complex and slower, but more s...read more
Interview Questions of Similar Designations
Top Interview Questions for Senior 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