— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet411/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   407   408   409   410   411   412   413   414   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

System.out.println(“Two’s type: “ + twoRestore.getType());
System.out.println(“Three’s type: “ + threeRestore.getType());
} catch(Exception ex) {
ex.printStackTrace();
}
}
File Edit Window Help Resuscitate
% java GameSaver
Elf 
Troll 
Magician
object 
power: 50
type: Elf
weapons: bow, 
sword, dust
power: 120
type: Magician
weapons: spells, 
invisibility
object 
power: 200
type: Troll
weapons: bare
hands, big ax
object 
serialization 
example
We set them to null so we can’t 
access the objects on the heap.
Make some characters...
Now read them back in from the file...
Check to see if it worked.


serialization 
and
file I/O
you are here
4
445
import java.io.*;
public class GameCharacter implements Serializable {
int power;
String type;
String[] weapons;
public GameCharacter(int p, String t, String[] w) {
power = p;
type = t;
weapons = w;
}
public int getPower() {
return power;
}
public String getType() {
return type;
}
public String getWeapons() {
String weaponList = “”;
for (int i = 0; i < weapons.length; i++) {
weaponList += weapons[i] + “ “;
}
return weaponList;
}
}
The GameCharacter class
This is a basic class just for testing 
Serialization, and we don’t have an 
actual game, but we’ll leave that to 
you to experiment.
Check to see if it worked.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   407   408   409   410   411   412   413   414   ...   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