answersLogoWhite

0


Best Answer
Java program without main

We need a main method for executing a program.

But YES we can write a program without using main() method.

TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.
TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main method

Whoa!!!!! we are done.


;)

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

A Java program needs an entry point - a class with a main() method. This tells the JVM where to start executing code. Once you have such a program, it can invoke other classes, which don't need a main() method.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

There can only be one entry point per program. The main method serves as that entry point and therefore cannot be overloaded.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

you can not write a java program without using even single class..............

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to write java program without using main method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg


Can you write a program without using any semicolon inside the main function?

not possible dude


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Is it possible to write a C program without using preprocesser directives?

Technically yes, practically no.


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


How do you write a program in C to swap two variables without using the third one using XOR?

a=a^b; b=a^b; a=a^b;


How do you write java program using two main method?

When you start your xxxx.class it will execute its 'public static void main (String args[])' method. Any other main methods won't be executed, only if your program explicitly calls them.


Can you write a program without main in c?

Certainly, you can write a program without main, but you cannot build an executable from it, if that is okay with you.


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?