*
The moose likes Beginning Java and the fly likes Has anyone done the GuessGame program in HeadFirst Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Has anyone done the GuessGame program in HeadFirst Java?" Watch "Has anyone done the GuessGame program in HeadFirst Java?" New topic
Author

Has anyone done the GuessGame program in HeadFirst Java?

Rita Chakras
Greenhorn

Joined: Aug 16, 2005
Posts: 10
I'm a little confused. The program has three classes. Do the three classes go in the same file? Or seperate files? If seperate, how do they find/talk to each other?

Just curious... not even sure if the code is supposed to work given the way it shown in the book.

Any help appreciated!

Thanks!
Rita C


Rita C.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
i have not seen the program.. but i can give an answer for your question.

simple rule is that if the class is defined as public it should be saved in a file with the same name. for eg

will be saved in a file called as Quiz.java

in other cases it can be placed along with any other classes.

the way the programs communicate is that the class file will be searched in the classpath.


Karthikeyan<br />SCJP 1.4, SCWCD.
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

You can also pick up the actual source code here:

http://www.wickedlysmart.com/HeadFirst/HeadFirstJava/code/codeKitchensTiger.jar
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
The program has three classes. Do the three classes go in the same file? Or seperate files? If seperate, how do they find/talk to each other?

It's usually best to put each class in its own file. Whether or not they are in the same source file, when you compile them with the "javac" command, they will become three separate ".class" files. The class files "find each other" by using the classpath when you run them with the "java" command.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
All three classes should be in the same directory.

I just noticed... I'm now a ranch hand


I'm a Hood Ornament
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
I just noticed, I'm still a ranch hand. I should be interim assistant secretary to the deputy trash collector by now. I feel a certain empathy with Fester on Gunsmoke.

For those not familiar with Gunsmoke, Fester was the deputy sheriff but also a world class producer whose works include The Giant Gila Monster. IMO, the cinematic equivalent of Chopin or Beethoven.

http://www.englewd.com/catalog/detail.cfm?ProdNum=59&GroupID=1
[ August 21, 2005: Message edited by: Rick O'Shay ]
 
jQuery in Action, 2nd edition
 
subject: Has anyone done the GuessGame program in HeadFirst Java?
 
Similar Threads
Passing Parameters
how can i separate string?
WSDL2JAVA generating some unnecessary holder classes
instanceof
Closing SSH connection kill deamon