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 ?
man_15Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_lychee_Commented:
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"...
0
sgomsCommented:
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

0
sgomsCommented:
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

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

CircleVCommented:
Well, if your code sample is exactly the contents of addition.java, then I'm surprised it compiled, as you're missing a close brace.  ie the code should
be:

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

and as sgoms said,

compile to a .class file using "javac addition.java"
and run it by using "java addition"

note also that this is actually a java application, and not an Applet.  The Oreilly book "Java in a Nutshell" has a pretty decent description of this.

as for the meaning of the message, it means that the java interpreter cannot find your .class file.  The interpreter looks in your classpath for the .class files it needs.  It has a default path which includes your current directory, so the above should work if you run "java addition" in the same directory as addition.class.

happy coding!

CircleV
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
man_15Author Commented:
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" ?
0
sgomsCommented:
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
0
heyhey_Commented:
very short comment

SET CLASSPATH=.;%CLASSPATH%
java myApp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.