Search This Blog

Wednesday, March 18, 2009

java twister

Q:How to run the java program without using the main function ?
Ans: Yes,we can run our java program without using the main function see below:
class sachin
{
static
{
System.out.println("hello! how are you");
System.exit();
}
}


-->so ,by using the above code we can easily run our java program without main function.
Logic-->Actually,static block always executes bafore the main function since JVM firstly executes the static block and before the control goes to the main function we can make it exit by using System.exit() so in this way their is only one way to execute the java program without main ,another way is by using applet.