High Occurrence
1. What is
2. OOP?
Answer:
OOP (Object-Oriented Programming) is a paradigm that organizes software
design around data, or objects, rather than functions and logic. The primary
concepts of OOP include:
Encapsulation: Grouping data (attributes) and methods (functions)
that operate on the data within one unit (class).
Abstraction: Hiding complex implementation details and exposing
only the necessary functionality.
Inheritance: Mechanism where one class can inherit properties and
methods of another class.
Polymorphism: The ability to perform the same operation on different
classes, with each class providing its own implementation of the
method.
2. What is the difference between Checked and Unchecked
exceptions?
Answer:
Checked Exceptions: These are exceptions that are checked at
compile-time. The programmer is required to handle them (using try-
catch blocks or declaring them with throws), otherwise, the program
will not compile. Examples: IOException, SQLException.
Unchecked Exceptions: These are exceptions that occur during
runtime and are not required to be handled or declared. They inherit
from RuntimeException. Examples: NullPointerException,
ArrayIndexOutOfBoundsException.
3. What methods in the Object class do you know?
Answer:
The Object class in Java is the root of the class hierarchy. It provides several
methods, including:
clone(): Creates and returns a copy of the object.
equals(Object obj): Compares the current object with another object for
equality.
hashCode(): Returns a hash code value for the object.
toString(): Returns a string representation of the object.
getClass(): Returns the runtime class of the object.
notify(), notifyAll(), wait(): Used for thread synchronization (used in
multi-threading).
4. Tell me about the hierarchy of exceptions.
Answer:
Java exceptions are organized into a hierarchy:
Throwable (root class)
o Error (serious errors that can't be handled, e.g.,
OutOfMemoryError)
o Exception (used for exceptional conditions that can be handled)
RuntimeException (unchecked exceptions)
IOException, SQLException, etc. (checked exceptions)
5. What is SOLID?
Answer:
SOLID is a set of five design principles intended to improve the
maintainability and flexibility of object-oriented software. These principles
are:
S: Single Responsibility Principle (SRP) – A class should have only
one reason to change.
O: Open/Closed Principle (OCP) – Software entities should be open
for extension but closed for modification.
L: Liskov Substitution Principle (LSP) – Objects of a superclass
should be replaceable with objects of a subclass without affecting the
program’s functionality.
I: Interface Segregation Principle (ISP) – Clients should not be
forced to depend on interfaces they do not use.
D: Dependency Inversion Principle (DIP) – High-level modules
should not depend on low-level modules. Both should depend on
abstractions.
6. Tell me about the hierarchy of collections in Java.
Answer:
The hierarchy of collections in Java is as follows:
Collection (root interface)
o List (ordered, allows duplicates)
ArrayList, LinkedList, Vector, etc.
o Set (unordered, no duplicates)
HashSet, TreeSet, LinkedHashSet
o Queue (ordered, typically FIFO)
LinkedList, PriorityQueue
o Map (key-value pairs, not a subclass of Collection)
HashMap, TreeMap, LinkedHashMap
7. What is the difference between the interface and the abstract
class?
Answer:
Interface: Defines a contract (set of methods) that classes must
implement. A class can implement multiple interfaces. It cannot have
implementation (except default methods in Java 8+).
Abstract Class: Can have both abstract (unimplemented) and
concrete (implemented) methods. A class can only extend one abstract
class but can implement multiple interfaces.
8. What is the difference between LinkedList and ArrayList?
Answer:
ArrayList: Uses a dynamic array to store elements. It provides fast
random access but slow insertion/deletion (O(n) in worst case).
LinkedList: Uses a doubly-linked list to store elements. It provides fast
insertion/deletion (O(1)) but slower random access (O(n)) compared to
ArrayList.
9. Tell me about Hashcode and Equals Contract.
Answer:
The hashCode() and equals() methods are crucial for comparing objects and
ensuring consistency in hash-based collections like HashMap and HashSet.
The contract is as follows:
If two objects are equal according to the equals() method, they must
have the same hash code.
If two objects have the same hash code, they may or may not be equal
according to the equals() method.
10. What is the difference between a primitive and a reference type
of data?
Answer:
Primitive Types: Basic data types in Java like int, char, double,
boolean, etc. They hold their actual value.
Reference Types: Types that store references (memory addresses) to
objects. Examples include arrays, classes, interfaces, etc. They point to
objects in memory.
11. How HashMap is organized?
Answer:
A HashMap in Java is organized using an array of buckets (or entries). Each
bucket corresponds to a hash code generated from the key. When inserting
an entry, the key's hash code determines which bucket the entry should be
placed in. If multiple keys hash to the same bucket, a linked list or a
balanced tree is used to store the entries.
12. What is your experience in programming?
Answer:
This is a subjective question. You should explain your hands-on experience
with Java and other programming languages, tools, libraries, frameworks,
and any relevant projects you have worked on.
13. What do you know about the Object class?
Answer:
The Object class is the root class of the Java class hierarchy. Every class
inherits from it, either directly or indirectly. Some important methods of the
Object class include toString(), equals(), hashCode(), clone(), and getClass().
14. What are the principles of OOP?
Answer:
The principles of OOP are:
Encapsulation
Abstraction
Inheritance
Polymorphism
15. What is ACID?
Answer:
ACID is a set of properties that guarantee reliable processing of database
transactions:
Atomicity: Ensures that all operations in a transaction are completed;
if not, the transaction is aborted.
Consistency: Ensures that a transaction brings the database from one
valid state to another.
Isolation: Ensures that the operations of a transaction are isolated
from other transactions.
Durability: Ensures that the changes made by a transaction are
permanent, even in case of a system failure.
16. What is Stream in Java?
Answer:
A Stream in Java (introduced in Java 8) is an abstraction that allows
processing sequences of elements (such as collections) in a functional style.
It supports operations like map, filter, reduce, etc., and can operate on both
ordered and unordered data sources.
17. What Spring Scopes do you know?
Answer:
Spring provides the following scopes for beans:
Singleton: A single instance of the bean for the entire application.
Prototype: A new instance of the bean each time it is requested.
Request: A new bean instance is created for each HTTP request (Web
apps).
Session: A new bean instance is created for each HTTP session (Web
apps).
Application: A single bean instance for the entire application context.
WebSocket: A new bean instance for each WebSocket connection.
18. What is a functional interface?
Answer:
A Functional Interface in Java is an interface that has exactly one abstract
method. These interfaces can have multiple default or static methods.
Functional interfaces are used as the basis for lambda expressions in Java.
An example is Runnable, Callable, and Comparator.