• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

First question in Beginners forum ...

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Marc! I see exactly what you mean ...
-Tonya
 
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
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.
 
I found a beautiful pie. And a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic