Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

how to find "main class" in order to run a program

Thread view: 
hthukral.mickey@gmail.com - 20 Feb 2007 22:32 GMT
hi..
 As per example in case of any JDK ..demo examples  are given.. one
can run it from command line by knowing which is the main class file
(i.e. where main class is being declared)
But how to find that out is a problem i'm facing ..
Andrew Thompson - 20 Feb 2007 22:46 GMT
On Feb 21, 9:32 am, hthukral.mic...@gmail.com wrote:
...
> But how to find that out is a problem i'm facing ..

Also, communication skills.
(Don't forget to ask a question)

Andrew T.
Lew - 21 Feb 2007 05:16 GMT
hthukral.mic...@gmail.com wrote:
> ...
>> But how to find that out is a problem i'm facing ..

You might find /Thinking in Java/ by Bruce Eckel very helpful on these kinds
of problems. It does a right fine job of helping one understand the
fundamentals of the Java language. Earlier versions of the book are available
for free on line.

There is not exactly a concept of "main class" in Java. In JAR files there is
a so-called "manifest" that tells a "java -jar" command what class to run, but
nothing prevents running the main() method of a different class in that same
JAR using other syntax.

There is a concept of a main() method in a class, and any public class that
has a properly defined main() method is a "main class".

If you are running a Java application from someone else, their documentation
should tell you what class to run. If it is your application, then you get to
choose any class for which you wrote a main() method (obeying the rules of
that method).

- Lew
Oliver Wong - 21 Feb 2007 16:10 GMT
> hthukral.mic...@gmail.com wrote:
>> ...
[quoted text clipped - 17 lines]
> application, then you get to choose any class for which you wrote a main()
> method (obeying the rules of that method).

   On the other hand, a couple of IDEs have a concept of a "main class"
(Eclipse is one of them), and that concept basically refers to which class's
main method the IDE should run when you tell it to run the application. Note
that every "run configuration" (that's the term Eclipse uses) has exactly
one main class, but a given project may have multiple main classes (which
implies multiple "run configurations" can be associated with a single
project).

   So as Lew said, if it's your application, then you, as the designer,
just choose a class to be your main class. If you're inheriting code from
someone else, then you just gotta search for static void methods called
"main" which take an array of String as an argument (different IDEs have
different ways of searching through the code base). If you gotta do this
programmatically, then you iterate through all the candidate classes, using
reflection to check for the existence of such a method.

   - Oliver
hthukral.mickey@gmail.com - 21 Feb 2007 16:12 GMT
> hthukral.mic...@gmail.com wrote:
> > ...
[quoted text clipped - 19 lines]
>
> - Lew

thanks LEW
Martin Gregorie - 21 Feb 2007 12:43 GMT
> hi..
>   As per example in case of any JDK ..demo examples  are given.. one
> can run it from command line by knowing which is the main class file
> (i.e. where main class is being declared)
> But how to find that out is a problem i'm facing ..

grep

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.