— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet407/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   403   404   405   406   407   408   409   410   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

What happens if two objects in 
the object graph are the same object? 
Like, if you have two different Cat 
objects in the Kennel, but both Cats 
have a reference to the same Owner 
object. Does the Owner get saved 
twice? I’m hoping not.
A: 
Excellent question! Serialization 
is smart enough to know when two 
objects in the graph are the same. In 
that case, only one of the objects is 
saved, and during deserialization, any 
references to that single object are 
restored. 
serialized 
objects
there are no
Dumb Questions


serialization 
and
file I/O
you are here
4
441
Deserialization: restoring an object
The whole point of serializing an object is so that you can 
restore it back to its original state at some later date, in a 
different ‘run’ of the JVM (which might not even be the same 
JVM that was running at the time the object was serialized). 
Deserialization is a lot like serialization in reverse.
FileInputStream fileStream = new FileInputStream(“MyGame.ser”);
Make a FileInputStream object. The FileInputStream 
knows how to connect to an existing file.
1
Make a FileInputStream
Object one = os.readObject();
Object two = os.readObject();
Object three = os.readObject();
3
read the objects
os.close();
5
Close the ObjectInputStream
Closing the stream at the top closes the ones 
underneath, so the FileInputStream (and the 
file) will close automatically.
If the file “MyGame.ser” doesn’t 
exist, you’ll get an exception.
ObjectInputStream os = new ObjectInputStream(fileStream);

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   403   404   405   406   407   408   409   410   ...   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