Hi. I'm starting a programming class on Tuesday that deals with Alice and Java. I want to learn a little bit before I get started, seeing as the only programming experience of any kind that I have is just some very basic html.
So, I'm following Sun's Java tutorial, I downloaded the Java SE Development Kit 6, and am following the steps to write a Hello World application. Where I'm hitting trouble is in trying to compile the source .java file. My command prompt window is returning the error "'javac' is not recognized as an internal or external command, operable program or batch file" According to the common problems page, this means that windows can't find the compiler. Ok..seems simple enough.
There are two solutions offered. Either type in the file path for javac before the javac command, or edit the PATH variables so that this shouldn't be necessary. I am having no success with either approach and could use some help.
First, I tried updating the PATH variable. This is supposed to tell Windows where to look for javac so that I don't need to manually type in the file path. The problem is, when I go to Environment Variables, like Sun's instructions tell me, I don't see anything called PATH which I can edit. (Judging by their instructions, it doesn't sound like I'm supposed to add it myself.)
So next, I just tried typing in the file path for javac manually. The first problem with this approach is that depending on which specific page of Sun's instructions I look at, it tells me to do this different ways.
When I do it this way, the command prompt returns the error that "C:\ is not an internal or external command ..." Another page reads
When I type the file path this way, I don't get an error, but nothing happens. So..that's my situation. I'm fairly sure whatever mistake I'm making is very obvious, but bear in mind I am just starting out learning this. Any help welcomed.
-
Your second approach could have compiled your java file successfully.
Check to see if you now have a MyClass.class file in the directory from which you wrote the "javac" command.
The next step is to run it with the "java" command.
------------------------------------------------------------------------------------
You can write a batch file to take care of this, once you see that it works, so that you don't have to keep typing (or cutting and pasting) the whole line each time.
You just save the command in a text file using notepad or some other program that doesn't add formatting (I like notepad+++, a free resource) with the extension ".bat" .
Then you can run it from the command line using the name of the file without ".bat"
So, if the file is called "Compile.bat" -- you'd type "Compile" on the command line.
-------------------------------------------------------------------------------------
Depending on what your school recommends, at some point, you may want to check out NetBeans, which is an environment for developing java and a bunch of other things -- and it's free. It takes care of compiling and running and lots of other little details. But it also can add to the confusion. -
Code:PATH=%PATH%;[ dir you want to set ]
Code:PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_\bin;
This is not permanent solution though. If you set it permanently, you have to go check out in Control panel | system | advanced system setting | advanced tab | Environmental Variable | look at Path in system variables and edit it like above. Then you will be all set.
I don't know if you prefer Notepad++ like Laughing Laura mentioned. I just think it might be better to use IDE such as eclipse. It's more complicated; there is a learning curve, but once you get used to it. It's faster/easier to code a program. Just my 2 cents. -
I only recommended notepad++ to create a batch file.
I recommended NetBeans for coding, though I believe it's probably wisest to stick with whatever approach is used in class while you take the class. -
Using Explorer, check the path to javac or javac.exe on your system. (You can search for it or browse under the Program Files directory.) Right-click the "javac" file and select "Properties".
The path of the file should be under the "Location" field in the properties window. Highlight this path and press Ctrl-C to copy it to your clipboard.
If you don't see a "PATH" environment variable, look for one called "Path". If that's not there either, try creating it. You can use Ctrl-V to paste the path you copied earlier.
You will probably have to open a new Command Prompt window after creating or modifying the env. variable.
In the new window, enter this command:
path
It should print out the value of path variable and you can make sure it shows the new path that you added.
Now try this command:
where javac
If your path is set up right, it should display the path to the javac.exe file.
Then try running javac again:
cd \directory\with\java\files\
javac MyClass.java
As an alternative to using the Path environment variable, you can try putting the path on the command line, as in:
" [path]"\javac MyClass.java
...where " [path]" is replaced by the path you copied to the clipboard. Keep the quotes though... that'll be needed if there are any spaces in the path. -
If you are using windows, go to textpad.com and download textpad. Install it. It should find the java compiler automatically, and you will be able to edit, compile and run from within TextPad, though some of my students have reported problems.
You could also try drjava.org for the Dr. Java editor that will hook to you compiler automatically.
I thought Alice included and IDE, so no need to use a command line compiler. Maybe I am wrong.
General advice - find a student that already has it working and have them sit down with you and your computer and walk you through the first couple of programs. This can save *hours* of wasted time.
EDIT: I just downloaded Java 6 SE and then textpad and it installed perfectly. And I know DrJava does also. If you want a heavy weight environment (which I don't recommend for a beginner) download netbeans (find on sun somewhere). But I'd check with the prof or his/her website and get whatever they recommend. -
You can get Visual Studio 2008 Professional for free at DreamSpark (owned by Microsoft) if you're a student.
Alice was fun. Good to see another person jumping into Java. I just got started this semester, too! -
Fellow java beginner here
Textpad is the way to go for beginners, and to compile from the command prompt you need to set your path.
To do it the graphical way you (IN XP) right click my computer, hit properties, advanced tab, select environment variables on the bottom. Create a new one named "Path" and set the location to where your java files are installed. (Usually program files > java >jdk....
In Vista its the same, just the path to the environment variables thing is a little different.
If there is already a Path variable, you can click edit, put a semicolon ; and your path to it.
Additionally once you do this, you have to make sure youre in the directory of your .java file when running javac so that the computer knows where YourClass.java is!
BTW The reason I say textpad is better for beginners is because using an IDE you start to forget whats happening "behind the scenes", and if you never used textpad then you dont even know whats happening behind the scenes!! You use textpad for a bit, then once you know whats flying you use an IDE...thats my opinion.
Im still with Textpad lol.. -
This is what I did to make it work.
1) Find the location of javac.exe [if you have the latest version, it's same as what I put in at #5.
2) Right Click 'Computer' and then Left Click 'Advanced system settings'
3) Left Click 'Environment Variables...'
4) Edit... 'Path'
5) Add C:\Program Files\Java\jdk1.6.0_11\bin to 'Path'
If you already have another things in path, just add ; before C:\.
Try test your javac file. It should compile. That's how I got mine started few days ago.
Is TextPad evaluation version?
Anyway, is it bad habit to start with Visual Studio from the beginning? Any book recommendation? Our textbook sucks.. I got a free copy through DreamSpark though.. -
thanks for all the responses. I got it sorted out by adding a PATH variable, as I see some of you suggested
Beyond getting the hello world app to run, sun's tutorial is actually very confusing about explaining the actual language lol >< I think I'll wait for the class before really diving in. -
http://www.allbookstores.com/book/9780321479273/Tony_Gaddis/Starting_Out_With_Java.html
I found it to be VERY good and explains things perfectly. Im currently up to chapter 6. This book teaches objects and methods AFTER teaching you the basics, which some like and some dont, I do.
There is a new version released this month apparently:
http://www.allbookstores.com/book/9780136080206/Tony_Gaddis/Starting_Out_With_Java.html
Shop around though it will be cheaper.
My teacher recommends starting with textpad, this teaches you the basics you need to know. -
-
Yea, I'm sure the book will be better...not to mention that I'll have a professor lol. This is the book we're going to work out of. Anyone know anything about it?
http://www.amazon.com/Programming-A...bs_sr_1?ie=UTF8&s=books&qid=1232650019&sr=8-1
Total beginner question about Java
Discussion in 'Windows OS and Software' started by Callidor, Jan 21, 2009.