• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head First Java Exercise

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone explain the code I am finding it difficult to understand because of 2 thing DAY_IM and x<60.

thank you.
 
Heta Dobariya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,currently doing this program but I am finding it difficult to understand because of two things : DAY_IM and x<60 .
Can anyone explain the code ?

thank you !
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at this link.
DAY_IM tells us how many milliseconds there are in a day.
Why do you think there would be x < 60 in a loop header?
Nobody uses Calendar any more. Look in the Java™ Tutorials to find out what you should use instead.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic