Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How do I run this program

  Asked By: Jody    Date: Nov 17    Category: Java    Views: 610

I have problem running this program

package p1;
class test
public static void main(String args[])
System.out.println("Hello world");

I have placed the files (.java and .class) in the p1 directory. I have tried
all the possible combinations of classpath and still it gives me
classnotfound exception



7 Answers Found

Answer #1    Answered By: Bathilda Schmidt     Answered On: Nov 17

what error does it give u?
Set the class  path to the package level.

Answer #2    Answered By: Joyce Edwards     Answered On: Nov 17

there is not any problem  your codes.

Answer #3    Answered By: Adel Fischer     Answered On: Nov 17

you can download oracle9i jdeveloper from oracle.com then try your code on it.it
is very simple.also oracle9i jdeveloper is free

Answer #4    Answered By: Teresa Rogers     Answered On: Nov 17

Are u sure, that u are running  your program  from the requiered place. Your
package directory  must be in your classpath  or another choice shell scripts.

set classpath=%classpath%;%cd%
java p1.myclass

4 ex: u can use the script above, from the upper directory of p1. This will
runtime path to your classpath(4 win platform) with "%cd%" option.

Answer #5    Answered By: Tammy Sanders     Answered On: Nov 17

run it in pi directory  only,it will surely run
look i will tell u dos promt command
c:\mkdir pi
c:\cd pi
c:\edit test.java

edit window

ur code
save it

exit to command promt

c:\pi\javac test.java
it will run

Answer #6    Answered By: Hilma Miller     Answered On: Nov 17

change the declaration form 'class test' to 'public class  test'
and try to recompile and execute.

Answer #7    Answered By: Earl Stone     Answered On: Nov 17

The current directory  should be in p1's parent directory. For
example (assuming Windows), if the path is c:\xxx\p1, then you should
be in xxx. Then to compile, do:

javac -classpath . p1\test.java

To run, do:

java -classpath . p1.test

Didn't find what you were looking for? Find more on How do I run this program Or get search suggestion and latest updates.