Java Software Engineer

20+ Java Software Engineer Interview Questions and Answers

Updated 20 Jan 2023

Popular Companies

search-icon

Q1. How to implement executor framework and it's 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.

Q2. 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);

Java Software Engineer Interview Questions and Answers for Freshers

illustration image

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

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

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

Are these interview questions helpful?

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

Q6. Explain OOP concepts in Java with real time 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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. Differentiate between Array and Array list in detail with example?

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 list = new ArrayList<>();

Q8. Find the shortest path in 0,1 matrix 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

Java Software Engineer Jobs

Java Software Engineer 2-6 years
Wipro Limited
3.7
Noida
Java Software Engineer 5-8 years
Wipro Limited
3.7
Bangalore / Bengaluru
Software Engineer (Java) 2-5 years
Digient Technologies
4.4
Chennai

Q9. write a user microservice to get the data from h2DB.

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

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

Q11. what does 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.

Q12. 1.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.

Q13. What is Daemon Thread?Give 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.

Q14. What is use of 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

Q15. how to create thread singleton

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

Q16. Find the shortest super common string

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

Q17. Multithreading in 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

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

Q19. Explain 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

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

Q21. Detach and merge 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);

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

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

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

Q25. Spring mvc vs springboot

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

Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.9
 • 7.8k Interviews
3.7
 • 7.3k Interviews
3.7
 • 5.2k Interviews
3.6
 • 3.6k Interviews
3.4
 • 771 Interviews
3.8
 • 491 Interviews
3.6
 • 399 Interviews
3.6
 • 337 Interviews
5.0
 • 143 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

Java Software Engineer 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