— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet431/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   427   428   429   430   431   432   433   434   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

True or False
D
exercise: 
True or False


serialization 
and
file I/O
you are here
4
467
This one’s tricky, so we promoted it from an Exercise to full Puzzle status. 
Reconstruct the code snippets to make a working Java program that 
produces the output listed below? (You might not need all of the magnets, 
and you may reuse a magnet more than once.)
public static void main(String [] args) {
DungeonGame d = new DungeonGame();
int getX() {
return x;
public int x = 3;
transient long y = 4;
private short z = 5;
File Edit Window Help Torture
% java DungeonTest
12
8
class DungeonTest {
Code Magnets
long getY() {
return y;
short getZ() {
return z;
d = (DungeonGame) ois.readObject();
} catch (Exception e) {
ois.close();
class DungeonGame implements Serializable {
e.printStackTrace();
FileOutputStream fos = new
FileOutputStream(“dg.ser”);
oos.close();
fos.writeObject(d);
ObjectOutputStream oos = new
ObjectOutputStream(fos);
ObjectInputStream ois = new
ObjectInputStream(fi s);
oos.writeObject(d);
try {
System.out.println(d.getX()+d.getY()+d.getZ());
FileInputStream fi s = new
FileInputStream(“dg.ser”);
import java.io.*;


468
 
chapter 14
Exercise Solutions
1. Serialization is appropriate when saving data for non-Java programs to use.
2. Object state can be saved only by using serialization.
3. ObjectOutputStream is a class used to save serialized objects. 
4. Chain streams can be usedon their own or with connection streams. 
5. A single call to writeObject() can cause many objects to be saved.
6. All classes are serializable by default. 
7. The transient modifier allows you to make instance variables serializable.
8. If a superclass is not serializable then the subclass can’t be serializable.
9. When objects are deserialized they are read back in last-in, first out sequence. 
10. When an object is deserialized, its constructor does not run. 
11. Both serialization and saving to a text file can throw exceptions.
12. BufferedWriters can be chained to FileWriters.
13. File objects represent files, but not directories.
14. You can’t force a buffer to send its data before it’s full.
15. Both file readers and file writers can optionally be buffered. 
16. The String split() method includes separators as tokens in the result array.
17. Any change to a class breaks previously serialized objects of that class. 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   427   428   429   430   431   432   433   434   ...   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