Table of contents
Java is one of the most used programming languages in the IT industry. Java is mainly used for making Android apps, Web Applications, etc. Because Java is platform-independent and secure, Java is used widely in so many fields. That's why there are so many opportunities available to work with Java. And for that, you have to give a company an interview about java. So, here are some most asked questions by an interviewer about Java programming language.
1. What is Java :
Java is high-level, object-oriented language. Developed by James Gosling for Sun Microsystems in 1995.
It is used for application development. Java is fast, secure, and robust, therefore, It is widely used for developing Java applications in laptops, data centers, and game consoles.
2. What do you mean by Constructor in Java?
When a new object is created in a program a constructor gets invoked corresponding to the class.
The constructor is a method that has the same name as the class name.
If a user doesn't create a constructor implicitly a default constructor will be created.
The constructor can be overloaded.
If the user created a constructor with a parameter he should create another constructor explicitly without a parameter.
3. What is meant by the local variable and the instance variable?
Local variables are defined in the method and scope of the variables that exist inside the method itself.
The instance variable is defined inside the class and outside the method and the scope of the variable exists throughout the class.
4. What is an Object?
An instance of a class is called an object. The object has a state and behavior.
Whenever the JVM reads the "new()" keyword then it creates an instance of that class.
5. What is meant by Method Overriding?
Method overriding happens if the sub-class method satisfies the below conditions with the Super-class method.
Rules for Overriding -
-The method name should be the same.
-The argument should be the same.
-The return type should also be the same.
The key benefit of overriding is that the sub-class can provide some specific information about that sub-class type than the super-class.
6. What is meant by Overloading?
Method overloading happens for different classes or within the same class.
For method overloading, the sub-class method should satisfy the below conditions with the Super-class method (or) methods in the same class itself.
-Same method name.
-Different argument types.
-There may be different return types.
7. What is meant by Interface?
Multiple inheritances cannot be achieved in java. To overcome this problem the interface concept is introduced.
An interface is a template that has only method declarations and not the method implementation.
-All the methods in an interface are internally public abstract void.
-All the variables are public static final that is constant.
-Classes can implement the interface.
-The class which implements the interface should provide an implementation for all the methods declared in the interface.
8. What is JDK?
JDK is a software development environment used for making applets and Java applications. JDK stands for Java Development Kit.
Java developers can use it on Windows, macOS, Solaris, and Linux. JDK helps them code and run Java programs. It is possible to install more than one JDK version on the same computer.
9. What is JVM?
Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language.
JVM is a part of the Java Run Environment (JRE). In other programming languages, the compiler produces machine code for a particular system. However, the Java compiler produces code for a Virtual Machine known as Java Virtual Machine.
10. What is JRE?
JRE is a part of JDK that is designed to run other software. It contains the class libraries, loader class, and JVM.
If you want to run a Java program, you need JRE. If you are not a programmer, you don’t need to install JDK, but you'll need JRE to run Java programs.