Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public static void main

 
Lutin Verasoi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me how to modify this code (taken directly from the SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065) book) so it executes?
I keep getting the error message java.lang.NoSuchMethodError: main
Exception in thread "main" when I try to execute the examples from this book. I am told it's because the code doesn't include the main method, but I haven't found any information on what the correct syntax is for including the main methods and the other methods in the class. Here is the code -- any advice on how to modify it would be appreciated. Other examples that only include the main method have worked when I've executed them so I don't think this is an issue with my Classpath.

class Zoo {public String coolMethod(){
return "Wow baby";
}

}
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't write in the prompt java class if this class don't have the method main.
 
Lutin Verasoi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply. I understand that it needs the method main. My question was how should the code be modified so that the main method is included? The example I gave showed a class that contained the method called coolMethod. How do I include this in the class as well as the main method? I need to know the syntax and I can't seem to find an example of this anywhere.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lutin Verasoi:
Can you please tell me how to modify this code (taken directly from the SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065) book) so it executes?
I keep getting the error message java.lang.NoSuchMethodError: main
Exception in thread "main" when I try to execute the examples from this book. I am told it's because the code doesn't include the main method, but I haven't found any information on what the correct syntax is for including the main methods and the other methods in the class. Here is the code -- any advice on how to modify it would be appreciated. Other examples that only include the main method have worked when I've executed them so I don't think this is an issue with my Classpath.

class Zoo {public String coolMethod(){
return "Wow baby";
}

}


Every program has to have at least one main method.

One way of doing this is (save as TestZoo.java):
/

You probably should be starting with a less advanced resource for learning the language than the exam study guide... you need to know the basics first.
 
Lutin Verasoi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you recommend one that would be a good precursor to the exam guide?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lutin Verasoi:
Can you recommend one that would be a good precursor to the exam guide?

Head First Java by Kathy Sierra and Bert Bates.
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
core java is good guide too!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic