Unit 1: Java Basics
Q1. What is Java and why is it popular?
Answer:
Java is a general-purpose, object-oriented, high-level programming language developed by Sun Microsystems (1995).
Its popularity comes from:
-
Platform Independence: Write once, run anywhere (WORA).
-
Robust & Secure: Automatic garbage collection, no explicit pointers.
-
Multi-threaded: Supports concurrent programming.
-
Rich API: Built-in libraries.
Q2. Why is Java called platform-independent?
Answer:
Because Java source code is compiled into bytecode, which runs on the Java Virtual Machine (JVM) on any OS (Windows/Linux/Mac).
Q3. Explain JVM, JDK, and JRE.
Answer:
-
JVM (Java Virtual Machine): Executes bytecode.
-
JRE (Java Runtime Environment): JVM + core libraries (for running).
-
JDK (Java Development Kit): JRE + development tools (compiler, debugger).
Q4. Difference between Java and C++.
Answer:
-
Java does not support multiple inheritance using classes (C++ does).
-
Java has automatic garbage collection, C++ requires manual memory management.
-
Java uses JVM for execution, C++ compiles into native code.
-
Java is fully object-oriented, C++ is not (supports procedural + OOP).
Q5. What is Bytecode in Java?
Answer:
Intermediate machine-independent code generated by Java compiler.
It is executed by JVM, ensuring portability.
Unit 2: OOP Concepts
Q6. Explain the four pillars of OOP in Java.
Answer:
-
Encapsulation: Wrapping data + methods in a class.
-
Inheritance: Reusing properties of a parent class.
-
Polymorphism: Same method with different forms (overloading/overriding).
-
Abstraction: Hiding implementation details.
Q7. Define Class and Object with example.
Answer:
-
Class: Blueprint for creating objects.
-
Object: Instance of a class.
Q8. What is Encapsulation? Give an example.
Answer:
Encapsulation = hiding data using private variables + public getters/setters.
Q9. What is Inheritance?
Answer:
Inheritance allows a class to acquire properties of another class using extends.
Q10. Difference between Overloading and Overriding.
Answer:
-
Overloading: Same method name, different parameter list (compile-time).
-
Overriding: Subclass redefines parent method with same signature (runtime).
Q11. What is Abstraction? How is it implemented?
Answer:
Hiding implementation details and exposing only functionality.
-
Abstract Class (with abstract methods).
-
Interface (pure abstraction).
Q12. Can Java support multiple inheritance?
Answer:
-
Not via classes (to avoid ambiguity).
-
Possible using interfaces.
Q13. Explain the this keyword.
Answer:
Refers to the current object. Example:
Q14. Explain the super keyword.
Answer:
Used to access parent class methods/variables/constructors.
Q15. Difference between Abstract Class and Interface.
Answer:
-
Abstract Class: Can have abstract + concrete methods, single inheritance.
-
Interface: Only abstract methods (till Java 7), supports multiple inheritance.
Unit 3: Java Programming
Q16. Difference between Constructor and Method.
Answer:
-
Constructor: Special method for object initialization, no return type.
-
Method: Defines behavior, can return value.
Q17. Types of Constructors.
-
Default constructor.
-
Parameterized constructor.
-
Copy constructor (manual).
Q18. What is static keyword?
-
Belongs to class, not object.
-
Used for variables, methods, blocks.
Q19. What is final keyword?
-
final variable → constant.
-
final method → cannot be overridden.
-
final class → cannot be inherited.
Q20. What is Garbage Collection?
Process of automatic memory management in Java, done by JVM.
Unit 4: Exception Handling
Q21. What is Exception Handling?
Mechanism to handle runtime errors using try-catch-finally.
Q22. Checked vs Unchecked Exceptions.
-
Checked → Compile-time checked (IOException).
-
Unchecked → Runtime errors (ArithmeticException).
Q23. Explain finally block.
Executes always, used for cleanup.
Q24. Difference between throw and throws.
-
throw→ Used to throw exception inside method. -
throws→ Declares exception in method signature.
Q25. Example of try-catch.
Unit 5: Multithreading
Q26. What is Thread?
Lightweight process.
Q27. Ways to create Thread.
-
Extending
Threadclass. -
Implementing
Runnableinterface.
Q28. Process vs Thread.
-
Process: Independent execution.
-
Thread: Subset of process.
Q29. Methods of Thread class.
start(), run(), sleep(), join(), getName().
Q30. What is Synchronization?
Prevents multiple threads from accessing shared resources simultaneously.
Unit 6: Java APIs
Q31. What is a Package?
Collection of related classes & interfaces.
Q32. How to create a Package?
Q33. Difference between import and package.
-
package: Define a package. -
import: Include external classes.
Q34. Common Java packages.
java.lang, java.util, java.io, java.sql.
Q35. What is Wrapper Class?
Converts primitive data type into objects (Integer, Double).
Unit 7: GUI & Applets
Q36. What is Applet?
Java program that runs in browser.
Q37. Lifecycle of Applet.
init() → start() → paint() → stop() → destroy().
Q38. Applet vs Application.
-
Applet: Runs in browser.
-
Application: Standalone with
main().
Q39. What is AWT?
Abstract Window Toolkit → GUI library.
Q40. AWT vs Swing.
-
AWT: Heavyweight, platform-dependent.
-
Swing: Lightweight, platform-independent.
Unit 8: JDBC
Q41. What is JDBC?
API for database access.
Q42. JDBC Architecture.
-
DriverManager
-
Connection
-
Statement
-
ResultSet
Q43. Steps in JDBC Program.
-
Load driver
-
Connect DB
-
Create statement
-
Execute query
-
Process results
-
Close connection
Q44. Statement vs PreparedStatement.
-
Statement → Static SQL.
-
PreparedStatement → Precompiled SQL, prevents SQL injection.
Q45. Example JDBC Code.
Unit 9: Miscellaneous
Q46. What is Serialization?
Converting object to byte stream.
Q47. What is Deserialization?
Reconstructing object from byte stream.
Q48. Java Collection Framework.
Library for data structures (List, Set, Map).
Q49. ArrayList vs LinkedList.
-
ArrayList → Fast random access.
-
LinkedList → Fast insert/delete.
Q50. What is HashMap?
Collection for key-value pairs, no duplicate keys.
Comments
Leave a Comment
Your email address will not be published. Required fields are marked *