Java Interview Questions Answers
Java Interview Questions Answers
Java
Asked in
Java Developer Interview
Q2. write a code to filter out loans with incomplete status using java 8 features.
Ans. Code to filter out loans with incomplete status using Java 8 features.
Use stream() method to convert the list of loans into a stream
Use collect() method to collect the filtered loans into a new list
Software Development
Java
Infosys Java Developer Interview Questions and Answers for Freshers
View all interview questions
illustration image
Asked in
Java Developer Interview
Q3. 1.What is Singleton in java and create your own singleton class countering all
breakable conditions? 2. What is Auto Configuration? 3. @Primary vs @Qualifier 4.
What is idempotent? 5. What is class loader? Type...read more
Ans. The interview questions cover various topics related to Java development,
including Singleton pattern, memory management, exception handling, Spring
framework, and design patterns.
Singleton pattern ensures a class has only one instance and provides a global point
of access to it.
@Primary annotation is used to give higher preference to a bean when mu...read more
Spring Boot
Discover Infosys interview dos and don'ts from real experiences
View 7.5k interview experiences
Asked in
Java Developer Interview
Q5. SpringBoot Question
What is the starter dependency of the Spring boot module?
Web Development
Spring Boot
Asked in
Java Developer Interview
Q6. OOPS Question
How would you differentiate between a String, StringBuffer, and a StringBuilder?
Java
Are these interview questions helpful?
yes
Yes
no
No
Asked in
Java Developer Interview
Q7. Spring Boot Question
How to enable debugging log in the spring boot application?
Web Development
Spring Boot
Asked in
Java Developer Interview
Q8. SpringBoot Question
What does the @SpringBootApplication annotation do internally?
Java
Share interview questions and help millions of jobseekers 🌟
Web Development
Asked in
Java Developer Interview
Q10. OOPS Question
What is meant by Interface?
Comparator can compare objects of different classes, while Comparable can only
compare objects of the same class.
Comparator uses the compare() method, while Comparable uses the compareTo() method.
View 1 answer
right arrow
Asked in
Java Developer Interview
Q12. OOPS Question
Explain the use of final keyword in variable, method and class.
Java
Asked in
Java Developer Interview
Q13. Java Question
What's the difference between User thread and Daemon thread?
Java
Multithreading
Asked in
Java Developer Interview
Q14. MVC Question
What are the different properties of MVC routes?
Web Development
MVC
Asked in
Java Developer Interview
Q15. Java Question
What are some standard Java pre-defined functional interfaces?
Java
Asked in
Java Developer Interview
Q16. OOPS Question
What is Garbage collector in JAVA?
Java
Asked in
Java Developer Interview
Q17. Spring Boot Question
What is dependency Injection?
Web Development
Spring Boot
Asked in
Java Developer Interview
Q18. Java Question
What are the features of a lambda expression?
Java
Asked in
Java Developer Interview
Q19. Hibernate Question
Can you explain what is lazy loading in hibernate?
Hibernate
Asked in
Java Developer Interview
Q20. Java Question
How ConcurrentHashMap works in Java
Java
Asked in
Java Developer Interview
Q21. MVC Question
How is the routing carried out in MVC?
Add your answer
right arrow
Web Development
MVC
Asked in
Java Developer Interview
Q22. Hibernate Question
What is hibernate caching?
Database Management
Hibernate
Asked in
Java Developer Interview
Q23. What is java and what is inheritance and what is oops concepts and what is
method
Ans. Java is an object-oriented programming language. Inheritance is a mechanism to
create new classes based on existing ones. OOPs is a programming paradigm. Method
is a block of code that performs a specific task.
Java is a high-level, class-based, and object-oriented programming language.
Inheritance is a mechanism in which one class acquires the properties and behaviors
of another class.
View 1 answer
right arrow
Java
Asked in
Java Developer Interview
Q24. Technical Question
What do you know about the Secure Socket Layer (SSL) ?
Networking
Asked in
Java Developer Interview
Q25. Hibernate Question
When is merge() method of the hibernate session useful ?
Hibernate
Asked in
Java Developer Interview
Q26. Spring Boot Question
What Are the Basic Annotations that Spring Boot Offers?
Web Development
Spring Boot
Asked in
Java Developer Interview
Q27. What is polymorphism in both overloading and overriding way?
Ans. Polymorphism is the ability of an object to take on multiple forms. It can be
achieved through method overloading and overriding.
Method overloading is when multiple methods have the same name but different
parameters. The compiler decides which method to call based on the arguments
passed.
View 1 answer
right arrow
Asked in
Java Developer Interview
Q28. OOPS Question
Difference between Abstract class and Interface.
Web Development
Asked in
Java Developer Interview
Q30. Technical Question
Explain in brief the role of different MVC components?
Web Development
Asked in
Java Developer Interview
Q31. OOPS Question
How does an exception propagate in the code?
Database Management
Hibernate
Asked in
Java Developer Interview
Q33. Is java object oriented language or not ?
Ans. Yes, Java is an object-oriented language.
Java supports all the features of object-oriented programming such as
encapsulation, inheritance, and polymorphism.
Example: Java's String class is an object that has methods and properties.
Java
Asked in
Java Developer Interview
Q34. Actuator,what is dependency injection, how to change imbeded server in spring
boot,W.A.P permutation of string
Ans. Answering questions related to Actuator, Dependency Injection, changing
embedded server in Spring Boot, and permutation of string.
Actuator is a Spring Boot feature that provides endpoints for monitoring and
managing the application.
To change the embedded server in Spring Boot, you can exclude the default server
dependency and add a new one.
Algorithms
Java
Spring Boot
Asked in
Java Developer Interview
Q35. DBMS Question
What is Self-Join and Cross-Join ?
DBMS
Asked in
Java Developer Interview
Q36. Java Question
Difference b/w Runnable Interface and Callable Interface
Java
Multithreading
Asked in
Java Developer Interview
Q37. Java Question
What is thread starvation?
Java
Asked in
Java Developer Interview
Q38. Hibernate Question
Explain brief about Session interface used in hibernate?
Hibernate
Asked in
Java Developer Interview
Q39. What is java and what is oops concepts and what is inheritance and what is
method
Ans. Java is an object-oriented programming language. OOPs concepts include
inheritance, encapsulation, polymorphism, and abstraction.
Java is a high-level programming language that is platform-independent.
Inheritance is a mechanism in which one class acquires the properties and behaviors
of another class.
Java
Asked in
Java Developer Interview
Q40. What is java and what is method and what is oops concepts and what is method
Ans. Java is an object-oriented programming language. Method is a block of code
that performs a specific task. OOPs concepts are principles of object-oriented
programming.
Java is a high-level programming language that is platform-independent.
Method is a block of code that performs a specific task and can be called multiple
times.
Inheritance allows a class to inherit properties and methods from another ...read
more
Java
Asked in
Java Developer Interview
Q41. MVC Question
Difference b/w View and Partial View
Web Development
MVC
Asked in
Java Developer Interview
Q42. Where should use for constructor injection?
Ans. Constructor injection should be used for mandatory dependencies.
Constructor injection is used to inject mandatory dependencies into a class.
It ensures that the class cannot be instantiated without the required dependencies.
Example: A Car class requires an Engine object to function. The Engine object is
injected via constructor injection.
Software Development
Design Patterns
Asked in
Java Developer Interview
Q43. What are aggregate and terminal operations in java8 streams
Ans. Aggregate operations perform operations on a stream of elements, while
terminal operations produce a result or side-effect.
Aggregate operations include map, filter, reduce, etc.
Java
Asked in
Java Developer Interview
Q44. What is java and what is method and what is oops concepts
Ans. Java is a programming language. Method is a block of code that performs a
specific task. OOPs is a programming paradigm.
Java is an object-oriented programming language used to develop applications and
software.
A method is a block of code that performs a specific task and can be called by
other parts of the program.
Java
Asked in
Java Developer Interview
Q45. Can we use try and finally without catch?
Ans. Yes, try and finally can be used without catch to handle exceptions.
try block is used to enclose the code that may throw an exception
If catch block is not present, exceptions will not be caught and handled
Java
Asked in
Java Developer Interview
Q46. Code in stream api - to find all the numbers less than 10 in a given array
list
Ans. Using stream api to find numbers less than 10 in an array list
Use stream() method on the array list to create a stream of elements
Use filter() method with a lambda expression to filter out numbers less than 10
Collect the filtered elements using collect() method to get the result
Java
Data Structures
Asked in
Java Developer Interview
Q47. Java Question
Difference between save and saveorupdate
Add your answer
right arrow
Java
Hibernate
Asked in
Java Developer Interview
Q48. Java Question
Differentiate between .ear, .jar and .war files.
Java
Asked in
Java Developer Interview
Q49. DBMS Question
Explain the concept of ACID properties in DBMS.
DBMS
Asked in
Java Developer Interview
Q50. What would you rate yourself in java on the scale of 1 to 10?
Ans. I would rate myself as an 8 in Java.
I have extensive experience in Java programming and have successfully completed
multiple projects using Java.
Java
Asked in
Java Developer Interview
Q51. OS Question
Explain any 5 essential UNIX commands .
Operating Systems
Asked in
Java Developer Interview
Q52. Explain project . How encapsulation and abstraction is used in your project
Ans. The project is a web application for managing inventory and sales of a retail
store.
Encapsulation is used to hide the internal implementation details of classes and
only expose necessary methods and properties.
For example, the Product class encapsulates details like name, price, and quantity,
while the InventoryManager class abstracts the ope...read more
Encapsulation
Asked in
Java Developer Interview
Q53. String s1=new String(null); what is the answer
Ans. The code will throw a NullPointerException.
The code tries to create a new String object with a null value, which is not
allowed.
Java
Asked in
Java Developer Interview
Q54. Write a functional interface. Refer it to a Lamda Expression. Show it
practically while explaining each step
Ans. A functional interface is a single abstract method interface. It can be
referred to using a lambda expression.
Functional interfaces have only one abstract method
Java
Asked in
Java Developer Interview
Q55. What is HashMap? While Interating through it is it mutable?
Ans. HashMap is a data structure in Java that stores key-value pairs. It is mutable
while iterating through it.
HashMap is part of the Java Collections Framework.
It provides constant-time performance for basic operations like get and put.
Algorithms
Data Structures
Asked in
Java Developer Interview
Q56. what is collection and collections, what is collection framework?
Ans. Collection is a group of objects, Collections is a utility class, Collection
framework is a set of interfaces and classes for handling collections.
Collection is an interface in Java that represents a group of objects known as
elements.
Collections is a utility class in Java that contains static methods for operating
on collections.
Data Structures
Collection Framework
Asked in
Java Developer Interview
Q57. What are the various annotations used in SpringBoot (explain)
Ans. Various annotations used in SpringBoot
1. @SpringBootApplication: Marks the main class of a Spring Boot application
Web Development
Asked in
Java Developer Interview
Q58. What are Java Generics, Collections, wrapper classes?
Ans. Java Generics are used to create classes, interfaces, and methods that operate
on objects of specified types. Collections are data structures to store and
manipulate groups of objects. Wrapper classes provide a way to use primitive data
types as objects.
Java Generics allow for type-safe operations on objects of specified types.
Example: List list = new ArrayList<>();
Collections provide data structures like List, Set, and Map to store and manipulate
groups of objects. Example:...read more
Java
Asked in
Java Developer Interview
Q59. Explain Final,Finally,Finalize() in Java?
Ans. Final, Finally, Finalize() are keywords in Java used for different purposes.
Final is used to declare a variable as constant.
Java
Asked in
Java Developer Interview
Q60. what is the difference between string and stringbuffer, difference between
throw and throws
Ans. String is immutable while StringBuffer is mutable. throw is used to explicitly
throw an exception, throws is used in method signature to declare exceptions that
can be thrown.
String is immutable, meaning its value cannot be changed once it is created.
StringBuffer is mutable, meaning its value can be changed.
Java
Asked in
Java Developer Interview
Q61. What is difference between Java and C, explain features of java
Ans. Java is a high-level programming language, while C is a low-level language.
Java is platform-independent and has automatic memory management.
Java is an object-oriented language, while C is a procedural language.
Java uses a virtual machine (JVM) for execution, while C directly compiles to
machine code.
Java has built-in garbage collection, while C requires manual memory management.
Java supports multithreading and exception handling, while C has limited support
for these feature...read more
Java
C
Asked in
Java Developer Interview
Q62. OS Question
Explain Piping in Unix/Linux
Operating Systems
Linux
Asked in
Java Developer Interview
Q63. 1.tell me about class loader in java and how it works? 2.Types of operators in
java. etc
Ans. Class loader in Java is responsible for loading classes into memory at
runtime. It follows a delegation hierarchy to find and load classes.
Class loader loads classes into memory dynamically at runtime
Java
Asked in
Java Developer Interview
Q64. What is the jQuery ajax GET request syntax?
Ans. The jQuery ajax GET request syntax is used to send an HTTP GET request to a
server and retrieve data.
Use the $.ajax() method with the 'type' parameter set to 'GET'
jQuery
JavaScript
Web Development
Asked in
Java Developer Interview
Q65. Find the duplicate element in a given array using Java 8 features.
Ans. Find duplicate element in array using Java 8 features.
Convert array to stream using Arrays.stream()
Java
Data Structures
Asked in
Java Developer Interview
Q66. What is Functional Interface? What is Flat Map? What is Method Reference? What
is stream API
Ans. Functional Interface is an interface with only one abstract method. Flat Map
is used to flatten nested collections. Method Reference is a shorthand notation for
lambda expressions. Stream API is used to process collections of objects.
Functional Interface is an interface with a single abstract method, such as
Runnable or Comparator.
Flat Map is a method in Java that is used to flatten nested collections, like List>
to List.
Java
Asked in
Java Developer Interview
Q67. have you worked on spring security then explain ?
Ans. Yes, I have worked on Spring Security. It is a powerful and customizable
authentication and access control framework for Java applications.
Implemented authentication and authorization using Spring Security annotations like
@Secured, @PreAuthorize, @PostAuthorize
Used Spring Security filters for protecting URLs, CSRF protection, session
management, etc.
Static methods in Java belong to the class itself and not to any specific object.
Java allows procedural programming constructs like static variables and methods.
Java
Asked in
Java Developer Interview
Q69. Prerequisites: Payment gateway If your order fails and payment has been
deducted, how do you manage this situation.
Ans. In case of order failure with payment deducted, refund the payment and
investigate the issue.
Initiate refund process for the deducted payment
Java
Spring Boot
Asked in
Java Developer Interview
Q71. Write code to put all the zeroes of an array to the end
Ans. Move all zeroes in an array to the end without changing the order of other
elements.
Iterate through the array and keep track of the index where non-zero elements
should be placed.
After the iteration, fill the remaining positions with zeroes.
Algorithms
Asked in
Java Developer Interview
Q72. What are the different bean scopes in Spring
Ans. The different bean scopes in Spring are singleton, prototype, request,
session, and application.
Singleton scope creates a single instance of a bean per Spring IoC container.
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.
Spring
Asked in
Java Developer Interview
Q73. WAJP to establish a JDBC connection and fetch results from a database and
print those results.
Ans. Establish a JDBC connection and fetch results from a database using Java.
Import the necessary JDBC packages
JDBC
SQL
Asked in
Java Developer Interview
Q74. What is static variables?
Ans. Static variables are variables that belong to the class itself, rather than an
instance of the class.
Static variables are declared using the 'static' keyword.
Static variables are initialized only once, at the start of the program.
They are useful for storing data that is common to all instances of a class.
View 1 answer
right arrow
Asked in
Java Developer Interview
Q75. Coding: Sort list of student details using mark.
Ans. Sort list of student details by mark.
Create a custom class Student with attributes like name, mark.
Add a constructor to the custom exception class to pass a message to the superclass
constructor.
Throw the custom exception using the 'throw' keyword in your code.
Handle the custom exception using try-catch blocks or propagate it up the call
stack.
Software Development
Java
Asked in
Java Developer Interview
Q77. What is transient keyword in Java?
Ans. The transient keyword in Java is used to indicate that a variable should not
be serialized.
Variables marked as transient are not included in the serialization process
Transient variables are not saved when an object is serialized and are set to their
default values when the object is deserialized
Java
Asked in
Java Developer Interview
Q78. What is agile?How it is used in your project?
Ans. Agile is a project management methodology that emphasizes flexibility,
collaboration, and iterative development.
Agile involves breaking down projects into small, manageable tasks called user
stories.
Examples of agile methodologies include Scrum, Kanban, and Extreme P...read more
Agile
Asked in
Java Developer Interview
Q79. java code to explain exceptions using throws and throw
Ans. Using throws and throw in Java to handle exceptions
Use 'throws' to declare an exception in a method signature
Java
Asked in
Java Developer Interview
Q80. what is oops conecpts and give example?
Ans. OOPs concepts refer to Object-Oriented Programming principles like
inheritance, encapsulation, polymorphism, and abstraction.
Inheritance: Allows a class to inherit properties and behaviors from another class.
Example: class Dog extends Animal.
Encapsulation: Bundling data and methods that operate on the data into a single
unit. Example: private variables with public getter and setter methods.
Polymorphism: Ability to present the same interface for different data types.
Example:...read more
They are used in lambda expressions and method references for functional
programming.
Java
Asked in
Java Developer Interview
Q82. Write a program to find the missing element from the array.
Ans. Program to find missing element from array of strings
Iterate through the array and store elements in a HashSet
Iterate through another array and check if each element is present in the HashSet
Algorithms
Asked in
Java Developer Interview
Q83. What are Java8 streams
Ans. Java8 streams are a sequence of elements that support functional-style
operations.
Streams allow for processing sequences of elements in a functional way
Streams are lazy, meaning they only process elements when needed
Java
Asked in
Java Developer Interview
Q84. What is String, collection, multithreading
Ans. String is a sequence of characters. Collection is a group of objects.
Multithreading is executing multiple threads simultaneously.
String is an immutable class in Java.
Multithreading
Asked in
Java Developer Interview
Q85. How to manage during strict deadlines
Ans. Prioritize tasks, break down work into smaller chunks, communicate with team,
utilize time management techniques
Prioritize tasks based on importance and urgency
The JVM looks for the main method to start the execution of the program.
Attempting to run a Java program without a main method will result in a compilation
error.
Java
Asked in
Java Developer Interview
Q87. Difference between list and set
Ans. List is an ordered collection that allows duplicate elements, while Set is an
unordered collection that does not allow duplicates.
List maintains the insertion order of elements, while Set does not guarantee any
specific order.
List allows duplicate elements, while Set does not allow duplicates.
Data Structures
Asked in
Java Developer Interview
Q88. Annotations in @springbootApplication
Ans. Annotations in @SpringBootApplication are used to configure the Spring Boot
application.
Annotations like @SpringBootApplication are used to enable auto-configuration and
component scanning in a Spring Boot application.
Java
Spring Boot
Asked in
Java Developer Interview
Q89. Is Java pass by value or by reference
Ans. Java is pass by value
Java is pass by value, meaning a copy of the variable is passed to a method
Changes made to the copy inside the method do not affect the original variable
Java
Asked in
Java Developer Interview
Q90. what is microservices ,how its works
Ans. Microservices are a software development technique where an application is
composed of small, independent services that communicate with each other.
Microservices break down a large application into smaller, loosely coupled services
Each service is responsible for a specific function and can be developed, deployed,
and scaled independently
Microservices
Asked in
Java Developer Interview
Q91. What is comparator annotation in Java?
Ans. Comparator annotation in Java is used to define custom sorting logic for
objects.
Comparator annotation is used to define custom sorting logic for objects in Java.
Java
Asked in
Java Developer Interview
Q92. Features of java 8,oops,Custom Exception ,Collections
Ans. Java 8 introduced new features like lambda expressions and streams, OOPs
concepts include inheritance and polymorphism, custom exceptions allow for user-
defined exceptions, and collections provide data structures like lists and maps.
Java 8 features include lambda expressions and streams
Java
Data Structures
Asked in
Java Developer Interview
Q93. what is serialization, deserialization, transient
Ans. Serialization is the process of converting an object into a byte stream,
deserialization is the reverse process. 'transient' keyword is used to exclude a
field from serialization.
Serialization is used to persist object state or transmit objects over a network
The 'transient' keyword in Java is used to indicate that a field should not be
serialized
Java
Data Structures
Asked in
Java Developer Interview
Q96. Write code to demonstrate the flow of Spring MVC
Ans. Demonstrate the flow of Spring MVC through code
Create a controller class with request mapping annotations
Spring MVC
Web Development
Asked in
Java Developer Interview
Q97. Difference btw string builder, and buffer
Ans. String Builder is not synchronized, while String Buffer is synchronized.
String Builder is faster than String Buffer because it is not synchronized.
Use String Builder when you do not need thread safety, and String Buffer when you
do.
Java
Asked in
Java Developer Interview
Q98. diffrenece between interafce and abstract class
Ans. Interface is a blueprint for classes to implement, while abstract class can
have both abstract and concrete methods.
Interface can only have abstract methods and constants, while abstract class can
have abstract and concrete methods.
A class can implement multiple interfaces but can only extend one abstract class.
It identifies frequently executed code and compiles it into native code for faster
execution.
JIT compilation occurs during the execution of the program, unlike ahead-of-time
compi...read more