JVM Internals Flashcards Preview

Software Developer Interview Prep > JVM Internals > Flashcards

Flashcards in JVM Internals Deck (58)
Loading flashcards...

What is JRE composed of?

Java API and JVM


What is role of JVM?

To read the Java application through the class loader and execute it along with the Java API


What is Virtual Machine (VM) in JVM?

A virual machine is a software implementation of a machine that executes program like a physical machine. Basically an abstraction on top of machine.


Is JVM hardware dependent?

Yes, JVM is hardware dependent portion. It executes the Java bytecode spit out by compiler. Java execution code does not need to change with changing hardware.


JVM is register based or stack based?

Even though most popular computer architectures like x86 or ARM run on register based implementation, JVM runs based on stack.


Platform independence and primitive data type

C/C++ have different int type size based on platform. JVM clearly defines primitives to maintain compatibility & guarantee platform independence.


Is JVM little endian or big endian?

Java class file uses network byte order which is big endian. This is done to maintain platform independence between Intel x86 uses little and RISC uses big endian.


Are there multiple JVM implementations?

Yes, any vendor can develop and provide JVM. JRockit, Hotspot, Azul, IBM, OpenJDK etc.


What is Java Bytecode?

Middle language between Java (user language) and the machine language. This is what helps in achieving WORA.


What is javap?

javap is disassembler. The result of javap is called Java assembly.


Which is the opcode to invoke a method in java?

invokevirtual is the OpCode used to run method in Java bytecode. 4 OpCodes are invokeinterface, invokespecial, invokestatic, invokevirtual.


4 OpCodes used to invoke method

invokeinterface - invokes an interface method
invokespecial - invokes an initializer, private method or superclass method
invokestatic - invokes static methods
invokevirutal - invokes instance methods


Show sample bytecode

public void add(java.lang.String);
0: aload_0
1: getfield #15;
4: aload_1
5: invokevirtual #23;
8: pop
9: return


What does number in front of the code mean? Ex
0: aload_0
1: getfield #15;
4: aload_1

It is the byte number. This is the reason why code executed by JVM is called "Byte code".


How many bytes is OpCode size?

1 byte. Therefore maximum number of Java Bytecode instruction OpCodes is 256.


What is the maximum size of java method?

65536 bytes. It is because the branch/jump instructions used in Byte code take 2 byte argument. So maximum value that can be expressed is 65535.


What happens if you run code compiled with higher version compiler and executed in lower version runtime?

You get runtime exception called java.lang.UnsupportedClassVersionError


What happens if you run code compiled in lower version compiler and run in higher version runtime?

It just runs! Java maintains backward compatibility.


JVM structure?

Java code (.java) is compiled using javac and the output is (.class). Then at execution time using java command, Classloader loads the classes in the Runtime data areas and executes the code using the execution engine.


Which classloader is parent of all class loaders?

Bootstrap class loader is parent of all classloaders


How classloading delegation works?

During class loading, first parent class loader is checked. If parent loads the class, it is used and if not the current classloader loads the class.


Visibility limit of class in classloader?

A child class loader can find the class in parent class loader but parent cannot find class in child classloader.


Can class be unloaded once loaded?

No. Instead the classloader can be deleted and a new one can be created.


Can two .class files of same java code be different?

Yes. If they are loaded with two different classloaders. Classloaders has its namespace that stores the loaded classes.


Show hierarchy of classloaders

Bootstrap classloader
Extension classloader
System classloader
User defined classloader
User defined classloader


What is Bootstrap classloader?

This is created when running the JVM. It loads java api, including Object classes. It is implemented in native code instead of Java.


What is Extension class loader?

It loads the extension classes excluding basic java apis. It also loads various security extension functions.


What is system class loader?

It loads application classes. It loads class in $CLASSPATH specified by user.


What is User defined classloader?

Classloader that a user creates using code is User defined classloader.


What are the steps in classloading?

1 - Loading
2 - Verifying
3 - Preparing
4 - Resolving
5 - Initializing