OOPs with Java - Viva Questions & Answers (Up to Multithreading)
UNIT I: Java Fundamentals & OOP Concepts
1. What is Java?
Java is a high-level, class-based, object-oriented programming language developed by James
Gosling at Sun Microsystems in 1995.
2. Difference between JDK, JRE, and JVM?
JVM: Executes Java bytecode.
JRE: JVM + Libraries to run Java applications.
JDK: JRE + development tools like javac.
3. Java Source File Structure:
Includes optional package declaration, imports, class declaration, and the main method.
4. Class and Object:
Class is a blueprint; object is an instance.
5. Constructor:
Special method to initialize objects. No return type. Invoked during object creation.
6. Access Specifiers:
public, private, protected, and default (package-private).
7. Method Overloading vs Overriding:
Overloading: Same method name, different parameters.
Overriding: Subclass modifies superclass method.
8. Inheritance:
Acquiring properties from parent class using 'extends'.
9. Encapsulation:
Data hiding using private variables with public getters/setters.
10. Abstraction:
Hiding internal details using abstract classes and interfaces.
11. Polymorphism:
Compile-time (overloading) and run-time (overriding) polymorphism.
12. Abstract Class vs Interface:
Abstract class can have implemented methods; interfaces define method signatures.
Packages
13. Package:
Collection of related classes/interfaces. Helps avoid conflicts.
14. Importing:
import java.util.Scanner;
15. Static Import:
Allows access to static members without class name.
Exception Handling
16. Exception:
Object representing runtime errors disrupting flow.
17. Types:
Checked (IOException) and Unchecked (ArithmeticException).
18. try-catch-finally:
Blocks used to handle exceptions and cleanup.
19. throw vs throws:
throw - to explicitly throw an exception.
throws - declares exceptions a method might throw.
Input/Output
20. Byte vs Character Streams:
Byte - binary data (FileInputStream); Character - text data (FileReader).
21. File I/O:
FileReader/Writer and BufferedReader/Writer used for text file handling.
Multithreading
22. Multithreading:
Concurrent execution of threads, improving efficiency.
23. Thread:
Smallest unit of process that runs concurrently.
24. Creating Threads:
Extending Thread class or implementing Runnable.
25. Thread Lifecycle:
New, Runnable, Running, Blocked/Waiting, Terminated.
26. Thread Priorities:
Range from 1 to 10. Default is 5.
27. Synchronization:
Controlling access to shared resources to avoid conflicts.
28. Inter-thread Communication:
Using wait(), notify(), notifyAll() for coordination between threads.