0% found this document useful (0 votes)
6 views

Complete_Java_Interview_Questions

The document contains a series of Java and Spring Boot interview questions along with their answers, covering topics such as dependency injection, DAO design pattern, core Java concepts, object-oriented programming, and output-based questions. Each question is graded based on difficulty from basic to advanced. The document serves as a comprehensive guide for interview preparation in Java and Spring Boot.

Uploaded by

Sarah Ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Complete_Java_Interview_Questions

The document contains a series of Java and Spring Boot interview questions along with their answers, covering topics such as dependency injection, DAO design pattern, core Java concepts, object-oriented programming, and output-based questions. Each question is graded based on difficulty from basic to advanced. The document serves as a comprehensive guide for interview preparation in Java and Spring Boot.

Uploaded by

Sarah Ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Java and Spring Boot Interview Questions

Spring Boot Questions


1. Q: How is dependency injection implemented in Spring Boot?

A: Dependency injection in Spring Boot is implemented using annotations like


@Autowired, @Component, @Service, and @Repository.
Grade: Intermediate
2. Q: What is the purpose of @SpringBootApplication?

A: @SpringBootApplication is a convenience annotation combining @Configuration,


@EnableAutoConfiguration, and @ComponentScan.
Grade: Basic

DAO Design Pattern Questions


3. Q: What is the DAO Design Pattern?

A: The DAO pattern is a structural pattern used to separate persistence logic from
business logic, providing an interface to access data.
Grade: Basic
4. Q: What are the key benefits of using the DAO Pattern?

A: Benefits include separation of concerns, ease of testing, flexibility in data source


changes, and reusability.
Grade: Intermediate

Core Java Questions


5. Q: What is the difference between String, StringBuilder, and StringBuffer?

A: String is immutable, StringBuilder is mutable and not thread-safe, and


StringBuffer is mutable and thread-safe due to synchronized methods.
Grade: Intermediate
6. Q: What are Java annotations, and how are they used?

A: Annotations provide metadata for code without affecting its execution. Built-in
annotations include @Override, @Deprecated, and @SuppressWarnings. Custom
annotations can be created using @interface.
Grade: Intermediate

C2 General
7. Q: What is the difference between Checked and Unchecked exceptions?

A: Checked Exceptions must be declared or handled in code using throws or try-


catch (e.g., IOException). Unchecked Exceptions do not require explicit handling
(e.g., NullPointerException).
Grade: Intermediate
8. Q: What is the difference between ArrayList and LinkedList?

A: ArrayList is backed by a dynamic array, making it fast for random access but
slower for insertions/deletions. LinkedList is backed by a doubly-linked list, making
it fast for insertions/deletions but slower for random access.
Grade: Intermediate
9. Q: What is the purpose of the final, finally, and finalize keywords?

A: final is used for constants, immutable classes, or preventing method/variable


overriding. finally ensures code execution in a try-catch block, regardless of
exceptions. finalize is a method invoked by the garbage collector before object
removal (deprecated in newer Java versions).
Grade: Intermediate

Object-Oriented Programming (OOP) Questions


10. Q: What is the purpose of the super keyword in Java?

A: The super keyword refers to the immediate parent class of the current object. It
can be used to call parent class methods and constructors.
Grade: basic
11.Q: What is the difference between abstract classes and interfaces in Java?

A: Abstract classes can have both abstract and concrete methods, while interfaces
can only have abstract methods (before Java 8). Java 8 allows default methods in
interfaces.
Grade: Basic
12.Q: What is the purpose of this keyword in Java?

A: The this keyword refers to the current instance of the class and is used to refer to
instance variables, methods, and constructors.
Grade: Basic
13.Can a static method be overridden in Java?

C2 General
A: No, a static method cannot be overridden in Java. Overriding applies to instance
methods (methods bound at runtime), Static methods are bound at compile time based
on the class type.

Grade: Advance
14.Q: Explain the concept of final in OOP.

A: final variables cannot be reassigned, final methods cannot be overridden, and


final classes cannot be subclassed.
Grade: Intermediate
15.Q: What is the difference between public, private, protected, and default
access modifiers in Java? Can access modifiers applied to classes?

A: public is accessible from anywhere, private is accessible only within the same
class, protected is accessible within the same package and by subclasses, default is
accessible only within the same package. We are allowed to use only “public” or
“default” access modifiers with java classes
Grade: Intermediate
16.Q: What is the significance of instanceof operator in Java?

A: instanceof is used to check whether an object is an instance of a specific class or


implements a particular interface.
Grade: Advanced
17.Q: What is an inner class in Java?

A: An inner class is a class defined within another class. It can be a member class,
static nested class, or anonymous class.
Grade: Intermediate
What happen if a constructor is private?
A: prevent creation of objects outside the class , used in the Singleton design pattern
where the constructor is private and the class return the current class instance to be
used.
Can this and super be added inside static methods?
A: this cannot be used in static methods because static methods are not tied to an instance.
super can be used in static methods, but it refers to the superclass's static members and not
the instance.

C2 General
Q:Can you achieve Runtime Polymorphism by data members?
A: No, because method overriding is used to achieve runtime polymorphism and
data members cannot be overridden. We can override the member functions but not
the data members.
Grade: Advance

Output-Based Questions

18. Q: What is the output of the following code?

A: 20. because obj1 and obj2 both refer to the same object in memory
19. Q: What is the output of the following code?

C2 General
A: The output is 'Child'. This demonstrates runtime polymorphism where the
overridden method in the subclass is invoked.
Grade: Basic
20. Q: What is the output of the following code

A: The output is '2 3 3'. The array is modified in the loop based on index computation.

21. What is the output of the following code

Output: A's Constructor


B's Constructor

C2 General
Explanation: The constructor of the parent class is always called first when creating a
subclass object.

What is the output of this code

Output: Hello

Explanation: Strings in Java are immutable. The + operation creates a new string, and s2 still
points to the original s1.

What is the output of the following:

C2 General
Output: 2

Explanation: Since the equals method is not overridden, two keys with the same id are
treated as different objects.

What is the output?

A: Static block executed

Static method executed

Regular method executed

The static block is executed first, when the class is loaded by the JVM. This happens even
before the main method starts executing, because the static block is part of the class
initialization process.

The static method staticMethod() is executed next, as it is explicitly called inside the main
method. Static methods belong to the class itself and can be invoked without creating an
object of the class.

C2 General
Regular Method:The regular method regularMethod() is executed last. To call this instance
method, an object of the class (obj) must first be created. Once the object is created, the
instance method is called using the object reference.

C2 General

You might also like