— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet297/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   293   294   295   296   297   298   299   300   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

False
False
False
True
False
False
True or False


314
 
chapter 10
Exercise Solutions
import java.util.*;
import static java.lang.System.out;
class FullMoons {
static int DAY_IM = 1000 * 60 * 60 * 24;
public static void main(String [] args) {
Calendar c = Calendar.getInstance();
c.set(2004,0,7,15,40);
long day1 = c.getTimeInMillis();
for (int x = 0; x < 60; x++) {
day1 += (DAY_IM * 29.52)
c.setTimeInMillis(day1);
out.println(String.format(“full moon on %tc”, c));
}
}
}
File Edit Window Help Howl
% java FullMoons
full moon on Fri Feb 06 04:09:35 MST 2004
full moon on Sat Mar 06 16:38:23 MST 2004
full moon on Mon Apr 05 06:07:11 MDT 2004
Notes on the Lunar Code Magnet:
You might discover that a few of the 
dates produced by this program are 
off by a day. This astronomical stuff 
is a little tricky, and if we made it 
perfect, it would be too complex to 
make an exercise here.
Hint: one problem you might try to 
solve is based on differences in time 
zones. Can you spot the issue?
code magnets 
solution


11

exception 
handling 
this is a new chapter
315
Stuff happens. The file isn’t there. The server is down.
 
No matter how 
good a programmer you are, you can’t control everything. Things can go wrong. Very wrong. 
When you write a risky method, you need code to handle the bad things that might happen.
But how do you know when a method is risky? And where do you put the code to handle the 
exceptional situation? So far in this book, we haven’t really taken any risks. We’ve certainly had 
things go wrong at runtime, but the problems were mostly flaws in our own code. Bugs. And 
those we should fix at development time. No, the problem-handling code we’re talking about 
here is for code that you can’t guaranatee will work at runtime. Code that expects the file to be 
in the right directory, the server to be running, or the Thread to stay asleep. And we have to do 
this now. Because in this chapter, we’re going to build something that uses the risky JavaSound 
API. We’re going to build a MIDI Music Player.
Risky Behavior
Sure it’s risky, 
but I can handle it if 
something goes wrong. 
Make it Stick



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   293   294   295   296   297   298   299   300   ...   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