JVM Tutorial For Beginners
To start with we will go through some basics about java. Java is an object oriented language which means everything in java is an object.
1. Java is a platform independent language ,i.e, you can write your code in java and run it on any computer ,that computer just needs to have a JRE(Java Run Time Environment) . Platform independent means, it doesn't matters which OS the computer is running.JRE is responsible to run the java code
2. JVM (Java Virtual Machine ) is started by JRE while execution of java code. It acts as a runtime engine.It does everything which makes a java code run.
3.When we compile a .java file then .class files containing byte-code with the same class names are generated .
When we run the java code by using javac , the classloader subsystem reads the .class file and loads the corresponding bytecode in the method area of JVM(will describe in detail about JVM Memory architecture).
ClassLoaders :- Classloader Subsystem has three parts :-
1. Loading:- Reading the .classfile and loading the corresponding bytecodes in the method area ofjvm memory.
2. Linking:- This step comprises of two parts: verification and preparation.
Verification:- In this step the classloader verifies the correctness of .class file
Preparation:- In this step jvm allocates memory to class variables and assigns them default values.
3.Initialization:- In this phase , all static variables are assigned with their values defined in the code and static block. This is executed from top to bottom in a class and from parent to child in class hierarchy.
Types of Classloaders
1. Bootstrap Classloader:- It loads core Java api classes. It is the parent classloader
2. Extension Classloader:- It loads all the classes present in extensions directory. It is child of Bootstrap Classloader.
3. Application Classloader:- It is child of Extension Classloader.It is responsible to load classes from application classpath.
JVM MEMORY
- Method Area:- All the class level information are loaded in this part of the memory ,for ex:-class name , immediate parent name,methods name and variable information etc.
2. Stack Area :- Whenever a thread is created jvm creates a stack, this stack is kept in the stack memory. For every method calls and related information jvm creates an individual block in the stack.This block stores data related to variables defined inside the method.For detailed understanding of stack memory study STACK MEMORY EXPLAINED.
3. Heap Area :- Information of all objects are kept in heap area. To understand in detail read HEAP MEMORY EXPLAINED.
4. PC Registers :- PC registers are used to store the program counters ,i.e, which is the next instruction which needs to be computed for every thread.
5. Native Method Stack :- For every thread, separate native stack is created , it stores native method information.
Execution Engine is a broad topic and i will cover it in my next blog.Feel free to ask in case of any doubt in the comments.
This video can help:-
https://www.youtube.com/watch?v=tigZGNAhGSI
This video can help:-
https://www.youtube.com/watch?v=tigZGNAhGSI
Great post! short and informative
ReplyDelete