Link Search Menu Expand Document

Detailed Java Interview Questions

Q1. What are the different memories available in JVM?

There are five allocated memories:-

Class Area - stores runtime constant pool, field, method data, and other per class structures.

Heap - Stores memory related to objects and is runtime memory.

Stack - the memory stores frames and is destroyed as method invocation completes. The memory contains local variables and partial results, etc.

Program counter registered - holds the currently executing Java Virtual Machine instructions' address.

Native method stack - the memory contains the application's entire native methods.

Q2. What makes Java platform different from other platforms?

While various other software can be hardware or software platforms, Java is essentially a software-based platform only. Also, another differing point is that while other platforms can only have hardware components, Java is executed on top of different hardware platforms.

Q3. Which are different access specifiers in Java?

Public - any classes methods or variables under public are open and can be accessed by all classes and methods.

Protected - these can only be accessed through the same class or the sub-classes under it; or also by the classes of the same package.

Default - all classes, methods, and variables under default are set as default scope and can be accessed only within the same package.

Private - the variable, class, or methods under private are to be accessed only under the class.

Q4. Why are Static methods and variables used?

When using static methods and variables, objects need not be created, as these are the components of the class and are shared among all the objects of the class. The static variables and methods are, hence, used when methods or variables common to all the objects of the class to be defined.

Q5. How does object-oriented and object-based programming differ?

Object-based programming usually does not undergo inheritance or polymorphism, which are otherwise essential components of object-oriented programming. On the other hand, object-oriented programming does not come with built-in objects, unlike object-based programming.

Q6. Why is a default constructor used?

Default constructors in Java have the function of assigning default values to the objects. Also, if there is no constructor in the class, the Java compiler inherently creates a default constructor.

Q7. Is the overloading of the constructors possible?

Upon changing the data type of the parameters, constructors can be overloaded. Another way of overloading constructors is to change the number of arguments that are accepted by the constructor.

Q8. What are copy constructors in Java?

Though copy constructors are not available in Java, the values of one object can be copied to another. You could copy the values from the constructor, assign values of a constructor to another constructor, or use the clone() method of the Object class.

Q9. What are the static variables?

The common property of all objects is called static variables. Static variables help in saving memory in a program and can access memory only one time from the class area, which is at the time of class loading. Though a property of all objects, static variables belong to the class.

Other useful articles:


Back to top

© , Java Interviews — All Rights Reserved - Terms of Use - Privacy Policy