Is there any way in which I can run a class without the main method?
NO. JVM requires main() method to run a class. In other way you can do ...like,if you have a class called Test class having main method, then you can create a thread object of the class that you want to run not having main() method...then call start() and it's run method will be executed..(provided your class should implement Runnable interface).
There are tricks to run a program without a main(...) method, but in any normal program you should always have a main(...) method. Here is an example - do not use something like this in any serious program:
Technically, when you run applications inside an application server, your classes are running without a main method.
Yeah, but that's stretching the meaning of "running" an application a bit, i think. In that sense, an "application" could take many forms (applets, EJB, servlets, RMI, web service, ...), none of which have a main method.
Ping & DNS - updated with new look and Ping home screen widget
I'm rather surprised no-one has mentioned this yet...
To run a Java program, you need a native program that will instantiate a JVM and tell it to run method(s) in Java class(es). One might call that program a Java launcher. By far the most common one is the "java[.exe]" program that comes with a JRE or JDK.
The main() method is only special when the Java program is run via "java[.exe]" launcher. Another launcher might have entirely different behaviour.
You can obtain, or write for yourself, another Java launcher. You do this via a part of the Java Native Interface (JNI) called the Java Invocation Interface (JII?). A user-written Java launcher would typically be a C or C++ program (other languages are probably possible), which calls native functions in the JII to instantiate a JVM, find some Java classes and execute Java methods.
As an example, I wrote a Java launcher that does some licensing checks before decrypting some Java code. The encrypted Java code won't run with "java[.exe]" command. For obvious reasons, can't tell you more!