Top 250 Java Interview Questions and Answers
Updated 2 Jul 2025

Asked in Maventic Innovative Solutions

Q. Can the 'this' keyword be equal to null?
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

Q. What are the different Spring bean scopes?
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

Q. What is C code in Java?
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

Q. What is the difference between Spring IOC and Dependency Injection?
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

Asked in DXC Technology

Q. How is Python different from Java?
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

Asked in BNP Paribas India Solutions

Q. What is the difference between the Runnable and Callable interfaces?
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

Asked in TCS and 78 others

Q. What is a constructor?
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

Asked in Veeva Systems

Q. Write Java code to find the day of the week for September 14th, given that January 1st is a Monday.
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

Q. What does the @SpringBootApplication annotation do?
@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

Q. Write a Java program to find the number of 'E's in the string 'SELENIUM'.
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




Asked in Morgan Stanley

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

Q. Explain Dependency Injection in Spring Boot.
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

Q. List the features of Java 8 and their use cases.
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

Asked in Deutsche Telekom Digital Labs

Q. What is the purpose of using default methods in Java 8?
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

Q. What is CompletableFuture?
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

Asked in NCR Corporation

Q. Explain what Spring Sleuth is.
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

Q. What is the difference between @Controller and @RestController annotations?
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

Q. Can you briefly explain Spring annotations?
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

Asked in Slk Software Services

Q. What is Component Scan?
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

Q. What are the advantages of Java?
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

Q. Why do we have @functionalInterface if we can make any interface a functional interface if it already has one abstract method?
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

Q. How do you monitor Java applications using New Relic?
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

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

Q. What is the difference between intermediate and terminal operations in streams?
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

Q. Define Functional interfaces.
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

Q. What are Spring Actuators?
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

Q. Which Java framework are you most familiar with?
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

Asked in WINIT Software

Q. What are the differences between Views and ViewGroups in Android?
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

Asked in ERGO Technology & Services

Q. What are the differences between List and Set in the Collection Framework?
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

Q. How do you find Java elements using Selenium?
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
Top Interview Questions for Related Skills
Interview Experiences of Popular Companies










Interview Questions of Java Related Designations



Reviews
Interviews
Salaries
Users

