Tag Archives: Interview question

Why do we have to override the equals() method in Java?

Why do we have to override the equals() method in Java?

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 that it tests for equality rather than identity. Thus most ...

Read More »

What is synchronization and why it is important?

What is synchronization and why is it important?

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 for the synchronized keyword. If a method or block declared as ...

Read More »

Difference between yield(), join(), sleep() method?

Difference between yield(), join(), sleep() method?

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 all waiting threads have low priority then the same thread ...

Read More »

Difference between final & finally & finalize keyword?

Difference between final & finally & finalize keyword?

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 used to handle exceptions, finalize is a method that operates ...

Read More »

What is finally block in Java?

What is finally block in Java?

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 then catch block won’t be executed. Hence we required someplace ...

Read More »

What is the checked and unchecked exception?

What are the checked and uncheched exception?

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 throws keyword otherwise we will get compile time error. Unchecked ...

Read More »

Responsive WordPress Theme Freetheme wordpress magazine responsive freetheme wordpress news responsive freeWORDPRESS PLUGIN PREMIUM FREEDownload theme free