• Post Reply Bookmark Topic Watch Topic
  • New Topic

My first Java Program  RSS feed

 
Tony Davis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am literally starting to learn java right now, and I am using head first java as my first resource. I entered the following two java programs.
the first one seems to have executed successfully, but the second one i am getting an error. i am confused about that because i entered it straight out of the book.

I know i am getting ahead of myself, but does the 2nd one below (the one that does not work) need the public statement at the top? just guessing....

the error is:
main method not found in class Party, please define the main method as:
public static void main(String [] args)



 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and welcome to the ranch.

First, thanks for using code tags on your first ever post. That's a great start...but you didn't quite get them right. Your code needs to go between the [ code] and [ /code] tag. You can edit your post and correct it if you like.

Next, I'm not sure as I don't the book in front of me, but I think that example is not supposed to be entered and compiled. I believe they are just trying to give you and idea of what you'll be seeing. Somewhere around it, it should say "this is not a working/complete exmaple".

Finally, that error message does tell you exactly what is wrong. Java programs require a 'main' method - this is where execution starts. There are some exceptions, like if you are writing an applet or web-based component, but any time you type "java <ClassName>", that class MUST have a method defined as



or it won't work. You could write one in that class, but if you are just beginning, there's probably more to it than you know right now.

In short, I'd just say don't worry about it. Assuming that is the code exactly as it is in the book, no, it won't run.
 
Tony Davis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply. I have attempted to correct the code tags. I should have seen that. Thanks again.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!