Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Java » Questions for Beginners

Java Interview Questions List for Beginners

1) What are the fundamental OOPs concepts followed by Java?

  • Inheritance
  • Abstraction
  • Polymorphism
  • Encapsulation

2) What is constructor overloading in Java?

A class can have any number of constructors. These constructors will have different list of arguments. The constructor with no argument is known as default constructor while constructor with one or more argument is known as parameterized constructor and it is called constructor overloading. Constructor overloading provides different ways to instantiate a class.

3) What is the method overloading in java?

If any class has more than one methods with same name but different type or different number of arguments then it is called method overloading in Java. Please note it is not called method overloading on the basis of their return type.

4) Does Java support multiple inheritance?

It support multiple inheritance but only through interfaces. It means any Java class can implement number of interfaces. Please note any Java class can not extend more than one class.

5) Can we have more than main methods in a Java class?

Yes. We can have those through method overloading but there must be one "public static void main(String[] args)" in a class. Please execute this code on your machine -
Does Java allows more than one main method in a class

6) What is PATH in Java?

PATH is one of the environment variables which need to be set in order to compile and run any Java programs.

7) What are differences between Error and Exceptions in Java?

An Error "indicates serious problems that a reasonable application should not try to catch." while An Exception "indicates conditions that a reasonable application might want to catch."

  • Both Errors and Exceptions are the subclasses of java.lang.Throwable class
  • Exceptions are defined in java.lang.Exception package

Note:- Please also learn about Checked & Unchecked Exception

8) What is the difference between method Overloading and Overriding in Java?

Overloading occurs when two or more methods in one class have the same method name but different parameters while Overriding term is used in inheritance and it means having two methods with the same method name and parameters (same signature). In overriding, one of the methods is in the parent class and the other is in the child class.

9) What is synchronization in Java?

Synchronization is a term used in multi threaded application where more than one thread try to execute same block of code at same time. Synchronization is one of the way to achieve thread safety.

10) What is static binding and dynamic binding in Java?

Static binding in Java occurs during compile time while dynamic binding occurs during runtime.

11) What are the differences between ArrayList and Vector class in Java?

Vector and ArrayList both uses Array internally as data structure. They are dynamically resizable.

  • ArrayList is non-synchronized which means multiple threads can work on ArrayList at the same time.
  • Vector is synchronized. This means if one thread is working on Vector, no other thread can get a hold of it
  • Both ArrayList and Vector can grow and shrink dynamically to maintain the optimal use of storage, however the way they resized is different
  • ArrayList grow by half of its size when resized while Vector doubles the size of itself by default when grows.
  • ArrayList gives better performance as it is non-synchronized. Vector operations gives poor performance as they are thread-safe
  • Vector & ArrayList both allows duplicate and null values.

12) What are differences between final, finally and finalize in Java?

1. Final Keyword- In Java, the final keyword can be used in three ways:

  • Variable can be declared final
  • The method can be declared final
  • The class can be declared final

1.1 Final Method - When a method is declared as final in a base class or parent class, then the method cannot be overridden by its child classes throughout the execution of the program.

1.2 Final Class - Whenever a class is declared as final, then the class cannot be inherited by any child class or subclass. When a class is declared as final then all its methods including the private methods behave as if they are final.

2. Finally Block - Finally block is used after the try/catch block as an optional block while performing exception handling. In java, finally block is used to perform operations such as resource cleanup or free up the memory space. Using finally and performing the cleanup operation is considered as a good coding practice. Hence irrespective of the fact, whether an exception is handled or not, finally gets executed.

3. Finalize method- The finalize method is defined within the Object class and is a protected, non-static method available for all objects in the java. Before an object is destroyed, the finalize method gets called by the garbage collector when it determines that there are no other references of the object present in the java virtual machine (JVM).

Browse Java Categories

Datatype Variables Operators Decision Making Loops Methods Reference Variables Arrays Classes and Objects Abstract Class Singleton Class Modifiers Inheritance Overriding Polymorphism Abstraction Encapsulation Files and I/O TypeCasting Packages Exceptions Collections Framework Numbers Class Date & Time Regular Expressions Data Structures Interfaces Multithreading Other