aspose file tools*
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes SCJA Java Examples Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "SCJA Java Examples" Watch "SCJA Java Examples" New topic
Author

SCJA Java Examples

Hrishikesh Pramod
Greenhorn

Joined: Apr 10, 2011
Posts: 8
Hi,
I am currently studying for the SCJA Exam. I was writing a program called Factorial3.java from the book Java Examples in a nutshell.
I wrote the program, and after i compiled it and ran it, it said

Exception in thread "main" java.lang.NoSuchMethodError: main

Here is the Program:


Please Help!!
Thanks
Hrishikesh Pramod
Greenhorn

Joined: Apr 10, 2011
Posts: 8
BTW, I am 13 and I want to take the SCJA.Is it allowed?
Thanks..
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Welcome to CodeRanch!

I added code tags to make the code more readable. Yes, you are allowed to take the test at 13. As long as your parents are ok with using their credit card to pay for it.

Java is telling you that you don't have a main method. To run a class at the command line, it needs a method that looks like this:



You would then call factorial(42) from the main method and it would run the rest of the code.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Hrishikesh Pramod
Greenhorn

Joined: Apr 10, 2011
Posts: 8
Thank you Jeanne
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Hrishikesh,

As mentioned by Jeanne, you need to add a 'main' method to your class Factorial3, so that you can execute it as a Java application, as follows:



Note that both 'main' and 'factorial' are static methods - methods that do not need existence of a class object to execute.

cheers
Mala


Author of Manning's OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Hrishikesh Pramod
Greenhorn

Joined: Apr 10, 2011
Posts: 8
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJA Java Examples