Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Program without a main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Program without a main method" Watch "Program without a main method" New topic
Author

Program without a main method

Anshul Kapoor
Greenhorn

Joined: Apr 09, 2010
Posts: 5

Is there any other way of creating a program without a main method ?
public class Test{
static{
System.out.println("Without a Main Method");
System.exit(1);

}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Depends on what your definition of "program" is. What you posted would not fit my definition of "program", but it is a Java class that can be executed without having a main method, yet still executes some code.


Ping & DNS - updated with new look and Ping home screen widget
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

And welcome to the Ranch!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program without a main method
 
Similar Threads
thread without main( String arg[])
Error: Exeption in thread "main" java.lang.NoSuchMethodError: main
how to run a normal java program without main method
Do Java program can run without main function()? If not please solve this problem
can a program without "main" method show output?