Java_Important_Topics_Detailed_with_Code
Java_Important_Topics_Detailed_with_Code
The Java Virtual Machine (JVM) is a virtual environment that enables a computer to run Java programs as
well as programs written in other languages that are compiled to Java bytecode.
Key Roles:
Diagram: Java Source Code (.java) --> Java Compiler (javac) --> Bytecode (.class) --> JVM -->
Machine-specific Instructions
- Compilation succeeds but Runtime Error occurs because JVM needs static 'main' method to start program
- Portable: Platform-independent.
class Student {
int id;
String name;
void display() {
System.out.println(id + " " + name);
}
}
Types:
- Default Constructor
- Parameterized Constructor
- Copy Constructor
Java Important Topics: Detailed Notes
class Bike {
String model;
// Default Constructor
Bike() {
model = "Unknown";
}
// Parameterized Constructor
Bike(String m) {
model = m;
}
// Copy Constructor
Bike(Bike b) {
model = b.model;
}
}
class Test {
protected void finalize() {
System.out.println("Finalize method called");
}