0% found this document useful (0 votes)
7 views6 pages

Top 20 Java Interview Questions & Answers

The document provides a comprehensive list of Java interview questions and answers, covering key concepts such as OOP principles, JVM, JRE, JDK, inheritance, polymorphism, and exception handling. It also distinguishes between various Java components like ArrayList and LinkedList, and explains the use of keywords like static and final. The content is aimed at helping candidates prepare for Java-related interviews, particularly for Cognizant GenC 2025.

Uploaded by

fakezomato6
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)
7 views6 pages

Top 20 Java Interview Questions & Answers

The document provides a comprehensive list of Java interview questions and answers, covering key concepts such as OOP principles, JVM, JRE, JDK, inheritance, polymorphism, and exception handling. It also distinguishes between various Java components like ArrayList and LinkedList, and explains the use of keywords like static and final. The content is aimed at helping candidates prepare for Java-related interviews, particularly for Cognizant GenC 2025.

Uploaded by

fakezomato6
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

[Link]

com/DebugWithShubham

[Link]

Cognizant GenC
[Link]

[Link]

[Link]
Cognizant GenC 2025

TOP- 20 JAVA

Interview
Question
With
Answers

By- Shubham Maurya


Q1. What is Java? Why is it platform independent?
Answer:
Java is a high-level, object-oriented programming language.
Java platform independent hai kyun ki code bytecode me convert hota hai jo JVM pe run hota
hai

One-liner:
Write once, run anywhere.

Q2. What is JVM, JRE, and JDK?


Answer:

JVM → Java Virtual Machine (runs bytecode)

JRE → JVM + libraries (to run Java programs)

JDK → JRE + development tools (to develop programs)

Q3. What is OOPs? Explain its pillars.


Answer:
OOPs organizes code using objects.

4 pillars:

-Encapsulation

-Abstraction

-Inheritance

-Polymorphism

Q4. What is Class and Object?


Answer:
-Class → Blueprint

-Object → Instance of class

Example:
class Car {}
Car c = new Car();

Q5. Di erence between == and equals()


Answer:
== → compares reference
equals() → compares content/value
ff
Q6. What is Constructor? Types?
Answer:
Constructor is a special method used to initialize objects.

Types:

-Default constructor

-Parameterized constructor

-Constructor name = class name.

Q7. What is Inheritance?


Answer:
Inheritance allows a class to acquire properties of another class using extends.

Bene ts:

-Code reuse

-Maintainability

Q8. What is Polymorphism?


Answer:
Polymorphism means one method, multiple behaviors.

Types:

-Compile-time (Method Overloading)

-Runtime (Method Overriding)

Q9. Di erence between Method Overloading and Overriding


Overloading Overriding
Same class Parent–Child class
Compile-time Runtime
Di erent parameters Same method signature

Q10. What is Abstraction?


Answer:
Abstraction hides internal details and shows only essential features.

Achieved using:

-Abstract class

-Interface
fi
ff
ff
Q11. Interface vs Abstract Class
Abstract Class Interface
Can have method body Only abstract methods (Java 7)
Supports constructor No constructor
Single inheritance Multiple inheritance

Q12. What is Encapsulation?


Answer:
Encapsulation binds data and methods together and protects data using access modi ers.

Example:
Private variables + public getters/setters

Q13. What are access modifiers in Java?


Answer:

-public

-private

-protected

-default

Controls visibility of data.

Q14. What is Exception Handling?


Answer:
Used to handle runtime errors using:

try
catch
nally
throw
throws

Example:

try {
int a = 10/0;
} catch(Exception e) {
[Link]("Error");
}

Q15. Checked vs Unchecked Exception


Checked Unchecked
Compile-time Runtime
IOException NullPointerException
fi
Q16. What is ArrayList vs LinkedList?
ArrayList LinkedList
Fast access Fast insertion/deletion
Uses array Uses nodes

Q17. What is String, StringBu er, StringBuilder?


String StringBu er. StringBuilder
Immutable Mutable. Mutable.
Thread-safe (NO) Thread-safe (YES) Thread-safe (NO)

Q18. What is static keyword?


Answer:
Static members belong to class, not object.

Used for memory management.

Q19. What is final keyword?


Answer:
nal variable → value cannot change

nal method → cannot override

nal class → cannot inherit

Q20. Why Java is preferred in enterprise applications?


Answer:
Because Java is secure, scalable, platform-independent, and has strong community support
fi
fi
fi
ff
ff

You might also like