Java Basics
1. What is Java?
A high-level, object-oriented language developed by Sun Microsystems.
2. Why is Java called platform-independent?
Because Java code compiles to bytecode, which runs on any system with a JVM.
3. What is JVM?
Java Virtual Machine, which interprets compiled Java bytecode.
4. Difference between JDK and JRE?
JDK is Java Development Kit (includes tools plus JRE), JRE is Java Runtime
Environment for running Java programs.
5. What are Java’s main features?
Object-oriented, platform-independent, robust, secure, multithreaded,
distributed.
6. Is Java 100% object-oriented?
No, because it supports primitive types.
7. What are primitive data types in Java?
byte, short, int, long, float, double, char, boolean.
8. What is a class in Java?
A blueprint for objects; defines data fields and methods.
9. What is an object?
An instance of a class containing state (fields) and behavior (methods).
10.What is a constructor?
A block that initializes new objects; same name as class.
Object Oriented Programming
11.What are the 4 pillars of OOP?
Encapsulation, Inheritance, Abstraction, Polymorphism.
12.Define encapsulation.
Wrapping data and code into a single unit (class).
13.Define inheritance.
Acquiring properties or behavior of another class.
, 14.Define abstraction.
Hiding implementation details, showing only essential features.
15.Define polymorphism.
Same interface, different implementations (overriding or overloading).
16.What is method overloading?
Multiple methods with the same name, different parameters within a class.
17.What is method overriding?
Subclass provides specific implementation for a method in its parent class.
18.What is an interface?
A contract: collection of abstract methods (Java 8+ allows default methods).
19.What is an abstract class?
A class that can’t be instantiated, may have abstract and non-abstract methods.
20.Difference between interface and abstract class?
Interfaces only declare methods and static or default methods; abstract classes
can have both method types and fields.
Java Syntax and Core Concepts
21.Default value of int variable in Java?
0
22.What is the final keyword for?
To declare constants, prevent overriding, or prevent inheritance.
23.What is static keyword?
Used for class-level fields and methods, shared across all instances.
24.What is the main() method signature?
public static void main(String[] args)
25.Difference between == and equals()?
== compares references; equals() compares values.
26.What is a package?
A way to organize classes; declares namespace.
27.How do you import a package?
Using the import keyword.
28.What is a default constructor?
A no-argument constructor provided automatically by Java if none is defined.
29.Can you overload constructors?
Yes, with different parameter lists within a class.