File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes private static void main(String args[]) ...!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "private static void main(String args[]) ...!!!!!!" Watch "private static void main(String args[]) ...!!!!!!" New topic
Author

private static void main(String args[]) ...!!!!!!

Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi ppl,
If we go by the defn of access modifiers whenever a method is denoted as private it means that it can be accessed from within a class only.
now what i did was i tried the private access modifier for PSVM(String args[]){} and it worked.
what i would like to know is how does the PSVM method fit into all this and where does the method lie exactly for it to work even with a private access modifier.
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
According to the JLS it should not work with a private modifier, but still some compilers and JVM work fine if you use the private modifier, it shouldn't though...
Rule of the thumb, follow the JLS in the code you're writting so that you will have no problem with any compilor, JVM


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi Alfred,
According to the JLS it should not work with a private modifier

That's exactly what i thought that it should not work but it does and i kinda wanted to know why and how it does work even in a few compilers that it works on.
i am not using the access modifier in any of my code and i stick to the JLS but why private SVM(String args[]) works is something i feels depends on how the JVM is built and the ClassLoader invocations.
any light on this by anyone who knows why it works will be very much appreciated.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It's a hole in the implementation. It's always been like that and if they changed now it might cause problems to existing code.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
In fact, they did change it to conform to the previously-existing spec, as of 1.4. Try creating a private main method now - you get "main method not public". Older JDKs allowed it, but not the latest ones.


"I'm not back." - Bill Harding, Twister
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It still compiles but you get the error message when you attempt to run. This solution is worse than treating private main methods as public.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private static void main(String args[]) ...!!!!!!
 
Similar Threads
Static method modifier question
JQPlus??
Java Interview Questions
Regrding Access Specifier used of main method
Overloading Signature