• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up environment variables for command line compiling  RSS feed

 
ras oscar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Pete Letkeman
Ranch Foreman
Posts: 912
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 912
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 912
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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).
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • 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.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out Are both java and javac tools in the same location?
 
ras oscar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds correct; you can get problems if your version of javac is newer than the j‍ava version.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!