Saturday, July 7, 2018

Frequently asked interview questions

1] Difference between String, StringBuffer and StringBuilder in Java?

String:

 * It's a final class
 * String is a immutable class
 * String object cannot be changed
 * String object reside in a String constant pool

StrngBuffer:
 * It's a mutable class
 * StringBuffer value can be changed
 * It resides in heap
 * We can do certain operation like insert, remove, update
 * StringBuffer is thread safe i.e. synchronized

StrngBuilder:

 * It's a mutable class
 * StringBuilder value can be changed
 * It resides in heap
 * We can do certain operation like insert, remove, update
 * StringBuilder is not thread safe i.e. not synchronized

2] What is difference between wait and notify in Java?


Notify:

When a thread calls notify on some monitor, it wakes up a single thread that's waiting on that monitor, but which thread gets woken is decided by the scheduler. That's why the target of the call is different, the notification is made to the monitor, which tells the scheduler to pick a thread to wake up

Wait:

Unlike notify, interruption targets a specific thread. And interruption does not require that the interrupted thread be waiting on a monitor. For a thread to call wait on a monitor it has to have acquired that monitor first, then wait releases that monitor until the thread is done waiting or is interrupted.

3] Difference between Serializable and Externalizable in Java?


Serializable:

* Serializable is a marker interface
*  default serialization is easy to implement, but has higher performance cost.
* Serializable interface pass the responsibility of serialization to JVM .   

Externalizable:

*Externalizable interface contains two ethods writeExternal() and readExternal()
* using Externalizable, add more responsibility to programmer but often result in better performance
* Externalizable provides control of serialization logic to programmer – to write custom logic 

4] What is difference between FileInputStream and FileReader in Java?


FileInputStream:

* FileInputStream is meant for reading binary data
* FileInputStream extends from InputStream class

FileReader:

* FileReader is meant for reading text data
*FileReader extends from Reader class

5] Can you override static method in Java?


we cannot override a static method, because static members are called as class member level object.


6] What are different types of Spring Bean autowiring?


* autowire byName

* autowire byType

7] What are different scopes of Spring Bean?


* singleton

* prototype
* request
* session

8] What is difference between Hibernate Session get() and load() method?


get():

* get() method returns null if object is not found
* It always hit database

load():

* load() method throws Exception if object is not found
* load() method may not always hit the database

9] What are different states of an entity bean?


* Transient

* Persistent
* Detached 

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...