Tag: Interview question
Why do we have to override the equals() method in Java? We can use the equals method to check equality of two objects. The equals() method of java.lang.Object class acts the same as the == operator; that is, it tests for object identity rather than object equality. The implicit contract of the equals() method, however, is . . . Read more
What is synchronization and why it is important? Synchronized is the modifier applicable only for methods and blocks but not for classes and variables. If multiple threads are trying to operate simultaneously on the same java object then there may be a chance of data-inconsistency problem. To overcome this problem we should go . . . Read more
Difference between yield(), join(), sleep() method? We can prevent thread execution by using the following method. yield() join() sleep() public static native void yield()Â yield() method causes to pause current executing thread to give the chance for waiting threads of the same priority. If there is no waiting thread or . . . Read more
Difference between final & finally & finalize keyword? The keyword final is an access modifier, finally is a block and finalize is a method. The keyword final is applicable to the classes, variables and methods of the classes finally is a block associated with the try catch block that is . . . Read more
What is finally block in Java? It is not recommended to maintain cleanup code inside try block because there is no guarantee for the execution of every statement inside the try block. It is not recommended to maintain cleanup code inside the catch block. Because if there is no exception . . . Read more
What is the checked and unchecked exception? The exceptions which are checked by the compiler for smooth execution of the program are called checked exceptions. In our program, if there is a chance of raising checked exception then compulsory we should handle that checked exception either by try-catch or by . . . Read more
Explain Default exception handling in Java? Inside a method, if any exception occurs the method in which it is raised is responsible to create exception object by including the following information. Name of exception Description of exception Location at which exception occurs(Stack trace). After creating exception object method handover that . . . Read more
What is Exception and Runtime stack mechanism? An unexpected unwanted even that disturbs normal flow of the program is called an exception. It is highly recommended to handle the exceptions and the main objective of exception handling is graceful termination of the program. Exception Handling doesn’t mean repairing an exception. . . . Read more
What are coupling and cohesion? Coupling The degree of dependency between the component is called coupling. If the dependency is more then it is considered as tightly coupling and dependency are less then it is considered as loosely coupling. Example Class A{ static int i=B.j } Class B{ Static int . . . Read more
Difference between IS-A relationship and Has-A relationship. IS-A Relationship It is known as an inheritance The main advantage of IS-A relationship is code reusability. By using extends keyword we can implement IS-A relationship. Whatever method parent has by-default available to the child and hence on the child reference we can call . . . Read more