Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to find "main class" in order to run a program

Reply
Thread Tools

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

 
 
hthukral.mickey@gmail.com
Guest
Posts: n/a
 
      02-20-2007
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 ..

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      02-20-2007
On Feb 21, 9:32 am, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-21-2007
(E-Mail Removed) 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
 
Reply With Quote
 
Martin Gregorie
Guest
Posts: n/a
 
      02-21-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      02-21-2007

"Lew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (E-Mail Removed) 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).


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


 
Reply With Quote
 
hthukral.mickey@gmail.com
Guest
Posts: n/a
 
      02-21-2007
On Feb 21, 10:16 am, Lew <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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


thanks LEW

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Program will not run, used to run, have reinstalled numerous times,no luck Boppy NZ Computing 15 01-24-2011 10:30 AM
Find.find reversed order on MacOSX Snow Leopard Raphaƫl Marmier Ruby 2 10-20-2009 07:39 AM
Scripts run using load in "for" loop run out of order Fa Sidd Ruby 12 01-26-2008 12:06 AM
Ruby must run in c:\ruby in order to find libraries (xp sp2) zenix Ruby 0 04-28-2007 03:55 PM



Advertisments