AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hello world with main?? need help

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.tech
View previous topic :: View next topic  
Author Message
Singleton
Guest





PostPosted: Wed Nov 23, 2005 4:37 pm    Post subject: Hello world with main?? need help Reply with quote



How do i write a java program that doesn't have any "public static void

main(String[] args)" method and prints "Hello World" to the console ?


Back to top
Brett Kirkness
Guest





PostPosted: Sat Dec 03, 2005 1:54 am    Post subject: Re: Hello world with main?? need help Reply with quote



Hi
You have to have a static void main.
you can't start any program without it

brett


"Singleton" <kuchbhi (AT) homecall (DOT) co.uk> wrote

Quote:
How do i write a java program that doesn't have any "public static void

main(String[] args)" method and prints "Hello World" to the console ?





Back to top
Errol Miller
Guest





PostPosted: Thu Dec 08, 2005 12:41 am    Post subject: Re: Hello world with main?? need help Reply with quote



This article shows another method. I got it from:
http://www.devx.com/tips/Tip/29837

Expertise: Intermediate
Language: Java
November 15, 2005
Write a Standalone Java Application Without a Main Method
Normally, you need a main method in a Java class if you want to run that
class from the command line. However, there is a little trick that allows
you to run one without a main method:

class NoMainMethod
{
static
{
System.out.println("Look ma! no main method");
System.exit(0);
}
}
The reason this works is that static initialization blocks get executed as
soon as the class is loaded-even before the main method is called. As soon
as the block exits, it will look for the main method. When it doesn't find
it, it throws an exception-so the statement exits the program before the
exception is thrown.

Sachin Kainth

"Singleton" <kuchbhi (AT) homecall (DOT) co.uk> wrote

Quote:
How do i write a java program that doesn't have any "public static void

main(String[] args)" method and prints "Hello World" to the console ?





Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.tech All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.