• Post Reply Bookmark Topic Watch Topic
  • New Topic

what am I doing wrong using Head First Java 2nd Edition?  RSS feed

 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly I'm running Mac OS X 10.9.2,
Java 7u51 (build 1.7.0_51-b13),

I I've written my first snippet of code from the book Head first Java, saved it as Party.java



Then I run javac on it and get this:


Party.java:6: error: illegal character: \8220
Label l = new Label(“Party at Tim’s”);
^
Party.java:6: error: ';' expected
Label l = new Label(“Party at Tim’s”);
^
Party.java:6: error: illegal character: \8217
Label l = new Label(“Party at Tim’s”);
^
Party.java:6: error: illegal character: \8221
Label l = new Label(“Party at Tim’s”);
^
Party.java:6: error: not a statement
Label l = new Label(“Party at Tim’s”);
^
Party.java:7: error: illegal character: \8220
Button b = new Button(“You bet”);
^
Party.java:7: error: ';' expected
Button b = new Button(“You bet”);
^
Party.java:7: error: illegal character: \8221
Button b = new Button(“You bet”);
^
Party.java:7: error: not a statement
Button b = new Button(“You bet”);
^
Party.java:8: error: illegal character: \8220
Button c = new Button(“Shoot me”);
^
Party.java:8: error: ';' expected
Button c = new Button(“Shoot me”);
^
Party.java:8: error: illegal character: \8221
Button c = new Button(“Shoot me”);
^
Party.java:8: error: not a statement
Button c = new Button(“Shoot me”);
^
13 errors


So is this code out of date for the current version of Java or am I jumping the gun and trying to compile something
not meant to be compiled?

-Rob
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob, welcome to CodeRanch!

What language setting do you have for your keyboard, and what editor are you using? While the characters you are using in your code certainly appear to be quotes and double quotes, it may be a result from misinterpretation between the font and the character set, or you're using a text editor like Word to write code in (this is a no-no).

Don't use , use ' . The same goes for , use " instead.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using smart quotes...you need to use plain old boring quotes.

What editor are you using? I don't know much about Macs, but my guess is that what you are using is trying to be 'helpful'. your code needs to look like this:

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dang...four seconds...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What did you use to type in that code, a word processor such as Microsoft Word or WordPad? The problem is that you have used fancy quotes “ and ” instead of normal, straight quotes ".

Don't use a word processing program to enter source code; use a text editor. I like Notepad++, it has syntax highlighting for Java.

*edit* Oh wait, you're using Mac OS X. Notepad++ is a Windows program. But I'm sure there are nice text editors for Mac OS X as well.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing...

When you get a whole slew of compiler errors, only worry about the first one. Many times a single mis-placed character cause the compiler to freak out, and mis-read the rest of the code. So if you fix the first error, many times several compiler errors that are seemingly unrelated go away.

so fix the first one, recompile, and see what (if any) are left.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick answers!

I'm actually using VIM, I also tried text wrangler I simply copy & pasted the
text from the PDF version of the book, me thinks the example was literally
just an example, as it does indeed use " instead '

You'all answered my question

-Rob
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

There is another problem: the Party application is incomplete and you cannot run it as stands.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!