Question 1- What is Virtual Machine?
Answer- In computing, a virtual machine (VM) is an emulation of a computer system, which can perform an operation like a Physical machine. They provide the functionality needed to execute the entire operating system. There are different kinds of virtual machines, each with different functions:
- Process virtual machines ( or Software Based or System Based) are designed to execute computer programs in a platform-independent environment. Examples- JVM ( Java virtual machine), CLR ( Common Language Runtime).
- System Based virtual machines ( or Hardware Based) provide several logical systems on the same computer with strong isolation from each other. Examples- KVM (Kernel Based VM for Linux System), VMware, Xen, cloud computing.
Question 2- What is JVM?
Answer – A Java virtual machine (JVM) is an abstract machine that enables a computer to run a Java program. It provides a runtime environment in which Java bytecode can be executed. The Java compiler compiles the .java file into a .class file, then that .class file is input into the JVM, which Loads and executes the class file. Java was developed with the concept of WORA (Write Once Run Anywhere).
- It is part of JRE (Java Runtime Environment).
- JVM is responsible for loading and running Java Applications.
Java Runtime Environment (JRE) is a software package that contains what is required to run a Java program. It includes a Java Virtual Machine implementation together with an implementation of the Java Class Library.
Java Development Kit (JDK) is a superset of a JRE and contains tools for Java programmers, e.g. a javac compiler.
Question 3 – Describe Internal Architecture of JVM.
Answer – JVM has three main components –
- Class Loader Subsystem
- Memory Area
- Execution Engine.
1- ClassLoader Subsystem: Classloader is a subsystem of JVM that is used to load class files.
2- Memory Area: The Java Virtual Machine defines different run-time data areas that are used at the time of execution of a program. Some of these data areas are created on JVM start-up and are destroyed only when the JVM exits. Other data areas are per thread. Per-thread data areas are created when a thread is created and destroyed when the thread exits.
3- Execution Engine: The bytecode which is assigned to the Memory Area will be executed by the Execution Engine. The Execution Engine reads the bytecode and executes it piece by piece.
Question 4- Describe the internal working of ClassLoader Subsystem.
Answer – Classloader Subsystem is responsible for the following 3 Activity:
- Loading
- Linking
- Initialization
1- Loading: Loading means reading class files and store corresponding binary data in method area. For each class file, JVM will store the following information in method area.
- Fully Qualified name of the Loaded class or interface or enum.
- Fully Qualified Name of its immediate Parent Class.
- Whether the .class file is related to class or interface or enum.
- The Modification Information.
- Variables of files Information.
- Methods Information.
Every class loader subsystem contains the following 3 class loaders:
- Bootstrap classLoader: This classloader is responsible for loading core Java API classes i.e. the classes present in rt.jar (jdk/jre7/lib/rt.jar).
- Extension classLoader: It is the child of Bootstrap classLoader the classLoader is responsible for loading (jre\lib).
- Application classLoader or System classLoader: It is the child of Extention classLoader This classLoader is responsible for loading classes from application class path.
It internally uses environment variable class path appplication, classLoader is implemented in java and corresponding .class file name is sun.misc.lanuncher$AppclassLoader.class
Leave a Reply