Two Laptop Bag
The moose likes Associate Certification (SCJA/OCAJ) and the fly likes SCJA Java Examples Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Associate Certification (SCJA/OCAJ)
Reply 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
internet detective
Marshal

Joined: May 26, 2003
Posts: 23635

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]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
Hrishikesh Pramod
Greenhorn

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

Joined: Sep 27, 2002
Posts: 126
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


SCWCD, SCJP
Hrishikesh Pramod
Greenhorn

Joined: Apr 10, 2011
Posts: 8
Thanks!
 
IntelliJ Java IDE
 
subject: SCJA Java Examples
 
Threads others viewed
Problem in checkbox
Hoare-Calculus
oddSum
New Free Online Java Compiler and Runner
what's the difference between "throw" and "throws"?
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture