Javac: file not found:

Finally got javac to work and now it can’t find my file. I created CLASSPATH in the system variables and entered C:\JavaSDK\JavaPrograms, which is where my is located. I don’t know what else to try. Sorry if this has been asked already. I couldn’t find it.

I also tried javac -cp c:\JavaSDK\JavaPrograms but that would be to easy

Try like this

javac -cp c:\\JavaSDK\\JavaPrograms c:\\JavaSDK\\JavaPrograms\\*.java

or even easier, go into the directory c:\JavaSDK\JavaPrograms and run

javac -cp . *.java

I think that should work, if not let us know

C:\JavaSDK\JavaPrograms>javac -cp . *.java package system does not exist
system.out.println(“Hello World! This is Tim.”);
1 error

This is weird. I didn’t even mention HelloWorld and it returned this error. HelloWorld is the only .java file in that folder. Here’s the code. I can’t imagine it being wrong, but maybe I’m missing something.

class HelloWorld {
public static void main (String args) {
system.out.println(“Hello World! This is Tim.”);

Change “system” to “System”, Java is case sensistive.

The * in “*.java” tells javac to compile all files in that directory with the .java extension, which is how it finds HelloWorld.

Thanks for your time. I wish I didn’t have another question but here is wat happend. I compiled the file and now have a HelloWorld.class in my bin folder.

C:\>javac HelloWorld
error: Class names, ‘HelloWorld’, are only accepted if annotation processing is
explicitly requested
1 error

Thanks again for your time. If I could get through this part, I could get to some Java coding, which would be awesome.

Use java to execute the class, as in:

c:\>java HelloWorld

javac compiles, java executes



It’s still not working. I’ve tried everything I can find. What happend is in the next message.

C:\>java HelloWorld
Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.

Here is the Code:
public class HelloWorld {
public static void main (String args) {
System.out.println(“Hello World! This is Tim.”);

This is a classpath issue, this is unfortunately one thing that Java does not make easy for beginners. Try this:

java -cp . HelloWorld

C:\Program Files\Java\jdk1.6.0_16\bin>java -cp . HelloWorld
Hello World! This is Tim.

Yea Booooooy! LOL
U’re alright man. I figured it was somethin dumb. As you can see tho I had to cd to the bin folder. I was wondering if u could help get my PATH’s straightend out. C:\Program Files\Java\jdk1.6.0_16\bin is where my bin is. I’m not sure if I’m supposed to put PATH and CLASSPATH my user variables or my system variables. And do I need JAVA_HOME? If you got the time this would be a big help. O yea and should I just save my .java files in the bin folder?

The best thing to do is put “C:\Program Files\Java\jdk1.6.0_16\bin” in the PATH variable and put “.” in the CLASSPATH variable. Then you should be able to run java.exe and javac.exe from anywhere in the file system. The “.” in the classpath tells Java to look in the current directory for classes. So then you could have your class file anywhere and go “java HelloWorld” and it should work.