Java Interview


1.What is JVM?
The Java interpreter along with the runtime environment required to run the Java application is called as Java virtual machine(JVM).

2. What is the most important feature of Java?
 Java is a platform independent language.

3. What do you mean by platform independence?
Platform independence means that we can write and compile the java code on one platform (eg Windows) and can execute the class in any other supported platform eg (Linux, Solaris, etc).

4. What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

5. What is the base class for all classes?
    java.lang.Object

6. What are the access modifiers in Java?
There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but a programmer cannot specify the friendly identifier explicitly.

7. What is are packages?
A package is a collection of related classes and interfaces providing access protection and namespace management.

8. What is meant by Inheritance and what are its advantages?
 Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

9. What is the difference between super class and subclass?
 A super class is a class that is inherited whereas sub class is a class who inherits the properties of a super class.

10. What is an abstract class?
A class that is declared with an "abstract" keyword, is known as an abstract class in java. It can have abstract and non-abstract methods both. 

11. What are the states associated with the thread?
Ready, Running, Waiting and Dead states.

12. What is synchronization?
Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.


13. What is a deadlock?
When two threads are waiting for each other and can’t proceed the program, is said to be a deadlock.

14. Why Java is written as"Write once & Run anywhere" language?


The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.


15. What is Constructor?


It is just like a method of a class that is used to provide the state of an object. It has the same name as Class. It is invoked at the time of an object creation.


16. Does Constructor return any value?



Yes, It returns the current instance without writing any return type before it.

17. How many types of the constructor are there in java?

There are two types of constructors:-
  • Default constructor
  • Parameterized constructor

18. What is Parameterized constructor?

A constructor that have parameters is known as a parameterized constructor. A parameterized constructor is used to provide different values to the objects.


No comments:

Post a Comment