Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Java Exercise

 
Alden Leatherman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 FullMoons.java
FullMoons.java:2: <identifier> expected
import static java.lang.System.out;
^
FullMoons.java:2: '.' expected
import static java.lang.System.out;
^
2 errors

Could someone give me a clue?

Thanks

D:\projects\javatest>
[ March 11, 2006: Message edited by: Marilyn de Queiroz ]
 
Alden Leatherman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Alden
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that "java -version" is also a new feature in Java 5.0, so if this doesn't work try "java -Jversion" instead.

Layne
 
Alden Leatherman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL

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
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 FullMoons.java

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
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alden Leatherman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. I had out-of-synch jre and sdk versions. Once I got the right sdk all worked as expected.

Onward!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic