• 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

Setting up environment variables for command line compiling

 
Ranch Hand
Posts: 42
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to learn java on my own for a couple years. Working with the netbeans interface and continually getting lost in my own code. Finally decided to go back to basics and do a few exercises from the command prompt. I went through the "your first java program" process of setting the environment variables. No luck. The problem is I allowed the installer to place and later update the components in the default location. Netbeans fires up and finds the components correctly, but I don't know which directories it is pointing to. I found the following directories that contain a subdirectory "java. Which one should my  environment variables point to?

C:\java
C:\ProgramData\Sun\Java
C:\ProgramData\Oracle\Java
C:\ProgramFiles(x86)\Java
C:\ProgramFiles\Java
 
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
To find out which Java you are using you should run the following commands from the command line:
echo %java_home%
echo %path%
"Java Home" should point to the location of Java that you are using. On my system this points to C:\Program Files\Java\jdk-9
"Path" may include the directory where Java is installed. Then again it may not. On my system it includes something C:\Program Files\Java\jdk-9\bin\
C:\Program Files\Java\jdk-9\bin is the directory where you can find java.exe and javac.exe
You can have more then one version of Java on your system, without any problems.
 
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
Oh, and any time you go about changing environment variables you usually have to close the command prompt and start a new instance of it.
 
ras oscar
Ranch Hand
Posts: 42
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll do a subsystem search of java.exe and javac.exe. Thanks

I assume javac is the compiler? no?
 
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

ras oscar wrote:I assume javac is the compiler? no?


Yes, javac is the compiler.

And as I stated previously you can have many different versions of Java installed on your system. You can even have the same version installed in many different places.
I would recommend that if possible that you do limit the total number of Java installs on your system.
If something like NetBeans needs Java it will most likely find it already installed on your system or you can configure the program afterwards to point the version you already have installed.

In the world of Java, nearly everything is backwards compatible, so if you have Java 8 installed on your system then you can run programs that require Java 7 and Java 6 and most likely even older versions of Java.
But seeing as you are starting out I would only concern myself with Java 8 and possibly Java 9 (Java 9 came out Sep 2017).
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pete Letkeman wrote:. . . If something like NetBeans needs Java it will most likely find it already installed on your system . . .

Not necessarily on Windows®.

if you have Java 8 installed on your system then you can run . . .most likely even older versions of Java. . . .

It complained when I tried to compile something to run on JDK1.4.2 a few months ago, but it still ran.

I would only concern myself with Java 8 and possibly Java 9 (Java 9 came out Sep 2017).

Get Java9.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a nifty utility installed on Windows called "where" (and on Unix-like systems called "which") that will tell you all the places in the PATH that a file can be found.  So for instance, on my system I get:

>where java
C:\ProgramData\Oracle\Java\javapath\java.exe
C:\Program Files\IBM\SPSS\Statistics\Subscription\JRE\bin\java.exe
C:\Program Files\Java\jdk1.8.0_144\bin\java.exe
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to add the location to the PATH first to use which, don't you? Is it the same with its Windows® counterpart where?
 
ras oscar
Ranch Hand
Posts: 42
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I'm getting closer. Found java.exe and added its location to the path statement. It was in c:\Program Files\Java\jre1.0_151. However, the only instance of javac is in the directory c:\Program Files\Java\jre1.0_45, which I assume is an earlier version of the compiler. I have no problem adding that to the path statement. However, is it possible that the java virtual machine ( java.exe) was updated but not the compiler? I thought those 2 guys worked together. I have searched the entire C drive for javac and that's the only version installed. I hesitate to move things around, lest I break netbeans in the process.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably follow the instructions here, but in short, you need to download and install the JDK (Java Developer's Kit).  It is common to save the JRE on a system and not the JDK (which includes the JRE).  You won't mess up NetBeans; just keep the Java installs you already have.

BTW, your Java folder names look odd.  Maybe you just copied the wrong when writing them?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You have to add the location to the PATH first to use which, don't you? Is it the same with its Windows® counterpart where?


You do, but sometimes a person will have Java in their PATH and not know it, or the system can find java but not javac.  In that case, which/where can help find where Java is already installed.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like the default position for a *nix box, which has the openJDK JRE only installed without the java tool.
 
ras oscar
Ranch Hand
Posts: 42
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
update: found both Java and Javac, added their respective locations to the path environmental variable. All is working. Re-acquainting myself with the wonderful world of the commend prompt and the function keys shortcuts ( its been a while). appreciate the assistance.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done sorting it out Are both java and javac tools in the same location?
 
ras oscar
Ranch Hand
Posts: 42
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had one copy of javac and 2 copies of java. Pointing to the virtual machine and compiler that reside in the same directory.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds correct; you can get problems if your version of javac is newer than the j‍ava version.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic