Java Interview Questions & Answers

Showing 10 of 301 questions | Page 24

Technical interview questions and answers are essential for any Java Interview because Java is one of the most widely used programming languages in software development. Companies expect candidates to know OOP concepts, multithreading, exceptions, JDBC, collections, and real-time coding questions. Java interviews are commonly part of campus placements and software development roles in companies such as TCS, Infosys, Wipro, Cognizant, and Accenture. For freshers and job seekers, understanding Java concepts clearly makes it easier to clear technical rounds, online coding tests, and project discussions. This guide includes the most important and frequently asked Java interview questions with detailed explanations to help you prepare efficiently. These questions will help you gain confidence during software developer interviews and competitive placement tests.

Java professionals should deepen their expertise through J2EE development  concepts and data structures  fundamentals 

Showing 10 of 301 questions

231. What is serialization?

Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

232. How do I serialize an object to a file?

The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.

233. Which methods of Serializable interface should I implement?

The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

234. How can I customize the seralization process? i.e. how can one have a control over the serialization process?

Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

235. What is the common usage of serialization?

Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

236. What is Externalizable interface?

Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

237. When you serialize an object, what happens to the object references included in the object?

The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

238. What one should take care of while serializing the object?

One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

239. Does Java provide any construct to find out the size of an object?

No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java.

240. What are wrapper classes?

Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character, Double etc.
Questions and Answers for Competitive Exams Various Entrance Test