Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


- By using Serialization, where you serialize the original object and returns the deserialized object as a clone -



Download 7,31 Mb.
Pdf ko'rish
bet34/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   30   31   32   33   34   35   36   37   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

By using Serialization, where you serialize the original
object and returns the deserialized object as a clone
By using external library of Apache Commons Lang.
Apache Common Lang comes with
SerializationUtils.clone() method for performing deep
copy on an object. It expects all classes in the hierarchy
to implement Serializable interfaces else
SerializableException is thrown by the system
Question 56: What is Serialization and De-
serialization?
Answer: Serialization is a mechanism to convert the state of an
object into a byte stream while De-serialization is the reverse
process where the byte stream is used to recreate the actual object
in memory. The byte stream created is platform independent that
means objects serialized on one platform can be deserialized on
another platform.
To make a Java Object serializable, the class must implement
Serializable interface. Serializable is a Marker interface.
ObjectOutputStream and ObjectInputStream classes are used for
Serialization and Deserialization in java.
We will serialize the below Employee class:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
56\color1.png


SerializationDemo.java:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
56\color2.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
56\color3.png


Output:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
56\output.png


Here, while de-serializing the employee object, salary is 0, that is
because we have made salary variable to be ‘transient’. ‘static’ and
‘transient’ variables do not take part in Serialization process. During
de-serialization, transient variables will be initialized with their default
values i.e. if objects, it will be null and if “int”, it will be 0 and static
variables will be having the current value.
And if you look at the file present in C:/temp/bytestream.txt, you can
see how the object is serialized into this file,


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
56\output1.png



Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   89




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish