Top 250 Java Interview Questions and Answers

Updated 15 Jul 2025

Asked in Caspex Corp

2w ago

Q. What is the difference between findFirst and findAny?

Ans.

findFirst returns the first element in a stream, while findAny returns any element in a stream.

  • findFirst is deterministic and will always return the first element in a stream, while findAny is non-deterministic and can return any element.

  • findAny is u...read more

Asked in Coforge

3d ago

Q. Where is the Observer pattern used in Spring Boot?

Ans.

The Observer pattern is used in SpringBoot for implementing event handling and notification mechanisms.

  • The Observer pattern is commonly used in SpringBoot for implementing event listeners and publishers.

  • It allows objects to subscribe to and receive n...read more

Asked in Sopra Steria

2w ago

Q. What is Metaspace in Java 8?

Ans.

Meta space is a memory space in Java 8 used to store class metadata.

  • Meta space replaces the permanent generation (PermGen) space in Java 8.

  • It stores class metadata such as class name, access modifiers, and constant pool.

  • Meta space is dynamically size...read more

Asked in Capgemini

1w ago

Q. What is concurrency in Java?

Ans.

Concurrency in Java refers to the ability of multiple tasks to run simultaneously within a program.

  • Concurrency allows for better utilization of resources by executing multiple tasks at the same time.

  • Java provides built-in support for concurrency thro...read more

Are these interview questions helpful?

Asked in Dataquad

3d ago

Q. How do you handle lazy loading in Hibernate?

Ans.

Lazy loading in Hibernate is a technique used to load data only when it is needed, improving performance.

  • Lazy loading is achieved by setting the fetch type to LAZY in the mapping of the entity relationship.

  • When an entity is loaded, associated entitie...read more

Asked in Infosys

1w ago

Q. What is an abstract method?

Ans.

An abstract method is a method that is declared without an implementation in an abstract class or interface.

  • Abstract methods do not have a body and must be implemented by subclasses.

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

  • Int...read more

Share interview questions and help millions of jobseekers 🌟
man with laptop

Q. Tell me about the Executor framework.

Ans.

Executor framework is a Java framework that provides a way to execute tasks asynchronously using a thread pool.

  • It provides a way to manage threads and execute tasks in a thread pool

  • It allows for better resource management and improved performance

  • It s...read more

Asked in TCS

6d ago

Q. what is java and new features of java

Ans.

Java is a popular programming language known for its platform independence and object-oriented approach. New features include modules, var keyword, and more.

  • Java is a high-level, class-based, object-oriented programming language.

  • New features in Java ...read more

Asked in Cognizant

2w ago

Q. How do you set the default value of a date field to the current date and time?

Ans.

To set the default value of a date field to the current date time value, use a script to assign the value.

  • Create a client script or business rule to set the default value

  • Use the GlideDateTime API to get the current date time value

  • Assign the current d...read more

Asked in Genpact

2d ago

Q. What is the difference between super and super()?

Ans.

super is a keyword used to access methods and properties of a superclass, while super() is used to call the constructor of a superclass.

  • super is used to access methods and properties of a superclass in a subclass.

  • super() is used to call the construct...read more

Java Jobs

Red Hat India Pvt Ltd logo
Senior Software Engineer - Full Stack 6-11 years
Red Hat India Pvt Ltd
4.3
₹ 19 L/yr - ₹ 33 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru
Red Hat India Pvt Ltd logo
Senior Software Quality Engineer - Model Inferencing (Pytest, ML Ops) 4-9 years
Red Hat India Pvt Ltd
4.3
Bangalore / Bengaluru
Red Hat India Pvt Ltd logo
Senior Software Engineer For Fabric8 Kubernetes Client- Java/K8s 6-11 years
Red Hat India Pvt Ltd
4.3
₹ 19 L/yr - ₹ 33 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru

Asked in Infosys and 2 others

5d ago

Q. What is the use of the super keyword?

Ans.

The super keyword is used in Java to refer to the immediate parent class object.

  • Used to access methods and variables of the parent class

  • Helps in achieving method overriding in inheritance

  • Can be used to call the constructor of the parent class

  • Example:...read more

1w ago

Q. Explain Wrapper Class in Java 8.

Ans.

Wrapper class in Java 8 is used to convert primitive data types into objects.

  • Wrapper classes provide a way to use primitive data types as objects.

  • They are used for converting primitive data types into objects and vice versa.

  • Examples include Integer, ...read more

Asked in HCLTech

1w ago

Q. What is a parallel stream?

Ans.

Parallel stream is a feature in Java that allows processing elements of a stream concurrently.

  • Parallel stream can be created from a regular stream using parallel() method.

  • It utilizes multiple threads to process elements in parallel, improving perform...read more

Asked in Amdocs

3d ago

Q. What is a Spring Actuator?

Ans.

Spring Actuator is a feature in Spring Boot that allows monitoring and managing the application.

  • Spring Actuator provides endpoints to monitor application health, metrics, info, etc.

  • It helps in understanding the internal state of the application and i...read more

Asked in Backbase

2w ago

Q. What are Spring bean scopes?

Ans.

Spring bean scopes define the lifecycle and visibility of beans in a Spring application context.

  • Singleton: One instance per Spring IoC container. Example: @Bean(name = 'myBean') in a configuration class.

  • Prototype: A new instance is created each time ...read more

2w ago

Q. MVC layers for Java web service

Ans.

MVC layers in Java web service help separate concerns for better organization and maintainability.

  • Model layer: Represents the data and business logic

  • View layer: Handles the presentation of data to the user

  • Controller layer: Manages user input and upda...read more

Asked in Amdocs

1w ago

Q. How would you implement a database connection pool in Java?

Ans.

Database connection pool in Java helps manage multiple database connections efficiently.

  • Use a connection pool library like HikariCP or Apache DBCP.

  • Set up the pool with a maximum number of connections, timeout settings, etc.

  • Acquire and release connect...read more

Asked in Wipro

2w ago

Q. Explain the internal workings of a Java HashMap.

Ans.

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

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

  • The key is hashed to find the index of the bucket where the value is stored.

  • If mult...read more

Asked in DigiValet

1w ago

Q. What are the advantages of using Spring Boot Starters?

Ans.

Spring Boot starters are dependency descriptors that simplify the dependency management process in Spring Boot applications.

  • Spring Boot starters provide a set of pre-configured dependencies that can be easily included in your project.

  • They help in red...read more

Asked in Blackrock

2w ago

Q. Java 8 in depth

Ans.

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

  • Lambda expressions allow for more concise code by enabling functional programming.

  • Streams provide a way to process collections of objects in a fun...read more

2w ago

Q. Design principles in Java.

Ans.

Design principles in Java focus on creating modular, reusable, and maintainable code.

  • Single Responsibility Principle - Each class should have only one responsibility.

  • Open/Closed Principle - Classes should be open for extension but closed for modifica...read more

Asked in H&M

1w ago

Q. Java 8 advantages

Ans.

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

  • Lambda expressions allow for more concise and readable code.

  • Functional interfaces enable the use of lambda expr...read more

1w ago

Q. How have you leveraged Spring Java in your projects?

Ans.

I leverage Spring Java for dependency injection, MVC framework, and transaction management in my projects.

  • Utilize Spring's dependency injection to manage object dependencies and improve code maintainability

  • Leverage Spring MVC framework for building w...read more

Asked in Wipro

1w ago

Q. Different technologies available in java

Ans.

Some technologies available in Java include Java EE, Spring Framework, Hibernate, Apache Struts, and JavaFX.

  • Java EE (Enterprise Edition) for building enterprise applications

  • Spring Framework for dependency injection and aspect-oriented programming

  • Hibe...read more

Asked in TechVerito

1w ago

Q. How to deploy Java apps?

Ans.

Java applications can be deployed using various methods such as manual deployment, using build tools like Maven or Gradle, or using containerization platforms like Docker.

  • Use build tools like Maven or Gradle to package the application into a JAR or W...read more

Q. What is the return type for getWindowHandles?

Ans.

The return type for get window handles is an array of strings.

  • Return type should be an array of strings

  • Each string in the array represents a window handle

  • Example: ['handle1', 'handle2', 'handle3']

Asked in ITC Infotech

1w ago

Q. JPA vs Hibernate

Ans.

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

  • JPA is a Java specification for managing relational data in applications.

  • Hibernate is an ORM framework that implements the JPA specification.

  • Hibernate provides additional features bey...read more

Asked in Cognizant

2w ago

Q. All Java 8 new features

Ans.

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

  • Lambda expressions allow you to pass functionality as an argument to a method.

  • Functional interfaces have a single abstract method...read more

2w ago

Q. How does AWT Token work?

Ans.

AWT Token is a security token used for authentication and authorization in Java applications.

  • AWT stands for Abstract Window Toolkit

  • AWT Token is used for managing user authentication and authorization in Java applications

  • It provides a secure way to co...read more

Asked in ITC Infotech

5d ago

Q. Spring JPA vs Hibernate

Ans.

Spring JPA is a part of the Spring Data project that makes it easier to work with JPA. Hibernate is a popular ORM framework.

  • Spring JPA is a higher level abstraction on top of JPA, providing more features and simplifying development.

  • Hibernate is a pow...read more

Previous
1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.7
 • 8.7k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
Cognizant Logo
3.7
 • 5.9k Interviews
Capgemini Logo
3.7
 • 5.1k Interviews
Tech Mahindra Logo
3.5
 • 4.1k Interviews
HCLTech Logo
3.5
 • 4.1k Interviews
LTIMindtree Logo
3.7
 • 3k Interviews
IBM Logo
4.0
 • 2.5k Interviews
View all
Interview Tips & Stories
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Java 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 Lakh+

Reviews

10L+

Interviews

4 Crore+

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