can not find java and javac files in dir
I am running windows vista hp 32 bit and just learning Java. I have written the first program HelloWorld, checked and saved it. I do not seam able to compile it and run it. I have changed my path accordingly, made a classpath that is .; and JAVA_HOME that is C:\Program Files\jdk1.7.0_02\bin;. I have checked java and javac on cmd and that is fine. Now I can not find my java and javac files in my dir. I have gone from one web post to another and now am really fed up with it.
Many Thanks
Gerard
Re: can not find java and javac files in dir
Are you sure you're running javac from the directory that your files are in? Can you tell us exactly what the error message is?
Re: can not find java and javac files in dir
JAVA_HOME shouldn't include the bin directory. in order to use java and javac from any directory add %JAVA_HOME%\bin to your PATH.
Re: can not find java and javac files in dir
Dear Shoss
I am running from the c directory and I made a folder called MyJava to store all my java projects. The error I get when I input at the promp, C:\java>javac Hello.java is:
javac: file not found: Hello.java
Usage: javac <options> <source files>
use -help for a list of possible options
C:\java>
I am confused about these settings;
CLASSPATH= .;
JAVA_HOME= C:\Program Files\jdk1.7.0_02
PATH= C\WINDOWS\system32:C\WINDOWS;C:\Program Files\Java\jdk1.7.0\bin;C:\Program Files\jdk1.7.0_02
I have changed these according to various sites.
Regards.
Gerard.
Re: can not find java and javac files in dir
If your files are saved in the directory C:\MyJava, then you should run "javac" from that directory.
So you would want to do:
C:\MyJava> javac Hello.java
Your environment variables look alright to me, those are always the worst part when installing java for the first time. Ideally, as j2me64 said, JAVA_HOME will point to your latest java directory (as yours does) so in the PATH variable you'd just have %JAVA_HOME%\bin. But what you have will work.
Re: can not find java and javac files in dir
in order to exclude compiling erros make a call to
javac -version
and
java -version
both commands should show the version of javac and java. if so, post your code of the class HelloWorld.java, perhaps there is an error in the class name or the main() method or somewhere else.
Re: can not find java and javac files in dir
Hello j2me64
Both Java and Javac -versions work. I input C:\Myjavac Hello.java and get the following error,
'C:\MyJava' is not recognized as an internal or external command, operable program or batch file. I have also tried it without the C:\, same error.
My java file is as follows;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main (String[] args) {
System.out.println ("Hello World!"); //Display the string.
}
}
Regards.
Gerard.
Re: can not find java and javac files in dir
j2me64
Hello again.
I now have my Hello.java and javac files in my java directory. There is still nothing in the e
even though I have saved my Hello file as Hello.java. I am using Notepad to write my text so should I save them as *txt files or .java.
When I compile and run my file (C:\java>java Hello) I get the following error, Could not find or load main class Hello.
Thanks.
Gerard.
Re: can not find java and javac files in dir
Somebody please help.
Thanks.
Gerard.
Re: can not find java and javac files in dir
You've called your file Hello.java, but the code states the class name as HelloWorldApp. So i suspect that you didn't actually compile your file successfully. The class and file name have to be the same, so either rename the class to Hello or rename your file to HelloWorldApp.java.
After you've done that you need to run the "javac Hello.java" command in the directory where your file is saved. This will create a Hello.class file which you can then run using "java Hello".
Edit: I'm incorrect, you can have a different class vs. file name if its not public. So you just need to run "java HelloWorldApp" instead since that is what your class is called.
Re: can not find java and javac files in dir
Thanks for replying.
I compile to cd C:\java, hit return and input javac Hello.java, hit return and get the java prompt again. I do not fully understand what I am doing wrong. In my dir I have 2 empty java files and 1 empty javac file. I cannot seam to be able to save the Hello.java file in notepad.
Gerard.
Re: can not find java and javac files in dir
As I save my java projects in a folder, Myjava I input, at the java prompt, Myjava>javac Hello.java and get the following error: 'HelloWorld' is not recognized as an internal or external command, operable program or batch file. I have no idea what I am doing wrong.
Gerard.
Re: can not find java and javac files in dir
rewrote file and called it Hello not HelloWorldApp.
Gerard.
Re: can not find java and javac files in dir
Try to read through this carefully and hopefully that will give you a better understanding of what you're missing. I'm slightly confused by what exactly it is you're doing and where you're running your code from. Your most recent error "'HelloWorld' is not recognized ..." would indicate that you just typed "HelloWorld" in the command line, and you've mentioned both of the directories "C:\java" and "C:\myjava".
Let's assume you have notepad open and you've written your Hello class.
Code:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class Hello {
public static void main (String[] args) {
System.out.println ("Hello World!"); //Display the string.
}
}
Save this file as "Hello.java" into your C:\MyJava directory.
Open the command prompt (start->run, type "cmd" for win xp)
It should automatically put you in the directory "C:\Documents and Settings\<username>\", but you want to be in the directory where your files are so type "cd C:\MyJava". This will change your directory (cd) to where you should have saved your files.
Now run the command "javac Hello.java". This will create a file, "Hello.class", that will be runnable by the java jvm. You can't read this file in notepad, its bytecode.
Now run the command "java Hello". This will execute the code in the file "Hello.class".
Re: can not find java and javac files in dir
Hello Shoss
I Have done as you suggested but to no avail. I wrote the file and saved it as Hello.java. I changed my directory to cd C:\MyJava and wrote cd C:\Myjava, got the error the system cannot find the path specified. I checked my C:\java directory and my 3 java/javac files are empty. I do not understand why. Java Hello = Error: Could not find or load main class Hello. This is what I do not understand. I have checked and rechecked, by the way you mised the semi colon on the System.out.println ("Hello World!");.
Thanks your time.
Gerard.
Re: can not find java and javac files in dir
I'm fairly certain i didn't miss a semicolon, as it is still there.
I don't understand why you keep referencing the "C:\Java" directory. If you did follow my instructions you shouldn't be doing anything with "C:\Java".
Where are you saving your java files to?
Please read the entire link i sent you and follow it word for word.
Re: can not find java and javac files in dir
When I open my shell the prompt is C:\WINDOWSsystem32>. I type in cd C:\Myjava. I
type cd C:\java and the prompt is C:\java>. I type in C:\Myjava in either and get the following error "The system cannot find the path specified". My files are saved in the Myjava folderin the documents section. I press start, open documents, open Myjava and click on the Hello file. All these are on the pc's C drive, if that is what you mean. I am completely new to all this. Thanks for your time, Gerard.
Re: can not find java and javac files in dir
Ok, that clears that up a bit. There are many things here that you aren't quite getting correct.
Have you read that link i gave you? I'll post it again.
"Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)
I strongly suggest you read through this and follow along step by step so you can greater understand what it is they're doing.
I doubt that C:\myjava and wherever (start -> documents -> myjava) leads to are the same place.
When you type "cd C:\myjava" you're using the "cd" command to change the directory to "C:\myjava". If that's where you saved your files then you have no need to type "cd C:\java" because you're just moving again to a different directory. Also, you're getting the "system cannot find path specified error" because you're just typing a directory into the command line. This doesn't do anything, so i'm not sure why you're trying that.
Re: can not find java and javac files in dir
Thank you for your time and patience shoss. I will work through the attached link again and
try to get a better understanding.
Gerard.