— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

False
False
True
False
True
False
False
False
False
True
True
True
False
False
True
False
False
exercise 
solutions


serialization 
and
file I/O
you are here
4
469
File Edit Window Help Escape
% java DungeonTest
12
8
import java.io.*;
class DungeonGame implements Serializable {
public int x = 3;
transient long y = 4;
private short z = 5;
int getX() {
return x;
}
long getY() {
return y;
}
short getZ() {
return z;
}
}
class DungeonTest {
public static void main(String [] args) {
DungeonGame d = new DungeonGame();
System.out.println(d.getX() + d.getY() + d.getZ());
try {
FileOutputStream fos = new FileOutputStream(“dg.ser”);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(d);
oos.close();
FileInputStream fis = new FileInputStream(“dg.ser”);
ObjectInputStream ois = new ObjectInputStream(fis);
d = (DungeonGame) ois.readObject();
ois.close(); 
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(d.getX() + d.getY() + d.getZ());
}
}
Good thing we’re 
finally at the answers. 
I was gettin’ kind of 
tired of this chapter.



Make a Connection
Make it Stick
15

networking 
and 
threads
Connect with the outside world. 
Your Java program can reach out and touch a 
program on another machine. It’s easy. All the low-level networking details are taken care of by 
classes in the java.net library. One of Java’s big benefits is that sending and receiving data over 
a network is just I/O with a slightly different connection stream at the end of the chain. If you’ve 
got a BufferedReader, you can read. And the BufferedReader could care less if the data came 
out of a file or flew down an ethernet cable. In this chapter we’ll connect to the outside world 
with sockets. We’ll make client sockets. We’ll make server sockets. We’ll make clients and servers
And we’ll make them talk to each other. Before the chapter’s done, you’ll have a fully-functional, 
multithreaded chat client. Did we just say multithreaded? Yes, now you will learn the secret of 
how to talk to Bob while simultaneously listening to Suzy.
this is a new chapter
471


472
 
chapter 15
skyler4: fast and funky
, good for 
sequence 12
evster2: like skyler2, but more 
Oakenfoldish 
skyler5: you WISH! T
oo perky
try this one... it’
s better for 
sequence 8 
beat box 
chat
Real-time Beat Box Chat
You’re working on a computer game. You and your team 
are doing the sound design for each part of the game. 
Using a ‘chat’ version of the Beat Box, your team can 
collaborate—you can send a beat pattern along with 
your chat message, and everybody in the Beat Box Chat 
gets it. So you don’t just get to read the other 
Download 40,57 Mb.

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