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 private Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main method private" Watch "main method private" New topic
Author

main method private

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
I was solving a 1.4 mock exam. It had private main method and print statement in it. The answer provided is that the print statement will be executed.
I tried this on my machine but found that I was getting a runtime message that main method is not public.

I am totally confused

Please help me
bing marquez
Greenhorn

Joined: Aug 06, 2006
Posts: 11
hi joshua,

There is only one signature of main that the JVM looks for to launch
an application, i.e. void main(String[] args) and that is must be
public and static. However you,re free to declare another method named
main in your code, apart from the main() method required by the JVM, but
with a different signature.

consider:



Anyway, can you show the code...
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Joshua,

perhaps you should show us the code. Was it perhaps something like this?




Yours,
Bu.


all events occur in real time
Deepak Mahboobani
Greenhorn

Joined: Aug 17, 2006
Posts: 11
"The Java Virtual Machine Specification," which in section 2.17.1 states, "The method main must be declared public, static, and void."

Sun introduced this problem in version 1.2 of Java. As of 1.3 the problem is still there.

After a quick search for "private main" at java.sun.com, I found (requires login):

http://developer.java.sun.com/developer/bugParade/bugs/4252539.html

As you can see, the main issue is a known problem with a bug report opened against it. However, Sun has closed the bug report and the problem will NOT be fixed, "The runtime allows call to private methods, because of reflection. Fixing it will cause potential troubles."

So there you have it.

However, be careful while taking the certification exam. Last time that I checked, the proper answer to "How do you define a main?" remains: "The method main must be declared public, static, and void." Reality and the correct answer seem to disagree.
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Hi,

As i have read main method should be public only from 1.4 or above before 1.4 it can have any access modifier.Please correct me if iam wrong.

Regards,
Praveen
joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
Hi All,

Thanks for your replies.

Here is the code

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method private