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

Discussion in 'Java' started by hthukral.mickey@gmail.com, Feb 20, 2007.

  1. Guest

    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 ..
    , Feb 20, 2007
    #1
    1. Advertising

  2. On Feb 21, 9:32 am, 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.
    Andrew Thompson, Feb 20, 2007
    #2
    1. Advertising

  3. Lew Guest

    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
    Lew, Feb 21, 2007
    #3
  4. 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 |
    Martin Gregorie, Feb 21, 2007
    #4
  5. Oliver Wong Guest

    "Lew" <> wrote in message
    news:...
    > 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
    Oliver Wong, Feb 21, 2007
    #5
  6. Guest

    On Feb 21, 10:16 am, Lew <> wrote:
    > 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
    , Feb 21, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cyril
    Replies:
    2
    Views:
    3,853
    cyril
    Aug 25, 2004
  2. learner9
    Replies:
    0
    Views:
    1,241
    learner9
    Apr 14, 2006
  3. zenix
    Replies:
    0
    Views:
    83
    zenix
    Apr 28, 2007
  4. Fa Sidd
    Replies:
    12
    Views:
    212
    ara howard
    Jan 26, 2008
  5. Raphaël Marmier
    Replies:
    2
    Views:
    152
    Raphaël Marmier
    Oct 20, 2009
Loading...

Share This Page