Link to home
Start Free TrialLog in
Avatar of man_15
man_15

asked on

What is wrong with my java applet ?

I used notepad to write a java applet as follows :

class addition {
public static void main (String args[]){
System.out.println(2+2);
}

Then saved it as addition.java.
Then javac addition.java. It gave me addition.class.
Then java addition
But an error message ocurred as follows:
Exception in thread "main" java.lang.NoClassDefFoundError:c:\addition/class

My question is :
1. What is the meaning of the error msg
2. How to make my program work ?
Avatar of _lychee_
_lychee_

u sure u used
java addition

and not
java addition.class
or
java c:\addition.class??

(ur error message sounds as if u were using java c:\addition.class)

ur errormessage means that the jvm was not able to find the class
c:\addition/class which i think refers to the class "class" in the package "c:\addition"...
1. First this is not an applet for a java application

2. and yes the above error indicates
    java addition.class

the procedure is,

javac addition.java > This compiels ur java source file to a set of byte codes put into the class file

java addition > (without .class) inteprets(or compiles with Just in time compiler is present) the byte code to native code.

happy programming!
-sgoms

1. First this is not an applet but a java "application"

2. and yes the above error indicates
    java addition.class

the procedure is,

javac addition.java > This compiels ur java source file to a set of byte codes put into the class file

java addition > (without .class) inteprets(or compiles with Just in time compiler is present) the byte code to native code.

happy programming!
-sgoms

ASKER CERTIFIED SOLUTION
Avatar of CircleV
CircleV

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of man_15

ASKER

Thanks u guys!
Originally my addition.class was in another directory. But then I put the file back into jdk1.2. It works.
I have two questions :
(1) Can addition.class be put in another directory other than jdk1.2 ?
(2) I was using dosprompt in win98. But the outlook is not good. Also the filename follows the 8+3 format. Is there any other area or application I can use to do "java addition" ?
man_15,

Yes. your java/class file can be in another directory.
what you need to set is something called as a PATH/CLASSPATH.

in your autoexec.bat file,

set PATH=<java_home>\bin;
set CLASSPATH=<java_home>\lib;

java_home cud be c:\jdk1.2.2 or any other directory where you have installed java.

PATH:
when you set your path, any excutable file under that directory is avaialble for execuetion under other directories too.
so you can access java.exe & javac.exe from other directories.

CLASSPATH:
when you invoke java/javac the class files need for compilation,
like (java.lang.* or java.awt.*) will be first located from this classpath directory & used.
JDK1.2 has a few jar files under <java_home>\lib which contain these java libraries.

make sure to execute c:\autoexec after makeing the changes.

2. There are quite a few IDE's that you can use for java. JBuilder, VJ++, Visual Cafe, Symantic Cafe, Visual Age etc.. are pretty good!
There are some small time IDE's which will have very basic options like Jpadpro, sitepadpro, kawa etc..

if you want expert opinion on what is best, there are quite a few outthere. so u can post another question seperately on this topic.

all the best!
-sgoms
very short comment

SET CLASSPATH=.;%CLASSPATH%
java myApp