Let say I am not a java developer and an ordinary person, and installing any application that is written in Java. So, do I need to first install the JRE or no all operating systems already have JRE installed on them?
Do all operating systems already have JRE installed for running java applications?
No.
First of all, Java is not necessarily available for all operating systems. (It is probably available for most operating systems that are targeted by your application ... but it might not be.)
Secondly, most operating system platforms don't have Java installed by default. Indeed many OS vendors don't support Java at all: Java is provided by a 3rd-party vendor.
So, do I need to first install the JRE or no all operating systems already have JRE installed on them?
Prior to Java 9, the answer is that you have to install a JRE or a JDK. This can be done by downloading and installing it directly, or installing it via a package management system on some OSes. It can also be done by embedding a JRE in your application's installer.
From Java 9 onwards, you can also use "jlink" to create an executable that contains a cut-down JRE which is tailored to run your application on a specific target platform. This is the approach recommended by Oracle for people who want to distribute "consumer grade" Java applications.
And from Java 11 onwards, for some Java vendors (Oracle for example), the JRE option is no longer available. For these vendors, if you want "full" Java to run your application, you / your users need to install a JDK.
The Java Runtime Environment has nothing to do with the OS. You could install any OS with or without the JRE. If you installed the OS yourself, I'd guess it doesn't have it. If you bought the computer with the OS on it, it depends who you bought it from.
Checking if you have JRE installed is pretty much the same on all OS. Open a Terminal (on windows run CMD) and type java --version.
If you don't have it, you need to install it. Just google install JRE on [insert your os here]
I have a question about the two versions of Java: JRE (Java Runtime Environment) and JDK (Java Development Kit).
Is the JDK installed and used in addition to the JRE or is it used instead of the JRE so that one could install the JDK as a JRE with simply more functions for developers?
You must understand that JDK includes JRE. JRE is Java Virtual Machine where your Java programs run on whereas JDK is full featured Software Development Kit for Java
From the docs:
JRE (Java Runtime environment):
It is an implementation of the Java Virtual Machine* which actually executes Java programs.
Java Runtime Environment is a plug-in needed for running java programs.
The JRE is smaller than the JDK so it needs less Disk space.
The JRE can be downloaded/supported freely from https://www.java.com
It includes the JVM , Core libraries and other additional components to run applications and applets written in Java.
JDK (Java Development Kit)
It is a bundle of software that you can use to develop Java based applications.
Java Development Kit is needed for developing java applications.
The JDK needs more Disk space as it contains the JRE along with various development tools.
The JDK can be downloaded/supported freely from https://www.oracle.com/technetwork/java/javase/downloads/
It includes the JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java applets and applications.
They're not two versions of Java. JRE is the Java Virtual Machine which executes bytecode. On the other hand, JDK is the Java Development Kit, which allows you to write Java code, compile it into bytecode and ships a JRE to execute it.
If your client just needs to execute Java, it needs to install the JRE only. If you want to run Java applications and create them install JDK.
One can install JDK..which has JRE also.
Does the JDK (Java Development Kit) update itself? I have noticed that I haven't gotten an update for JDK but only Java updates.
The JDK is used for writing java applications and is only updated manually.
The JRE is used for running java applications, such as jars and applets. Depending on the OS the JRE can be scheduled for automatic or manual update.
Some links with more details:
http://java.com/en/download/help/mac_java_update.xml
http://java.com/en/download/faq/expire_date.xml
I have been learning about Java web start and got interested in its features. But can my Java app downloaded and run from browser run on a device without a JRE(Java environment) installed?
I have tried download a sample jar from browser with Java web start but my app can't run.
Second question: Is there a feature in Java web start to check for an installed JRE and automatically setup the environment?
a JRE is required on the client to run your java Web Start application as it is downloaded and executed localy and all Java applications need an installed JRE.
Java Web Start provides the option to declare a JRE (with version number) and download it if it is not installed. (But I never used it so I can't tell you how to set this up) found on wikipedia.
You cannot do such a things with applet/jnlp, but you can package your jar into an application package: http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm
Java Webstart (JavaWS) is part of the Java Runtime Environment (JRE)
http://www.java.com/en/download/faq/java_webstart.xml
An installed JRE is - as far as I know - required to run JavaWS applications.
I'm not aware of any method which would facilitate an automatic download/install of the current JRE.
However, JavaWS allows you to enforce the use of a specific JRE version.
If "setup" refers to checking if a runtime is installed - that feature cannot of course be part of the Java runtime - that would turn it into a chicken-egg type of situation. At best an existing runtime will be able to detect that it is outdated.
But Oracle provides the Java Deployment Toolkit which is based on javascript:
http://www.java.com/en/download/faq/deployment_toolkit.xml
http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/depltoolkit_index.html
JavaFX 2 provides ant tasks to automate those things away:
http://docs.oracle.com/javafx/2/deployment/deployment_toolkit.htm#BABJHEJA
We have a couple of applications running on Java 5 and would like now to bring in an application based on Java 6. Can both java versions live together under Windows?
Is there any control panel to set the appropriate Java version for different applications, or any other way to set up, what version of Java will be used to run that particular application?
Of course you can use multiple versions of Java under Windows. And different applications can use different Java versions. How is your application started? Usually you will have a batch file where there is something like
java ...
This will search the Java executable using the PATH variable. So if Java 5 is first on the PATH, you will have problems running a Java 6 application. You should then modify the batch file to use a certain Java version e.g. by defining a environment variable JAVA6HOME with the value C:\java\java6 (if Java 6 is installed in this directory) and change the batch file calling
%JAVA6HOME%\bin\java ...
I was appalled at the clumsiness of the CLASSPATH, JAVA_HOME, and PATH ideas, in Windows, to keep track of Java files. I got here, because of multiple JREs, and how to content with it. Without regurgitating information, from a guy much more clever than me, I would rather point to to his article on this issue, which for me, resolves it perfectly.
Article by: Ted Neward: Multiple Java Homes: Giving Java Apps Their Own JRE
With the exponential growth of Java as a server-side development language has come an equivablent
exponential growth in Java development tools, environments, frameworks, and extensions.
Unfortunately, not all of these tools play nicely together under the same Java VM installation. Some
require a Servlet 2.1-compliant environment, some require 2.2. Some only run under JDK 1.2 or above,
some under JDK 1.1 (and no higher). Some require the "com.sun.swing" packages from pre-Swing 1.0
days, others require the "javax.swing" package names.
Worse yet, this problem can be found even within the corporate enterprise, as systems developed using
Java from just six months ago may suddenly "not work" due to the installation of some Java Extension
required by a new (seemingly unrelated) application release. This can complicate deployment of Java
applications across the corporation, and lead customers to wonder precisely why, five years after the
start of the infamous "Installing-this-app-breaks-my-system" woes began with Microsoft's DLL schemes,
we still haven't progressed much beyond that. (In fact, the new .NET initiative actually seeks to solve the
infamous "DLL-Hell" problem just described.)
This paper describes how to configure a Java installation such that a given application receives its own,
private, JRE, allowing multiple Java environments to coexist without driving customers (or system
administrators) insane...
It is absolutely possible to install side-by-side several JRE/JDK versions. Moreover, you don't have to do anything special for that to happen, as Sun is creating a different folder for each (under Program Files).
There is no control panel to check which JRE works for each application. Basically, the JRE that will work would be the first in your PATH environment variable. You can change that, or the JAVA_HOME variable, or create specific cmd/bat files to launch the applications you desire, each with a different JRE in path.
We can install multiple versions of Java Development kits on the same machine using SDKMan.
Some points about SDKMan are as following:
SDKMan is free to use and it is developed by the open source community.
SDKMan is written in bash and it only requires curl and zip/unzip programs to be present on your system.
SDKMan can install around 29 Software Development Kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x.
We do not need to worry about setting the _HOME and PATH environment variables because SDKMan handles it automatically.
SDKMan can run on any UNIX based platforms such as Mac OSX, Linux, Cygwin, Solaris and FreeBSD and we can install it using following commands:
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Because SDKMan is written in bash and only requires curl and zip/unzip to be present on your system. You can install SDKMan on windows as well either by first installing Cygwin or Git Bash for Windows environment and then running above commands.
Command sdk list java will give us a list of java versions which we can install using SDKMan.
Installing Java 8
$ sdk install java 8.0.201-oracle
Installing Java 9
$ sdk install java 9.0.4-open
Installing Java 11
$ sdk install java 11.0.2-open
Uninstalling a Java version
In case you want to uninstall any JDK version e.g., 11.0.2-open you can do that as follows:
$ sdk uninstall java 11.0.2-open
Switching current Java version
If you want to activate one version of JDK for all terminals and applications, you can use the command
sdk default java <your-java_version>
Above commands will also update the PATH and JAVA_HOME variables automatically. You can read more on my article How to Install Multiple Versions of Java on the Same Machine.
It should be possible changing setting the JAVA_HOME environment variable differently for specific applications.
When starting from the command line or from a batch script you can use set JAVA_HOME=C:\...\j2dskXXX to change the JAVA_HOME environment.
It is possible that you also need to change the PATH environment variable to use the correct java binary. To do this you can use set PATH=%JAVA_HOME%\bin;%PATH%.
I use a simple script when starting JMeter with my own java version
setlocal
set JAVA_HOME="c:\java8"
set PATH=%JAVA_HOME%\bin;%PATH%;
java -version
To have a java "portable"
you can use this method here:
https://www.whitebyte.info/programming/java/how-to-install-a-portable-jdk-in-windows-without-admin-rights
Or use links. While it is rather unpleasant to update the PATH in a running environment, it's easy to recreate a link to a new version of JRE/JDK. So:
install different versions of JDK you want to use
create a link to that folder either by junction or by built-in mklink command
set the PATH to the link
If other version of java is to be used, delete the link, create a new one, PATH/JAVA_HOME/hardcoded scripts remain untouched
Invoking Java with "java -version:1.5", etc. should run with the correct version of Java. (Obviously replace 1.5 with the version you want.)
If Java is properly installed on Windows there are paths to the vm for each version stored in the registry which it uses so you don't need to mess about with environment versions on Windows.
If you use Java Web Start (you can start applications from any URL, even the local file system) it will take care of finding the right version for your application.
Using Java Web Start, you can install multiple JRE, then call what you need.
On win, you can make a .bat file:
1- online version:
<your_JRE_version\bin\javaws.exe> -localfile -J-Djnlp.application.href=<the url of .jnlp file.jnlp> -localfile -J "<path_temp_jnlp_file_.jnlp>"
2- launch from cache:
<your_JRE_version\bin\javaws.exe> -localfile -J "<path_of_your_local_jnlp_file.jnlp>"