Top 250 Java Interview Questions and Answers

Updated 2 Jul 2025

Q. Can the 'this' keyword be equal to null?

Ans.

No, the 'this' keyword cannot be equal to null.

  • The 'this' keyword refers to the current instance of a class.

  • It is used to access the members of the current object.

  • Since 'this' refers to an object, it cannot be null.

Asked in Nuclei

2d ago

Q. What are the different Spring bean scopes?

Ans.

Spring bean scope defines the lifecycle and visibility of a bean in the Spring container.

  • Singleton scope: Only one instance of the bean is created and shared across the application.

  • Prototype scope: A new instance of the bean is created every time it ...read more

Asked in TCS

4d ago

Q. What is C code in Java?

Ans.

C code in Java refers to the use of the Java Native Interface (JNI) to incorporate C code into Java programs.

  • C code in Java is typically used when performance optimization or low-level system access is required.

  • JNI allows Java programs to call C func...read more

Asked in Crisil

5d ago

Q. What is the difference between Spring IOC and Dependency Injection?

Ans.

Spring IOC is a container that manages the lifecycle of Java objects. Dependency Injection is a design pattern that allows objects to be loosely coupled.

  • Spring IOC is a container that manages the creation and destruction of objects

  • Dependency Injectio...read more

Are these interview questions helpful?
1d ago

Q. How is Python different from Java?

Ans.

Python is dynamically typed and has simpler syntax, while Java is statically typed and has more complex syntax.

  • Python is interpreted, while Java is compiled

  • Python has automatic memory management, while Java requires manual memory management

  • Python has...read more

Q. What is the difference between the Runnable and Callable interfaces?

Ans.

Runnable interface is used for running a task, while Callable interface is used for returning a result after running a task.

  • Runnable interface has a run() method that does not return any value.

  • Callable interface has a call() method that returns a val...read more

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

Asked in TCS and 78 others

2d ago

Q. What is a constructor?

Ans.

A constructor is a special method in a class that is automatically called when an instance of the class is created.

  • Constructors have the same name as the class they belong to.

  • They can be used to initialize the object's state or perform any necessary ...read more

2d ago

Q. Write Java code to find the day of the week for September 14th, given that January 1st is a Monday.

Ans.

Calculate the day of the week for September 14, given January 1 is a Monday.

  • January 1 is a Monday.

  • Count the total days from January 1 to September 14.

  • Days in each month: Jan(31), Feb(28), Mar(31), Apr(30), May(31), Jun(30), Jul(31), Aug(31), Sep(14)....read more

Asked in Ernst & Young and 8 others

5d ago

Q. What does the @SpringBootApplication annotation do?

Ans.

@SpringBootApplication is a Spring Boot annotation that enables auto-configuration and component scanning.

  • Enables auto-configuration of the Spring application context

  • Enables component scanning for beans

  • Provides a convenient shortcut for @Configuratio...read more

Asked in Nisum

3d ago

Q. Write a Java program to find the number of 'E's in the string 'SELENIUM'.

Ans.

This Java program counts the occurrences of the letter 'E' in the string 'SELENIUM'.

  • Use a loop to iterate through each character of the string.

  • Check if the character is 'E' (case-sensitive).

  • Maintain a counter to keep track of the occurrences.

  • Example:...read more

Java Jobs

Sodexo Food Solutions India Pvt. Ltd.ces logo
Supervisor 3-5 years
Sodexo Food Solutions India Pvt. Ltd.ces
4.1
Tiruchirappalli
Sodexo Food Solutions India Pvt. Ltd.ces logo
Supervisor 2-3 years
Sodexo Food Solutions India Pvt. Ltd.ces
4.1
Chennai
Sodexo Food Solutions India Pvt. Ltd.ces logo
Supervisor 2-3 years
Sodexo Food Solutions India Pvt. Ltd.ces
4.1
Rajkot
3d ago
Q. How can you print even and odd numbers in increasing order using two threads in Java?
Ans.

Use two threads to print even and odd numbers in increasing order.

  • Create two threads, one for printing even numbers and one for printing odd numbers.

  • Use a shared variable to keep track of the current number to be printed.

  • Synchronize access to the sha...read more

Asked in Cognizant

3d ago

Q. Explain Dependency Injection in Spring Boot.

Ans.

Dependency Injection in Spring Boot is a design pattern that allows for better code management and testing by injecting dependencies.

  • Promotes loose coupling between components.

  • Facilitates easier unit testing by allowing mock dependencies.

  • Implemented ...read more

Asked in IBM

3d ago

Q. List the features of Java 8 and their use cases.

Ans.

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

  • Lambda expressions: Allow for more concise and readable code by enabling functional programming.

  • Streams: Provide a way to work with collections of...read more

Q. What is the purpose of using default methods in Java 8?

Ans.

Default methods in Java 8 allow interfaces to have method implementations, enhancing flexibility and backward compatibility.

  • Enable adding new methods to interfaces without breaking existing implementations.

  • Facilitate multiple inheritance of behavior ...read more

Asked in Bristlecone

4d ago

Q. What is CompletableFuture?

Ans.

completableFuture is a class in Java that represents a future result of an asynchronous computation.

  • It is used for asynchronous programming in Java.

  • It can be used to chain multiple asynchronous operations.

  • It supports callbacks and combinators.

  • It can ...read more

5d ago

Q. Explain what Spring Sleuth is.

Ans.

Spring Sleuth is a distributed tracing solution for Spring applications, enabling monitoring and debugging of microservices.

  • Integrates with Spring Cloud to provide tracing capabilities.

  • Automatically adds trace and span IDs to logs for better correlat...read more

Asked in Infogain

5d ago

Q. What is the difference between @Controller and @RestController annotations?

Ans.

The @Controller annotation is used to create a controller class in Spring MVC, while @RestController is used to create RESTful web services.

  • The @Controller annotation is used to create a controller class in Spring MVC, which is used to handle traditi...read more

Asked in TCS

4d ago

Q. Can you briefly explain Spring annotations?

Ans.

Spring annotations are used to provide metadata to Spring framework classes and methods.

  • Annotations like @Component, @Controller, @Service, and @Repository are used for component scanning and auto-wiring.

  • @Autowired is used for dependency injection.

  • @R...read more

6d ago

Q. What is Component Scan?

Ans.

Component Scan is a Spring framework feature that automatically detects and registers beans in the application context.

  • It uses annotations like @Component, @Service, @Repository, and @Controller to identify beans.

  • Configured via @ComponentScan annotat...read more

Asked in OpenText Technologies and 2 others

1d ago

Q. What are the advantages of Java?

Ans.

Java offers platform independence, strong community support, and robust security features, making it ideal for diverse applications.

  • Platform Independence: Java's 'Write Once, Run Anywhere' capability allows applications to run on any device with a Ja...read more

Asked in Deloitte

2d ago

Q. Why do we have @functionalInterface if we can make any interface a functional interface if it already has one abstract method?

Ans.

Functional interfaces provide clarity and enforce single abstract method constraint.

  • Functional interfaces provide clarity to developers by explicitly indicating that the interface is intended to be used as a functional interface.

  • Using @FunctionalInte...read more

Asked in Accenture

6d ago

Q. How do you monitor Java applications using New Relic?

Ans.

Monitoring Java applications with New Relic involves setting up agents and configuring alerts.

  • Install New Relic Java agent in the application server

  • Configure New Relic settings in the newrelic.yml file

  • Set up custom dashboards and alerts in New Relic ...read more

Asked in Tredence

6d ago
Q. What is the Front Controller in Spring MVC?
Ans.

Front Controller in Spring MVC is a design pattern that handles all requests and acts as a central point of control.

  • Front Controller is a servlet in Spring MVC that receives all requests and then dispatches them to the appropriate handlers.

  • It helps i...read more

Asked in Trianz

4d ago

Q. What is the difference between intermediate and terminal operations in streams?

Ans.

Intermediate operations return a stream and do not produce a result, while terminal operations produce a result.

  • Intermediate operations are lazy and do not execute until a terminal operation is called

  • Examples of intermediate operations include filter...read more

Asked in Nagarro

1d ago

Q. Define Functional interfaces.

Ans.

Functional interfaces are interfaces with a single abstract method, enabling lambda expressions in Java.

  • A functional interface can have multiple default or static methods.

  • It is annotated with @FunctionalInterface for clarity.

  • Example: Runnable (void r...read more

Asked in Infosys

2d ago

Q. What are Spring Actuators?

Ans.

Spring actuators are devices that use the force generated by a spring to move or control a mechanism.

  • Spring actuators convert the potential energy stored in a spring into mechanical motion.

  • They are commonly used in various applications such as valves...read more

Asked in Optiontown

5d ago

Q. Which Java framework are you most familiar with?

Ans.

I am most familiar with the Spring framework, known for its comprehensive features for building Java applications.

  • Dependency Injection: Spring's core feature that promotes loose coupling. Example: Using @Autowired to inject beans.

  • Aspect-Oriented Prog...read more

3d ago

Q. What are the differences between Views and ViewGroups in Android?

Ans.

Groups and View Groups are components of Android UI that help in organizing and displaying UI elements.

  • View Groups are containers that hold other UI elements, such as LinearLayout, RelativeLayout, etc.

  • Groups are a type of View Group that allow for th...read more

Q. What are the differences between List and Set in the Collection Framework?

Ans.

Lists allow duplicates and maintain order; sets are unique and unordered collections.

  • List allows duplicate elements, e.g., List<String> list = Arrays.asList('A', 'B', 'A');

  • Set does not allow duplicates, e.g., Set<String> set = new HashSet<>(Arrays.as...read more

Asked in TCS

4d ago

Q. How do you find Java elements using Selenium?

Ans.

Java elements in Selenium can be found using various methods like findElement, findElements, etc.

  • Use findElement method to locate a single element in the DOM

  • Use findElements method to locate multiple elements in the DOM

  • Locate elements by ID, class na...read more

1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.8
 • 8.6k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6k 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 and stories logo
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