JVM Internals Flashcards Preview

Software Developer Interview Prep > JVM Internals > Flashcards

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

What is JRE composed of?

Java API and JVM

2

What is role of JVM?

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

3

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.

4

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.

5

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.

6

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.

7

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.

8

Are there multiple JVM implementations?

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

9

What is Java Bytecode?

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

10

What is javap?

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

11

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.

12

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

13

Show sample bytecode

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

14

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".

15

How many bytes is OpCode size?

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

16

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.

17

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

18

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

It just runs! Java maintains backward compatibility.

19

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.

20

Which classloader is parent of all class loaders?

Bootstrap class loader is parent of all classloaders

21

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.

22

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.

23

Can class be unloaded once loaded?

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

24

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.

25

Show hierarchy of classloaders

Bootstrap classloader
^
|
Extension classloader
^
|
System classloader
^
|
------------
User defined classloader
^
|
User defined classloader

26

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.

27

What is Extension class loader?

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

28

What is system class loader?

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

29

What is User defined classloader?

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

30

What are the steps in classloading?

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