JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls the main method present in a java code. JVM is a part of JRE(Java Run Environment).
Java applications are called WORA (Write Once Run Everywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java enabled system without any adjustment. This is all possible because of JVM.
When we compile a .java file, a .class file(contains byte-code) with the same filename is generated by the Java compiler. This .class file goes into various steps when we run it. These steps together describe the whole JVM.
Image Source : https://en.wikipedia.org/wiki/Java_virtual_machine
Image Source : https://en.wikipedia.org/wiki/Java_virtual_machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test{ | |
public static void main(String args[]){ | |
Student s1 = new Student(); | |
Class c1 = s1.getClass(); | |
//getting class by creating JVM | |
System.out.println(c1.getName()); | |
//Method m[] = c1.getDeclaredMethods(); | |
// for (Method method : m) | |
// System.out.println(method.getName()); | |
// Field f[] = c1.getDeclaredFields(); | |
// for (Field field : f) | |
// System.out.println(field.getName()); | |
// String class is loaded by bootstrap loader, and | |
// bootstrap loader is not Java object, hence null | |
System.out.println(String.class.getClassLoader()); | |
// Test class is loaded by Application loader | |
System.out.println(Test.class.getClassLoader()); | |
} | |
static class Student{ | |
private String name; | |
private int roll; | |
public void setName(String name){ | |
this.name = name; | |
} | |
public String getName(){ | |
return name; | |
} | |
public int getRoll(){ | |
return roll; | |
} | |
public void setRoll(int r){ | |
this.roll = r; | |
} | |
} | |
} |