Senior Java Developer

filter-iconFilter interviews by

300+ Senior Java Developer Interview Questions and Answers

Updated 2 Mar 2025

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

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

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

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

Are these interview questions helpful?

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

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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

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

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

Senior Java Developer Jobs

Senior Java Developer 8-13 years
SAP India Pvt.Ltd
4.2
Bangalore / Bengaluru
Senior Java Developer 3-8 years
CGI Information Systems and Management Consultants
4.0
Hyderabad / Secunderabad
Senior Java Developer 10-14 years
Tata Consultancy Services
3.7
Chennai

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

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

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

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

Q113. What is index in DB? What is spring security? What is cloning ? Deep cloning , swallow cloning What is SOLID principles.

Ans.

Index in DB is a data structure that improves the speed of data retrieval operations on a database table.

  • Index in DB is used to quickly locate and access the rows in a table based on the values in specific columns.

  • It helps in optimizing query performance by reducing the number of rows that need to be scanned.

  • Examples of indexes include primary keys, unique keys, and composite indexes.

  • Creating indexes on frequently queried columns can significantly improve database performance...read more

Q114. Find the average sal of employee in each department using java 8 Stream?

Ans.

Calculate average salary of employees in each department using Java 8 Stream.

  • Use Java 8 Stream to group employees by department

  • Calculate average salary for each department using Stream's 'collect' method

  • Use 'Collectors.averagingDouble' to calculate average salary

Q115. What is saga design pattern

Ans.

Saga design pattern is used to manage long-lived transactions between microservices.

  • It ensures that all services involved in a transaction are either committed or rolled back together.

  • It uses a sequence of local transactions to achieve global consistency.

  • It can be implemented using either choreography or orchestration.

  • Example: A customer places an order, which involves multiple microservices such as inventory, payment, and shipping. Saga pattern ensures that if any of these s...read more

Q116. write code for time conversion- string "10:00 AM" if added 10 in that, op 8 pm

Ans.

Convert time string by adding 10 hours and display in 12-hour format

  • Split the input string into hours and minutes

  • Convert the hours to 24-hour format and add 10 hours

  • Handle the case where the result goes past 12 hours

  • Convert the result back to 12-hour format and display

Q117. In java How hasmap works internally

Ans.

HashMap is a data structure that stores key-value pairs and uses hashing to retrieve values.

  • HashMap uses an array of buckets to store key-value pairs

  • The hash code of the key is used to determine the index of the bucket

  • If multiple keys have the same hash code, they are stored in a linked list within the bucket

  • HashMap allows null keys and values

  • HashMap is not thread-safe and requires synchronization for concurrent access

Q118. Differnce between application server vs web server , OOPS , Collection ,Thread

Ans.

Application server manages business logic while web server handles HTTP requests.

  • Application server provides services like security, transaction management, messaging, etc.

  • Web server handles HTTP requests and serves static content like HTML, CSS, JS, etc.

  • OOPS is a programming paradigm that focuses on objects and their interactions.

  • Collection is a framework that provides interfaces and classes to store and manipulate groups of objects.

  • Thread is a lightweight process that enabl...read more

Q119. Design patterns used in Microservices

Ans.

Design patterns used in Microservices

  • Service Registry Pattern

  • API Gateway Pattern

  • Circuit Breaker Pattern

  • Event Sourcing Pattern

  • Saga Pattern

Q120. Create a rest api all the way from controller to repository using NOTEPAD

Ans.

Creating a REST API from controller to repository using NOTEPAD

  • Create a controller class with mapping annotations for REST endpoints

  • Implement service layer to handle business logic and interact with repository

  • Define repository interface with methods for data access operations

  • Use Spring Boot for easy setup and configuration

  • Test API endpoints using tools like Postman

Q121. What are the main dependencies added while creating application

Ans.

Main dependencies added while creating an application include libraries, frameworks, and external services.

  • Libraries: such as Apache Commons, Guava, or Jackson for additional functionality

  • Frameworks: like Spring, Hibernate, or Angular for structuring the application

  • External services: such as databases like MySQL or MongoDB, or APIs for integration

Q122. Find the kth Largest element of array using Stream API (java 8)

Ans.

Use Stream API to find the kth largest element in an array of strings.

  • Convert array of strings to Stream

  • Sort the Stream in reverse order

  • Skip k-1 elements and get the kth element

Q123. SQL Query to find highest salary of employee in each department

Ans.

Use SQL query to find highest salary of employee in each department

  • Use GROUP BY clause to group by department

  • Use MAX() function to find highest salary in each group

  • Join the employee table with department table to get department information

Q124. Explain the practical difference between GET & POST method calls?

Ans.

GET is used to request data from a specified resource, while POST is used to submit data to a specified resource.

  • GET requests are idempotent, meaning they can be repeated without changing the result, while POST requests are not.

  • GET requests can be cached, bookmarked, and shared, while POST requests cannot.

  • GET requests have a limit on the amount of data that can be sent, while POST requests do not have such limitations.

  • GET requests should only be used for retrieving data, whil...read more

Q125. What is volatile ? And write program

Ans.

Volatile is a keyword in Java used to indicate that a variable's value may be modified by multiple threads.

  • Volatile variables are not cached in thread's local memory

  • Changes made to volatile variables are immediately visible to other threads

  • Volatile keyword is used to ensure visibility and ordering of variables in multithreaded environment

  • Example: volatile int count = 0;

Q126. Difference between String s = "xyz" and String s = new String("xyz")

Ans.

The first statement creates a string literal in the string pool, while the second statement creates a new string object in the heap memory.

  • String s = "xyz" creates a string literal in the string pool.

  • String s = new String("xyz") creates a new string object in the heap memory.

  • Using String s = new String("xyz") can lead to unnecessary memory usage.

Q127. what is broker, message, corelation id in kafka

Ans.

In Kafka, a broker is a server that stores and manages the message data, a message is a unit of data sent through Kafka, and a correlation id is used to link related messages.

  • A broker in Kafka is a server that stores and manages the message data.

  • A message in Kafka is a unit of data sent through Kafka from a producer to a consumer.

  • A correlation id in Kafka is used to link related messages together, allowing for tracking and processing of related messages.

Q128. write a program to get the 3rd element in the integer list.

Ans.

Program to get the 3rd element in an integer list.

  • Create an integer list

  • Access the 3rd element using index 2

  • Return the element

Q129. Explain OOPs concept with your current Project?

Ans.

OOPs is a programming paradigm based on the concept of objects.

  • My current project is built using OOPs concepts.

  • I have used classes and objects to represent real-world entities.

  • Inheritance and polymorphism are used to achieve code reusability and flexibility.

  • Encapsulation is used to hide the implementation details of the classes.

  • Abstraction is used to provide a simplified view of the complex system.

  • For example, I have a class called 'Employee' with properties like name, age, a...read more

Q130. How HashMap work internally?

Ans.

HashMap is a data structure that stores key-value pairs and uses hashing to retrieve values quickly.

  • HashMap uses an array of buckets to store key-value pairs

  • The hash code of the key is used to determine the index of the bucket where the key-value pair is stored

  • If two keys have the same hash code, they are stored in the same bucket as a linked list

  • When retrieving a value, the hash code of the key is used to find the bucket and then the linked list is searched for the key

  • HashMa...read more

Q131. Write a sample code to settle the accounts of 4 persons after they spent their money together for a trip

Ans.

Sample code to settle accounts of 4 persons after a trip

  • Create a Person class with attributes like name, spentAmount, and remainingAmount

  • Calculate the total spent amount by all persons

  • Distribute the total spent amount equally among all persons to settle the accounts

Q132. Difference between caching levels, interfaces from JPA & Hibernate.

Ans.

Caching levels, interfaces from JPA & Hibernate differences

  • Caching levels are first level and second level cache in Hibernate

  • JPA interfaces are EntityManager, Query, CriteriaQuery, CriteriaBuilder

  • Hibernate interfaces are Session, Query, Criteria, CriteriaBuilder

  • JPA is a specification while Hibernate is an implementation of JPA

  • Hibernate provides additional features like HQL, Criteria API, etc.

Q133. java code to filter even numbers from a list and store the square of those in another list

Ans.

Java code to filter even numbers from a list and store the square of those in another list

  • Create two ArrayLists to store the original list and the squared even numbers list

  • Iterate through the original list and check if each number is even

  • If the number is even, square it and add it to the squared even numbers list

Q134. create a spring boot project and implement crud operation for user table.

Ans.

Implement CRUD operations for user table in a Spring Boot project.

  • Create a Spring Boot project using Spring Initializr

  • Define a User entity with necessary fields and annotations

  • Create a UserRepository interface extending JpaRepository

  • Implement methods in a UserService class for CRUD operations

  • Use RESTful endpoints to expose the CRUD operations

Q135. what is difference between class and interface?

Ans.

Classes can have both implemented and abstract methods, while interfaces can only have abstract methods.

  • Classes can be instantiated to create objects, while interfaces cannot be instantiated.

  • A class can only extend one other class, but it can implement multiple interfaces.

  • Classes can have constructors, while interfaces cannot.

  • Classes can have fields (variables), while interfaces cannot have fields with values that are specific to each implementing class.

Q136. Flow of a String Boot Application

Ans.

A Spring Boot application follows a predefined flow of execution.

  • Application starts with main() method

  • Spring Application Context is initialized

  • Beans are created and dependencies are injected

  • Application starts serving requests

  • Requests are handled by Controllers and Services

  • Responses are returned to the client

Q137. Default methods and when do we use it

Ans.

Default methods in Java 8 allow interfaces to have method implementations.

  • Default methods were introduced in Java 8 to allow interfaces to have method implementations.

  • Default methods are used to provide a default implementation for a method in an interface.

  • Default methods are useful when adding new methods to existing interfaces without breaking the classes that already use them.

  • Default methods can be overridden by classes that implement the interface if needed.

  • An example of ...read more

Q138. How do you achieve Pagination in APIs?

Ans.

Pagination in APIs is achieved by using query parameters like page number and page size.

  • Use query parameters like 'page' and 'size' to specify the page number and number of items per page.

  • Implement logic in the backend to fetch and return only the specified page of data.

  • Calculate the total number of pages based on the total number of items and page size.

  • Include links to navigate to the next and previous pages in the API response.

Q139. What are actuators in Spring boot?

Ans.

Actuators in Spring Boot are built-in tools that help monitor and manage the application.

  • Actuators provide endpoints to monitor application health, metrics, info, etc.

  • They can be used to interact with the application at runtime.

  • Examples include /actuator/health, /actuator/metrics, /actuator/info, etc.

Q140. Sessions in hibernate

Ans.

Sessions in Hibernate are used to manage the interaction between the application and the database.

  • A session is a single-threaded object that represents a connection between the application and the database.

  • It is responsible for managing the persistence of objects, executing queries, and providing transactional support.

  • A session can be obtained from a session factory and should be closed when no longer needed.

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

  • Example: ses...read more

Q141. Difference between @component and @configuration ?

Ans.

The @Component annotation is used to mark a class as a bean, while @Configuration is used to define a configuration class.

  • The @Component annotation is used to auto-detect and auto-configure beans using classpath scanning.

  • @Configuration classes are used to define beans and their dependencies explicitly.

  • A @Configuration class can contain @Bean methods that return bean instances.

  • A @Component class can be used as a bean in a Spring application context.

Q142. Given an integer array segregate odd and even numbers without using another array

Ans.

Segregate odd and even numbers in an integer array without using another array

  • Iterate through the array and maintain two pointers, one for odd numbers and one for even numbers

  • Swap elements at the odd and even pointers until all odd numbers are on one side and even numbers on the other

  • Example: Input array [3, 6, 8, 5, 4], Output array [6, 8, 4, 5, 3]

Q143. how to remove autoconfiguration in springboot

Ans.

To remove autoconfiguration in Spring Boot, exclude the specific autoconfiguration class from the application.

  • Exclude the autoconfiguration class using @EnableAutoConfiguration annotation with exclude attribute

  • Create a configuration class and exclude the specific autoconfiguration class using @EnableAutoConfiguration annotation

  • Use application.properties or application.yml to exclude autoconfiguration classes

Q144. find the occurence of first non-repeating char in a string

Ans.

Use a hashmap to store the frequency of each character and then iterate through the string to find the first non-repeating character.

  • Create a hashmap to store the frequency of each character in the string.

  • Iterate through the string and update the frequency in the hashmap.

  • Iterate through the string again and return the first character with frequency 1.

Q145. Return starting and ending indices of a repetitive character in a string.

Ans.

Find starting and ending indices of repetitive character in a string.

  • Iterate through the string and keep track of the current character and its count.

  • When a different character is encountered, check if the count is greater than 1 and store the indices.

  • Repeat the process until the end of the string is reached.

Q146. Functional Programming in Java,Oops Concepts

Ans.

Functional programming in Java focuses on using functions to perform tasks, while OOPs concepts revolve around classes and objects.

  • Functional programming in Java involves using higher-order functions, lambda expressions, and streams to process data.

  • OOPs concepts in Java include inheritance, encapsulation, polymorphism, and abstraction.

  • Functional programming promotes immutability and avoids side effects, while OOPs allows for stateful objects and behavior.

  • Combining functional ...read more

Q147. What is microservices why we use it

Ans.

Microservices are a software development technique where applications are composed of small, independent services that communicate with each other.

  • Microservices allow for easier scalability and maintenance of complex applications.

  • Each service in a microservices architecture can be developed, deployed, and scaled independently.

  • Microservices promote flexibility and agility in software development.

  • Examples of companies using microservices include Netflix, Amazon, and Uber.

Q148. Write a code for get a reverse String having a comma separated value in java

Ans.

Code to reverse a comma separated string in Java

  • Split the input string by comma to get an array of strings

  • Iterate through the array in reverse order and append each element to a new string with a comma

  • Return the reversed comma separated string

Q149. Exchange the value of two int variables without using a third one.

Ans.

Use bitwise XOR operation to swap values of two int variables without using a third one.

  • Use bitwise XOR operation to swap values of two int variables: a = a ^ b; b = a ^ b; a = a ^ b;

  • Example: int a = 5, b = 10; a = a ^ b; b = a ^ b; a = a ^ b; // Now a = 10, b = 5

Q150. ApplicationContext vs BeanFactory

Ans.

ApplicationContext is a sub-interface of BeanFactory in Spring Framework.

  • ApplicationContext provides more advanced features like AOP, i18n, event propagation, etc.

  • BeanFactory is a basic container that provides the fundamental functionality of DI and IOC.

  • ApplicationContext is preferred over BeanFactory in most cases due to its advanced features.

  • Example: ApplicationContext can be used to load properties files, whereas BeanFactory cannot.

  • Example: ApplicationContext can publish a...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
 • 10.5k Interviews
3.6
 • 7.6k Interviews
3.7
 • 5.6k Interviews
3.7
 • 5.6k Interviews
3.7
 • 4.8k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
3.8
 • 2.9k Interviews
3.7
 • 539 Interviews
3.3
 • 520 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
COMPANY BENEFITS
Concentrix Corporation
No Benefits
DESIGNATION
REVIEWS
Vodafone Idea
No Reviews
REVIEWS
Infosys
No Reviews
REVIEWS
Genpact
No Reviews
SALARIES
Genpact
SALARIES
Infosys
COMPANY BENEFITS
Vodafone Idea
No Benefits
COMPANY BENEFITS
Wipro
No Benefits
REVIEWS
Concentrix Corporation
No Reviews
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

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