File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main method with command line args. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main method with command line args." Watch "main method with command line args." New topic
Author

main method with command line args.

saiprasad raut
Ranch Hand

Joined: Aug 29, 2003
Posts: 40
i was going through the mock exam on http://www.danchisholm.net/nov11/guide/chapter2/exam1.html
and came across a question.
class GRC1 {public static void main(String[] args) {}} // 1
class GRC2 {protected static void main(String[] args) {}} // 2
class GRC3 {private static void main(String[] args) {}} // 3
What is the result of attempting to compile each of the three class declarations and invoke each main method from the command line?
a. Compile-time error at line 1.
b. Compile-time error at line 2.
c. Compile-time error at line 3.
d. An attempt to run GRC1 from the command line fails.
e. An attempt to run GRC2 from the command line fails.
f. An attempt to run GRC3 from the command line fails.

The answer is given as 'e' and 'f' with the description as
'Section 12.1.4 of the JLS requires the main method to be declared public. The main methods of GRC2 and GRC3 are not declared public and can not be invoked from the command line using a JVM that is compliant with section 12.1.4. Not every JVM enforces the rule. Even so, for the purposes of the SCJP exam, the main method should be declared as required by the JLS. '
But when i tried to compile and run code with the main method as private and protected and passed the command line args. it worked and run without any error.
Can anybody give me the explanation?
Thanks.
Saiprasad
Suresh Thota
Ranch Hand

Joined: Sep 24, 2003
Posts: 152
Hai Sai,
This is due to a bug in JDK (prior to 1.4. I believe it's fixed in 1.4). You can find many links on this topic.
For the exam, assume that main method should be public.


SCJP 1.6
saiprasad raut
Ranch Hand

Joined: Aug 29, 2003
Posts: 40
Thanks suresh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method with command line args.