File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes public static void main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "public static void main " Watch "public static void main " New topic
Author

public static void main

Lutin Verasoi
Greenhorn

Joined: Sep 08, 2008
Posts: 3
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

Joined: Aug 08, 2007
Posts: 202
you can't write in the prompt java class if this class don't have the method main.


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Lutin Verasoi
Greenhorn

Joined: Sep 08, 2008
Posts: 3
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

Joined: Oct 06, 2007
Posts: 338
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

Joined: Sep 08, 2008
Posts: 3
Can you recommend one that would be a good precursor to the exam guide?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"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
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
core java is good guide too!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public static void main