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

N

Nikhil

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
 
O

Oliver Wong

Nikhil said:
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
 
L

Lew

Oliver said:
Nikhil said:
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?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Nikhil said:
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
 
J

Jussi Piitulainen

Arne said:
Lew said:
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>
 
C

Chris Uppal

Jussi said:
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
 
J

Jussi Piitulainen

Chris said:
Jussi said:
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.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Jussi said:
Arne said:
Lew said:
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
 
A

Andrew Thompson

Lew said:
..
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
 
J

Jussi Piitulainen

Arne said:
Jussi said:
Arne said:
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.
 
O

Oliver Wong

Andrew Thompson said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,706
Latest member
MaggieThor

Latest Threads

Top