954,190 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java

How to run a java program without main function.

farook ahammad
Newbie Poster
5 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 

there is no "main function" in Java, only a "main method".
It is required to have the exact signature "public static void main(String[] args)" or a lexical equivalent (it can for example be made final, or you may use another name instead of args).

Without that the JVM will not start executing the program.

There is one way to get something done, but that's NOT running a program.
That way involves creating a static initialiser block in the class, which will be executed at class loading time.

This smells horifically like a homework question so I won't show you how to do it :)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

you can run it without main method, but then it have to be Applet

Am'I correct jwenting?

peter_budo
Code tags enforcer
Moderator
15,433 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
 

An applet isn't technically a program :)
Same as a servlet or an EJB, both of which run without a "main" method.
Same for a SOAP service.
All can exist only within a specific runtime environment, and are effectively plugins to that environment.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You