JAVA FAQs

What is Java?
Java is an Object-Oriented programming language, used to develop various application including web apps, enterprise softwares and mobile apps.
What is the most important feature of Java?
Java is platform independent.
Is JVM platform independent?
JVM is not platform independent. JVM's are platform specific run time implementation.
Why Java is not pure object-oriented?
Java uses primitive data types such as boolean, byte, char, short, int, long, float, double which are not objects.
Why Java doesn't support pointers?
Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.
What is difference between Path and Classpath?
Path and Classpath are environment variables in Operating System. Path is used to specify the locations of .exe files whereas classpath specify .class files.
How does Java enable high performance?
Java uses Just-In-Time(JIT) compiler to enable high performance.
What is JIT compiler in Java?
JIT compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.
What is the difference between local variable and instance variable?
Local variables are defined in the method or block and the scope of those variables within the method or block.
Instance variables are defined inside the class and outside the method and scope of these variables throughout the class.
What are access modifiers in Java?
Access modifiers in Java helps to restrict the scope of a class, constructor, variable and method. There are four types of access modifiers:
  1. Default
  2. Private
  3. Protected
  4. Public
How to define a constant variable in Java?
The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.
Is main() method should be compulsorily declared in all Java classes?
Not required. main() method should be defined only if the source class is a Java application.
What is the return type of the main() method?
main() method doesn't return anything hence declared void.
Why main() method declared as static?
main() method is called by the JVM even before the instantiation of the class hence it is declared as static.
Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.
public class MainOverloaded{
  public static void main(String[] name) {
    System.out.println("Normal main() method");
    MainOverloaded mo=new MainOverloaded();
    mo.main(11,"Govardhan");
    mo.main(11,"Govardhan",67.1);
  }
  public void main(int rollno, String name) {
    System.out.println("main() method with two arguments::");
    System.out.println(rollno+" "+name);
  }
  public void main(int rollno, String name,double percentage) {
    System.out.println("main() method with three arguments::");
    System.out.println(rollno+" "+name+" "+percentage);
  }
}
Which package is imported by default?
java.lang package.
What is the base class of all classes?
java.lang.Object
What is difference between final, finally and finalize?
final is a keyword used to indicate that a variable holds a constant value.
finally is a block, it will be executed whether exception handled or not.
finalize is a method, used to perform clean up processing just before object is garbage collected.
What is difference between throw and throws?
throw is a keyword used to throw an exception explicitly.
throws is a clause used to declare an exception.
What is the first object-oriented programming language?
Simula
What is the first truly object-oriented programming language?
Smalltalk