Java Software Engineer

20+ Java Software Engineer Interview Questions and Answers

Updated 27 Jun 2025
search-icon
6d ago

Q. How do you implement the Executor Framework, and what are its benefits?

Ans.

Executor framework is used to manage threads and execute tasks asynchronously.

  • Executor framework provides a way to manage threads and execute tasks asynchronously.

  • It provides a thread pool and a queue to manage tasks.

  • It helps in improving the performance of the application by reducing the overhead of creating and destroying threads.

  • It also provides a way to handle exceptions and errors in the tasks.

  • Example: Executors.newFixedThreadPool(10) creates a thread pool of 10 threads.

6d ago

Q. Given an array, find the next largest element on the right side for each element in the array.

Ans.

Find the next largest in the right side for every array element.

  • Iterate through the array from right to left

  • Use a stack to keep track of elements

  • Pop elements from stack until a greater element is found

  • If no greater element is found, assign -1

Java Software Engineer Interview Questions and Answers for Freshers

illustration image

Asked in Trie Coder

6d ago

Q. Can we pass values during object creation?

Ans.

Yes, we can pass values during object creation using constructors.

  • Constructors are special methods that are called when an object is created.

  • They can take parameters to initialize the object's state.

  • Values passed during object creation are used to initialize instance variables.

  • Example: public class Person { String name; int age; public Person(String name, int age) { this.name = name; this.age = age; } }

  • Example usage: Person person = new Person("John", 30);

Asked in Trie Coder

4d ago

Q. what are exceptions. How many times are there?

Ans.

Exceptions are errors that occur during program execution. There are two types: checked and unchecked.

  • Exceptions are objects that represent errors or exceptional conditions that occur during program execution.

  • Checked exceptions are checked at compile time and must be handled or declared in the method signature.

  • Unchecked exceptions are not checked at compile time and can be handled or left to propagate up the call stack.

  • Examples of exceptions include NullPointerException, Arra...read more

Are these interview questions helpful?
6d ago

Q. 1. Inheritance 2. Interface vs Abstract class 3. Exception throw vs throws 4. Multi-threading methods

Ans.

Java interview questions on inheritance, interface vs abstract class, exception handling, and multi-threading.

  • Inheritance allows a subclass to inherit properties and methods from a superclass.

  • An interface defines a set of methods that a class must implement, while an abstract class can have both implemented and abstract methods.

  • Throw is used to throw an exception, while throws is used to declare that a method may throw an exception.

  • Multi-threading methods include start(), run...read more

Asked in Trie Coder

5d ago

Q. Explain OOP concepts in Java with real-world examples.

Ans.

OOP concepts in Java with real time examples

  • Encapsulation - hiding implementation details of a class. Example: private variables in a class

  • Inheritance - creating a new class from an existing class. Example: subclass extending a superclass

  • Polymorphism - ability of an object to take many forms. Example: method overloading and overriding

  • Abstraction - showing only necessary details to the user. Example: abstract classes and interfaces

Java Software Engineer Jobs

NatWest Group logo
Java Software Engineer, AVP 14-15 years
NatWest Group
3.8
Bangalore / Bengaluru
UPLERS SOLUTIONS PRIVATE LIMITED logo
Lead Java Software Engineer 4-6 years
UPLERS SOLUTIONS PRIVATE LIMITED
3.9
Bangalore / Bengaluru
UPLERS SOLUTIONS PRIVATE LIMITED logo
Lead Java Software Engineer 4-9 years
UPLERS SOLUTIONS PRIVATE LIMITED
3.9
Bangalore / Bengaluru
3d ago

Q. Given a 0-1 matrix, find the shortest path from (0,0) to (n-1, n-1).

Ans.

Find shortest path in 0,1 matrix from (0,0) to (n-1,n-1)

  • Use Breadth First Search (BFS) algorithm to find shortest path

  • Create a visited matrix to keep track of visited nodes

  • Create a distance matrix to keep track of distance from source node

  • Start BFS from (0,0) and keep updating visited and distance matrices

  • Return distance value at (n-1,n-1) in distance matrix

Asked in Trie Coder

1d ago

Q. What are the key differences between an Array and an ArrayList, and can you provide examples?

Ans.

Array is a fixed-size data structure while Array list is a dynamic data structure.

  • Array has a fixed size while Array list can grow dynamically.

  • Array can store only homogeneous data types while Array list can store heterogeneous data types.

  • Array is faster than Array list in terms of accessing elements.

  • Array list provides more functionality like add, remove, and search.

  • Example of Array: int[] arr = new int[5]; Example of Array list: ArrayList<String> list = new ArrayList<>();

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Asked in Wipro

4d ago

Q. Write a user microservice to get data from an H2 database.

Ans.

A user microservice to retrieve data from h2DB

  • Create a REST API endpoint to handle user requests

  • Use JDBC to connect to the h2DB and retrieve data

  • Implement caching to improve performance

  • Ensure proper error handling and logging

  • Secure the API with authentication and authorization

4d ago

Q. Find the peak in an array in less than O(n) time.

Ans.

Find peak in array in less than O(n) time

  • Use binary search to find peak element

  • Compare middle element with its neighbors to determine direction

  • Repeat search in direction of larger neighbor until peak is found

Asked in Wipro

1d ago

Q. What is Spring Boot Starter POM?

Ans.

Spring Boot Starter POM is a parent POM that provides a set of dependencies for Spring Boot applications.

  • It includes commonly used dependencies such as Spring Framework, Spring Boot, and Spring Data.

  • It simplifies the process of configuring and deploying Spring Boot applications.

  • Developers can add additional dependencies to the POM file as needed.

  • Examples of Spring Boot Starter POMs include spring-boot-starter-web, spring-boot-starter-data-jpa, and spring-boot-starter-test.

2d ago

Q. What are IOC and DI?

Ans.

IOC stands for Inversion of Control and DI stands for Dependency Injection.

  • IOC is a design pattern that allows the flow of control to be inverted, where the framework controls the flow of the program.

  • DI is a technique where the dependencies of an object are injected into it, rather than the object creating them itself.

  • IOC and DI are closely related and often used together in software development.

  • Spring Framework is a popular example of a framework that uses IOC and DI.

Q. What is a Daemon Thread? Give an example.

Ans.

Daemon thread is a low priority thread that runs in the background and provides services to user threads.

  • Daemon threads are used for tasks that don't require user interaction, such as garbage collection.

  • They can be created using setDaemon() method.

  • They terminate automatically when all user threads have finished execution.

  • Example: Timer thread in Java is a daemon thread.

Asked in ServiceNow

1d ago

Q. What is the use of the static keyword?

Ans.

Static keyword is used to create class-level variables and methods.

  • Static variables are shared among all instances of a class

  • Static methods can be called without creating an instance of the class

  • Static blocks are used to initialize static variables

  • Static import is used to import static members of a class

Asked in Wipro

2d ago

Q. How do you create a thread-safe singleton in Java?

Ans.

To create thread singleton, use double-checked locking or enum.

  • Use double-checked locking to ensure only one instance is created

  • Alternatively, use enum to create a singleton with thread safety

  • Ensure proper synchronization to avoid race conditions

6d ago

Q. Explain multithreading in the executor framework.

Ans.

Executor framework provides a way to execute tasks asynchronously using multithreading.

  • Executor framework provides a way to manage thread pools and execute tasks asynchronously.

  • It uses a pool of threads to execute tasks and provides a way to submit tasks to the pool.

  • The tasks are executed in a separate thread, allowing for parallel execution.

  • Executor framework provides different types of thread pools like fixed, cached, and scheduled.

  • It also provides a way to handle exception...read more

5d ago

Q. Given two strings, find the shortest string that has both as subsequences.

Ans.

Finding the shortest super common string among an array of strings.

  • Create a set of all substrings of the first string

  • Iterate through the remaining strings and remove substrings not present in them

  • Return the shortest remaining substring

3d ago

Q. Design pattern in java

Ans.

Design patterns are reusable solutions to common software problems.

  • Design patterns provide a standard way of solving recurring problems in software development.

  • There are three types of design patterns: creational, structural, and behavioral.

  • Examples of design patterns include Singleton, Factory, Observer, and Decorator.

  • Design patterns can improve code readability, maintainability, and scalability.

Q. Explain the Collection Framework in depth.

Ans.

Collection framework is a set of classes and interfaces that provide a way to store and manipulate groups of objects.

  • Collection framework is part of Java's core libraries.

  • It includes interfaces like List, Set, and Map, and their respective implementations like ArrayList, HashSet, and HashMap.

  • Collections can be sorted, searched, and filtered using various methods.

  • Iterators are used to traverse through collections.

  • Collections can also be synchronized for thread safety.

  • Example: ...read more

Q. Method overloading vs Methodoverriding

Ans.

Method overloading is having multiple methods with the same name but different parameters. Method overriding is having a method in child class with the same name and signature as in parent class.

  • Method overloading is compile-time polymorphism

  • Method overriding is run-time polymorphism

  • Method overloading is used to provide different ways of calling the same method

  • Method overriding is used to provide a specific implementation of a method in a child class

  • Method overloading can hav...read more

4d ago

Q. What are detach and merge operations in Spring?

Ans.

Detach and merge are used in Spring to manage the persistence of entities.

  • Detach is used to remove an entity from the persistence context.

  • Merge is used to update the state of a detached entity and merge it back into the persistence context.

  • Both detach and merge are commonly used in Spring Data JPA.

  • Example: entityManager.detach(entity); entityManager.merge(entity);

Asked in Genpact

2d ago

Q. What is your current CTC?

Ans.

The current CTC (Cost to Company) is the total salary package of an employee including all benefits and allowances.

  • CTC includes salary, bonuses, incentives, and other monetary benefits.

  • It also includes non-monetary benefits like health insurance, retirement plans, and company-provided facilities.

  • CTC is used to calculate the net salary after deducting taxes and other deductions.

  • It is an important factor for job seekers to evaluate job offers and negotiate salaries.

  • Example: Cur...read more

1d ago

Q. Scopes in spring

Ans.

Scopes in Spring refer to the lifecycle of a bean and its visibility within the application context.

  • Spring has four standard scopes: singleton, prototype, request, and session.

  • Singleton scope creates only one instance of a bean and is the default scope.

  • Prototype scope creates a new instance of a bean every time it is requested.

  • Request scope creates a new instance of a bean for each HTTP request.

  • Session scope creates a new instance of a bean for each HTTP session.

6d ago

Q. What are the components of IOC?

Ans.

IOC stands for Inversion of Control. Its components are Dependency Injection and Aspect Oriented Programming.

  • Dependency Injection: injecting dependencies into a class instead of creating them within the class

  • Aspect Oriented Programming: separating cross-cutting concerns from the main logic of the application

  • Examples: Spring Framework, Guice

Asked in IBM

3d ago

Q. What are the differences between Spring MVC and Spring Boot?

Ans.

Spring MVC is a web framework while Spring Boot is an opinionated way of building Spring applications.

  • Spring MVC requires more configuration and setup compared to Spring Boot

  • Spring Boot provides a pre-configured environment for building Spring applications

  • Spring Boot includes an embedded server, making it easier to deploy applications

  • Spring MVC is more flexible and customizable compared to Spring Boot

  • Both frameworks are built on top of the Spring framework

6d ago

Q. Write an SQL query to find the maximum salary.

Ans.

The SQL MAX function retrieves the highest value from a specified column in a database table.

  • The MAX function is used in SQL to find the maximum value in a numeric column.

  • Example: SELECT MAX(salary) FROM employees; retrieves the highest salary from the employees table.

  • It can also be used with GROUP BY to find maximum values for different groups.

  • Example: SELECT department, MAX(salary) FROM employees GROUP BY department; shows the highest salary in each department.

Interview Experiences of Popular Companies

Accenture Logo
3.8
 • 8.6k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
HCLTech Logo
3.5
 • 4.1k Interviews
Mphasis Logo
3.3
 • 845 Interviews
View all
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

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

Java Software Engineer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits