Question:
Why wont my extremely simple java program run?
2008-08-11 08:09:35 UTC
I'm trying to learn java and I'm just starting to try and write some extremely simplistic code. The code I'm using is below:

public class TestApp
{
public static void main(String[] args)
{
System.out.println("Testing Testing Testing!!!");
}
}

The java file is called TestApp and is located on my desktop. When I bring up command prompt and enter "javac TestApp.java" it tells me there is no such internal command or batch or something. I can compile it by dragging the file into the javac executable though.

I then enter in command prompt "java TestApp" and it tells me theres an exception in thread main where there is no such class as TestApp.

Any suggestions?
Four answers:
Bill
2008-08-11 08:21:36 UTC
Well, your first problem is, your OS doesn't seem to have its own java compiler.

Your next problem is that you don't seem to be in the correct directory. If TestApp is on the desktop, you need to say:

cd desktop

Then you can run it.
chan23j
2008-08-11 15:24:07 UTC
So first you need to configure your work environment.



If you want to compile your java code from command prompt as you have mentioned then you need to set your javac into your path variable.



Once you get your code compiled it will create a .class file for you.



Then try java TestApp
kobipe3
2008-08-11 17:28:32 UTC
I know that the problem is in your path variable.

But none of this is important - nowadays, there is no reason to compile a java program yourself. You have eclipse to do it for you. Just download the IDE for java developers at: http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/ganymede/R/eclipse-java-ganymede-win32.zip

There are also tutorials for java in eclipse.
2008-08-11 15:41:15 UTC
listen carefully..

Then javac is present in ur jdk folder>bin

to compile it ur path in promt should be in that folder...

to make it available in all folders open notepad and write

SET PATH=BIN);

SET CLASS=LIB);

save in the name "autoexec.bat"

replace existing file and restrt ur computer

next time when u save ur file.java save it in c:

then in promp go in c: path and use javac...

best of luck


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...