JAVA Interview Questions


Enlist the difference between the Array list and vector in Java programming language?

The main difference between Array list and vector are given below-

    Array List: 

    Array List is fast, non-synchronized, and increases its Array size by 50% if an element is inserted in it. Increment size is not defined by the Array List. However, it can only use the Iterator for traversing an Array List.

    Vector:  

    Vector is slow, synchronized, and doubled the size of its array by default. Moreover, it defines the increment size and uses both Enumeration and Iterator for traversing. Vector is a thread-safe.

Java does not use pointer. Why?

Pointers are not used on the Java platform. This is due to the fact that pointers are unsafe. Moreover, they enhance the complexity of the program.  Java is a simplified coding language, and pointers will enhance complexity. Thus, contradicting the concept. You may be familiar that JVM is responsible for memory allocation in Java. Therefore, if pointers are used, it may lead to direct access to memory. 

What is the application of the JIT compiler in Java?

JIT is the abbreviation of the Just-In-Time compiler in Java. JIT compiler is for Java application's performance optimization at the run time. This program plays an important role in the conversion of Java bytecode into instructions. These instructions are further supplied to the processor. 

  • JIT compiler is present in Java by default. It gets activated once the java method is invoked.  
  • Afterward, it quickly compiles the invoked method bytecode into the native machine. 

Once the method got compiled, compiled code was introduced directly by JVM. 

Define the classloader? What are its types?

Classloader is nothing but a subsystem of JVM. It is meant to load class files. Do you know a java program is first run by classloader?

 The three types of classloaders in Java are:

  • Extension ClassLoader: It usually loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  • Bootstrap ClassLoader: It is the superclass of the Extension classloader. It deals with the rt.jar file that contains all class files of Java Standard Edition. 
  • System/Application ClassLoader: The other name for this is the Application classloader. In this class, files are loaded from the classpath. For changing the classpath, either use "-cp" or "-classpath" switch. 

Describe the role of static methods and variables? 

The variables can be defined as static if they are shared among all the objects of the class. You should understand that the static subdivision of class and it has no relation with the object. Therefore, there is no need to create an object for accessing these kinds of variables. So whenever variables or methods have to be defined, static is used. Additionally, these methods or variables should be common to all objects of the class. 

A good illustration of this is supposed there is a class that simulates student collection in that college. In this case, the college name is a common attribute of students. Hence the college name is known as static.