Basics
1) What is JVM?
JVM = Java Virtual Machine.
It executes Java bytecode.
It makes Java platform-independent.
2)JDK
JDK (Java Development Kit)
Definition: JDK is a software development kit used to develop Java
applications.
It contains:
1. JRE (Java Runtime Environment) → to run programs.
2. JVM (Java Virtual Machine) → executes bytecode.
3. Development tools → compiler (javac), debugger, archiver, etc.
In simple terms:
JDK = JRE + Development tools
✅ Example:
If you only want to run Java → install JRE.
If you want to develop & run Java → install JDK.
3) What is JRE?
JRE = Java Runtime Environment.
It provides libraries + JVM to run Java programs (but not for development).
4) What is IDE?
IDE = Integrated Development Environment (like Eclipse, IntelliJ, NetBeans).
Helps write, debug, and run programs easily.
5) JVM is platform dependent or independent?
JVM is platform dependent (different JVMs for Windows, Linux, Mac).
But Java is platform independent (same bytecode runs on any JVM).
6) What is bytecode?
Bytecode = Intermediate code generated by Java compiler (.class file).
It runs on JVM.
7) How Java program executes?
Source code (.java) → Compiler → Bytecode (.class) → JVM → Machine
code.
---
Compiler & Interpreter
8) What is compiler?
Converts source code into bytecode (in Java).
9) What is interpreter?
Executes bytecode line by line on JVM.
---
Features of Java
10) What are the features of Java?
Simple
Object-Oriented
Secure
Portable
Platform Independent
Robust
Multithreaded
Distributed
11) How Java is robust, secure, portable, and platform-independent?
Robust: Strong memory management, exception handling.
Secure: No explicit pointers, has security manager.
Portable: Bytecode runs anywhere.
Platform-independent: WORA (Write Once, Run Anywhere).
---
Datatypes & Variables
12) What are the primitive datatypes?
byte, short, int, long, float, double, char, boolean
13) Difference between int and float?
int → whole numbers (no decimal).
float → decimal values (single precision).
14) Difference between double and float?
float → 32-bit, 6–7 digits precision.
double → 64-bit, 15–16 digits precision.
15) Difference between String, StringBuffer, and StringBuilder?
String → Immutable (cannot change).
StringBuffer → Mutable, thread-safe.
StringBuilder → Mutable, faster, not thread-safe.
16) Difference between String and StringBuffer?
String = immutable.
StringBuffer = mutable.
17) What is String in Java?
Sequence of characters enclosed in " ".
Example: String name = "Monica";
18) Methods in String (common ones):
length(), charAt(), substring(), toLowerCase(), toUpperCase(), equals(),
compareTo().
19) Difference between equals() and compareTo()?
equals() → checks content equality.
compareTo() → compares lexicographically (returns -ve, 0, +ve).
---
Arrays & Command Line
20) What is an array?
Collection of elements of same datatype stored in continuous memory.
21) What is command line argument?
Passing values to main(String args[]) while running program.
Example: java MyProgram Monica 21
---
Operators
22) What is unary operator?
Works on single operand. Example: ++a, --a.
23) What is ternary operator?
condition ? true_value : false_value;
24) What is shift operator?
<< (left shift), >> (right shift).
---
Control Statements
25) What are conditional statements?
if, if-else, switch.
26) What is jumping statement?
break, continue, return.
27) Difference between for & while loop?
for → when iterations are known.
while → when iterations are unknown.
28) Difference between for & for-each loop?
for → index-based.
for-each → element-based.
29) Difference between while & do-while loop?
while → condition checked first.
do-while → executes at least once.
---
Datatypes, Variables
30) What is a variable?
A name given to memory location.
31) Difference between datatype & variable?
Datatype = type of data (int, float).
Variable = container that holds data.
32) Sizes of datatypes:
byte (1B), short (2B), int (4B), long (8B), float (4B), double (8B), char (2B),
boolean (1 bit JVM dependent).
---
OOPs
33) Why Java is bottom-up approach?
Because it focuses on objects (OOPs), not procedures.
34) Which is better C or Java?
C → faster, system programming.
Java → portable, secure, OOPs, application development.
35) What is OOPs?
Object-Oriented Programming System (class, object, inheritance,
polymorphism, abstraction, encapsulation).
36) What is class and object?
Class = blueprint/template.
Object = instance of class.
37) Difference between class and object?
Class = definition.
Object = actual entity.
38) Difference between this and super keywords?
this → current class reference.
super → parent class reference.
39) What is Constructor?
Special method used to initialize object.
40) Why use constructor?
To initialize values automatically.
41) Types of constructors?
Default, parameterized, copy.
42) What is parameter?
Variable passed to a method/constructor.
---
Polymorphism
43) What is polymorphism?
Ability of object to take many forms.
44) Why go for polymorphism?
Code reusability + flexibility.
45) Real-time example of polymorphism?
Method overloading (print different types).
Method overriding (dog, cat → speak).
46) Types of polymorphism?
Compile-time (method overloading).
Run-time (method overriding).