This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

First question in Beginners forum ...

 
Tonya Cash
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I am working through the 2nd edition book Head first Java, and trying to figure out the following example code. As far as I can tell, everything is ok. Other classes compile fine, so I know it's not my PATH or CLASSPATH or anything like that. I have checked my brackets, and I am hoping someone here can see something I can't. Any Ideas?

Thank you!
- Tonya

I am getting this error:
SimpleDotCom.java:1: 'class' or 'interface' expected
public static void main(String[] args) {

when I try to compile the following code:
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A method (like main) needs to be a member of a class or interface. So the compiler is telling you that you need to enclose your code within a class definition...

 
Tonya Cash
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Marc! I see exactly what you mean ...
-Tonya
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, now that I look at this in more detail, it appears the classes SimpleDotCom and GameHelper are probably defined elsewhere. So rather than enclosing main in SimpleDotCom, you might name your class something like MySimpleTest...

But the point is that a method can't be compiled on its own.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic