Java Interview Questions

  1. What is Java? Java is an object-oriented, high-level programming language that is used to develop robust and secure applications. It was first released by Sun Microsystems in 1995 and is now owned by Oracle Corporation.
  2. What are the key features of Java? Java has several key features, including platform independence, automatic memory management, multi-threading support, security, and robustness.
  3. What is the difference between an abstract class and an interface in Java? An abstract class can have both abstract and non-abstract methods, whereas an interface can only have abstract methods. An abstract class can also have instance variables, whereas an interface can only have static constants.
  4. What is the difference between a constructor and a method in Java? A constructor is a special method that is called when an object is created. It is used to initialize the object’s state. A method is a function that is called on an object to perform some operation.
  5. What is the difference between static and non-static methods in Java? A static method belongs to the class and not to any particular instance of the class. It can be called using the class name. A non-static method, on the other hand, belongs to a specific instance of the class and can only be called on that instance.
  6. What is the difference between final, finally, and finalize in Java? Final is used to declare a constant variable or to make a method or class immutable. Finally is a block of code that is executed after a try-catch block, regardless of whether an exception is thrown or not. Finalize is a method that is called by the garbage collector when an object is about to be destroyed.
  7. What is a JVM? A JVM, or Java Virtual Machine, is a software that interprets compiled Java code and executes it on the underlying platform. It is responsible for managing memory, running threads, and providing security to the Java applications.
  8. What is a thread in Java? A thread is a lightweight process that runs concurrently with other threads in a Java application. It is used to perform multiple tasks simultaneously and can improve the performance of an application.
  9. What is the difference between an array and an ArrayList in Java? An array is a fixed-size data structure that can hold a collection of values of the same type. An ArrayList is a dynamic data structure that can hold a collection of values of any type and can grow or shrink in size as needed.
  10. What is the difference between a checked and an unchecked exception in Java? A checked exception is a type of exception that must be declared in the method signature or handled by a try-catch block. An unchecked exception, on the other hand, does not need to be declared or caught explicitly. Examples of checked exceptions include IOException and SQLException, while examples of unchecked exceptions include NullPointerException and ArrayIndexOutOfBoundsException.