aspose file tools*
The moose likes Beginning Java and the fly likes Wonder!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wonder!!!!" Watch "Wonder!!!!" New topic
Author

Wonder!!!!

Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
class abc
{
public void display()
{
System.out.println("Abc");
}
public void display(int a)
{
System.out.println("int");
}
private static void main(String[] args)
{
System.out.println("Hello World!");
}
}

This code works fine for JDK1.3 evevn if main is private.but fails to run on JDK1.4 saying "Main is not public".

The question is How it is possible to invoke main method from startup code evenif it is private? or i am misunderstanding something?


Thanks in advance
Shrinivas
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

"How is it possible?" Remember that nothing marks a method private other than a flag in the class file; it's not as though it's hidden or encrypted or the class will bite you with three inch fangs if you call a private method. The application launcher doesn't have to follow the normal Java access rules, as it's not a Java program itself.

Regarding why it works in 1.3 vs. 1.4: it's always been required that main() be public, but this requirement hasn't always been enforced. Now it is.


[Jess in Action][AskingGoodQuestions]
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Originally posted by Shrinivas Mujumdar:

The question is How it is possible to invoke main method from startup code evenif it is private? or i am misunderstanding something?


Who said that JVM must play by the rules? After all, JVM is the one who makes the rules work


SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello,
Well the question is about the consisteny of rules. wheather it is Normal application or JVM itself.I do agree with Ernest about enforcing the rule in JDK1.4. One intresting stuff is in jdk 1.4 it simply flashes a message i.e. Main is not public it do not display any Error message. wheather it uses Assertion ?


Shrinivas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wonder!!!!