It's not a secret anymore!
The moose likes Bunkhouse Porch and the fly likes Missing something Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Books » Bunkhouse Porch
Bookmark "Missing something" Watch "Missing something" New topic

Missing something

Phil Kirsch

Joined: Jun 14, 2006
Posts: 1
I got the code below from Head First Java, Edition 2, page 567.

1 import java.util.*;
3 public class TestMap {
5 public static void main(String[] args) {
6 HashMap<String, Integer> scores = new HashMap<String, Integer>();
8 scores.put("Kathy", 42);
9 scores.put("Bert", 343);
10 scores.put("Skyler", 420);
12 System.out.println(scores);
13 System.out.println(scores.get("Bert"));
15 }
16 }

I get the following errors at compile time:

javac not a statement
HashMap<String, Integer> scores = new HashMap<String, Integer>();
^ ';' expected
HashMap<String, Integer> scores = new HashMap<String, Integer>();
2 errors

I've checked my typing and gone back in the book. Can't figure out what's going on. I may feel really stupid when someone explains this, but right now I'm stumped.
Orem Hun

Joined: May 24, 2005
Posts: 28
Which version of JDK are you using ?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
the only reason that could happen is if the compiler doesn't know about the Collections framework.
That excludes every compiler from 1.2 onwards except gcj (which is a disaster, never use it!) AFAIK.

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Phil, it seems to me that even if you were using a JDK so old it did not recognize HashMap, you should get a different error message in that case: cannot find symbol
symbol : class HashMap

I think there's still a typo somewhere, perhaps in line 5. I suggest you copy and paste the code you're trying to compile. Don't insert line numbers - just copy exactly what you have.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Missing something
jQuery in Action, 3rd edition