wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Valid signatures for 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 "Valid signatures for main" Watch "Valid signatures for main" New topic
Author

Valid signatures for main

Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
In the RHE book, question 3 in chapter 1 asks, "Which of the following signatures are valid for the main() method entry point of an application?"
It gives 5 possible answers, one of which is
"public static int main(String[] arg)"
According to the answers in the back of the book, this is valid. However, when I try it, I get:
Exception in thread "main" java.lang.NoSuchMethodError: main
using this code:

What am I missing?
- Rob
Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351
This is one of those SCJP trick questions you just have to learn.
The example you gave will compile without error, but will throw a runtime exception because you to have a runnable application the main method signature must be found:
public static void main( String args[] )
{
...stuff
}
You'll have to read the question carefully and think like a compiler. Don't read more into the question than what is asked.
[ April 15, 2002: Message edited by: Michael Pearson ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
The following discussion might help
http://www.coderanch.com/t/195318/java-programmer-SCJP/certification/Prototype-Main-method-java


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Which version of the RHE book do you have?

In the first edition, the answer is "B and D are both acceptable. Answer A will compile but will not be called."

In the second edition, the answer is "B, D"

Where B is public static void main( String arg[] )
and D is public static void main( String[] arg )
( and A is public static void main() )
[ April 16, 2002: Message edited by: Marilyn deQueiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
Originally posted by Marilyn deQueiroz:
Which version of the RHE book do you have?


Yeh, I have the second edition. All the answer says is Answer: B, D, E
There is no real description. Hence, the question.

Thanks for the tips. I guess "valid" means compile, not execute.
- Rob
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
If the question is:
"Which of the following signatures are valid for the main() method entry point of an application?"
public static int main(String[] arg) is wrong. Because, may be its a valid methid but not a valid main entry point.


Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
Steven Wong
Ranch Hand

Joined: Mar 07, 2002
Posts: 295
I think the following would be the list of the main method for the main entry points.
public static void main(String[] args)
static public void main(String[] args)
final public static void main(String[] args)
public final static void main(String[] args)
where String[] args can be put in anyway like Sring[] args, String args[], etc. etc. etc.
Correct me if I am wrong.


best regards,<br />Steven<br />SCJP, SCEA
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
You must have an earlier printing than I do. It's in the RHE errata. The answer should be B and D.

Page 716
3. Which of the following signatures are valid for the main() method entry point of an application? Answer: B and D

[ April 17, 2002: Message edited by: Marilyn deQueiroz ]
 
GeeCON Prague 2014
 
subject: Valid signatures for main