— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet400/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   396   397   398   399   400   401   402   403   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

434
 
chapter 14
Objects on the heap have state—the 
value of the object’s instance 
variables. These values make one 
instance of a class different from 
another instance of the same class.
What really happens to an object 
when it’s serialized?
Foo myFoo = new Foo();
myFoo.setWidth(37);
myFoo.setHeight(70);
FileOutputStream fs = new FileOutputStream(“foo.ser”);
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(myFoo);
1
Object on the heap
2
Object serialized
serialized 
objects
00100101
width
01000110
height
00100101
01000110
Serialized objects save the values 
of the instance variables, so that 
an identical instance (object) can be 
brought back to life on the heap.
The instance variable values 
for width and height are 
saved to the file “foo.ser”, 
along with a little more info 
the JVM needs to restore 
the object (like what its 
class type is).
foo.ser
Object with two primitive 
instance variables.
The values are sucked 
out and pumped into 
the stream.
Make a FileOutputStream that connects 
to the file “foo.ser”, then chain an 
ObjectOutputStream to it, and tell the 
ObjectOutputStream to write the object.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   396   397   398   399   400   401   402   403   ...   555




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