Senior Java Developer

300+ Senior Java Developer Interview Questions and Answers

Updated 17 Jan 2025
search-icon

Q1. Remove the Kth Node from the End of a Linked List

You are given a singly Linked List with 'N' nodes containing integer data and an integer 'K'. Your task is to delete the Kth node from the end of this Linked Li...read more

Q2. Intersection of Linked List Problem

You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.

Your task is to determine the data...read more

Frequently asked in,

Senior Java Developer Interview Questions and Answers for Freshers

illustration image

Q3. Merge Two Sorted Linked Lists Problem Statement

You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.

Input:...read more

Q4. LRU Cache Design Question

Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:

1. get(key) - Return the value of the key if it exists in the cache; otherwise, re...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. Why is Java considered platform-independent while the Java Virtual Machine (JVM) is 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

Senior Java Developer | SAP Sales Cloud V2 8-12 years
SAP India Pvt.Ltd
4.2
Bangalore / Bengaluru
Senior Java Developer 4-7 years
Yamaha Motor Solutions India Pvt Ltd
4.2
Faridabad
Senior Java Developer 6-11 years
Way Dot Com
4.7
₹ 20 L/yr - ₹ 35 L/yr
Thiruvananthapuram

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. What is the 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. Can you 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. Given an array {1, 2, 1, 4, 5, 4, 8, 7}, how can you use Streams to remove duplicates while retaining only the even numbers?

Ans.

Use Streams to remove duplicates and retain only even numbers from an array.

  • Convert the array to a stream using Arrays.stream()

  • Use distinct() to remove duplicates

  • Filter out odd numbers using filter()

  • Collect the result using collect(Collectors.toList())

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

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

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

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

Q26. Design a Railway Reservation System.

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

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

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

Q30. What is the difference between the DELETE and TRUNCATE commands in DBMS?

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

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

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

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

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

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

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

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

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

Q40. Internal architecture of Spring boot, how enable autoconfiguration works

Ans.

Spring Boot uses autoconfiguration to automatically configure the Spring application based on dependencies and properties.

  • Spring Boot autoconfiguration is achieved through @EnableAutoConfiguration annotation

  • Autoconfiguration classes are located in the org.springframework.boot.autoconfigure package

  • Autoconfiguration classes are conditionally applied based on the presence of specific classes or properties

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

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

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

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

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

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

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

Q48. Singleton class in Java Why string is immutable in Java ? Difference between ArrayList & 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

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

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

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.4k Interviews
3.6
 • 7.6k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.8k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
3.8
 • 3k Interviews
3.8
 • 533 Interviews
3.3
 • 513 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

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