Here we are sharing the most asked JAVA interview questions with answers (Topic Wise). Please refer them before going to an interview in Top MNC’s
Question1: Explain public static void main(String args).
● public: Public is an access modifier, which is used to specify who can access
this method. Public means that this Method will be accessible by any Class.
● static: It is a keyword in java that identifies it is class-based i.e it can be accessed without creating the instance of a Class.
● void: It is the return type of the method. Void defines the method which will not return any value.
● main: It is the name of the method which is searched by JVM as a starting
point for an application with a particular signature only. It is the method where the main execution occurs.
● String args: It is the parameter passed to the main method.
Question2: Why Java is platform-independent?
Platform independent practically means “write once run anywhere”. Java is called so because of its byte codes which can run on any system irrespective of its underlying operating system.
Question3: Why java is not 100% Object-oriented?
Java is not 100% Object-oriented because it makes use of eight primitive data types
such as boolean, byte, char, int, float, double, long, short which are not objects.
Q-4. What do you mean by Object?
An object consists of methods and class which depict its state and
perform operations. A java program contains a lot of objects instructing
each other on their jobs. This concept is a part of core java.
Q-5 What is association?
Association is a relationship where all object have their own lifecycle and there is no
owner. Let’s take the example of Teacher and Student. Multiple students can
associate with a single teacher and a single student can associate with multiple
teachers but there is no ownership between the objects and both have their own lifecycle. This relationship can be one to one, One to many, many to one, and many to many.
Q-6. What do you mean by aggregation?
An aggregation is a specialized form of Association where all object have their own
lifecycle but there is ownership and child object can not belong to another parent
object. Let’s take the example of the Department and teacher. A single teacher can not
belongs to multiple departments, but if we delete the department teacher object will
Q-7. What is a composition in Java?
A composition is again a specialized form of Aggregation and we can call this a
“death” relationship. It is a strong type of Aggregation. Child objects dose does not have
their lifecycle and if parent object deletes all child object will also be deleted. Let’s
take again an example of the relationship between House and rooms. House can contain
multiple rooms there is no independent life of room and any room can not belongs to
two different houses if we delete the house room will automatically delete.
Q-8. What’s the difference between an array and Vector?
Ans: An array groups data of the same primitive type and is static in nature while vectors are dynamic in nature and can hold data of different data types.
Q-9. What is multi-threading?
Ans: Multithreading is a programming concept to run multiple tasks in a concurrent manner within a single program. Threads share the same process stack and running in parallel. It helps in the performance improvement of any program.
Q-10. Why Runnable Interface is used in Java?
Ans: Runnable interface is used in java for implementing multi-threaded applications. Java.Lang. A runnable interface is implemented by a class to support multi-threading.