File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Head First Java Exercise Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Exercise" Watch "Head First Java Exercise" New topic

Head First Java Exercise

Alden Leatherman

Joined: Mar 09, 2006
Posts: 7
I am working through Head First Java 2nd edition. It's been amazingly good. I am having a problem getting the code magnet exercise solution on p. 314 to compile. My code looks just like the solution:

I get the compile error message:
D:\projects\javatest>javac <identifier> expected
import static java.lang.System.out;
^ '.' expected
import static java.lang.System.out;
2 errors

Could someone give me a clue?


[ March 11, 2006: Message edited by: Marilyn de Queiroz ]
Alden Leatherman

Joined: Mar 09, 2006
Posts: 7
The formatting moved the ^ symbol on my original post.
If it helps, on the first error the ^ points to the first letter of static.
The second ^ point to the semicolon at the very end.

marc weber

Joined: Aug 31, 2004
Posts: 11343

Hi Alden, welcome to JavaRanch!

This code compiles and runs fine for me. But static imports (along with the String.format methods) are new with Java 5.0, so my guess is that you are using a prior version.

What do you get when you type the following at the command prompt?

java -version

Note: To keep your indentation intact in these posts, use Code Tags.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Note that "java -version" is also a new feature in Java 5.0, so if this doesn't work try "java -Jversion" instead.


Java API Documentation
The Java Tutorial
Alden Leatherman

Joined: Mar 09, 2006
Posts: 7
I get the following:

D:\projects\javatest>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

Is that version 5?
Max Bean
Ranch Hand

Joined: Mar 09, 2006
Posts: 31

I can steal her idea in order to tell you that you can easily check it by typing java -Jversion at the command prompt. If it can't understand, your version is Java2 and vice versa for Java5 checking.
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
meaning of version ids: j2se 1.5.xx = j2se 5 = java Tiger

i know it is a bit confusing, but that is how marketing works .
tiger and 5 sound superiour to 1.5.

aldana software engineering blog & .more
marc weber

Joined: Aug 31, 2004
Posts: 11343

Yes, 1.5.x is another name for 5.0.

My understanding is that a Windows PATH variable applies to both java.exe and javac.exe, so I would expect your compiler (javac) to be 5.0 as well. Try typing the following:

javac -version

Note that this is different than the above because it's "javac" instead of "java." (The -version option is new for javac with 5.0, but has been available for some time with java.)

I copied your code exactly, and here's what I'm getting on a Mac...

Again, the code runs fine for me.
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
if you are using version < 1.5 then make the following changes for it to compile.

1. remove the import statement or comment it.
2. Also, the out.println(.............) to System.out.println("printing " + c);

alternatively, install JDK 1.5.

java j2ee job interview questions with answers | Learn the core concepts and the key areas
Alden Leatherman

Joined: Mar 09, 2006
Posts: 7
Thanks everyone. I had out-of-synch jre and sdk versions. Once I got the right sdk all worked as expected.

I agree. Here's the link:
subject: Head First Java Exercise
It's not a secret anymore!