Basic Java Viva Questions
1. What is Java?
2. What are the features of Java?
3. What is the difference between JDK, JRE, and JVM?
4. What are the different data types in Java?
5. What is the default value of an int variable in Java?
6. What is the difference between == and .equals()?
7. What is type casting in Java?
8. What are access specifiers?
9. What is the difference between private, protected, public, and default access?
10. What is the use of the static keyword?
11. What is the main() method? Why is it public static void main(String[] args)?
12. What is the difference between break and continue?
13. What is the use of the final keyword?
14. What is a constructor? Types of constructors?
15. Can we overload constructors?
16. What is method overloading and overriding?
17. What is the difference between this and super?
18. What is inheritance? Types of inheritance in Java?
19. What is polymorphism?
20. What is encapsulation?
Object-Oriented Concepts
1. Explain the four pillars of OOP.
2. What is abstraction? How is it implemented in Java?
3. What is an abstract class?
4. What is an interface? How is it different from an abstract class?
5. Can Java support multiple inheritance? How?
6. What is the difference between a class and an object?
7. What is the use of instanceof operator?
8. What is the difference between is-a and has-a relationship?
Advanced Topics
1. What is exception handling in Java?
2. What are try, catch, finally, throw, and throws?
3. What is the difference between checked and unchecked exceptions?
4. What is a package? How to import a package?
5. What is a thread in Java? How do you create one?
6. What is the difference between Runnable and Thread class?
7. What are synchronized blocks and methods?
8. What is the lifecycle of a thread?
9. What is garbage collection in Java?
10. How does the finalize() method work?
Collections and Arrays
1. What is the difference between an array and an ArrayList?
2. What is the Java Collection Framework?
3. Difference between List, Set, and Map?
4. What is the difference between HashMap and Hashtable?
5. What is the difference between ArrayList and LinkedList?
6. What is the difference between Iterator and ListIterator?
File Handling and I/O
1. How to read and write files in Java?
2. What are InputStream and OutputStream?
3. What is serialization in Java?
4. What is the use of File class in Java?
Miscellaneous
1. What is JDBC? How does it work?
2. What are the different types of JDBC drivers?
3. What is the use of transient keyword?
4. What is StringBuffer and StringBuilder?
5. Difference between String, StringBuffer, and StringBuilder?
6. What is the difference between == and .equals() for strings?
7. What is autoboxing and unboxing?
8. Can we make a class immutable? How?
Basic Java Viva Questions with Answers
1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language
developed by Sun Microsystems.
2. Features of Java?
o Object-Oriented
o Platform Independent (via JVM)
o Secure
o Robust
o Multithreaded
o Portable
3. Difference between JDK, JRE, and JVM?
o JDK: Java Development Kit (includes JRE + tools to develop Java apps)
o JRE: Java Runtime Environment (contains JVM + libraries to run Java apps)
o JVM: Java Virtual Machine (executes Java bytecode)
4. Primitive data types in Java?
byte, short, int, long, float, double, char, boolean
5. Difference between == and .equals()?
o == compares references (memory location)
o .equals() compares object content
6. What is type casting?
Converting one data type to another.
o Implicit: smaller to larger type
o Explicit: larger to smaller (e.g., (int) 3.14)
7. Access Specifiers in Java?
o public: visible everywhere
o private: visible only within class
o protected: visible in same package or subclasses
o Default (no modifier): visible within package
8. Use of static keyword?
Belongs to class rather than instance; used for variables, methods, and blocks.
9. Why main method is public static void main(String[] args)?
o public: accessible by JVM
o static: called without object
o void: no return
o String[] args: receives command-line arguments
10. Difference between break and continue?
break: exits loop or switch
continue: skips current iteration
11. What is a constructor?
Special method used to initialize objects.
Types: Default, Parameterized, Copy Constructor (manual in Java)
12. Method Overloading vs Overriding?
Overloading: same method name, different parameters (within same class)
Overriding: same method name and parameters (in subclass)
13. What is this and super?
this: refers to current class object
super: refers to parent class object
14. What is inheritance?
Mechanism to inherit properties from parent class using extends.
15. What is polymorphism?
One interface, multiple forms. Types: Compile-time (overloading), Run-time (overriding)
16. What is encapsulation?
Wrapping data and methods in one unit; achieved using private variables + public methods.
OOP & Advanced Java
1. What is abstraction?
Hiding internal details and showing only essential features. Achieved via abstract classes or
interfaces.
2. Abstract class vs Interface?
o Abstract class: can have both abstract and concrete methods
o Interface: only abstract methods (Java 8+ allows default & static methods)
3. Can Java support multiple inheritance?
Not via classes, but through interfaces.
4. What is instanceof?
Checks whether an object is an instance of a specific class or subclass.
5. Exception Handling Keywords?
o try: block to monitor
o catch: handles exception
o finally: runs always
o throw: manually throw exception
o throws: declare exceptions
6. Checked vs Unchecked exceptions?
o Checked: checked at compile-time (IOException)
o Unchecked: checked at run-time (NullPointerException)
7. Thread creation in Java?
o Extending Thread class
o Implementing Runnable interface
8. Thread lifecycle?
New → Runnable → Running → Blocked/Waiting → Dead
9. What is synchronization?
Prevents thread interference using synchronized keyword.
10. What is garbage collection?
Automatic memory management to remove unused objects.
11. What is finalize() method?
Called by GC before destroying an object (rarely used now).
OOP Concepts in Java – Viva Questions
6. What are the four main principles of OOP?
o Encapsulation
o Inheritance
o Polymorphism
o Abstraction
7. What is encapsulation?
Encapsulation means wrapping data and code together. Achieved by using private
variables with public getter/setter methods.
8. What is inheritance?
Inheritance allows a class to acquire properties and behaviors of another class using
extends.
9. What is polymorphism?
It allows one action to behave differently based on the context.
o Compile-time: method overloading
o Run-time: method overriding
10. What is abstraction?
Hiding complex implementation details and showing only essential features.
Achieved using abstract classes and interfaces.
11. What is the difference between an abstract class and an interface?
Abstract class: can have method bodies
Interface: all methods are abstract by default (until Java 8+)
12. What is method overloading and method overriding?
Overloading: same method name, different parameters (within class)
Overriding: subclass redefines superclass method with same signature
13. What is the use of super and this keywords?
super: refers to the parent class
this: refers to current class instance
14. Can you explain constructor overloading?
Yes. A class can have multiple constructors with different parameter lists.
15. What is a static method?
A method that belongs to the class rather than instances and can be called without
creating an object.
Collections & Arrays
1. Array vs ArrayList?
o Array: fixed size, stores same data type
o ArrayList: dynamic size, part of Collection framework
2. List vs Set vs Map?
o List: ordered, allows duplicates
o Set: unordered, no duplicates
o Map: key-value pairs
3. HashMap vs Hashtable?
o HashMap: not synchronized, allows one null key
o Hashtable: synchronized, no null keys
4. ArrayList vs LinkedList?
o ArrayList: fast for access, slow for insert/delete
o LinkedList: fast for insert/delete, slow for access
File Handling & Misc
1. File handling classes in Java?
File, FileReader, FileWriter, BufferedReader, etc.
2. Serialization?
Process of converting object to byte stream for storage or transmission.
3. String vs StringBuffer vs StringBuilder?
o String: immutable
o StringBuffer: mutable, thread-safe
o StringBuilder: mutable, not thread-safe (faster)
4. What is JDBC?
Java Database Connectivity – API to connect and interact with databases.
More Java Viva Questions with Answers
⚙️Object-Oriented Programming (Advanced)
1. Can we create an object of an abstract class?
No. Abstract classes cannot be instantiated directly.
2. What happens if a class has a constructor with parameters and no default constructor?
You must explicitly define a default constructor if you want to use it; Java won’t add it
automatically.
3. What is the use of the super() keyword in a constructor?
It is used to call the constructor of the parent class.
4. What is constructor chaining?
The process of calling one constructor from another in the same class or parent class using
this() or super().
Multithreading and Concurrency
5. What is the difference between sleep() and wait() in Java?
o sleep(): from Thread class, pauses thread for specified time
o wait(): from Object class, releases lock and waits to be notified
6. What is deadlock?
When two or more threads are blocked forever, each waiting on the other.
7. What is thread priority?
Every thread has a priority (1–10). Higher-priority threads get preference by the thread
scheduler.
🔗 Java Keywords & Concepts
8. What is the difference between transient and volatile?
o transient: variable is not serialized
o volatile: variable value is always read from main memory (used in multithreading)
9. What is the use of synchronized keyword?
To prevent multiple threads from executing a block/method simultaneously.
10. Can we override a static method?
No. Static methods belong to the class, not the instance.
11. Can we override private or final methods?
private: No, not visible in subclass
final: No, cannot be overridden
12. What is method hiding?
When a subclass defines a static method with the same name as in the superclass, it hides it,
not overrides it.
Memory and Performance
13. What is the difference between stack and heap memory?
Stack: stores method calls and local variables
Heap: stores objects and class instances
14. What is memory leak in Java?
Unused objects not being garbage collected due to lingering references.
15. How can you make a class immutable?
Make class final
Make all fields private and final
No setters, only getters
Deep copy objects returned
Miscellaneous & Real-Time Concepts
16. What is marker interface?
An interface with no methods (e.g., Serializable). Used to convey metadata to the
JVM/compiler.
17. What is the use of default and static methods in interfaces (Java 8+)?
default: allows adding methods to interfaces without breaking existing implementations
static: utility methods related to the interface
18. What is functional interface?
An interface with exactly one abstract method. Example: Runnable, Callable, or custom with
@FunctionalInterface.
19. What is lambda expression in Java?
Introduced in Java 8, used to implement functional interfaces using concise syntax:
(a, b) -> a + b
20. Difference between compile-time and run-time polymorphism?
Compile-time: method overloading
Run-time: method overriding via dynamic dispatch
File I/O, Serialization, and Networking
21. What is the purpose of Serializable interface?
To allow Java objects to be written to a file or sent over a network.
22. What is the difference between FileInputStream and BufferedInputStream?
FileInputStream: reads byte by byte
BufferedInputStream: adds a buffer for faster reading
23. What is Socket in Java?
A class used to establish communication between client and server over TCP/IP.
24. What are streams in Java?
Streams are data pipelines used to read/write data (byte or character streams).