English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

this is my prog
class printer
{
public void print()
{
System.out.println("Hello from java");
}
}

public class app
{
public static void main(String[] args)
{
printer printer1 = new printer();
printer1.print();
}
}

when i tried to run it it didn't work....
then i entered the sdk bin path in the path(using the environmental variable setting) and also noticed that there is no CLASSPATH variable in the list!!!
any way after adding the sdk bin path it get compiled...
and generated the clases files for printer and app
but when i tried to run it with the java app command it get an error
(Exception in thread "main" java.lang.NoClassDefFoundError: C:\work\New\app)

also when i tried to place them in seperate files printer.java and app.java and compiled separatly printer.java get compiled but when tried to run app.java i got an error message
C:\work>javac app.java
app.java:1: '.' expected
import printer;
^
1 error
Please help..i will gave u more info if needed

2006-07-04 07:18:06 · 6 answers · asked by Harisankar S 2 in Computers & Internet Programming & Design

6 answers

Your code is fine. The problem is that the interpreter cannot locate the class file (app.class). Either add the path of the class to the classpath environment variable (if it does not exist then just create one), or run the interpreter (i.e type java app) from inside the directory in which the class file resides.

2006-07-04 07:26:36 · answer #1 · answered by isita 5 · 3 2

Make sure u have the following setup:
1) Command javac recognized on command prompt without giving the any file name.
2) when u complile u will get a .class file created in the same path where ur .java file is located.
3) During execution the java will look for the class files in the path mentioned in ur CLASSPATH.
4) if u do not have any CLASSPATH varible u can add it as follows:
on command prompt. C:\set CLASSPATH=your .java dir path.
5) Run the program just by giving
C:\java filename(without .class or .java)

Hope it helps

2006-07-04 07:32:36 · answer #2 · answered by avi_iitr 1 · 0 0

do like this

in command prompt go to the directory where app.java is stored
type this

>set path="d:/j2sdk1.4.2_04/bin";
>javac app.java
>set classpath=%classpath%;
>java app

substitute your installation path of java/bin folder in place of "d:/j2sdk1.4.2_04/bin"

want more help? contact me on silentsakky@gmail.com

2006-07-04 07:33:06 · answer #3 · answered by $$-SilentSakky-$$ 4 · 0 0

Go to the directory where the class app resides and give command java app

2006-07-04 08:16:04 · answer #4 · answered by binaryFusion 5 · 0 0

you want to have them put in because a number of the web content require Java to demonstrate good. in case you replace contemporary variations you would possibly want to no longer get rid of the older ones as each replace elements functionalities to the older variations.

2016-11-30 06:56:05 · answer #5 · answered by ? 4 · 0 0

Why aren't you trying to start with more easy programs....you started your first program with clases.....try something more easy and then dezvolt it....it will be more easy for you to learn.

2006-07-04 07:30:38 · answer #6 · answered by Yoda 2 · 0 0

fedest.com, questions and answers