• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wonder!!!!

 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic