This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJA Java Examples

 
Hrishikesh Pramod
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, I am 13 and I want to take the SCJA.Is it allowed?
Thanks..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hrishikesh Pramod
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne
 
Mala Gupta
Author
Ranch Hand
Posts: 291
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hrishikesh Pramod
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic