• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

public static void main(String args[])

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very simple and basic question.
I was trying out the psv main() on my machine, and removing the public access specifier (and replacing it with any other or none at all) doesn't cause any run-time error.
I was always of the opinion that it shouldn't work, since the main() method is accessed by the Java Run-time which is not an instance of the class which spawns main() (and hence absolutely requires the public access specifier to access main()).
Rahul
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think if you dont give public in main then you can not run it (through commandline) from any directory other than the directory where the class file exists.
thanks
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Sathi
i tested that's the way it behaves
 
Rahul Ramachandran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
Within the same directory, all access specifiers work.
However, I tried moving up a directory and tried again.
Compiling is okay but runtime error is thrown.Exception in thread "main" java.lang.NoClassDefFoundError along with the path where the .class file is contained (this occurs despite the fact that the main() method has a public access specifier).
Rahul
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun has identified this as a bug. Please check the following link http://developer.java.sun.com/developer/bugParade/bugs/4235155.html
It will be fixed in future JDK release.
Tom
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic