Results 1 to 7 of 7
Thread: Without main
- 08-14-2010, 06:10 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
- 08-14-2010, 07:07 PM #2
No and yes. The program that is started by the java command must have the main() method. I don't know a way to tell the java program to use another static method.
If you write an 'interface program' with a main, that program can create an instance of another class and optionally call any method in that class.
Another type of program not needing a main is an applet. In that case instead of being required to have a main, it is required to have an init method.
- 08-15-2010, 04:53 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
For an example,
Java Code:class NoMainMethod { static { System.out.println("this is a text"); System.exit(0); } }
- 08-15-2010, 07:36 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
Thanks
Thank you.
- 08-15-2010, 01:33 PM #5
Thanks. I learned two new things yesterday.
- 08-15-2010, 03:23 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-15-2010, 03:24 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
[SOLVED] Why main() in java is declared as public static void main?
By piyu.sha in forum New To JavaReplies: 5Last Post: 10-06-2008, 12:11 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
exception in thred main java.lang.nosuchmethoderror: main
By fernando in forum Java AppletsReplies: 1Last Post: 08-06-2007, 09:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks