File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid signatures for main

 
Rob Keefer
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 351
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following discussion might help
http://www.coderanch.com/t/195318/java-programmer-SCJP/certification/Prototype-Main-method-java
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rob Keefer
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steven Wong
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic