Core Java interview questions

Core Java interview questions Download Core Java interview questions PDF

Core Java interview questions

An object is a basic entity in an object-oriented programming language which represents the real-life entities. Many objects are created by a java program which interacts by the invoking methods. The state of an object is represented by its attributes and reflects its properties. The behavior of an object is represented by the methods of the object and reflects the relationship of an object with the other objects. The identity of an object is a unique name provided to an object which helps one object to interact with other objects.
The “super” keyword in java is basically related to the parent class. A super keyword can be used for several reasons such as-
  • It can be used to call the superclass or the parent class constructor.
  • It can also be used to access the method of the superclass which has been hidden by a subclass.
  • A super keyword can also be used to call the constructor of the parent class.
In Java, there are basically two ways by which arguments can be passed in any function. They are: –
  • Pass by value- in this, a copy of the value of the arguments is passed in the function. If any changes are made to the parameters of the sub-routine, then there is no effect on the arguments which are used to call it.
  • Pass by reference- In this, the copy of the address of the parameters are passed in the function and if any changes are made to the parameters, then it will have an effect on the arguments used to call the sub-routine.

We do expectation handling to handle the errors or problems that arise due to the syntax error or logical error. If these errors are not handled properly then it disturbs the flow of the application and performs abnormal behavior like stops the application.so, these errors need to be handled carefully for smooth and error-free flow.

There are 2 types of exceptions.

  1. Checked Exception
  2. Unchecked Exception

Deadlock is a situation that occurs when the same resource is required by two processes. This situation occurs in multithreading when one thread holds a resource which is required by the second thread and second thread holds a resource which is required by the first thread. To identify the deadlock, we can use the jConsole/VisualVM, it will show exactly which threads are getting locked and on which object.

After creating the object JVM internally calls the toString method to generate the indirect address of the object. To string method is present inside object class, which is defined as non-static. So that object class makes it as a superclass for every class in java.

The process of the connecting function call with function body is called binding. When this binding is done at compile time, it is called early binding. Early binding is static binding it is done when the type of an object is determined at compile time. On the hand, late binding is done at runtime. Late binding is dynamic binding because it is done at runtime by the compiler itself.