— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet427/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   423   424   425   426   427   428   429   430   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

% serialver Dog
Dog: static final long 
serialVersionUID = -
5849794470654667210L;
public class Dog {
static final long serialVersionUID =
-6849794470754667710L;
private String name;
private int size;
// method code here
}
File Edit Window Help serialKiller
% serialver Dog
Dog: static final long 
serialVersionUID = -
5849794470654667210L;
1
Use the serialver command-line tool 
to get the version ID for your class
2
Paste the output into your class
3
Be sure that when you make changes to 
the class, you take responsibility in your 
code for the consequences of the changes 
you made to the class! For example, be 
sure that your new Dog class can deal with 
an old Dog being deserialized with default 
values for instance variables added to the 
class 
after the Dog was serialized.
When you think your class 
might evolve after someone has 
serialized objects from it...


462
 
chapter 14
Code Kitchen
Let’s make the BeatBox save and 
restore our favorite pattern
When you click “serializeIt”, 
the current pattern will 
be saved.
“restore” loads the saved 
pattern back in, and resets 
the checkboxes.
Code 
Kitchen


serialization 
and
file I/O
you are here
4
463
Remember, in the BeatBox, a drum pattern is nothing more than a bunch of 
checkboxes. When it’s time to play the sequence, the code walks through the 
checkboxes to figure out which drums sounds are playing at each of the 16 
beats. So to save a pattern, all we need to do is save the state of the checkboxes.
We can make a simple boolean array, holding the state of each of the 256 
checkboxes. An array object is serializable as long as the things in the array are 
serializable, so we’ll have no trouble saving an array of booleans.
To load a pattern back in, we read the single boolean array object (deserialize 
it), and restore the checkboxes. Most of the code you’ve already seen, in the 
Code Kitchen where we built the BeatBox GUI, so in this chapter, we look at 
only the save and restore code.
This CodeKitchen gets us ready for the next chapter, where instead of writing 
the pattern to a 
file, we send it over the network to the server. And instead of 
loading a pattern in from a file, we get patterns from the server, each time a 
Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   423   424   425   426   427   428   429   430   ...   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