I'm trying to get the command prompt to run Java from a notepad saved file. I have a little programming background with Game Maker. One of my students wants to create Mine Craft mods so we're learning Java together.
I've set the environment variable path to: C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin
I've created a folder in C:\Users\Ryan\Java and that's where I am in the command prompt. When I type java MyFirstJavaProgram I just keep getting this 'java' is not recognized as an internal or external command, operable program or batch file.
was your command prompt opened before you updated your path? If so, close it and open a new one. Or, type "path" to see what that window thinks the path is, and confirm that directory is there.
navigate to the c:\Program Files\java\jdk\bin and see if there really is a "java.exe".
Have you used the javac.exe command to compile the source file and create a class file? Normally the JRE install sets the PATH variable so the java command works.
So I'm confused about an error getting to the java command. The path would have been set or found for the javac command to have been executed.
Ryan Daniele - Does this website have good learning tools/examples?
I don't think that they web site has any online tutorials, but many if you were to search this site I'm sure that you would find people mentioning and/or linking to sites on the web or books etc.
Java is also rather large with many different areas/specialties, much like programming itself. You may want to either open up your mind to narrow your focus, depending on what exactly you are planning on doing.
Some people have come to this web site for help with Java certification, others have come solely to help other people out and still others came post questions to problems (usually fairly specific) or to read and learn from the community posts.
If you are trying to get into Java then you may want to look into the book titled Head First Java.
Once you can navigate your way though the different loops (for, do, while) and decision constructs (if/else/switch) you may want to start learning methods, classes and then other object orientated programming.
Do not be discouraged when learning Java or programming for that matter. Nearly everyone started out printing something like "Hello World" to the screen and everyone makes mistakes, some more then others. It's though making mistakes that you learn (or hopefully learn eventually).
Programming is something that is usually easy to start, but difficult to master.
Thank you so much for the advice. I will look into that book. I ran into a problem with the student, I did the exact same setup of everything on his computer as on mine but it ran into the same error. I'll work more on it next week.
Both of our Environment Variable Paths are: C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin
Both of our java folders are c:\Users\Java
But when I type javac MyFirstJavaProgram.java for him, it says 'javac' is not recognized as an internal or external command, operable program or batch file
I'm able to compile and run it on my computer just fine. I hope the pictures I attached are helpful.
When you are in the command prompt and you type pathyou should see something like
C:\Program Files\Java\jdk1.8.0_131\bin\ This should be the location of the javac file on the system in question.
When you get a chance please do that and paste the results in your reply.
As well in your reply can you paste the results of the following command echo %java_home% You may not have a java_home defined, which is fine. This is not always needed.
Please note that after you change the path, you may need to close the command prompt and open up a new one for the results to be noticed.
Being a Windows system you can do either
echo %java_home% or
echo %JAVA_HOME% and you will get the same result.
When I type path on my comp it shows it correctly, but on my students it shows all of the paths in the picture.
So I have a feeling I need to delete or disable all of those extra paths. But they were already there and I'm afraid to delete things if I'm not sure if it will mess up anything else.
Should I delete everything except the one for java?
I'm not sure what the echo %java_home% did, after I typed it in it just said that same thing on the next line.
they were already there and I'm afraid to delete things if I'm not sure if it will mess up anything else.
I wouldn't change anything that you didn't enter. The OS uses PATH to find executable files when the path to the file is not given. There are probably programs on your PC that require PATH.
I don't know what programs use the JAVA_HOME variable. I don't think the JDK or JRE use it. Maybe its used by some IDEs.
It would be more useful if text were posted instead of images. The contents of images can not be copied to include in responses.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Are you still using Windows® Vista? I would consider upgrading Windows® if I were you.
Do all your other programs still work? I would have anticipated problems finding programs at all if you are missing the other things which are in the PATH on the other computer.
The positions of the "s are not consistent. They should wrap paths that contain spaces.
You show:
PATH="C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin";"C:\WINDOWS\SYSTEM32; ...
I think proper positions for the "s would be:
PATH=C:\WINDOWS\SYSTEM32;"c:\Program Files\java\jdk\bin";C:\WINDOWS\SYSTEM32; ...
when I try to put "s where you suggested, it gives me an error saying: A path component can't contain any control characters nor any of the following characters: / " < > |
On my Windows 10 Pro system I have zero quotes in the path variable as noted here (get ready it's a long one):
Note that in on line 12 I have the directory where javac is located and everything works fine for me.
I know that I probably have more then you and more then what is needed.
I just thought I'd show you mine to show you quotes are not needed for this to work.
I think that the issue that you are experiencing is the quotes.
If you take them out of yours or your students path you should be set I think, providing you are pointing to the correct directories that is.
On Win10 when I display the value in PATH, some paths with embedded spaces are wrapped in "s and some are not. There is never two paths within one pair of "s
I tried adding a path to PATH with "s before and after the path and it worked, but the "s were stripped off when it was saved.
I don't know what Windows is doing or why some paths are wrapped in '"s and some are not.
The problem with what you posted was that several paths were within one pair of "s instead only a single path within a pair of "s.
I don't have any ideas why that could happen.
Here is my PATH with a small edit to end each line with a ;