Senior Java Developer

300+ Senior Java Developer Interview Questions and Answers

Updated 10 Dec 2024

Popular Companies

search-icon

Q51. What is the different technique to inject bean in application context

Ans.

Different techniques for injecting beans in application context

  • Constructor Injection

  • Setter Injection

  • Field Injection

  • Method Injection

Q52. How do you accumulate heap to the jvm and what values do you pass?

Ans.

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

Q53. what is equals and hashcode and does Object class implement equals method ?

Ans.

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

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

Ans.

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

Are these interview questions helpful?

Q55. What is difference between get & load in hibernate

Ans.

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.

Q56. Using single API endpoint can you perform all 3 operations, 1- Get the data, 2- Supply the data, 3- delete the data?

Ans.

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.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q57. what is difference between springboot and spring

Ans.

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

Q58. Java 8 features and stream api example of distinct element in a list

Ans.

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

Senior Java Developer Jobs

Java Senior Developer (Banking or Payments) 5-12 years
FIS Global Business Solutions India Pvt. Ltd.
3.9
Kolkata
Senior Java Developer 4-6 years
Yamaha Motor Solutions India Pvt. Ltd.
4.1
₹ 18 L/yr - ₹ 25 L/yr
Faridabad
Senior Java Developer 6-8 years
CGI Information Systems And Management Consultants
4.0
Hyderabad / Secunderabad

Q59. What are the common issues faced while deploying a service to AWS?

Ans.

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

Q60. what about concurrent HashMap? spring framework IOC And DI

Ans.

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

Q61. How to enable debugging log in the spring boot application

Ans.

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

Q62. What is the difference between Monolithic SOE and Microservices architecture

Ans.

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

Q63. What are the Spring boot annotations you use commonly?

Ans.

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

Q64. What are other principles apart from SOLID for best coding practices.

Ans.

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

Q65. write program in java to print even no by one thread and odd no by another thread

Ans.

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

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

Ans.

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

Q67. HOW TO CREATE OUR OWN IMMUTABLE CLASS? WHY IMMUTABLE CLASS

Ans.

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

Q68. IN WHICH SITUATION WE USE @PRIMARY AND @ QUALIFIER ?

Ans.

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

Q69. what is oops, abstraction, ioc container, application context

Ans.

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.

Q70. Different exceptions in Spring Boot

Ans.

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

Q71. What happens when the Liskov Substitution principle breaks?

Ans.

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.

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

Ans.

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

Q73. What are the advantages of spring boot over spring?

Ans.

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

Q74. How to optimize your database when you have to handle large data ?

Ans.

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.

Q75. WHAT IS DIFFERENCE BETWEEN COMPOSITION AND AGGREGATION ?

Ans.

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

Q76. How to create and consume end point with spring boot microservices

Ans.

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

Q77. apring annotations, how to exclude class configuration

Ans.

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

Q78. How to make an entity as composite key in spring boot

Ans.

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

Q79. Microservice architecture Difference between rest n graphql Java solid principles Pagination concept n implementation

Ans.

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

Q80. Can we create own immutable class

Ans.

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

Q81. How ClassLoader work & what is JIT

Ans.

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

Q82. What is difference between JDK & JRE

Ans.

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

Q83. how do you use JPA in your project write it

Ans.

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

Q84. How microservices communicate in your project

Ans.

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.

Q85. How the communication is happening between the microservices ?

Ans.

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

Q86. What is the to begin a software ?

Ans.

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

Q87. Principal of garbage collection

Ans.

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

Q88. what are the time complexities of various data structures.

Ans.

Time complexities of data structures vary based on operations like insertion, deletion, search, etc.

  • Arrays - O(1) for access, O(n) for insertion/deletion

  • Linked Lists - O(n) for access, O(1) for insertion/deletion at head/tail

  • Stacks - O(1) for push/pop operations

  • Queues - O(1) for enqueue/dequeue operations

  • Hash Tables - O(1) for average case search/insert/delete

  • Binary Trees - O(log n) for search/insert/delete in balanced trees

  • Heaps - O(log n) for insert/delete, O(1) for find-mi...read more

Q89. What is N tier and 2 tier architecture?

Ans.

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

Q90. What is linked list and stack in data structure

Ans.

A linked list is a linear data structure where elements are stored in nodes with pointers to the next node. A stack is a data structure that follows Last In First Out (LIFO) principle.

  • Linked list: elements are connected through pointers, can be singly or doubly linked

  • Stack: operations include push (add element) and pop (remove top element)

  • Example: Linked list - 1 -> 2 -> 3 -> null, Stack - [3, 2, 1]

Q91. What is method referencing and where do we use it

Ans.

Method referencing is a way to refer to methods without invoking them directly.

  • Used to simplify lambda expressions in Java

  • Commonly used in functional interfaces

  • Types of method referencing include static, instance, and constructor referencing

Q92. Difference between run and start methods in multi threading What is fail fast and fail safe Difference between List Iterator and iterator

Ans.

Explaining differences between multi-threading concepts and List Iterator

  • The run() method is used to execute the thread's task, while the start() method is used to start the thread.

  • Fail fast means to immediately stop the program when an error occurs, while fail safe means to continue running the program and handle the error.

  • List Iterator is used to traverse a list in both forward and backward directions, while Iterator is used to traverse a collection in only forward directio...read more

Q93. What is Hash collusion

Ans.

Hash collusion is when two different inputs produce the same hash value.

  • It is a security vulnerability in hash functions.

  • Attackers can exploit this vulnerability to create a collision attack.

  • For example, an attacker can create a malicious file with the same hash value as a legitimate file to bypass security checks.

Q94. What is role of pom.xml in a maven project?

Ans.

pom.xml is a configuration file in a Maven project that defines project dependencies, build settings, and plugins.

  • Defines project dependencies and their versions

  • Specifies build settings such as source directory, target directory, and compiler version

  • Configures plugins for various tasks like compiling code, running tests, packaging the project

  • Helps in managing project lifecycle phases like clean, compile, test, package, install, deploy

Q95. What is the latest REST API you have developed?

Ans.

I recently developed a REST API for a banking application to handle customer transactions.

  • Implemented CRUD operations for customer accounts and transactions

  • Used Spring Boot framework for building the API

  • Secured API endpoints using OAuth 2.0 authentication

  • Utilized Swagger for API documentation

Q96. Difference between post & get mapping in spring boot and can we update the data using post mapping?

Ans.

Post mapping is used to create or update data, while get mapping is used to retrieve data. Yes, data can be updated using post mapping.

  • Post mapping is used to create or update data in the server, while get mapping is used to retrieve data from the server.

  • Post mapping is typically used for operations that modify data, such as creating a new resource or updating an existing one.

  • Get mapping is used for operations that do not modify data, such as retrieving information or fetchin...read more

Q97. For insertion and deletion which list u use?why?

Ans.

I use LinkedList for insertion and deletion as it provides constant time complexity.

  • LinkedList provides constant time complexity for insertion and deletion operations.

  • ArrayList provides linear time complexity for these operations.

  • LinkedList is preferred when frequent insertion and deletion operations are required.

  • ArrayList is preferred when frequent access to elements is required.

Q98. Tree data structure and how to optimize them?

Ans.

Tree data structure is a hierarchical data structure where each node has a value and children nodes.

  • Optimizing tree traversal by using efficient algorithms like depth-first search or breadth-first search.

  • Balancing the tree to ensure operations like insertion and deletion are efficient.

  • Using memoization to store results of expensive computations in dynamic programming.

  • Implementing efficient data structures like AVL trees or Red-Black trees for better performance.

Q99. what is difference between method reference and functional interface?

Ans.

Method reference is a shorthand syntax for lambda expressions, while functional interface is an interface with a single abstract method.

  • Method reference is used to refer to methods or constructors without invoking them, providing a more concise way to write lambda expressions.

  • Functional interface is an interface that has only one abstract method, which can be implemented using lambda expressions or method references.

  • Example: Consumer consumer = System.out::println; is a metho...read more

Q100. How is transaction managed in microservices architecture?

Ans.

Transactions in microservices are managed using distributed transactions or compensating transactions.

  • Distributed transactions involve multiple microservices coordinating with a transaction manager to ensure data consistency across services.

  • Compensating transactions involve each microservice having a compensating action to rollback changes if a transaction fails.

  • Saga pattern is commonly used in microservices to manage long-running transactions by breaking them into smaller, i...read more

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
 • 10k Interviews
3.9
 • 7.8k Interviews
3.7
 • 7.3k Interviews
3.7
 • 5.2k Interviews
3.8
 • 4.6k Interviews
3.6
 • 3.7k Interviews
3.6
 • 3.6k Interviews
3.6
 • 2.3k Interviews
3.7
 • 507 Interviews
3.4
 • 492 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

Senior 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
Get AmbitionBox app

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