• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

How to add an entry to your PATH (direction in the Head First Java book)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to get an SDK downloaded and run and then figured out where the API was. The next thing was that the book said to add an entry to your PATH environment variable that points to the /bin directory. I see the bin directory and the javac item in that folder, but there was no direction on how to add this entry.
Thank you!
 
Marshal
Posts: 71070
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please tell us which directory you installed Java®, i.e. the full path to the bin (short for binary) directory, and which OS you are using.
 
Sheriff
Posts: 15995
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It varies slightly between operating systems (Windows, Linux/Mac OS X, etc.) but you can easily find out how if you search for "How to add to PATH on ... (your OS)"
 
Saloon Keeper
Posts: 22790
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And from me as well. Welcome!

The PATH points to a directory containing executable files. Or more accurately, a list of directories containing executable files.

Java is organized under a single directory, so that it can be installed by unzipping a single JVM archive if you don't use an OS installer. The JVM location is thus the root directory of the unzipped archive. If, for example, I unzip jdk-114--92_3.1.159.zip to my /usr/java directory and want to set the JAVA_HOME environment variable to point to it, then JAVA_HOME would be assigned /usr/java/jdk-114--92_3.1.159

And then I'd add $JAVA_HOME/bin (in Linux/MacOS) or %JAVA_HOME%\bin (Windows) to my PATH.
 
Druscilla Conn
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone. This is the absolute first day I have ever tried anything with Java so none of these answers makes any sense to me. I will just keep reading and see if it ever clicks. I so appreciate your kind responses and hopefully I'll be able to come back here someday and read your answers and know what they are telling me to do. Thanks again everyone and have a beautiful weekend!
 
Campbell Ritchie
Marshal
Posts: 71070
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Careful: you may get out of date information including telling you to set a system CLASSPATH. It is usually straightforward to set a PATH, but as Junilu said, it varies between OSs.
 
Rancher
Posts: 3968
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the PATH is to make it possible for the OS to find an executable file.  But it is NOT necessary if you take the trouble to give the full path to the OS when you want it to find a .exe file.  
For example this command works to execute the javac.exe fiile:


C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp . UploadBlastToSite.java


It has the full path to the javac.exe file so that the OS can find it;
 
Tim Holloway
Saloon Keeper
Posts: 22790
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Careful: you may get out of date incorrect information including telling you to set a system CLASSPATH.



To the best of my knowledge it has never been necessary to set CLASSPATH at either system or local levels.

Yes, you might need to define a classpath to find user-coded components, but the JVM's internal classes are supposed to already be on the JVM's internal classpath and thus no need to declare them explicitly.
 
Campbell Ritchie
Marshal
Posts: 71070
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:. . . it has never been necessary to set CLASSPATH . . ..

. . . but some books told readers to set a CLASSPATH.
 
lowercase baba
Posts: 12933
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something I found confusing (many) years ago...your PATH variable is really not a Java thing at all...it's an operating system thing.  It vastly pre-dates Java.

Generally, binary files (the ones that can actually be run by the computer) can live in all kinds of different places.  And programmers are lazy.  We don't like having to type the full path to each and every binary - and this is even more so true on Unix like systems, where you may string several commands together, something like:

/usr/bin/grep fred myFile.txt | /usr/etc/bin/cut -b 11-20 | /usr/bin/grep -v -i rosenberger > notMe.txt

Here, "grep" and "cut" are both binary executable files where I have typed the full path to where that executable file is.  That's a lot of typing.

So, someone created the concept of a PATH variable.  It is basically a list of directories that the OS uses to try and find executables.  if you type a command like this:

grep fred myFile.txt

the OS would say "Hmm...i know that "grep" is the command they want to run.  But I don't know where that file is.  So, let me check my PATH list.  I will search each directory listed there to see if it contains an executable file named "grep", and if so, i'll run that with the other two arguments...". It will start with the first directory, and if it finds it, runs it. Else, it checks the second, then the third...until it either finds one to run, or has tried every directory in the PATH and gives up.

So the idea is you want to add the directory where your java.exe file lives, so when you type "java", the OS will have the correct directory from the PATH variable to look in to find it.
 
Rancher
Posts: 4743
50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked whether you actually need to set the PATH?

Depending on the OS the installer often sorts that out for you.

So, open a terminal and try:
java -version

and then try:
javac -version

If they both return something sensible, then don't worry about the PATH.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic