Exception in thread "main" java.lang.NoClassDefFoundError: Just

Discussion in 'Java' started by Nikhil, Apr 3, 2007.

  1. Nikhil

    Nikhil Guest

    class Just
    {
    public static void main(String[] args)
    {
    System.out.println("Hello World!");
    }
    }


    Even this simple piece of code is not executing on my machine.
    It compiles and at runtime it throw the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: Just


    please please please help me....
    Thanks
    Nikhil, Apr 3, 2007
    #1
    1. Advertising

  2. Nikhil

    Oliver Wong Guest

    "Nikhil" <> wrote in message
    news:...
    > class Just
    > {
    > public static void main(String[] args)
    > {
    > System.out.println("Hello World!");
    > }
    > }
    >
    >
    > Even this simple piece of code is not executing on my machine.
    > It compiles and at runtime it throw the following error:
    >
    > Exception in thread "main" java.lang.NoClassDefFoundError: Just


    http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR

    If this doesn't fix it, you need to provide more info: What you typed
    at the command prompt, what your classpath environment variable is set to,
    what your directory structure is like, what directory you were in when you
    typed in the command, etc.

    - Oliver
    Oliver Wong, Apr 3, 2007
    #2
    1. Advertising

  3. Nikhil

    Lew Guest

    Oliver Wong wrote:
    > "Nikhil" <> wrote in message
    > news:...
    >> class Just
    >> {
    >> public static void main(String[] args)
    >> {
    >> System.out.println("Hello World!");
    >> }
    >> }
    >>
    >>
    >> Even this simple piece of code is not executing on my machine.
    >> It compiles and at runtime it throw the following error:
    >>
    >> Exception in thread "main" java.lang.NoClassDefFoundError: Just

    >
    > http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR
    >
    > If this doesn't fix it, you need to provide more info: What you typed
    > at the command prompt, what your classpath environment variable is set to,
    > what your directory structure is like, what directory you were in when you
    > typed in the command, etc.
    >


    Doesn't the class need to be public?

    --
    Lew
    Lew, Apr 4, 2007
    #3
  4. Nikhil wrote:
    > class Just
    > {
    > public static void main(String[] args)
    > {
    > System.out.println("Hello World!");
    > }
    > }
    >
    >
    > Even this simple piece of code is not executing on my machine.
    > It compiles and at runtime it throw the following error:
    >
    > Exception in thread "main" java.lang.NoClassDefFoundError: Just


    Try:

    java -cp . Just

    instead of:

    java Just

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Apr 4, 2007
    #4
  5. Lew wrote:
    >> "Nikhil" <> wrote in message
    >> news:...
    >>> class Just
    >>> {
    >>> public static void main(String[] args)
    >>> {
    >>> System.out.println("Hello World!");
    >>> }
    >>> }


    > Doesn't the class need to be public?


    It should according to JLS.

    But java does not check.

    There are several bug reports on that.

    Arne
    =?UTF-8?B?QXJuZSBWYWpow7hq?=, Apr 4, 2007
    #5
  6. Arne Vajhøj writes:
    > Lew wrote:
    >>> Nikhil wrote:
    >>>
    >>>> class Just
    >>>> {
    >>>> public static void main(String[] args)

    ....
    >> Doesn't the class need to be public?

    >
    > It should according to JLS.
    >
    > But java does not check.
    >
    > There are several bug reports on that.


    Where does JLS say the class should be public? I failed to find it in
    the index and in the following page that explains how a program is
    executed. In none of the example programs on that page is the main
    class public: they are all just "class Test".

    <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44444>
    Jussi Piitulainen, Apr 4, 2007
    #6
  7. Nikhil

    Chris Uppal Guest

    Jussi Piitulainen wrote:

    > Where does JLS say the class should be public? I failed to find it in
    > the index and in the following page that explains how a program is
    > executed.


    I don't remember ever seeing any suggestion that the class has to be public
    either. Section 12.1.4 of the JLS states what that the main(String[]) method
    must be public, static, and void, but makes no mention of conditions that the
    class itself must meet.

    In any case, it's far from clear that that section is intended to be
    normative -- it is embedded in a whole sequence of text which is clearly
    descriptive rather than normative (and which explicitly references the JVM
    spec, describing itself as "an overview"). In my opinion, whether or not it
    is /intended/ to be normative, it damn-well /shouldn't/ be normative as
    written; because if it was it would be requiring a behaviour that no complete
    Java implementation has ever exhibited, nor ever will. The public static void
    main(String[]) thing is just how one way of launching Java programs works -- it
    is incidental to that specific program, and other programs can and do work in
    different ways. That has been true ever since JDK 1.0.2, and probably before.

    FWIW, the code for the java.exe launcher is simple, and it would be trivial to
    add a check that the entry-point class is public (and perhaps that it's a
    top-level class too). Similar trivial code already exists only a few lines
    away to ensure that main() is public. So, if this is a bug, there hardly seems
    to be a plausible reason for it to have remained unfixed for so long.

    -- chris
    Chris Uppal, Apr 4, 2007
    #7
  8. Chris Uppal writes:
    > Jussi Piitulainen wrote:
    >
    >> Where does JLS say the class should be public? I failed to find it
    >> in the index and in the following page that explains how a program
    >> is executed.

    >
    > I don't remember ever seeing any suggestion that the class has to be
    > public either. Section 12.1.4 of the JLS states what that the
    > main(String[]) method must be public, static, and void, but makes no
    > mention of conditions that the class itself must meet.


    Yes, it's quite explicit about _main_ being _public static void_, and
    seems, to me, quiet about the class (other than actually using the now
    allegedly forbidden form as example code).

    As of now, I suspect the allegation upthread was mistaken.

    >
    Jussi Piitulainen, Apr 4, 2007
    #8
  9. Jussi Piitulainen wrote:
    > Arne Vajhøj writes:
    >> Lew wrote:
    >>>> Nikhil wrote:
    >>>>
    >>>>> class Just
    >>>>> {
    >>>>> public static void main(String[] args)

    > ...
    >>> Doesn't the class need to be public?

    >> It should according to JLS.
    >>
    >> But java does not check.
    >>
    >> There are several bug reports on that.

    >
    > Where does JLS say the class should be public? I failed to find it in
    > the index and in the following page that explains how a program is
    > executed. In none of the example programs on that page is the main
    > class public: they are all just "class Test".
    >
    > <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44444>


    I just checked. You are rigth. I must have messed up class and method.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Apr 5, 2007
    #9
  10. Lew wrote:
    >>> class Just
    >>> {

    ..
    >Doesn't the class need to be public?


    I watched the discussion about public (or not) classes
    and the JLS with interest. AFAIU, normal classes with
    main() do not need to be public, OTOH *Applet* classes
    must be public..

    <sscce>
    class DefaultAccessApplet extends
    java.applet.Applet {

    public void init() {
    add( new
    java.awt.Label("Default Access") );
    }
    }
    </sscce>

    [console]
    load: DefaultAccessApplet.class is not public or has no public constructor.
    java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access
    a
    member of class DefaultAccessApplet with modifiers ""
    [/console]

    I could not say whether that was according to the JLS,
    or simply an 'implementation detail' but it explains why
    a lot of people are used to seeing 'main()' classes as
    needing to be public, as so many (far too many) simple
    code examples are written as Applets.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
    Andrew Thompson, Apr 5, 2007
    #10
  11. Arne Vajhøj writes:
    > Jussi Piitulainen wrote:
    >> Arne Vajhøj writes:
    >>> Lew wrote:
    >>>>> Nikhil wrote:
    >>>>>
    >>>>>> class Just
    >>>>>> {
    >>>>>> public static void main(String[] args)

    >> ...
    >>>> Doesn't the class need to be public?
    >>> It should according to JLS.

    ....
    >> Where does JLS say the class should be public? I failed to find it in
    >> the index and in the following page that explains how a program is

    ....
    > I just checked. You are rigth. I must have messed up class and
    > method.


    Thanks.
    Jussi Piitulainen, Apr 5, 2007
    #11
  12. Nikhil

    Oliver Wong Guest

    "Andrew Thompson" <u32984@uwe> wrote in message news:703b4eee2f6eb@uwe...
    > Lew wrote:
    >>>> class Just
    >>>> {

    > .
    >>Doesn't the class need to be public?

    >
    > I watched the discussion about public (or not) classes
    > and the JLS with interest. AFAIU, normal classes with
    > main() do not need to be public, OTOH *Applet* classes
    > must be public..
    >

    [snip code demonstrating this fact]
    >
    > I could not say whether that was according to the JLS,
    > or simply an 'implementation detail' but it explains why
    > a lot of people are used to seeing 'main()' classes as
    > needing to be public, as so many (far too many) simple
    > code examples are written as Applets.


    When I first learned Java, it was mainly through desktop applications
    (and of those, mainly console based ones), as opposed to applets. I too
    assumed that not only did the main method had to be public, but it's
    containing class had to be so as well. I suspect it may be because the
    (oversimplified) explanation I had internalized at the time was that main
    had to be "public" so that java could "see" the method in order to invoke
    it. If that were the case, it'd only make sense that java had to be able
    to "see" the class as well.

    - Oliver
    Oliver Wong, Apr 5, 2007
    #12
    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.

Share This Page