aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java 2nd Ed. Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java 2nd Ed. Problems" Watch "Head First Java 2nd Ed. Problems" New topic
Author

Head First Java 2nd Ed. Problems

El Mitchel
Greenhorn

Joined: Jun 03, 2007
Posts: 1
Hi I'm new here. I do have some basic Java background but very minimal. I first learned it from school like a year ago.

I just started reading Head First Java 2nd Edition and I already have problems with the first two chapters.

First was the PhraseOMatic from chapter 1. I followed the directions at the side and typed the source code word by word. Now the problem was when I compile it. It displays "package System does not exist" when compiled in JCreator. It's the same in MSDOS also. I left it for a while to test it in school when i'll go there to check if they have the same result. I moved to chapter 2.

I also typed the code as it was written like this:


When I compiled it, it displays this:
class GuessGame is public, should be declared in a file named GuessGame.java
class Player is public, should be declared in a file named Player.java
cannot find symbol class Guessgame

I'm 99% sure I don't have any typos ther.

BTW, I'm using the latest version Java SE. Thanks for your solutions in advance.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I haven't read HF java recently. But I guess they must have mentioned that all these classes need to be in different files. Either make all the classes expect the class with main method package private (remove the public from public class) or declare them in different files in the same directory.
swapnil deo
Greenhorn

Joined: May 30, 2007
Posts: 6
till what extent i know we can have only 1 public class in 1 file.
in the code you mentioned you have declared more than 1 " public " classes in 1 file
try declaring all the classes in different files
it might work out for you!
Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
Your first error message
class GuessGame is public, should be declared in a file named GuessGame.java
is an error message with which I am all too familiar. What file name did you save your code under? It should have been saved as GuessGame.java. (Not, for example, as something like Chap2Game.java - which is what I tend to do ...)

Also, the advice about putting each public class in a file with exactly the same name as the class is exactly correct.

I am completely new to Java and am working my way through the same book. So far, pretty much all of the example code has worked for me.

Good luck!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java 2nd Ed. Problems