• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help adding entry to PATH environment variable that points to /bin

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I recently purchased the book Head First Java, because I'm interested in learning Java.
The book asks me to "add an entry to your PATH environment variable that points to the /bin directory inside the main Java directory. For example, if the J2SDK puts a directory on your drive called "j2sdk1.5.0", look inside that directory and you'll find the "bin" directory where the Java binaries (the tools) live. The bin directory is the one you need a PATH to, so that when you type: javac at the command-line, your terminal will know how to find the javac compiler."

I have no idea what this is talking about, but I have Windows 10, I've downloaded the latest version of Java Development kit, and also the API documentation for that kit. Can someone please help me out in doing this?
Thanks in advance!
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch Daniel.
I hope you find the community here welcoming, sharing and helpful.

I understand that setting this up can be troublesome and please note that I'm not brushing you off, however, will you please start with going over these two postings:
  • https://coderanch.com/t/687593/java/Setting-environment-variables-command-line
  • https://coderanch.com/t/689105/java/Win
  • These may help you point you in the correct direction.

    I do have a couple of follow up questions, if I may:
  • Also, which version of Java are are you using?
       There are many to choose from, the most people are using either Java 8 or Java 9 or possibly Java 10.
  • Are you using (or planning on using) an IDE? If so which one?

  •  
    Daniel Maguire
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Pete! That was a very quick response, thank you.
    Okay I read the posts, my java version is 1.8.0_171
    Now I made it to adding a path variable in my environment variables, I added the following one;
    C:\Program Files (x86)\Java\jre1.8.0_171\bin
    which I found by finding the java install on my computer and copying the directory, it's not working though (when I type in javac in command line it comes up with "javac is not recognizable as an internal or external command, operable program or batch file").
    Do you know what I'm doing wrong and if so can you help me fix it?
    Thanks in advance.
     
    Daniel Maguire
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    By IDE, would Eclipse Java Oxygen be an IDE? Because I have that at the moment though currently I'm just planning on sticking to whatever it teaches in this book to get a basic/intermediate understanding of Java.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, so the next step would be to see what is in your path variable. You can do this by opening up the command prompt and typing path. You should end up with something like (I shortened mine for this post)
    The important parts are the ones with Java in them, in my case C:\Program Files\Java\jdk-9\bin\.
    This works for me because that is where javac.exe is located on my system.

    On you system you should have javac.exe located C:\Program Files (x86)\Java\jre1.8.0_171\bin.
    If you don't have javac.exe located there then you need to update your path to point to the correct place where javac.exe is located.
    After you have updated you path you will need to close all command prompts and start a new one to get the changes to take affect.

    If you are still experiencing issues then please post back and share with us the full path of javac.exe on your system and the complete value of you path variable.
    You may need to provide the trailing slash "\" to the variable.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Daniel Maguire wrote:By IDE, would Eclipse Java Oxygen be an IDE?


    Yes, sorry IDE stands for Integrated Development Environment and Eclipse is a very popular IDE for Java (and other) developers.
     
    Daniel Maguire
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay it's working now, turns out the location was "C:\Program Files\Java\jdk1.8.0_171\bin".

    Thanks for the help!

    If it's not too much trouble could you please explain why I need to do this so I can understand what i'm doing?
    If it's a hassle don't worry about it I'm sure i'll figure it out sooner or later.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It great that you go it working and now you can move forward with programming.

    Daniel Maguire wrote:If it's not too much trouble could you please explain why I need to do this so I can understand what i'm doing?
    If it's a hassle don't worry about it I'm sure i'll figure it out sooner or later.

    Sure, I can try to explain this and that is a great question.

    Javac is the Java compiler. It takes the source could that you create (the .java files) and transforms them into the for that the Java virtual machine can understand.
    You want this setup correctly at the beginning so that you can compile and run your code from the command line if you need to.

    Many IDEs hide these steps from you and in doing so you may not learn all of the steps needed to create your program.
    IDEs are great tools and offer amazing features like code formatting, code completion, integrated debugging, syntax highlighting and more.
    But is useful to know the commands which run in the background so that you can see all the moving part.

    Some IDEs expect you have to Java setup in your path variable so that they can execute the correct commands.
    Other IDEs can automatically find and setup Java for you, however this is still something that you should know how todo.

    I suspect the book you are learning from is trying to teach you all that you would need to know so that you can be an effective Java programmer.
    On some systems you may not have the ability to install an IDE...maybe it's a server and you don't have the correct user permissions.
    However if Java was previously setup on the system by the administrator then you can go back to basics and do things the 'hard' way.
     
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Welcome again

    The operating system goes through the PATH looking for the instruction you have given it; in this case javac and later java, each followed by arguments. The PATH tells it the ocation of that instruction; if you don't use some way to give it that location you will get an error message like the first one shown in this Java™ Tutorials section.
    I hope you didn't pay full price for your book; HFJ is now quite old, but maybe still the best introductory book, and you should be able to get a good copy second hand. Sierra and Bates believe that it is best for people to learn command line instructions including setting a CLASSPATH, which you won't have to so for several weeks “the 'hard' way” before moving on to use an IDE. I think hey are correct in that view.
     
    Daniel Maguire
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the responses everyone!
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For anyone looking for a solution - just search YouTube "install java jdk on Windows 11", there'll be detailed step by step instructions
     
    Rancher
    Posts: 326
    14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Gamal Mazhikov wrote:For anyone looking for a solution - just search YouTube "install java jdk on Windows 11", there'll be detailed step by step instructions


    Although your reply may be valid please note that you found and replied to a thread from may 2018 - so you'rexabout 4 years late to the party.
    In addition a more valuable result for beginners is how to set system and user variables in general as aside rrom modify the PATH variable the CLASSPATH is also important when dealing with java.
    Also: Due to tools often rely on JAVA_HOME, like ant, maven, gradle and other build tools, it's recommended to set JAVA_HOME to the jdk base directory and then JAVA_HOME/bin to PATH.
    Although I doubt that's relevant: Welcome to the ranch.
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matthew Bendford wrote:. . . the CLASSPATH is also important . . .

    You usually need a different CLASSPATH for different applications, so setting a system CLASSPATH usually causes more trouble than it is worth.

    Although I doubt that's relevant: Welcome to the ranch.

    That bit is very relevant
     
    Matthew Bendford
    Rancher
    Posts: 326
    14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As Java supports a per-instance classpath via parameter I don't see an issue there.

    Although I agree with that a system-wide classpath can (and often will) cause issues with applications not designed to take such into account by explicit override it for me (or rather my "style" of developing) it's quite convenient as I often only write code using a terminal. As I collected quite a collection of libs over the years it's helpful to not worry about imports or runtime dependencies. Sure, as I don't use build tools like maven or ant or gradle it comes in handy, but sure it's a mess about manual version management.

    I also tried both eclipse and netbeans, and although I prefer netbeans and projects using maven as build environment I'm no "professional". I see myself only as "advanced beginner". For me it's just simpler / easier.

    Fun fact: I use Apache James as my mail-server. It uses the bouncy-castle lib for the crypto stuff. A few versions ago there were issues with TLS1.3 as the version bundled with james was in beta for it. It was an easy fix to either downgrade to not support tls1.3 or upgrade to a newer release which had the issues fixed. So I'm used to manual resolve version conflicts and dependencies. I actually see this as a helpfull skill to be able to understand and handle dependency hell only with a terminal.
     
    Saloon Keeper
    Posts: 27762
    196
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matthew Bendford wrote:
    Although your reply may be valid please note that you found and replied to a thread from may 2018 - so you're about 4 years late to the party.

    Hopefully they figured it out by now.


    No YouTube video on installking java JDK on Windows 11 is going to help me. I haven't used Windows for many years now. And I don't like videos when they're just lazy excuses for not writing things down.

    Fortunately I do have a few years experience on setting up Java on Linux, though.
     
    Matthew Bendford
    Rancher
    Posts: 326
    14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim Holloway wrote:Fortunately I do have a few years experience on setting up Java on Linux, though.


    As most distributions come with package managers and have several versions of java listed in the repos it's just like:
    (sudo) <package manager> <install/update/sync> <java-version>
    As most packages often include post-install scripts today and put links in paths already in PATH one is usually good to go right after install. I've already seen on some distros they set up JAVA_HOME on their own linked together with the (update-)alternatives system to quickly and easy switch versions. Also many distros seem to prefer a jdk over a jre these days so often it's already enough to just install "java" instead of "java-devel" or so. It's really way more straight forward and thereby easier to get a jdk running on linux than on windows.
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matthew Bendford wrote:. . . Also many distros seem to prefer a jdk over a jre these days . . . .

    I thought the separate JREs had all been withdrawn.
     
    Tim Holloway
    Saloon Keeper
    Posts: 27762
    196
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think JREs are mostly a dead issue now. It's no longer a concern that a JRE takes slightly less disk space/download time than a full JDK.

    Caution on package managers, though. If the OS provides an installable JDK, it's almost certainly OpenJDK and NOT the Oracle JDK.

    Oracle does do OS-specific packaging for some platforms (though Debian/Ubuntu was not one of them last I looked) and it doesn't come from OS vendors. You have to download straight from Oracle/java.sun/com after first agreeing to their license.

    Mostly it's a matter of whether you need the "official" Java or the open-source version these days, although in earlier time I discouraged using Iced-T Java (OpenJDK's predecessor) on enterprise projects. OpenJDK has pretty well filled the holes that Iced-T had.
     
    Matthew Bendford
    Rancher
    Posts: 326
    14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @Campbell @Tim
    As I use OpenSuse on my servers it does provide java in quite a complicated way:
    java
    java-headless
    java-devel
    Whereas the simple java is a meta package and it auto-selects java-headless but not java-devel. So, at least on opensuse when just installing java it seem to only install a jre. To install a jdk one has to install java-devel. There're several "flavors" like openjdk, openj9, ibm and several versions: 1.8, 9, 10, 11 and 17.
    Arch does pretty much the same: There're jre packages and jdk packages - but in difference to opensuse when installing just java via pacman it defaults to the jdk packages.
    As for openjdk vs oracle: I stopped worry about that since I moved from windows to linux when microsoft dropped support for windows 7.
    I only noticed differences on code used internals or reflections - as long as one stay to the public api as listed on the docs I never noticed any differences.

    btw: sorry for hijacking - maybe it should be split of into its own topic
     
    There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic