3 - JVM As An Interpreter and Emulator
3 - JVM As An Interpreter and Emulator
3 - JVM As An Interpreter and Emulator
▰ In this system:
▰ The class loader is responsible for correctly loading classes and connecting
them with the core Java class libraries.
▰ The JVM is responsible for ensuring Java applications have the resources they
need to run and perform well in your device or cloud environment.
▰ The JRE is mainly a container for those other components, and is
responsible for orchestrating their activities.
JAVA VIRTUAL MACHINE (JVM)
▰ JDK – Java Development Kit (in short JDK) is Kit which provides the environment
to develop and execute(run) the Java program. JDK is a kit(or package) which includes
two things
▻ Development Tools(to provide an environment to develop your java programs)
▰
Other base libraries, including international support,
input/output (I/O), extension mechanism, Beans, Java
Management Extensions (JMX), Java Native Interface (JNI),
Math, Networking, Override Mechanism, Security,
Serialization and Java for XML Processing (XML JAXP).
JVMs are available for many hardware and software platforms. JVM,
JRE, and JDK are platform dependent because the configuration of
each OS is different from each other. However, Java is platform
independent.
Bytecode
▰ Loading: This component handles the loading of the .class files from the
hardware system into the JVM memory and stores the binary data (such as
fully qualified class-name, immediate parent class-name, information
about methods, variables, constructors etc.) in the method areas.
▰ For every loaded .class file, JVM immediately creates an object on the
heap memory of type java.lang.class. Do remember, even though the
developers call a class multiple time, only one class object will be created.
Components of JVM
▰ 1) Classloader
▰ There are three built-in classloaders in Java.
▰ Bootstrap ClassLoader: This is the first classloader which is the super class
of Extension classloader. It loads the rt.jar file which contains all class files of
Java Standard Edition like java.lang package classes, java.net package
classes, java.util package classes, java.io package classes, java.sql package
classes etc.
▰ Extension ClassLoader: This is the child classloader of Bootstrap and parent
classloader of System classloader. It loades the jar files located
inside $JAVA_HOME/jre/lib/ext directory.
▰ System/Application ClassLoader: This is the child classloader of Extension
classloader. It loads the classfiles from classpath. By default, classpath is set to
current directory. You can change the classpath using "-cp" or "-classpath"
switch. It is also known as Application classloader.
Memory Area Allocated by JVM
▰ 2) Class(Method) Area
▰ Class(Method) Area stores per-class structures such as the runtime constant pool,
field and method data, the code for methods.
▰ 3) Heap
▰ It is the runtime data area in which objects are allocated.
▰ 4) Stack
▰ Java Stack stores frames. It holds local variables and partial results, and plays a
part in method invocation and return.
▰ Each thread has a private JVM stack, created at the same time as thread.
▰ A new frame is created each time a method is invoked. A frame is destroyed when
its method invocation completes.
▰ 5) Program Counter Register
▰ PC (program counter) register contains the address of the Java virtual machine
instruction currently being executed.
Components of JVM (Cont,,,,)
Open Notepad
Write java program
Compile your program
D:Amit>javac Welcome.java
To understand how the JRE works let us consider a Java source file saved as Welcome.java.
▰ The file is compiled into a set of Byte Code that is stored in a “.class” file. Here it will
be “Welcome.class“.
Java byte-code
CPU2
Java virtual machine
Java Program Execution
▰ Interpreter
▰ At runtime the Byte Code is loaded, checked and run by the
interpreter. The interpreter has the following two functions:
▻ Execute the Byte Code
▻ Make appropriate calls to the underlying hardware
▰
Complete Execution of Java Program
Interactions between JDK and JRE
▰ JVM becomes an
instance of JRE at
runtime of a Java
program.
▰ It is widely known as
a runtime interpreter.
▰ JVM largely helps in
the abstraction of
inner implementation
from the
programmers who
make use of libraries
for their programmes
from JDK.
JVM as an Interpreter and
Emulator
Interpreter & Emulator