Java is a high level programming language. Main characteristics include
Java requires both compiler and interpretor to run.
The compiler converts the source code into byte code. The interpretor interprets this bytecode and excutes the application/logic. Since java is interpreted language, it is platform independent
Java Virtual Machine or JVM provides an environment to support execution of java bytecode. It compiles a .java file to .class which contains byte code understandable by the machine. It is a specification which must be implemented by computer system.
java file -> {compiler} -> java byte code -> {run on java VM specific to OS to convert to native code} -> java .class file executes code
Classloader
|
Allocated Memory Locations
| | | | |
|--------------------------------|
|Class Heap Stack Native Program |
|Area Method Counter |
| Stack Register|
|--------------------------------|
|
Execution Engine
|
Native Method Interface
|
Java Libraries
For Example, in a given program
class Student {
int rollNo;
String name;
static String college = "University";
Student(int rollNo, String name) {
this.rollNo = rollNo;
this.name = name;
}
void display() {
System.out.printf("RollNo: %s, Name:%s, College:%s \n",rollNo, name, college);
}
public static void main(String[] args) {
Student s1 = new Student(57, "Tony");
Student s2 = new Student(60, "Peter");
s1.display();
s2.display();
}
}
static String college
is stored in Class Area.
Student object s1 and s2
are stored in Java Stack, s2 being at top (First in Last out).
Object attributes rollNo and name
are stored in Heap memory.
A classloader is subsystem of a JVM. Whenever a java program is executed, it is first loaded by classloader
rt.jar
files. The jar contains basic standard edition files.$JAVA_HOME/jre/lib/ext
directory