Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling main() method

 
Chandra Mouli
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wrote a program like the one below.
public class Test {
private static void main(String args[]) {
System.out.println("Hello");
}
}
Instead of declaring main method as public, I declared it as private.
But still the program was running without any error and printed "Hello".
Can anyone please tell what is actually happening?
Thankx in advance...
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously it depends of java (JVM).
How it works - search in public class the main function, and
check its signature (type of argument, output value, static/not
static, public/private/protection/default)
Probably used version of JVM don't have check of access attribute,
or the check accepted not only public, but your case.
What is the problem?
Exists a lot of JVM.
And men writing JVM aren't alwais perfect.
 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes .. It does work perfectly OK...
As a matter of fact private main method issue is a known problem with a bug report opened against it.
Sun has however closed the bug report and the problem will NOT be fixed.
But be careful while taking the certification exam.
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so Sun doesn't think that is important.
Igor
Sun Uncertified java programmer.
[ December 22, 2003: Message edited by: Igor Ko ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that this was an issue of older JVMs. Sun's latest 1.4.2 JVM requires that the main method be public.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic