suraj k sahu


{ City } pune
< Country > india
* Profession * tl
User No # 111686
Total Questions Posted # 30
Total Answers Posted # 42

Total Answers Posted for My Questions # 47
Total Views for My Questions # 91941

Users Marked my Answers as Correct # 177
Users Marked my Answers as Wrong # 9
Answers / { suraj k sahu }

Question { Syntel, 3414 }

How do we make a class serialize?


Answer

We have to fallow below steps to serialize an object
1. The object to be serialized need to implement java.io.Serializable / java.io. Externalizable interface.
2. Generate serial version id for that serializable object.
3. ObjectOutputStream is used to write [writeObject(..) or wirteExternal()] object.
4. FileOutputStream is used to persist in flat file.
5. The flat file extension should be (.ser)

Is This Answer Correct ?    3 Yes 0 No

Question { Syntel, 3414 }

How do we make a class serialize?


Answer

We have to fallow below steps to serialize an object
1. The object to be serialized need to implement java.io.Serializable interface.
2. It will use Java’s default serialization mechanism.
3. Generate serial version id for that serializable object.
4. Only default constructor is applicable to all class hierarchy (from child to all super classes if any). It is necessary at deserialization otherwise throw InvalidClassException.
5. Generate serial version UID for all super classes in hierarchy (all super classes if any) otherwise the properties of all its super classes will be assigned to its default value during deserializtion.
6. ObjectOutputStream is used to write [writeObject] object.
7. FileOutputStream is used to persist in flat file.
8. The flat file extension should be (.ser)

Is This Answer Correct ?    1 Yes 0 No


Question { Syntel, 3414 }

How do we make a class serialize?


Answer

Here is the updated answer
We have to fallow below steps to serialize an object
1. The object to be serialized need to implement java.io.Serializable interface.
2. It will use Java’s default serialization mechanism.
3. Generate serial version id for that serializable object.
4. Generate serial version UID for all super classes in hierarchy (all super classes if any) otherwise the properties of all its super classes will be assigned to its default value during deserializtion.
5. ObjectOutputStream is used to write [writeObject] object.
6. FileOutputStream is used to persist in flat file.
7. The flat file extension should be (.ser)

Is This Answer Correct ?    0 Yes 0 No

Question { KPIT, 2906 }

What is serialVersionUID and what is its need?


Answer

The serial version UID is metadata about the serializable object, it is hash code for the serializable object. It contains information about class name, field name, field type, implemented interfaces and super classes. For each modification to serializable object, we have to update serial version UID explicitly. If we do not provide any serial version UID, JVM’s default serialization mechanism generates serial version UID for the object at runtime.

During deserialization, JVM matches the serial version UID from object stream with the serializable object which will receive the stream data. If there is a mismatch in serial version UID, JVM throws InvalidClassException

Is This Answer Correct ?    7 Yes 0 No

Question { Synechron, 3633 }

What is deserialization and how do we do deserialization?


Answer

Deserialization is a process of retrieving object from byte stream. We have to fallow below steps for de-serialization
1. The object to be serialized need to implement java.io.Serializable / java.io. Externalizable interface.
2. Generate serial version id for that serializable object.
3. ObjectInputStream is used to read [readObject() or readExternal()] object.
4. FileInputStream is used to read from flat file.
5. The flat file extension should be (.ser)

Is This Answer Correct ?    1 Yes 1 No

Question { Synechron, 3633 }

What is deserialization and how do we do deserialization?


Answer

Deserialization is a process of retrieving object from byte stream. We have to fallow below steps for de-serialization
1. The object to be serialized need to implement java.io.Serializable interface.
2. It will use Java’s default serialization mechanism.
3. Generate serial version id for that serializable object.
4. Only default constructor is applicable to all class hierarchy (from child to all super classes if any). It is necessary at deserialization otherwise throw InvalidClassException.
5. Generate serial version UID for all super classes in hierarchy (all super classes if any) otherwise the properties of all its super classes will be assigned to its default value during deserializtion.
6. ObjectInputStream is used to read [readObject()] object.
7. FileInputStream is used to read from flat file.
8. The flat file extension should be (.ser)

Is This Answer Correct ?    1 Yes 0 No

Question { Synechron, 3633 }

What is deserialization and how do we do deserialization?


Answer

Here is updated answer
Deserialization is a process of retrieving object from byte stream. We have to fallow below steps for de-serialization
1. The object to be serialized need to implement java.io.Serializable interface.
2. It will use Java’s default serialization mechanism.
3. Generate serial version id for that serializable object.
4. Generate serial version UID for all super classes in hierarchy (all super classes if any) otherwise the properties of all its super classes will be assigned to its default value during deserializtion.
5. ObjectInputStream is used to read [readObject()] object.
6. FileInputStream is used to read from flat file.
7. The flat file extension should be (.ser)

Is This Answer Correct ?    1 Yes 0 No

Question { Synechron, 3485 }

What is difference between compatible and incompatible changes in serialization?


Answer

Compatible changes
Some modifications that happed in serializable class after serialization (written to flat file / DB) but there is no exception during de-serialization is called compatible change. These are as below
1. Addition of new field.
2. Static field became non-static.
3. Transient field became non-transient
4. New super class added in class hierarchy.

Incompatible changes
Some modifications that happed in serializable class after serialization (written to flat file / DB) and there is an exception during de-serialization due to the changes is called incompatible change. These are as below
1. Delete existing field.
2. Non-static field became static.
3. Non-transient field became transient
4. Any super class removed in class hierarchy.
5. Field data type changed.

Is This Answer Correct ?    1 Yes 0 No

Question { IBM, 3368 }

What is Difference between Serializable and Externalizable in Java serialization?


Answer

Serializable: It is marker interface, it has no method to override in implemented class. It enables the object to be serialized. If any object is tried to serialize without implementing Serializable interface, then JVM throws NotSerializableException. It uses JVM’s default serializing mechanism. There is no control by the program over serialization.

Advantages (Serializable implemented object)
1. JVM takes responsibility to store the state of object.
2. No overhead of method implementation for logic to write or read object state, to or from stream.
3. It is recommended to use as suitable as possible.
4. No default constructor is required.

Disadvantages
1. No control over object serialization.
2. We need to manually take care of static or transient state of objects
3. We have to implement serializable interface in all of its super class (if any) that we need to serialize.

Externalizable: It is not as serializable interface. The interface has two methods to implement for logic to write (writeExternal()) or read (readExternal()) object sate or behavior, to or from stream.

Advantages (Externalizable implemented object)
1. We have full control over content of object stream.
2. There is no special attention we need to provide for static or transient properties of an object.
3. No need to implement enternalizable interface to all of its super class (if any) that we need to serialize.

Disadvantages
1. It should not use as there is really need of it.
2. Takes overhead of writing logic to save state of an object.
3. Default constructor is required.

Is This Answer Correct ?    7 Yes 0 No

Question { IBM, 3946 }

What is an object in Java and what are its benefits?


Answer

An object in java is a runtime entity of a java class. It has two characteristics 1. State (variables) and 2. Behavior (methods). It has below benefits
1. Encapsulation (Data hiding): It hides data and internal implementation from other objects.
2. Modularity (task modulation): It contains a set of activities for a specific task of an application.
3. Reusability: It facilitates reusability of functionality through inheritance.
4. Easy maintenance: It enhance the readability and understandability of an application. It also helps the developer to trace bugs in an application.
5. Pluggable/Unpluggable: An erroneous/unwanted object can be removed and a new object can be added in an application.

Is This Answer Correct ?    1 Yes 2 No

Question { Cap Gemini, 4978 }

How is object created in java?


Answer

Object is created in four different ways
1. Using new operator
2. Class.forName(..)
3. Cloning
4. Serializing and De-serializing

Is This Answer Correct ?    6 Yes 2 No

Question { Syntel, 6349 }

What is the life-cycle of an object?


Answer

The life cycle of an object starts with instantiation and ends with garbage collection

Is This Answer Correct ?    51 Yes 3 No

Prev    1   2    [3]