This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private main method in java

 
gokulanand narayanan
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can i have a class like this? and will i be able to run this?

class A
{
private static void main(String args[])
{
System.out.println("Hello World!");
}
}

I am able to do this (only with the version jdk1.3.1_20)

Can anyone explain me!!!

Thanks
Gokul
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can certainly have such a class.

You should not be able to run it, using the normal "java[.exe]" launcher; to do that, your class and its main() should be public.

If you find you can run it, that might be a feature of your ancient Java version.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:

If you find you can run it, that might be a feature of your ancient Java version.


Or rather a bug...
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
..
If you find you can run it, that might be a feature of your ancient Java version.


I wonder was there an earlier version of Java supporting this first of all?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, older versions of Java allowed this, for no apparent reason. This changed around JDK 1.4. The JLS has always said that the main method must be public, although it doesn't say what should happen if it's not publuc. So one might argue that this behavior was simply unspecified, not technically a bug. Regardless, anyone who uses a private main method should consider the code to be extremely unreliable at best.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic