What exactly is the purpose of JDK - running java programs or developing?
There seems to be too many packages that include java and jdk/sdk in their title. Which one should I install if I want to develop Java applications?
Who uses JAVA_HOME and what should I set it to be?
JDK is development environment. JVM is runtime environment.
You should download java installer from oracle web site or install it from repositiry manager
JAVA_HOME system variable usually is required for enterprice java software (application servers, DBs, development tools and so on). You should set JAVA_HOME variable to root directory of JDK or JVM(setting it to JDK always works, but maybe some software will run as expected with JAVA_HOME pointing to JRE). If you set JAVA_HOME right then $JAVA_HOME/bin/java -version command should pring version of java.
JRE means Java Runtime Environment. Most Java Software only needs a JRE to run.
JDK means Java Development Kit. A JDK allways includes a JRE. If you develop you most certainly allways use the JDK, since it contains source and docs of java's own Classes.
Also there is software (usually software for development) that uses tools of the JDK to run, e.g. this software needs the JDK as runtime environment (for example: ant).
JVM means Java Virtual Machine and is the program that runs your java program no matter if in JRE or JDK.
JAVA_HOME is the path to the JDK
JRE_HOME is the path to the JRE
JDK - Java Development Kit (in contrast to JRE - Java Runtime Environment).
If you don't know which version of Java you need, just get the latest (currently Java Platform (JDK) 7u5). Unless you already have a development tool, you might want the Netbeans bundle instead.
JAVA_HOME is used by some software that depends on Java - ant, which is a build tool, is one that comes to mind. It should be set to the directory which contains the bin directory, which in turn contains the java executables.
Related
When the JDK already includes JRE for the execution of code, why do I have to download JRE separately to execute my java code is the doubt that's bothering me
As far as I remember this depends on your OS, browser and JDK version.
Eg. if you're using a 64-bit OS and installed a 64-bit JDK, but are using a 32-bit browser, then you might have to install a 32-bit JRE if you need Java support in the browser.
Otherwise a separate JRE installation should not be required, since the JDK installation also installs the JRE.
JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on.
JDK: It is a group of utilities one needs to develop programs in Java including JRE, and the compilers and tools (like JavaDoc, and Java Debugger) to convert the source code into bytecode.
Refer: http://javarevisited.blogspot.de/2011/12/jre-jvm-jdk-jit-in-java-programming.html
Similar, post is there on below link as well.
What is the difference between JDK and JRE?
So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.
I just installed Linux Mint and am trying to configure SpringSource Tool Suite which requires you to direct it to the system "JDK path". Although I haven't explicitly downloaded/installed Java on this system yet, when I ran the update manager I did see Open JDK get installed and found several directories under /usr/lib/jvm (see screenshot below). My questions are:
Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
How do I tell which of these is my JAVA_HOME?; and
What's the difference between the "JDK path" and JAVA_HOME?
Thanks in advance!
Edit:
echo $PATH --> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
java -version -> java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)
which java -> /usr/bin/java
Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
This can only be answered according to the needs of your application. Do you need the stability of Java 6 or the features added in Java 7? Are there APIs you intend to use that are only available in Java 7 or are the Java 6 libraries sufficient? Do you have customers that require the use of one JVM over another? Only you can answer these questions.
How do I tell which of these is my JAVA_HOME?; and
You will want to make JAVA_HOME reference the specific JVM environment that you've decided on for your project. For example, if you decide on Java 6 you'll probably want to set your JAVA_HOME to /usr/lib/jvm/java-6-openjdk-amd64.
What's the difference between the "JDK path" and JAVA_HOME?
The JDK path refers to the Java Development Kit - which includes the java compiler, debugger and other tools associated with developing java programs. JAVA_HOME can reference either the JDK root or the JRE (Java Runtime Environment) root directory when running java programs; but you should, for development purposes, always have JAVA_HOME reference the JDK root.
How to check, is Java is installed on Windows systems ?
You can read this out of the registry. Look in this key:
HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment
and read the string value named:
CurrentVersion
This setting lives in the 32 bit view of the registry, so if you ever build 64 bit code make sure you include the KEY_WOW64_32KEY flag.
Visit the officail website http://www.java.com/en/download/testjava.jsp and click "test currently installed version of java"
Some information which might be helpful:
a Java run time environment (JRE) can be installed by simply copying it to the computer (no Windows system entries are required)
there can be many different JRE versions on the computer at the same time (many commercial apps are bundled with their own JRE)
your Delphi app could check whether there is a java.exe in the system path (and so avoid scanning all folders)
the JAVA_HOME environment variable normally indicates the location of the Java Development Kit (JDK), but in a typical installation the JDK directory also contains a JRE folder
For my Inno Setup I check this key :
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\javaw.exe
If I remove JAVA the key doesn't exist anymore.
I have JRE 6 in my PC (Windows XP) but when I compile a program in the command prompt it shows javac is not recognised as internal or external command. Which software is needed to compile a Java program?
You need to download and install a JDK, not a JRE.
As a (very rough) explanation, the JRE contains just the Java Virtual Machine, whereas the JDK contains not only the JRE but also the compiler (javac), some debugging tools (javap, jvisualvm, ...), extra libraries and the API documentation.
See also:
What is the difference between JRE and JDK?
as recommended by dogbane, you can follow the Java Hello World for Windows Tutorial.
I suggest you run through the steps of the Hello World! Tutorial.
As per the instructions:
Download JDK6. (Make sure you download the JDK, not the JRE.)
Update the PATH variable to be able to conveniently run the JDK executables such as javac from any directory without having to type the full path of the command
JRE stands for Java Runtime Environment. It allows you to run already compiled java programs. To compile your own programs, you need JDK which stands for Java Development Kit. You can download it at JDK Downloads Page.
You need to install JDK-6 (Java Development Kit) which contains javac Java compiler. JRE does not contain it.
Instead of a simple JRE, you'll need a full JDK. As an example, youc an download sun one here : http://www.oracle.com/technetwork/java/javase/downloads/index.html#need (and don't forget to select "download JDK").
JDK is needed to develop applications whereas JRE is enough to run applications.
In other words JRE is enough to run a application (i.e) it includes java.exe and doesnot contain javac.exe
JDK contains both java.exe and javac.exe
There are also other chances that you dint set your class path properly.