Even the official documentation of javac
says nothing about the -version option.
Javac -version tells you about the JDK version. That is, it gives the information of Compiler.
Official page does mention about it:
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
Why you cannot find on the page is, -version is not available for javac until Java 6 I believe (I am sure it is not available in 1.4 and before). That's why it is not showing on your page, which is javac ref page for Java 1.5. However, go to java command reference page of Java 1.5 and you should be able to find the -version switch.
This command outputs your java compiler's version. In mine case it shows 1.6.0
Just to expand, both display the same; the version of Java that the tools are part of.
You can ASSUME that what one reports, the other will automatically also report and so it is overkill to have the option in both. Until the moment you encounter a machine where there are multiple versions of Java installed and you can compile something yet you can't run it. Displaying the versions of javac and java can then quickly tell you that the setup of the machine is messed up enough that different versions of Java are being used to compile and run. And then you thank the designers for adding it in.
You are looking at the official documentation for an OBSOLETE version of javac Java 5. The -version option is documented in the javac manual entry for Java 6 and Java 7.
And in response to your question about what -version actually shows (for javac and java) the best answer is "unspecified" or "it depends on what version / platform you are using". In practice, your best bet is to just try it for yourself.
If your reason for asking is that you want to extract some useful information about the Java platform from the version strings ... I recently tried searching for a web page that listed the version strings for the java command, and came up empty. A better approach would probably be to write a tiny Java application to print out the relevant properties from the System properties object. The javadoc for System lists a number of properties that are standardised.
Related
I have a machine with several java installs. Below is snippet from alternatives java and javac:
JAVA:
/usr/java/jdk1.8.0_xx1/bin/java
/usr/java/jdk1.8.0_xx2-amd64/jre/bin/java
/usr/lib/jvm/jre-1.8.0-openjdk/bin/java
JAVAC:
/usr/java/latest/bin/javac
/usr/java/jdk1.8.0_xx2-amd64/jre/bin/java
(3 is missing)
Machine setup:
Why would they exist in different directories (/usr/java vs /usr/lib)? What is the linux/java reason for this, if any?
Why /jre/bin/java rather than /bin/java in the second listing, and would the /bin/java be preferred?
Why no javac for openjdk?
I am trying to ascertain if these alternatives were setup correctly because I need JDK for compiling code. Other machines show different alternatives.
When there are several programs that respond to the same command in a system, the ‘alternatives‘ command let us set which will be the real program that will be executed when that command is called. This is very clear to see in the case of Java. There are several JDK implementations: OpenJDK, GNU, JDK from Oracle, etc. All these JDKs come with a ‘java‘ executable. Supposing we got several JDKs from different vendors installed, which will be the one executed in our system when the ‘java‘ program runs
for more explanation check this blog.
https://blogs.igalia.com/dpino/2011/10/13/configuring-different-jdks-with-alternatives/
I can find java, javac and javadoc but there is no javah.exe in my jdk\\bin folder.
I tried to reinstall the JDK but it is still missing. How can I get it, why is it missing?
I found a similar question where the operating system was Linux but I can not find answers for Windows users.
My OS is Windows 10. The Java version is 10.0.1.
The tool javah.exe was removed in Java 10. The reason is simple, it is obsolete. From JEP 313: Remove the Native-header Generation Tool (javah):
Motivation
The tool has been superseded by superior functionality in javac, added in JDK 8 (JDK-7150368). This functionality provides the ability to write native header files at the time that Java source code is compiled, thereby eliminating the need for a separate tool.
Focusing on the support provided by javac eliminates the need to upgrade javah to support recent new paradigms, such as API access via the Compiler API in javax.tools.*, or the new java.util.spi.ToolProvider SPI added in JDK 9.
So you can just use javac.exe if you are on Java 8 or newer.
javah has been superseded by the -h option added to javac in JDK 8.
It is deprecated since Java 9.
See here for details.
According to several posts (e.g. Towards the "true" definition of JAVA_HOME ), and searching through some of the documentation available, JAVA_HOME has nothing to do with the JVM itself and is not used by it.
Yet some software requires it to be set, likely to exactly the value that the system property java.home has. Under the assumption that java is in the PATH, is there anyway to squeeze this system property out of the JVM that is portable between Windows/Unix/Mac --- except writing and compiling this handful lines of code to sysout the property?
I am really hoping for some less known command line option or other cute trick. Assuming a jdk (rather than jre) would be fine. How about some self-referential stuff with jps, jstack, jidunnothatitevenexits?
jshell in Java-9 makes it easy. But I need a solution for Java-8, maybe even -7. :-(
The Nashorn JavaScript engine is available in Java 8:
$ jjs
jjs> print(java.lang.System.getProperty("java.home"))
That's JavaScript, not Java code. ;-)
Works in Java 9, too. Sadly, not in Java 7.
Update
I think this works in 7, 8, and 9.
jrunscript -e 'print(java.lang.System.getProperty("java.home"))'
Update 2
Reversing the roles of the quote characters is allowed ...
jrunscript -e "print(java.lang.System.getProperty('java.home'))"
... and apparently necessary for Windows PowerShell.
I am not able to run jitwatch. It always returns me with compilation error.
Here is what I did:
git clone https://github.com/AdoptOpenJDK/jitwatch.git
mvn clean install exec:java
Has anyone ever found a similar problem?
How do we fix this ?
I've merged in the PR from Alex (thanks!) and that makes JITWatch build again under Java 1.7 which I intend to keep supporting.
I notice you have JDK 8 installed but maven didn't pick it up as it wasn't set as your %JAVA_HOME% environment variable.
FYI JITWatch has a Google Group here: https://groups.google.com/forum/#!forum/jitwatch where you can ask support queries directly.
Thanks for your interest in JITWatch.
Chris
It looks like this method was added in Java 1.8, and I suspect the command line compiler that you're using is using a 1.7 compatibility flag (and thus not able to see the method). Check to see if you're specifying a different version of Java with an environment variable that Maven is using instead, or running with the -verbose flag to find out what the Java version used is.
It looks like there's a Java 1.7 profile which is selected when the build thinks it's on a 1.7 runtime, and that might be a problem:
https://github.com/AdoptOpenJDK/jitwatch/blob/master/pom.xml#L108
So: check your Java version that's being used by Maven and investigate why it's not a Java 1.8 runtime.
I am trying to Build a JAR File of Interface Classes
I am using Linux and working throughout the terminal
I keep getting this error
Syntax error , type parameters are only available if source level is 1.5
I searched many sites and most solutions were about java on windows
to change properties
but how can I do that on linux ?
how can I solve this issue please ?
In your javac command line, add "-source 1.5".
It should read:
javac -source 1.5 ...
See also:
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/javac.html
Check your java version in your command line using:
java -version
and be sure that you are using a version 1.5 or more. And check that in your build.xml you are not saying that your java version is less than 1.5.
It can be fixed in same way as on windows.
If you are using Ant to build your project just add or change source attribute of the javac task, see Ant javac documentation. It should be looks like:
<javac ...
source="1.5"/>
If you are using command line tool to perform compilation ensure that you are using the correct version of the java compiler (see output of the java -version, you can't compile java15 java source classes using 1.4 or lower java compiler) and add -source 1.5 parameter to compile command. It should be like:
javac -source 1.5 ...java classes...
You have Java source code that uses generics, which is a feature added to Java 5, but you are most likely using a Java compiler from an older version (Java 1.4 or older). You can check which version of Java you are running with a command like java -version.
Install a newer JDK. What the best way is to do that depends on your Linux distribution.