1. What is Java?
Java is a high-level, object-oriented programming language that
runs on the Java Virtual Machine (JVM), enabling write-once, run-anywhere functionality.
2. What are the main features of Java?Platform independence, object-oriented,
robustness, security, multithreading, and automatic garbage collection.
3. What is the JVM?The Java Virtual Machine (JVM) executes Java bytecode and
enables platform independence by running the code on any device with a JVM.
4. Differentiate between JDK, JRE, and JVM.JDK (Java Development Kit) is for
development, JRE (Java Runtime Environment) runs Java programs, and JVM is the virtual
machine executing the bytecode.
5. What is a variable in Java?A variable is a named container for storing data
values; it must be declared with a specific data type.
6. List the primitive data types in Java.byte, short, int, long, float, double,
boolean, char.
7. What is a class in Java?A class is a blueprint that defines the fields and
methods for objects.
8. What is an object in Java?An object is an instance of a class, representing a
real-world entity.
9. How do you write the main method in Java?public static void main(String[]
args) { /…/ }
10. What is a constructor?A constructor initializes a new object and has the same
name as the class without a return type.
11. What is method overloading?Method overloading means having multiple
methods with the same name but different parameters within a class.
12. What is method overriding?Method overriding means redefining a method in
a child class that already exists in the parent class.
13. What is inheritance?Inheritance is the mechanism by which one class
acquires the fields and methods of another class.
14. What is polymorphism?Polymorphism lets objects take many forms, typically
through method overriding and interface implementation.
15. What is encapsulation?Encapsulation is the practice of wrapping fields and
methods together and controlling access using access modifiers.
16. What is abstraction?Abstraction is the process of hiding implementation
details and showing only the essential features of an object.
17. What is an interface?An interface is a reference type with abstract methods,
used for abstraction and multiple inheritance in Java.
18. What are wrapper classes?Wrapper classes convert Java primitives to
objects, e.g., Integer, Double, Character.
19. What is autoboxing?Autoboxing automatically converts Java primitives into
their wrapper class objects.
20. What is unboxing?Unboxing is the reverse process, converting wrapper
objects into primitives.
21. Explain static keyword.static indicates that a member belongs to the class
rather than instances. Static variables and methods are shared across all objects.
22. What is a package?A package is a namespace that organizes related classes
and interfaces.
23. What are access modifiers?Access modifiers control the visibility of classes,
methods, and variables (public, private, protected, default).
24. What is the difference between == and equals()?== compares references,
while equals() compares values or contents of objects.
25. What is an array?An array is a container object that holds a fixed number of
values of a single type.
26. What is typecasting?Typecasting converts a variable from one data type to
another (implicit or explicit).
27. What is final keyword?final prevents modification: a final variable cannot
change value, a final method can’t be overridden, and a final class can’t be extended.
28. What are exceptions in Java?Exceptions are problems that arise during
program execution and are handled using try-catch blocks.
29. What is the purpose of try-catch?try-catch is used for exception handling to
manage runtime errors gracefully.
30. What is garbage collection?Garbage collection is the automatic process of
reclaiming memory from objects that are no longer referenced.