Which is the Best Java Web Framework ?

Java - Things to know before your OCJP exam - Main Method Declaration


Following are valid main method declarations


    public static void main(String[] args)
    static public void main(String[] args)
    public static void main(String... args)
    public static void main(String...      args)
    public static void main(String      ...args)


Following declarations are not valid and result in compilation errors

    public void static main(String[] args)  // modifiers should be placed before return types.
    static void public main(String[] args) // modifiers should be placed before return types.
    public static void main(String[]) // reference name missing
    public static void main(String.. args) // 2 dots in the variable argument
    public static void main(String.   .. args) // variable argument declared wrong
    public static void main(String args...) // variable argument declared wrong


Following declarations gets compiled correctly but the program gives runtime exception / errors

    public static void main(String args) // Upon execution JVM looks for main with argument String array 
    public void main(String[] args) // static missing
    private static void main(String[] args) // method declared private and hence not accessible
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.