java training

Java Interview Questions

Java Interview Questions

1.What is Java?
Ans. Java is the object oriented, high-level programming language. It is a platform-independent, multithreaded, high performance, and portable programming language.

2. Why is Java not a pure object oriented language?
Ans. Java supports primitive data types like byte, boolean, char, short, int, float, long, and double. Hence it is not a pure object oriented language.

3. What is a ClassLoader?
Ans. A classloader is a subsystem of Java Virtual Machine, which is dedicated to loading class files when a program is executed. ClassLoader is the first to load the executable file. Java has Bootstrap, Extension, and Application classloaders.

4. Explain Why Java is platform independent?
Ans. Java is called platform independent due to its byte codes which can be run on any system irrespective of its underlying operating system.

5. Can the static methods be overloaded?
Ans. Yes, the static methods can be overloaded. There can be 2 or more static methods in a class with same name but differing input parameters.

6. What is JIT compiler?
Ans. JIT means Just-In-Time compiler, which is used to improve the performance. JIT compiles parts of the bytecode which have similar functionality and it reduces the amount of time needed for compilation. The term “compiler” means a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

7. Why Java is said ‘write once and run anywhere’ nature?
Ans. Due to bytecode. Java compiler converts the Java programs into the class file or Byte Code which is the intermediate language between source code and machine code. The bytecode is not a platform specific and it can be executed on any computer.

9. What is the default value of the local variables in Java?
Ans. In Java the local variables are not initialized to any default value, to to any primitives or object references.

10. Name some advantages of Packages in Java?
Ans. There are many advantages of packages in Java.
*It is easier to locate the related classes.
*They provide easier access control.
*Packages avoid the name clashes.
*We can have the hidden classes that are not visible outside and used by the package.

11. Define an object?
Ans. An Object is the real-time entity which has some state and behavior. Object is an instance of the class which has instance variables as the state of the object and the methods as the behavior of the object in Java. The object of a class is created by using the new keyword.

12. What are the Memory Allocations available in Java?
Ans. Java has 5 types of memory allocations.
Class Memory
Heap Memory
Stack Memory
Program Counter-Memory
Native Method Stack Memory

13. What is the constructor?
Ans. The constructor is a special type of method which is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for an object. Whenever an object is created using the new keyword, the default constructor of the class is called. The name of the constructor has to be similar to the class name. The constructor should not have an explicit return type.

Leave a Reply

Your email address will not be published. Required fields are marked *