The Artima Developer Community
Sponsored Link •

Java Answers Forum
Public Main

1 reply on 1 page. Most recent reply: Nov 22, 2004 3:40 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Steve Schooler

Posts: 17
Nickname: zugzwang
Registered: Aug, 2004

Public Main Posted: Nov 22, 2004 2:53 PM
Reply to this message Reply
Advertisement
/*  
    As is, the program below compiles okay but yields a run-time error:
     
        Main method not public.
        
    Although I can not duplicate the situation, I seem to recall occasionally
    forgetting to specify that main was public (as below) but having the CONSOLE
    program run okay anyway.  Can anyone identify situations where the console 
    program will run okay even though ITS main method is not public?  
*/
        
public class PublicMain {
    static void main(String[] args) { 
        System.out.println("Hello World"); 
    }
} 


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Public Main Posted: Nov 22, 2004 3:40 PM
Reply to this message Reply
main() method doens't necessarily has to be public. Here is question I sent to Sun and the reply I got (in 2001).

****************************************************
At 08:43 PM 1/22/01, Kishori wrote:

Hi
I am running Java2 v1.3. The Java Virtual machine Specification says that to run a class JVM calls public static main(String[] args ) method of the initail class. IN in v1.3 even if the main method is declared as private, or with no modifier, it works. Is it a bug in Java2 v1.3 JVM?


There is no bug, though the specification is perhaps to subtle. If you read JVMS 5.2 carefully, you will understand that the initial class that a user provides (often on the command line) is not the initial class that the spec is referring to. The initial class of the user's program need not be public. The JLS is somewhat misleading in this regard (even though it does refer to the binding specification in the JVMS).

Cheers, Gilad

Flat View: This topic has 1 reply on 1 page
Topic: KODO JDO performance Previous Topic   Next Topic Topic: What is the problem in this applet ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use