[go: up one dir, main page]

0% found this document useful (0 votes)
16 views41 pages

Java Interview PDF

Uploaded by

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

Java Interview PDF

Uploaded by

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

JAVA

INTERVIEW

2026
youtube.com/@teknouf
UBK ANNA
1 . L I S T E N C A R E F U L LY
PAY C L O S E AT T E N T I O N T O T H E Q U E S T I O N .
I F U N C L E A R , A S K F O R C L A R I F I C AT I O N B E F O R E S TA R T I N G .

2. THINK ALOUD
S H A R E Y O U R T H O U G H T P R O C E S S S T E P - B Y- S T E P S O T H E
I N T E R V I E W E R U N D E R S TA N D S Y O U R A P P R O A C H .
EVEN IF THE FINAL ANSWER IS WRONG, A GOOD APPROACH
CAN STILL IMPRESS.

3 . S TA R T S I M P L E
B E G I N W I T H T H E M O S T S T R A I G H T F O R WA R D S O L U T I O N .
T H E N D I S C U S S P O S S I B L E O P T I M I Z AT I O N S I F T I M E P E R M I T S .

4 . H A N D L E M I S TA K E S G R A C E F U L LY
I F Y O U G E T S T U C K , E X P L A I N W H AT Y O U ’ R E T RY I N G A N D W H Y
IT’S NOT WORKING.
S M A L L C O R R E C T I O N S A R E F I N E — S H O W P R O B L E M - S O LV I N G
S K I L L S , N O T PA N I C .

5. SHOW CONFIDENCE
M A I N TA I N G O O D P O S T U R E , M A K E E Y E C O N TA C T, A N D S P E A K
C L E A R LY.
AV O I D F I L L E R W O R D S L I K E " U M M " A N D " I T H I N K " — R E P L A C E
W I T H " I N M Y U N D E R S TA N D I N G . . . " .

6. ASK BEFORE USING SHORTCUTS


I F Y O U WA N T T O U S E I N B U I LT F U N C T I O N S , C O N F I R M I F I T ’ S
ALLOWED.
S O M E I N T E R V I E W S P R E F E R A M A N U A L I M P L E M E N TAT I O N .

7 . E N D W I T H A S U M M A RY
ONCE DONE, EXPLAIN YOUR FINAL APPROACH, TIME
C O M P L E X I T Y, A N D W H Y I T W O R K S .
T H I S S H O W S Y O U U N D E R S TA N D B O T H I M P L E M E N TAT I O N A N D
E F F I C I E N C Y.
1. What is the difference between JDK, JRE, and
JVM?

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
2. Why java is platform independent?

Java is considered platform-independent because of its "write once,


run anywhere" capability. This means that you can write Java code on

F
one operating system and run it on any other operating system without
modification. Here's how it works:

U
1. Java Source Code: You write your Java program in a text file using
the Java programming language. This is called the source code.

2. Java Compiler: The source code is then compiled by the Java


O
compiler (javac). Instead of translating the source code directly into
machine code (which is specific to an operating system), the Java
compiler translates it into an intermediate form called bytecode. This
KN
bytecode is stored in a file with a `.class` extension.

3. Java Bytecode: The bytecode is not specific to any particular type


of computer or operating system. It's a universal code that can be
understood by any Java Virtual Machine (JVM).
TE

4. Java Virtual Machine (JVM): The JVM is a special program that


runs on your computer. There are different JVMs for different operating
systems (Windows, Mac, Linux, etc.), but they all understand and can
execute Java bytecode.

When you run a Java program, the JVM interprets the bytecode and
translates it into machine code that your computer's operating system
can understand. Since the JVM handles the platform-specific details,
the same Java bytecode can run on any operating system that has a
compatible JVM.
In summary:
- Write once: You write and compile your Java program into bytecode.
- Run anywhere: Any computer with a JVM can run your bytecode,
regardless of the underlying operating system.

F
Java is Platform Independent and JVM Is platform dependent.

U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
3. What is the difference between String,
StringBuilder, and StringBuffer?

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
4. What is string Pool ?

The string pool is a special memory area in Java where string literals
are stored. When you create a string literal (e.g., String s =

F
"hello";), Java checks the string pool first. If the string already
exists, it reuses the existing string. If not, it adds the new string to the
pool. This helps save memory because identical strings are shared

U
rather than duplicated.

O
KN
TE
5. Explain Constructor and Types of Constructor

Constructor in Java

F
A constructor in Java is a special method used to initialize objects. It is
called when an instance of a class is created. The constructor has the
same name as the class and does not have a return type.

U
Types of Constructors

1. Default Constructor
O
- A constructorwith noparameters.
- If no constructor is defined in a class, Java provides a default
constructor automatically.
KN
- Used to initialize objects with default values.

2. Parameterized Constructor
- Aconstructor that takes one or more parameters.
- Allows you to provide different values while creating an object.
TE

- Used to initialize objects with custom values.

These constructors help ensure that objects are properly initialized


before they are used in your program.

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
6. Explain OOPS Concepts in Java

Encapsulation : Encapsulation means binding of data (attributes) and methods


(behaviors) that operate on the data into a single unit, called a class. This helps keep
the implementation details hidden from the outside world, allowing for better

F
organization and security.

By encapsulation we can keep data related to two different Department separate.For

U
example in a company there are two department Sales and Accounts. So here sales
data and people are separate from Accounts data and people.

Abstraction : Abstraction means showing only the necessary details to user and
hiding the implementation of it.
O
For example : We use ATM , we just press some buttons and cash comes out , but we
dont know what actually is happening behind machine.
KN
Polymorphism : It means existing in various forms . Two important types of
Polymorphism is discussed later in this pdf.

Inheritance : Inheritance is a way to create new classes based on existing ones. It


allows a new class (called a derived class or subclass) to inherit properties and
behaviors from an existing class (called a base class or superclass). This promotes
TE

code reuse and helps establish a hierarchy of classes.

For all materials


Must visit - topmate.io/tekno_uf/
7. What are Interfaces in Java ? Why static and
default methods were introduced in Java 8

Interfaces in Java provide a way to define a contract for classes. They

F
contain only method signatures (without implementations) and
constants. Classes that implement an interface must provide
implementations for all the methods declared in the interface.

U
We use interfaces to achieve abstraction and provide a common way
for classes to interact without worrying about the specific
implementation details. They allow us to define a set of methods that
O
classes must implement, ensuring consistency and interoperability in
our code.
KN
Static and default methods were introduced in Java 8 to enhance the
functionality of interfaces:

Static methods in interfaces allow us to define methods that belong to


the interface itself, rather than to individual implementing classes.
TE

These methods can be called directly on the interface without the need
for an implementing class instance.

Default methods in interfaces provide a way to add new methods to


existing interfaces without breaking compatibility with implementing
classes. These methods have a default implementation in the interface
itself, which can be overridden by implementing classes if needed.

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
8. What is the difference between abstract class
and interface in Java?

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
9. Explain Different Types of Interfaces

Marker Interface:

F
A Marker Interface, also known as a tag interface, is an interface that
doesn't declare any methods. It simply marks (or tags) a class to
provide some information to the compiler or runtime environment.

U
Classes that implement marker interfaces indicate that they possess
certain characteristics or capabilities.
Examples of marker interfaces in Java include Serializable, Cloneable,
and Remote.
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
Functional Interface:
AFunctionalInterface is an interface that contains only one abstract
method (SAM), though it can have multiple default or static methods.
FunctionalInterfaces are used to enable functional programming in
Java

F
Java 8introduced the @FunctionalInterface annotation to explicitly
mark aninterface as a functional interface.

U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
10. What are Access Modifiers in Java?

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
11. Difference Bw Method Overloading and
Method Overriding

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
Overload example

F
U
O
KN
Override Example
TE

For all materials


Must visit - topmate.io/tekno_uf/
12. Explain Final , static and super Keyword In
Java`

Final Keyword

F
Final Variable:A variable declared as final cannot be changed once it

U
is assigned.

Final Method: A method declared as final cannot be overridden by


subclasses.
O
Final Class: A class declared as final cannot be subclassed.
static Keyword
KN
Static Keyword

Static Variable : A variable declared as static belongs to the class


ratherthaninstances of the class.
TE

Static Method: A method declared as static belongs to the class and


can be called without creating an instance of the class.

Static Block: A block of code that is used to initialize static variables


and is executed when the class is loaded.

For all materials


Must visit - topmate.io/tekno_uf/
Super Keyword

Access Superclass Method: The super keyword is used to call a

F
method from the superclass.

U
Access Superclass Variable: The super keyword is used to access a
variable from the superclass.

Call Superclass Constructor: The super keyword is used to call a


O
constructor from the superclass.
KN
TE
13. Explain Concept of Multithreading in java

Definition:
Multithreading is a programming technique that allows multiple threads

F
to run concurrently within a single program. Each thread runs a
separate path of execution, enabling the program to perform multiple
tasks simultaneously.

U
Key Concepts:
Thread: A thread is a lightweight subprocess, the smallest unit of
processing. It has its own call stack but shares resources with other
threads in the same process.
O
Main Thread: When a Java application starts, the JVM creates a main
KN
thread to execute the main method.

Creating Threads: In Java, threads can be created in two main ways:


By extending the Thread class.
TE

By implementing the Runnable interface.

Advantages:
Concurrency: Multiple threads can run concurrently, making efficient
use of CPU resources.

Improved Performance: Multithreading can improve the performance


of applications by allowing tasks to run in parallel, reducing execution
time.
Responsiveness: In GUI applications, multithreading keeps the user
interface responsive by performing time-consuming tasks in the
background.

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
14. Explain synchronised Keyword in java
The synchronized keyword in Java is used to control access to a
block of code or a method by multiple threads. It ensures that only one
thread can execute the synchronized block or method at a time, which
helps to prevent thread interference and consistency problems.

F
U
Synchronized Method: When a method is declared as
synchronized, only one thread can execute that method on the
same object instance at any given time.
O
Synchronized Block: You can also synchronize a specific block of
code inside a method. This gives more control and can reduce the
overhead of synchronization by limiting it to only the critical section of
KN
the code.
TE

For all materials


Must visit - topmate.io/tekno_uf/
15. What are errors and Exceptions?

F
U
16. What are wrapper classes?
O
Wrapper classes in Java are used to convert primitive data types into
objects. In Java, primitive types like int, float, char, etc., are not
KN
objects. Wrapper classes like Integer, Float, Character, etc.,
provide a way to treat primitive types as objects. This allows you to use
them in places where objects are required, like in collections (e.g.,
ArrayList) or when working with Java generics.
TE

Output for both is 10


17. Explain Optional Classes In Java

Definition:
The Optional class in Java is a container object which may or may not

F
contain a non-null value. It is used to avoid null checks and prevent
NullPointerException.

U
Purpose:
Avoid NullPointerException: Provides a safer way to handle
potentially null values.
O
ExpressIntention: Clearly indicates that a value might be absent.
Basic Methods:
KN
Common Methods
isPresent(): Checksif a value is present.

ifPresent(Consumer): Executes a code block if a value is present.


TE

orElse(T other): Returns the value if present, otherwise returns the


default value.

orElseGet(Supplier): Returns the value if present, otherwise invokes


a supplier function.

orElseThrow(Supplier): Returns the value if present, otherwise


throws an exception.

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
18. Explain Stream Apis in Java

Definition: Stream APIs in Java provide a modern way to process


collections of objects. They allow you to perform operations like

F
filtering, mapping, and reducing in a more readable and concise way.

U
Key Features:
Declarative:Allowsyou to write concise and readable code.

Chained Operations:Supports method chaining for operations.


O
Lazy Evaluation:Operations are not executed until a terminal
operation is called.
KN

Common Operations:
filter:Selectselementsbased on a condition.

map: Transforms elements.


TE

collect:Convertsthestream back to a collection.

forEach: Iterates over elements.

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
19. Explain Lambda Function In Java

Lambda functions in Java are a way to define and pass around blocks
of code. They are anonymous functions that can be used as method

F
arguments or to create concise implementations of functional
interfaces. Here's a simple explanation with an example:

U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
20. Date Time Api In Java

The Date Time API in Java, introduced in Java 8, provides classes to


handle dates, times, and durations.

F
Key Points:
The Date Time API provides immutable and thread-safe classes for

U
date and time manipulation.

It supports operations such as addition, subtraction, comparison,


formatting, and parsing of dates and times.
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
21. Diff bw Comparator and Comparable

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
22. Explain Internal Working of Hashmap

Overview: HashMap is a data structure that stores key-value pairs and


provides constant-time performance for basic operations like get and

F
put. It uses an array of buckets to store the key-value pairs and a
hashing mechanism to determine the index of each key-value pair in
the array.

U
Hashing Mechanism:
Whenyou put a key-value pair into a HashMap, the key is hashed to
generate a hash code.
O
The hash code is then mapped to an index in the array using a hashing
function.
This index is the location where the key-value pair will be stored.
KN

Handling Collisions:
Collisions occurwhen two different keys hash to the same index.
To handle collisions, HashMap uses a linked list (or a tree in Java 8
and later versions) at each bucket to store multiple key-value pairs that
TE

hash to the same index.

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
23. What is TreeMap and LinkedHashmap

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
24. Explain Collection Framework in Java

Definition:
TheCollection Framework in Java is a unified architecture for

F
representing and manipulating collections of objects. It consists of
interfaces, implementations, and algorithms to work with collections
efficiently.

U
Key Components:
Interfaces: Core interfaces like List, Set, Queue, and Map define
commonbehavior for different types of collections.
O
Implementations: Concrete classes like ArrayList, HashSet,
LinkedList, and HashMap provide specific implementations of the
KN
collection interfaces.

Algorithms: The framework includes algorithms for searching, sorting,


and manipulating collections, making it easy to perform common tasks.
TE

For all materials


Must visit - topmate.io/tekno_uf/
F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
25. Difference Bw ArrayList and Linked List

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
26. Explain the difference between the throw and
throws keywords in Java.

F
U
O
KN
TE

For all materials


Must visit - topmate.io/tekno_uf/
27. Difference between == and .equals Method in
java.

F
U
O
KN
TE
28. Explain Public Static Void Main

"public static void main" is a special line in Java programming. Here's


what it means:

F
public : It means that this method (which is a block of code in Java)

U
can be accessed from anywhere in the program.
static : This means the method belongs to the class itself, rather than
any particular instance (object) of the class.
void : It means the method doesn't return any value after it is done
running. O
main : This is the name of the method. It's a special name because it's
where the Java program starts running.
KN
So, when you write `public static void main(String[] args)`, you're telling
Java that this is the starting point of your program.
TE

29. What is the meaning of import java.util.*


import java.util.*; essentially means that you want to use any
classes or interfaces from the java.util package without specifying
each one individually. This helps keep your code cleaner and more
readable by grouping similar functionalities together from different
packages.

You might also like