Link Search Menu Expand Document

TOP-10 Basic Java Interview Questions

Q1. So, what is JAVA?

Ans. In the year 1995 Java was created by Sun Microsystems. Java makes use of objects, everything is linked to objects. One of the appealing aspects of Java was that it was introduced as WORA, which means ‘write once and run anywhere’. This simplified coding applications extensively. Java is necessary to be installed for many applications to run on different platforms and more are built every day.

Q2. State some features of JAVA?

Ans. Here are some of the features of Java:

  1. Java is Platform Independent: Java applications don't require special modifications to run different platforms.
  2. High Performance: One of Java's core features is the Just in Time compiler (JIT), which puts Java in high-performance mode. It converts bytecode into machine language, and that begins the JVM executions.
  3. OOP concepts such as:
  • Object-oriented
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Abstraction
  1. It is Multi-Threaded: Thread is a stream of execution. JVM is the primary executor, which creates the main thread. After that, a user can create multiple threads by using thread class extensions or Runnable Interface.

Q3. What is the platform?

Ans. The hardware and software environment on which an application is coded and executed is known as a platform. Java is a software based-platform and not a hardware-based platform.

Q4. What is a JIT compiler?

Ans. JIT compiler is an acronym for Just-In-Time. It is mainly used to improve performance. Bytecode with similar features is processed at the same instant, which reduces the time taken for compilation. The compiler means that it acts as a translator from the instruction set of a Java virtual machine (JVM) based on a CPU’s set instructions.

Q5. What is JVM?

Ans. JVM stands for Java Virtual Machine. The primary function of JVM is that it helps in loading other Java programs on any other platform or operating system. This makes the Java platform-independent. It can also run other programs written in different languages that have been converted into java bytecode.

Q6. What is the 'write once and run anywhere' aspect of Java?

Ans. This is linked to bytecode. The bytecode. Java compiler transforms Java programs into a class file (that is bytecode), which creates a link between source code and machine code. Bytecode is not restricted to any one platform. Thus it can be used on any computer.

Q7. Can  Empty .java file name be called a valid source file name?

Ans. Yes, .java is the one in which we save our java file. This is compiled by javac .java and run by java classname. Here is an example:

//save by .java only
Class A{
public static void (String args[]){
System.out.printIn("Hello Java");
}
}
//compile by javac .java
//run by java A
This code can be compiled by javac. Java
And run by Java A

Q8. If written static public void instead of public static void, what will be the consequences?

Ans. The specifiers’ order doesn’t raise a concern in Java; thus, the program will compile and run correctly.

Q9. What is an object?

Ans. An object is the instance of a class. It has a state and behavior.

Q10. What are the advantages of packages in Java?

Ans. Some of the advantages of packages in Java are:

  1. It helps in avoiding name clashes.
  2. It eases access control.
  3. The package can access hidden classes not visible outside.
  4. It makes it easy to locate related classes.

Other useful articles:


Back to top

© , Java Interviews — All Rights Reserved - Terms of Use - Privacy Policy