Search This Blog

Sunday, October 15, 2023

Most Important Core Java Interview Questions Answers

 1.) What is serialization?

Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file system, or more generally, to a transmission medium or storage facility. A serializable object must implement the Serializable interface. We use Object Output Stream to write this object to a stream and Object Input Stream to read it from the stream.


2.) Is synchronized a modifier? identifier?? what is it??

It's a modifier. Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.


3.) What is a singleton class? where is it used?

Singleton is a design pattern meant to provide one and only one instance of an object. Other objects can get a reference to this instance through a static method (class constructor is kept private). Why do we need one? Sometimes it is necessary, and often sufficient, to create a single instance of a given class. This has advantages in memory management, and for Java, in garbage collection. Moreover, restricting the number of instances may be necessary or desirable for technological or business reasons--for example, we may only want a single instance of a pool of database connections.


4.) Why java does not have multiple inheritance?

The Java design team strove to make Java:

• Simple, object-oriented, and familiar

• Robust and secure

• Architecture neutral and portable

• High performance

• Interpreted, threaded, and dynamic


The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object-oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).

In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.


5.)Why java is not 100% oops?

Many people say this because Java uses primitive types such as int, char, double. But then all the rest are objects. Confusing question.


6.) What is a resource bundle?

In its simplest form, a resource bundle is represented by a text file containing keys and the text value for each key.


7.) What is a transient variable?

The transient variables can't be serialized. For example, if a variable is declared as transient in a Serializable class and the class is written to an Object Stream, the value of the variable can't be written to the stream instead when the class is retrieved from the Object Stream the value of the variable becomes null.


No comments:

Post a Comment

Submit a Comment