Wednesday, October 26, 2016

Java Internals Interview Questions and answers

Today, we are going to discuss about  Java Internals interview Questions that means JVM internal questions,Memory Leak Management interview questions,class Loader and Runtime constant pool etc.. For these questions can answer only who have real time experience in java. Of course, who have strong knowledge on core java they can answer also.
I am writing Top 10 java internals interview questions,go through this article before attend the interview.These questions would face in interview experienced candidates only. Let's start our journey towards read and get knowledge on java internals.

1. What is the Java code execution process?

Ans: This is the  basic question for java internals.As a fresher, this question also feels difficult. Here,i am writing java code execution process by fallowing step by step 
  • Source creation: Java Source(.java) file is created
  • Source compilation: Java Compiler(javac) is used to compile the Java Source to java Byte code(.class)
  • class Loading: Java class Loader is used to dynamically load and link the java Byte code to the runtime
  • Memory allocation:  Runtime data access are used to assign the java Byte code or class file to a memory space before execution
  • Execution: Execution engine reads the Java Byte code into Native Code and unit of instructions are executed. The java Byte code or class file needs to be translated into machine language through interpreter/JIT for the execution Engine to execute.
2. What is Class Loader?

Ans: A Class Loader loads the compiled java Byte code to the Run time Data Areas.
Java provides a dynamic load feature,it loads and links the class when it refers to a class for the first time at runtime,not compile time. JVM's class loader executes the dynamic load.

3. What are the features of Class Loader?

Ans:  There are several features of Class Loader. They are
  • Delegation Mode: Based on the hierarchical structure,load is delegated between class loaders. When a class is loaded, the parent class Loader is checked to determine whether or not the class is in the parent class loader. If the upper class loader has the class,the class is used. If not,the class Loader requested for loading loads the class
  • Hierarchical Structure: Class Loaders in java are organized into a hierarchy with a parent-child relationship. The Bootstrap Class Loader is the parent of all class Loaders.
  • Visibility limit: A child class loader can find the class in the parent class loader,however a parent class loader can not find class in the child class loader.
  • Unload is not allowed: A class loader can load a class but can not unload it.Instead of unloading, the current class loader can be deleted,and a new class loader can be created.
4. Explain about static and dynamic class loading?

Ans: In static class loading , Classes are statically loaded with java's new operator. Dynamic loading is a technique for pro grammatically invoking the functions of a class loader at run time. Class.forName is and example for dynamic class loading.


5. What JVM Stack does per thread? 

Ans: One JVM stack exists for one thread,and is created when the thread starts. JVM just pushes or pops the stack frame to the JVM stack. If any exception occurs,each line of the stack trace shown as a method such as printStackTrace() expresses one stack frame.

6. What is Native Method Stack does per Thread?

Ans: Native Method Stack is a stack for native code written in a language other than java. In other words,it is a stack used to execute C/C++ codes invoked through JNI(java native interface). According to the language, a C stack or C++ stack is created.

7. What is the purpose of java Heap shared by all Threads?

Ans: Heap is a space that stores instances or objects, and is a target of garbage collection.This space is most frequently mentioned when discussing issues such as JVM performance. JVM vendors can determine how to configure the heap or not to collect garbage.

In other words, Heap memory is used by java runtime to allocate memory to objects and JRE classes.Whenever we create any object,it's always created in the Heap space.Garbage collection runs on the heap memory to free the memory used by objects that doesn't have any reference. Any object created in the heap space has global access and can be referenced from anywhere of the application.

8. Difference between Heap and Stack Memory?

Ans:
 The fallowing are the major differences between Heap and stack:

  • Heap memory is used by all parts of the application whereas stack memory is used only by one thread of execution
  • Whenever an object is created,it's always stored in the heap space and stack memory contains the reference to it. Stack memory only contains local primitive variables and reference variable to objects in heap space.
  • Memory management in stack is done in LIFO manner whereas it's more complex in Heap memory because its' used globally.
  • Objects are stored in the heap and globally accessible whereas stack memory can't be accessed by other threads.
  • Stack memory is short-lived whereas  heap memory lives from that start till the end of application execution
9. What is use of Execution engine with in JVM?

Ans:  The bytecode that is assigned to the runtime data areas in the JVM via class loader is executed by the execution engine. The execution engine reads the java Byte code in the unit of instruction. It is like a CPU executing the machine command one by one

The execution engine contains  a virtual processor,interpreter,JIT(just-in-time)

10. How does  a JIT compiler internally works?

Ans: As the execution engine runs are not defined in the JVM specifications,JVM vendors improve their execution engines using various techniques,and introduce various types of JIT compilers. Most of the JIT compiler converts the bytecode  to an intermediate Representation(IR),optimizer to execute optimization,and then code Generator converts the expression to native code.




No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...