javac NotRecognized - Java version 1.8.0_161 | - java

I'm testing out some code on a computer running Windows 8.1.
I'm using the command prompt and I can't seem to get javac (or javaC) to compile my text file. I've added the path as an environment variable (...\bin) and it doesn't do work. java -version and java prints information to the console, just can't get javac to work.

Seems like you are having JRE installed on your machine. You can go to your JAVA_HOME/bin folder, check if javac file is there or not. If not, it means you have JRE installed. You need to install java JDK.
FOr download jdk, this is the url for JDK 8:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Previous version available here:
http://www.oracle.com/technetwork/java/archive-139210.html

Related

Confused about what jdk and jre my command prompt is using for java

I was super confused about compatibility on a java tool I was using and ended up downloading different versions of java so now I do not know what versions of jdk or jre I am actually using. When I compile I use -- release 8 in my command prompt, what does that exactly mean?
Currently my programs folder has jdk-18 in the java folder
and my program files(x86) folder has
jdk1.6.0_45
jdk 1.7.0_80
jre 1.8.0_ 321
jre6
jre7
My java home environment variable is C:\Program Files\Java\jdk-18
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
when I type java -version in my command prompt I get
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) Client VM (build 25.321-b07, mixed mode)
So does that mean my cmd uses jre 1.8.0_ 321? What about the jdk? How do I change it if I need to?
When you run java -version - first java found in PATH environment variable is used. To be sure use commands where java (Windows) or which java (Linux) - it will tell you the location.
When you run mvn install - JDK found in JAVA_HOME environment variable is used. To be sure use mvn -version - it will tell you the location.
When you run from IDE - IDE settings matter, usually you specify JDK per project.
When you run javac --release 8 Something.java you are asking compiler to produce output compatible with the version you specified - it has nothing to do with JDK you are actually running it on. This flag was added in JDK 9, so if it doesn't fail for you then it means you are running on JDK>=9.
If you want to be 100% sure just fully qualify the path - for example on Windows "C:\Program Files\Java\jdk1.8.0_152\bin\javac.exe" Something.java
So does that mean my cmd uses jre 1.8.0_ 321?
Yes.
What about the jdk?
Unclear.
Run javac -version and that will tell you what version compiler you will run by default.
The versions of the Java tools that you get when you type java, javac, jar (etcetera) at the CMD prompt are solely determined by the PATH environment variable setting in effect at the command prompt.
The other variables do other things ... but not this.
How do I change it if I need to?
If you want to change what typing java does, change PATH.
Note that the PATH variable is a standard Windows environment variable that affects all* commands, not just the Java tools. There should be lots of tutorials on how to set PATH, and on the Windows CMD prompt in general. You should probably take the time to read them.
You can also just use the absolute path for the Java tools; e.g. "C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe" is probably the correct path for the Java 7 java command. (You can easily check ... and find the correct path by looking at the installation tree.)
Regarding your other variables:
My java home environment variable is C:\Program Files\Java\jdk-18
That is presumably JAVA_HOME. That tells (many) 3rd-party tools which Java tools to use. But unless you have configured PATH to depend on JAVA_HOME, it won't alter what typing java does.
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
That is presumably CLASSPATH. That variable provides a default path that java will use to find classes to load. For example, if you run java com.acme.Example, it will use CLASSPATH to search for the compiled Example class.
So "C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar" is almost certainly incorrect. (That JAR file contains the classes that implement various Java tools. It doesn't need to be on the classpath, unless your Java application is running one of those tools. And even then there would need to be other things on the classpath for your application to work.
You need to do some reading on what the Classpath is, how it works, and how to set it correctly. Setting it to stuff randomly is a sure fire way to make your Java code not work ...

installed java 7 but terminal responds with version 6

So I installed Java 7 and verified that it was installed Java now shows up under System preferences. However when I run java -version it still returns
java version "1.6.0_65
How do i fix this so that my computer points to the correct version? Also, is this a problem in the future if i choose to not fix this?
Thanks
You need to set your java 7 directory bin path to system PATH variable. As you are using Mac OS, use this article to set path correctly:
JAVA HOME in Mac OS
Use the following command to list the installed versions of Java:
/usr/libexec/java_home -V
From the output of the above command, copy the path for the version of Java you want to use.
Open up your ~/.bash_profile or ~/.bashrc file and add/edit the line:
export JAVA_HOME=/Path/copied/from/step/2
In your terminal, reload the the file you edited in the previous step using the corresponding command below:
source ~/.bash_profile
source ~/.bashrc
Now, you should see the the correct version of Java on the command line:
java -version

Diamond shorthand syntax not working javac

When I compile this:
LinkedBlockingDeque<Integer> q = new LinkedBlockingDeque<>();
in Eclipse Java EE Kepler version, everything works fine, but once I try to compile the same program in in the terminal with
javac myProgram.java
in the command line, I receive a "illegal start of type" error, on the <>
I know the Diamond Shorthand came with java 7, so why would the terminal use the javac of java 6 and not 7? And how do I correct this permanently? I'm on Linux, Mint 15.
Running javac -version revealed this
~ $ javac -version
javac 1.6.0_27
Apparently you have two separate versions of java installed. In Eclipse, you can specify the location of your JDK - which is set to 1.7. However in the terminal, your PATH variable contains (first) the location of JDK 1.6. As it looks like you're running linux/unix, try printing your PATH variable:
$ echo $PATH
You'll see in there path to JDK 1.6; path to JDK 1.7 may also be there but after the JDK 1.6 path. Edit your ~/.profile file and edit the path accordingly - remove JDK 1.6 and add JDK 1.7.
If, on the other hand, path to JDK 1.6 is set on the system level (e.g. in /etc/profile), then the easiest thing to do would be to add this line to your ~/.profile file:
export PATH="/path/to/jdk1.7/bin:$PATH"
After editing this file, log out and log back in.
You haven't added the Java 7 bin directory to your PATH environment variable. Or maybe Java 6 is also in there and is before the Java 7 path.
In eclipse.. Go to project properties -> Java Compiler and select the required java compiler version.

javac cannot be run, and furthermore does not seem installed

I have a problem involving setting up Java.
I have installed the JRE, added its path to PATH, and set JAVA_HOME and CLASSPATH. Now, java and javacpl work fine, but running javac generates a command-not-found error. Furthermore, javac.exe does not even seem to exist in the JRE's bin folder.
How do I run javac?
The JRE is merely the Java Runtime Environment, which includes only the infrastructure needed to run Java programs that are already compiled.
To compile Java source code using javac, you need the Java Development Kit (JDK).
On Oracle's Java download page, choose the package labelled "JDK".
In order to use javac in cmd , JDK must be installed in your system...
javac will not work if you are pointing "bin" folder inside JRE (C:\Program Files\Java**jre7**\bin)
Please check for javac.exe inside your bin folder(C:\Program Files\Java**jdk1.7.0_45**\bin)
javac.exe must be inside JDK(C:\Program Files\Java\jdk1.7.0_45\bin) not inside JRE (C:\Program Files (x86)\Java\jre7\bin) "JRE doesn't come with a compiler. It is simply a java runtime environment. What you need is the developmental kit." in order to use compiler javac
For javac path(Points to remember while setting system env variable)
path = C:\Program Files (x86)\Java\jre7\bin this is wrong
path = C:\Program Files\Java\jdk1.7.0_45\bin this is correct
Make sure "javac.exe" must be inside your "C:\Program Files\Java\jdk1.7.0_45\bin"
Dont confuse with JRE and JDK both are totally different
if you dont have JDK pls download from this link http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
reference thread for JDK VS JRE What is the difference between JDK and JRE?
Procedure:-
Install JDK
open cmd prompt
type "cd C:\Program Files\Java\jdk1.7.0_45\bin " press enter(path may change based on jdk version and 32bit and 64bit os version)
type "javac" press enter
its done
Now go and change your system environment variable
path = C:\Program Files\Java\jdk1.7.0_45\bin
this will set the path permanently
The JRE doesn't have javac - you need to download the JDK (Java Development Kit).
First, you need to install the jdk, then add the path of bin folder of jdk in the path vaiable.
you can refer to this link

Java -version shows 1.3 when I updated the classpath to c:\java\jdk1.6.0_20\bin

I need to run a java -jar on command line and so installed jdk6 but whenever i do java -version in command line it still shows the old version (1.3) How do I update it to show the latest version ??
Add the new Java bin folder to your path. And remove any other java references from your path.
You should set the PATH environment variable. On the command prompt, do:
> set JAVA_HOME=c:\java\jdk1.6.0_20
> set PATH=%JAVA_HOME%\bin;%PATH%
Now doing java -version should give you the expected version information.
The JDK install does not update the default Java installation on the system.
Go to http://java.com/en/download/installed.jsp and use the suggested installation procedure there when it finds that your default Java is outdated.

Categories