wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes New In Java need a little help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New In Java need a little help please" Watch "New In Java need a little help please" New topic
Author

New In Java need a little help please

diego godoy
Greenhorn

Joined: Aug 21, 2008
Posts: 1
why when I try to run the example in page 3 of Book Head First Java in my mac OS 10.5 Leopard I don't get results; get error. This is the Exercise:





1 save as Party.java
2 compile the Party.java by running javac (the compiler application)
if you don't have any errors, you'll get a second document named Party.class
3 compiled code Party class
4 Virtual Machine get the actual box with buttons by running the Java Virtual Machine
The JVM tranlate the bytecode into something the underlying platform
undestands

when I tried to compile the source code Party.java I get 2 error code
"class" or "interface" expected
}
"class" or "interfaced" expected
}
2 errors



can you plase help out I'm really into it Thanks!!!

[edit]Add code tags. CR[/edit]
[ August 22, 2008: Message edited by: Campbell Ritchie ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Welcome to the Ranch.

I don't believe that there's anything Mac-specific about your issue, so I'll move this along the the general java forum.

Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
I don't have the book but wouldn't you need something like public class party rather than just class party at the beginning?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
The code you've posted looks fine. A class doesn't have to be public. The error you are getting is usually caused by mismatched opening { and closing }. Check that first and if you can't find a miismatch, post the whole of the file here (using code tags).


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
I don't have that book, but I believe some of the earlier examples are incomplete and will compile but not run.

If that particular error occurs at the beginning of the file then you have probably put something incorrect before the class declaration or spelt it wrongly, eg classParty or Class Party or classs Party.
If you get that error towards the end of the file you have (as Joanne has already said) more { than } somewhere.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Originally posted by Iain Emsley:
I don't have the book but wouldn't you need something like public class party rather than just class party at the beginning?
It is probably better to declare the class "public" but not essential.
Vihung Marathe
Greenhorn

Joined: Apr 24, 2006
Posts: 7
Fundamental Question - is the source file in plain text?

What are you using as your editor? If it is TextEdit, then have you saved the file as plain text?
blingo james
Greenhorn

Joined: Oct 12, 2008
Posts: 25
Pasted your code, javac, and it worked for me (some warnings, but no errors)
,and .class file created.

Is what you've pasted in here exactly what you have on file?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Campbell Ritchie:
I don't have that book, but I believe some of the earlier examples are incomplete and will compile but not run...

That's exactly right.

See the note at the bottom of page 3: "... you'll be writing real code in a moment, but for now, we just want you to get a feel for how it all fits together."

The Party example is just part of a high-level sketch illustrating the process of writing source code, compiling to bytecode, and running with the JVM. It won't "do" anything as shown.

The code you posted compiles fine for me (also on a Mac). But the errors you posted are exactly what you would get if your code has an extra closing brace "}" at the end. The error messages should also display line numbers. For example, if that extra brace were at line 13, it would say:

(The first error message points ^ to the brace, and the second message points ^ at the space after the brace. But it's really just one error.)
[ October 26, 2008: Message edited by: marc weber ]

"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
sscce.org
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Originally posted by blingo james:
Pasted your code, javac, and it worked for me (some warnings, but no errors)
,and .class file created.

Is what you've pasted in here exactly what you have on file?


Since the previous post is 6 weeks old, is the previous poster likely to be reading?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Campbell Ritchie:
... Since the previous post is 6 weeks old, is the previous poster likely to be reading?

Doh! I didn't even notice that.

Well, in the event he's been scratching his head over page 3 for the past month and a half, hopefully this will provide what he needs to move on.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
You're obviously not British; in this country "scratching your head over page 3" would mean something completely different.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New In Java need a little help please