Senior Java Developer

300+ Senior Java Developer Interview Questions and Answers

Updated 10 Dec 2024

Popular Companies

search-icon
Q1. Delete Kth node From End

You have been given a singly Linked List of 'N' nodes with integer data and an integer 'K'. Your task is to remove the Kth node from the end of the given Linked List.

For example:
The gi...read more
Q2. Intersection of Linked List

You are given two Singly Linked List of integers, which are merging at some node of a third linked list.

Your task is to find the data of the node at which merging starts. If there is...read more

Frequently asked in,

Senior Java Developer Interview Questions and Answers for Freshers

illustration image
Q3. Merge Two Sorted Linked Lists

You are given two sorted linked lists. You have to merge them to produce a combined sorted linked list. You need to return the head of the final linked list.

Note:

The given linked ...read more
Q4. LRU Cache Implementation

Design and implement a data structure for Least Recently Used (LRU) cache to support the following operations:

1. get(key) - Return the value of the key if the key exists in the cache, o...read more
Frequently asked in,
Are these interview questions helpful?

Q5. When to use abstract class and when should we use interfaces in Java?

Ans.

Abstract classes are used for code reuse and interfaces are used for multiple inheritance and loose coupling.

  • Abstract classes can have both abstract and non-abstract methods while interfaces can only have abstract methods.

  • Abstract classes can have constructors while interfaces cannot.

  • Interfaces are used when a class needs to implement multiple behaviors while abstract classes are used for code reuse.

  • Interfaces promote loose coupling while abstract classes promote tight coupli...read more

Q6. Suppose you are responsible for setting up a CICD pipeline to automate the build test and deployment process for your spring boot microservices. So how would you configure jenkins or git, GitLab's CICD pipeline...

read more
Ans.

Setting up CICD pipeline for Spring Boot microservices using Jenkins/GitLab

  • Configure Jenkins/GitLab to listen for changes in the repository

  • Set up build steps to compile the code, run unit tests, and perform integration tests

  • Use Docker for containerization and Kubernetes for container orchestration

  • Deploy artifacts to Artifactory and promote to production environment

  • Automate the entire process with appropriate triggers and notifications

Share interview questions and help millions of jobseekers 🌟

man-with-laptop
Q7. OS Question

Why Java is platform independent and JVM platform dependent?

Q8. Adding port number as 0 for a service in Spring boot

Ans.

Setting port number as 0 in Spring Boot for a service

  • Setting port number as 0 allows the operating system to choose an available port

  • This is useful when running multiple instances of the same service on the same machine

  • To set port number as 0 in Spring Boot, add 'server.port=0' to application.properties or application.yml

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

Q9. Suppose the organization has a legacy system written in different programming language integrated with your java application. How would you approach the integration considering factors such as data exchange for...

read more
Ans.

I would assess the legacy system's data exchange formats and communication protocols, then design a seamless integration plan.

  • Analyze the data exchange formats used by the legacy system and determine compatibility with Java application

  • Identify the communication protocols utilized by the legacy system and ensure they can be integrated with Java

  • Design a middleware layer or API to facilitate communication between the legacy system and Java application

  • Implement data mapping and t...read more

Q10. Suppose your microservice expose API that require authentication and authorization to access specific data. So how would you implement secure authentication and authorization using Auth or JWT token. So what me...

read more
Ans.

Implement secure authentication and authorization using Auth or JWT token to prevent security vulnerabilities.

  • Use HTTPS to encrypt communication between client and server to prevent eavesdropping.

  • Implement strong password policies and use password hashing to securely store user credentials.

  • Use JWT tokens with short expiration times and refresh tokens to prevent token theft.

  • Implement role-based access control to ensure users only have access to authorized resources.

  • Regularly u...read more

Q11. Suppose your task is optimizing a java application that handles a high calling of concurrent requests. So how would you design the concurrency model and what techniques would you employ to ensure thread safety ...

read more
Ans.

Designing a concurrency model for a high calling java application to ensure thread safety and maximize throughput while minimizing deadlock risks.

  • Use a combination of thread pools and executor services to manage concurrent requests efficiently.

  • Implement synchronization mechanisms such as locks, semaphores, or atomic variables to ensure thread safety.

  • Utilize non-blocking algorithms and data structures to reduce contention and avoid deadlocks.

  • Consider using asynchronous program...read more

Q12. Suppose your task is to design an high available and scalable data storage solution for a mission critical application. So How would you choose between AWS and Dynamo DB based on the application requirement

Ans.

Choose AWS for flexibility and customization, choose Dynamo DB for simplicity and scalability

  • Consider AWS if you need more flexibility and customization in your data storage solution

  • Choose Dynamo DB if you prioritize simplicity and scalability for your mission critical application

  • AWS offers a wide range of services and configurations for high availability and scalability, while Dynamo DB is a fully managed NoSQL database service that can automatically scale based on demand

  • If ...read more

Q13. OOPS Question

What is Garbage collector in JAVA?

Frequently asked in,

Q14. 1.difference between list,set and map in java collections 2.exception Handling 3.difference between throw and throws 4.why to create a thread 5.maker interface in java and its use 6.Spring boot which you used i...

read more
Ans.

Interview questions for Senior Java Developer

  • List is an ordered collection, Set is an unordered collection with no duplicates, Map is a key-value pair collection

  • Exception handling is used to handle runtime errors and prevent program crashes

  • Throw is used to throw an exception explicitly, Throws is used to declare an exception that a method may throw

  • Threads are used to execute multiple tasks simultaneously and improve program performance

  • Marker interface is an interface with no ...read more

Q15. OS Question

Explain the Life Cycle of a Thread in Java .

Q16. Suppose you need to implement a reliable messaging system for communication between distributed components of your application. How could you design the messaging architecture using technologies like Kafka and ...

read more
Ans.

Design a reliable messaging system using Kafka and RabbitMQ for communication between distributed components.

  • Use Kafka for high-throughput, low-latency messaging with strong durability guarantees.

  • Implement RabbitMQ for reliable message queuing and delivery.

  • Integrate Kafka for real-time event streaming and RabbitMQ for asynchronous communication.

  • Leverage Kafka Connect to easily connect Kafka with external systems and RabbitMQ plugins for enhanced functionality.

Q17. 1. What are the Java 8 Features you've worked with?

Ans.

Java 8 introduced several new features including lambda expressions, functional interfaces, and streams.

  • Lambda expressions allow for more concise and functional programming style.

  • Functional interfaces enable the use of lambda expressions.

  • Streams provide a powerful way to process collections of data in a functional manner.

  • Default methods in interfaces allow for adding new methods to existing interfaces without breaking compatibility.

  • Optional class helps to handle null values m...read more

Q18. Impact of changing annotations on spring boot classes

Ans.

Changing annotations on Spring Boot classes can have significant impact on the application.

  • Changing annotations can affect the behavior of the application

  • Annotations can control the lifecycle of beans, security, caching, etc.

  • Removing or modifying annotations can cause runtime errors

  • Adding new annotations can introduce new functionality

  • Annotations can affect the performance of the application

Q19. Write program to filter employees using java streams

Ans.

Program to filter employees using Java streams

  • Create a list of employees

  • Use stream() method to convert list to stream

  • Use filter() method to filter employees based on condition

  • Use collect() method to convert stream back to list

Q20. What is immutable and how we can create our own immutable class ?

Ans.

Immutable objects are those whose state cannot be changed after creation.

  • Use final keyword to make class immutable

  • Make all fields private and final

  • Do not provide setter methods

  • If a field is mutable, return a copy of it instead of the original object

  • Examples: String, Integer, LocalDate

Q21. Suppose your microservice need to handle failures by cascading failures in a distributed environment So you have to implement the circuit breaker pattern using the spring boot to detect and recover from failure...

read more
Ans.

Implementing circuit breaker pattern in Spring Boot to handle failures in a distributed environment

  • Use Spring Boot's resilience4j library to implement the circuit breaker pattern

  • Configure the circuit breaker to monitor the external service dependency and trip open when failures exceed a certain threshold

  • Handle the circuit breaker state transitions (OPEN, HALF_OPEN, CLOSED) appropriately in your code

  • Implement fallback mechanisms to gracefully handle failures when the circuit b...read more

Q22. What is Dependency Injection? What are it's types (Constructor Based, Setter Based, Field Injection).

Ans.

Dependency Injection is a design pattern where the dependencies of an object are provided externally rather than created within the object itself.

  • Types of Dependency Injection: Constructor Based, Setter Based, Field Injection

  • Constructor Based: Dependencies are provided through the constructor of the class

  • Setter Based: Dependencies are provided through setter methods

  • Field Injection: Dependencies are directly assigned to fields of the class

Q23. What is Springboot? difference between Spring and Springboot. What is difference between @Component and @ComponentScan

Ans.

Springboot is a framework that simplifies the development of Java applications by providing pre-configured settings and conventions.

  • Springboot is built on top of the Spring framework, providing a more streamlined way to build Spring applications.

  • Springboot eliminates the need for XML configuration files and allows for easier setup of dependencies.

  • Difference between @Component and @ComponentScan: @Component is used to mark a class as a Spring component, while @ComponentScan is...read more

Q24. What is the difference between the different versions of java (8, 11, 17). Tell about the new features you have worked on?

Ans.

Java versions 8, 11, and 17 have introduced various new features and improvements.

  • Java 8 introduced lambda expressions, streams, and the new Date and Time API.

  • Java 11 introduced local-variable syntax for lambda parameters, HTTP client API, and Flight Recorder.

  • Java 17 introduced sealed classes, pattern matching for switch statements, and enhanced foreign function and memory API.

Q25. System Design Question

Design a Railway Reservation System

Q26. Monolith vs Microservices difference? which is better and why?

Ans.

Monolith is a single, large application while microservices are smaller, independent services. Microservices are better for scalability and flexibility.

  • Monolith is a single, large application where all components are tightly coupled. Microservices are smaller, independent services that communicate with each other through APIs.

  • Monoliths are easier to develop and deploy initially but become harder to maintain and scale as they grow. Microservices allow for better scalability an...read more

Q27. Garbage Collection in Java? what is the process of GC? how can we explicitly invoke Garbage Collector?

Ans.

Garbage Collection in Java is the process of automatically reclaiming memory by destroying unused objects.

  • Garbage Collection is a process in Java where the JVM automatically reclaims memory by destroying objects that are no longer referenced.

  • The process of GC involves marking objects that are still in use, sweeping and deleting objects that are no longer in use, and compacting the memory to reduce fragmentation.

  • We can explicitly invoke Garbage Collector in Java using System.g...read more

Q28. A query in backend yields to 500 results but in UI you have to sort it to 10 results per page, how will you help UI achieve this?

Ans.

Implement pagination in UI by limiting results to 10 per page.

  • Implement pagination logic in UI to display 10 results per page.

  • Use backend query parameters like 'offset' and 'limit' to fetch specific results.

  • Utilize front-end frameworks like React or Angular for efficient pagination implementation.

Q29. DBMS Question

Difference between the DELETE and TRUNCATE command in DBMS.

Q30. What is singleton and how to create singleton class and benefits ?

Ans.

Singleton is a design pattern that restricts the instantiation of a class to one object.

  • To create a singleton class, make the constructor private, create a static method to get the instance of the class, and create a private static variable to hold the instance.

  • Benefits of singleton include ensuring only one instance of the class exists, providing a global point of access to the instance, and reducing the number of objects created in the system.

  • Example: java.lang.Runtime is a...read more

Q31. BELOW SQL QUESTIONS: 1.TRUNCATED VS DELETE VS DROP 2.WHAT IS COMPOSITE KEY 3.Write query to find customer details whos average between 1000 and 2000 customer and order different table link with customer_id

Ans.

SQL questions on Truncate, Delete, Drop, Composite Key and Query to find customer details

  • Truncate removes all data from a table, Delete removes specific data, Drop removes the entire table

  • Composite key is a combination of two or more columns that uniquely identifies a row in a table

  • SELECT * FROM customer c JOIN order o ON c.customer_id = o.customer_id WHERE AVG(o.amount) BETWEEN 1000 AND 2000

Q32. Find the complexity of the given algorithms? How do you optimise this further for performance and scalability?

Ans.

Complexity analysis and optimization of algorithms for performance and scalability.

  • Determine the time complexity (Big O notation) and space complexity of the algorithm.

  • Identify bottlenecks and optimize code by reducing unnecessary operations or improving data structures.

  • Use efficient algorithms and data structures like hash maps, binary search trees, and dynamic programming.

  • Parallelize tasks to leverage multi-core processors for improved performance.

  • Consider scalability by de...read more

Q33. How will you handle an out-of-memory exception?

Ans.

Handle out-of-memory exception by analyzing heap dump and optimizing code.

  • Analyze heap dump to identify memory leaks

  • Optimize code to reduce memory usage

  • Increase heap size if necessary

  • Use memory profiling tools like JProfiler or VisualVM

  • Avoid creating unnecessary objects

  • Use caching to reduce object creation

  • Implement garbage collection strategies

Q34. What is the system or process of an software company?

Ans.

The system or process of a software company involves various stages from planning to deployment.

  • The process starts with requirement gathering and analysis.

  • Then comes the design and development phase.

  • Testing and quality assurance is an important part of the process.

  • Deployment and maintenance are the final stages.

  • Agile and DevOps methodologies are commonly used.

  • Tools like JIRA, Git, Jenkins, etc. are used for project management and automation.

Q35. Write simple ms architecture layer to fetch emp list? Explain about monolithic and MS archtecture? Write Singleton class? And why the variable is static? How to return list of emp where salary > 1000 in java? A...

read more
Ans.

Answering questions related to Java development and architecture

  • Monolithic architecture is a traditional approach where all components of an application are tightly coupled into a single unit

  • Microservices architecture is a modern approach where an application is divided into smaller, loosely coupled services

  • Singleton class is a design pattern that restricts the instantiation of a class to a single object

  • Static variables in Singleton class are shared among all instances and ca...read more

Q36. How Constructor or Setter based injection is used in the traditional Spring framework?

Ans.

Constructor or Setter based injection is used in Spring framework to inject dependencies into a bean.

  • Constructor injection involves passing dependencies as arguments to the constructor of a class.

  • Setter injection involves setting dependencies using setter methods.

  • Constructor injection is preferred for mandatory dependencies, while setter injection is used for optional dependencies.

  • Example: Constructor injection - public class MyClass { private Dependency dependency; public My...read more

Q37. What is meta space and how it is improved in Java 11?

Ans.

Meta space is a memory space in Java that stores metadata about classes and methods.

  • Meta space replaces the permanent generation in Java 8 and earlier versions.

  • In Java 11, meta space is improved by introducing a new flag called 'UseContainerSupport' which allows the JVM to use container-specific memory limits.

  • This improvement helps in better managing memory usage in containerized environments.

Q38. Multiply ele E.g:[1,8,7,3,2] => 1 = 8*7*3*2 [336,42,48,112,168] If 1 then you should multiply all except 1 i.e 8*7*3*2=336

Ans.

The question asks to multiply all elements in an array except for a given number.

  • Iterate through the array and calculate the product of all elements except the given number.

  • Use a variable to keep track of the product.

  • If the given number is 1, multiply all other elements.

  • Return the resulting array.

Q39. Can we override or replace the embedded tomcat server in spring boot

Ans.

Yes, we can override or replace the embedded tomcat server in Spring Boot.

  • You can override the embedded Tomcat server by excluding the Tomcat dependency in the pom.xml file and adding a different embedded server dependency like Jetty or Undertow.

  • You can also customize the embedded server configuration by creating a bean of type EmbeddedServletContainerCustomizer in a @Configuration class.

  • For example, to replace Tomcat with Jetty, exclude the Tomcat dependency and add the Jett...read more

Q40. How does and Amazon S3 provides high availability and low latency

Ans.

Amazon S3 provides high availability and low latency through data replication and global edge locations.

  • Amazon S3 replicates data across multiple availability zones within a region to ensure high availability.

  • Global edge locations cache frequently accessed data closer to users, reducing latency.

  • Amazon S3 uses a content delivery network (CDN) to deliver content quickly to users worldwide.

Q41. What are recovery time objective and recovery point objective in AWS

Ans.

Recovery Time Objective (RTO) and Recovery Point Objective (RPO) are key metrics in disaster recovery planning in AWS.

  • RTO is the maximum acceptable downtime for restoring services after a disaster.

  • RPO is the maximum acceptable data loss in case of a disaster.

  • RTO and RPO help in determining the appropriate backup and recovery strategies.

  • For example, if RTO is 4 hours and RPO is 1 hour, it means services should be restored within 4 hours with a maximum data loss of 1 hour.

Q42. What do you understand by stopping and terminating an EC2 instance

Ans.

Stopping an EC2 instance puts it into a stopped state, while terminating an EC2 instance permanently deletes it.

  • Stopping an EC2 instance preserves the data on the instance's EBS volumes

  • Terminating an EC2 instance deletes the instance and all associated data

  • Stopped instances can be started again, while terminated instances cannot be recovered

  • Stopping an instance does not incur charges, but terminating an instance does

Q43. What is default server in springboot application? And how can we configure Other server? HashSet set = new HashSet(); for(int i=0; i<100; i++){ set.add(i); set.remove(i-1); } sop(set.size()); What is the o/p of...

read more
Ans.

The default server in a Spring Boot application is Tomcat. Other servers can be configured by adding dependencies and modifying the configuration.

  • The default server in Spring Boot is Tomcat, but other servers like Jetty or Undertow can be used.

  • To configure a different server, you need to exclude the default server dependency and add the desired server dependency in the pom.xml file.

  • You also need to modify the application.properties or application.yml file to specify the serve...read more

Q44. What is meta space and how it is different from PermGen

Ans.

Meta space is a memory space in Java 8 and later versions that replaces PermGen for storing class metadata.

  • Meta space is a part of the native memory and is used to store class metadata, such as class structures and method information.

  • Unlike PermGen, meta space is not part of the Java heap and is not subject to the same memory limits.

  • Meta space automatically resizes based on the application's demand, unlike PermGen which had a fixed size.

  • Meta space can be monitored and tuned u...read more

Q45. Difference between shallow and deep comparision in Strings with code example.

Ans.

Shallow and deep comparison in Strings with code example

  • Shallow comparison checks if two String variables refer to the same object in memory

  • Deep comparison checks if two String variables have the same sequence of characters

  • Shallow comparison can be done using the '==' operator

  • Deep comparison can be done using the 'equals()' method

  • Example: String str1 = 'hello'; String str2 = 'hello'; str1 == str2; //shallow comparison returns true

  • Example: String str1 = 'hello'; String str2 = ...read more

Q46. Singleton class in Java Why string is immutable in Java ? Difference between ArrayList &amp; LinkedList What is IOC in Spring Find 3rd largest integer in integer array using streams in java. Java 8 nee features Sor...

read more
Ans.

A set of interview questions for a Senior Java Developer position.

  • Singleton class in Java is a class that allows only one instance of itself to be created.

  • String is immutable in Java because it ensures thread safety and allows for efficient memory management.

  • ArrayList and LinkedList are both implementations of the List interface, but differ in their underlying data structure and performance characteristics.

  • IOC (Inversion of Control) in Spring is a design principle that allows...read more

Q47. If I have OS and JDK only How will you setup a Spring-Boot project in my laptop?

Ans.

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

Q48. what is marker interface what is Stream api difference between Runnable and callable difference between comparable and compartor Internal working of hashMap Difference between Spring and Springboot

Ans.

Marker interface is an interface with no methods, used to mark classes for special treatment.

  • Marker interface is an empty interface with no methods

  • It is used to mark classes for special treatment

  • Examples include Serializable, Cloneable interfaces

Q49. 1.Calculate age without without using any inbuilt function 2.Department wise highest salary 3.Factorial number

Ans.

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

Q50. Differnce between ArrayList and LinkedList

Ans.

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.

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
 • 505 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