File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Junior/Associate Certification (SCJA,OCAJ 5/6/8) 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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Junior/Associate Certification (SCJA,OCAJ 5/6/8)
Bookmark "SCJA Java Examples" Watch "SCJA Java Examples" New topic

SCJA Java Examples

Hrishikesh Pramod

Joined: Apr 10, 2011
Posts: 8
I am currently studying for the SCJA Exam. I was writing a program called 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!!
Hrishikesh Pramod

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

Joined: May 26, 2003
Posts: 32848

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Hrishikesh Pramod

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

Joined: Sep 27, 2002
Posts: 276

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.


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

Joined: Apr 10, 2011
Posts: 8
I agree. Here's the link:
subject: SCJA Java Examples
It's not a secret anymore!