quick-docs/modules/ROOT/pages/installing-java.adoc

212 lines
8.3 KiB
Text

= Installing Java
Héctor Louzao; Ankur Sinha ; alciregi
:revnumber: F37
:revdate: 2021-02-02
:category: Software installation
:tags: How-to Programming languages Java
//:page-aliases:
Java is a popular programming language that allows you run programs on many platforms, including Fedora.
If you want to create Java programs, you need to install a JDK (Java Development Kit).
If you want to run a Java program, you can do that on a JVM (Java Virtual Machine), which is provided with the JRE (Java Runtime Environment).
If in doubt, install the JDK because this is sometimes required even if the intention is not to write Java programs.
Many flavors of Java exist and also many versions of each flavor.
If you want to just run a specific application, check the documentation of that software to see what versions of Java are supported or have been tested.
Most Java applications run on one of the following:
* OpenJDK -- an open-source implementation of the Java Platform, Standard Edition.
This version is preferred, and included in Fedora.
* Oracle Java SE -- a free JDK from Oracle.
This version is not open-source and we recommend that it only be used if OpenJDK is not sufficient.
You can find the following Versions:
* Version (Ex. 8)
* Long Term Support or `LTS`
* Latest
== Installing OpenJDK
To install OpenJDK from the Fedora repository:
* Run the following command to list available versions:
----
dnf search openjdk
----
* Copy the version of OpenJDK you want to install.
[NOTE]
Various flavors of OpenJDK are available. For information about these options, search the link:https://openjdk.java.net/[OpenJDK web site].
* Run the following command to install OpenJDK:
----
sudo dnf install <openjdk-package-name>
----
Examples:
----
sudo dnf install java-1.8.0-openjdk.x86_64
----
----
sudo dnf install java-11-openjdk.x86_64
----
----
sudo dnf install java-latest-openjdk.x86_64
----
=== Installing OpenJDK for development
In order to install the Java Development Kit, runtime environment and associated development tools.
----
sudo dnf install <openjdk-package-name>-devel
----
Examples:
----
sudo dnf install java-1.8.0-openjdk-devel.x86_64
----
----
sudo dnf install java-11-openjdk-devel.x86_64
----
----
sudo dnf install java-latest-openjdk-devel.x86_64
----
== Installing Oracle Java SE
include::{partialsdir}/3rdparty-message.adoc[]
To install Oracle Java SE:
. Navigate to link:https://www.oracle.com/java/technologies/javase-downloads.html[Oracle Java SE downloads page], and choose the version of Java you wish to use.
. Accept the license agreement and download the appropriate tar.gz file for your systems architecture.
. Unpack the tar.gz file somewhere.
For example, to extract it to the _/opt_ directory:
`sudo tar xf Downloads/jdk-18_linux-x64_bin.tar.gz -C /opt`
. Set the _JAVA_HOME_ environment variable to that directory.
For example: `export JAVA_HOME=/opt/jdk-18.0.1.1`
Note: Always make sure to download latest version available.
== Switching between Java Versions
You might have installed several versions of Java on your system, you can switch from one.
After running this command, you will see a list of all installed Java versions, select:
----
sudo alternatives --config java
----
Simply enter a selection number to choose which java executable should be used by default.
* verify:
----
java -version
----
== JDK reference
See the following list of Java-related acronyms for reference:
JRE:: Java Runtime Environment; required to run Java code and applications
JVM:: Java Virtual Machine; main component of the JRE
JDK:: Java Development Kit; required only for development, coding
SDK:: Software Development Kit; see JDK
JavaWS:: link:https://en.wikipedia.org/wiki/Java_Web_Start[Java Web Start] is a framework to start application from the Internet
JavaFX:: link:https://en.wikipedia.org/wiki/JavaFX[JavaFX] is a platform to create and deliver desktop and Rich Internet Apps
OpenJFX:: is the JavaFX Open Source implementation
OpenJDK:: Open Source project behind the Java Platform link:https://openjdk.java.net/[openjdk.java.net].
IcedTea:: is a support project for OpenJDK (concern only developers) link:http://icedtea.classpath.org/[icedtea.classpath.org]
IcedTea-Web:: is the Java Web Start package (contains only JavaWS, no applets anymore); install to run *JNPL* files
applets:: are obsolete technology; Not implemented in any recent package
JSE, J2SE, JEE, ...:: obsolete acronyms for Java Standard & Enterprise Edition; JavaSE is like JRE
[discrete]
=== JDK components
The JDK has as its primary components a collection of programming tools, including:
`appletviewer`:: this tool can be used to run and debug Java applets without a web browser
`apt`:: the annotation-processing tool
`extcheck`:: a utility which can detect JAR-file conflicts
`idlj`:: the IDL-to-Java compiler. This utility generates Java bindings from a given Java IDL file.
`jabswitch`:: the Java Access Bridge. Exposes assistive technologies on Microsoft Windows systems.
`java`:: the loader for Java applications. This tool is an interpreter and can interpret the class files generated by the javac compiler. Now a single launcher is used for both development and deployment. The old deployment launcher, jre, no longer comes with Sun JDK, and instead it has been replaced by this new java loader.
`javac`:: the Java compiler, which converts source code into Java bytecode
`javadoc`:: the documentation generator, which automatically generates documentation from source code comments
`jar`:: the archiver, which packages related class libraries into a single JAR file. This tool also helps manage JAR files.
`javafxpackager`:: tool to package and sign JavaFX applications
`jarsigner`:: the jar signing and verification tool
`javah`:: the C header and stub generator, used to write native methods
`javap`:: the class file disassembler
`javaws`:: the Java Web Start launcher for JNLP applications
`JConsole`:: Java Monitoring and Management Console
`jdb`:: the debugger
`jhat`:: Java Heap Analysis Tool (experimental)
`jinfo`:: This utility gets configuration information from a running Java process or crash dump. (experimental)
`jmap`:: This utility outputs the memory map for Java and can print shared object memory maps or heap memory details of a given process or core dump. (experimental)
`jmc`:: Java Mission Control
`jps`:: Java Virtual Machine Process Status Tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. (experimental)
`jrunscript`:: Java command-line script shell.
`jstack`:: utility which prints Java stack traces of Java threads (experimental)
`jstat`:: Java Virtual Machine statistics monitoring tool (experimental)
`jstatd`:: jstat daemon (experimental)
`keytool`:: tool for manipulating the keystore
`pack200`:: JAR compression tool
`policytool`:: the policy creation and management tool, which can determine policy for a Java runtime, specifying which permissions are available for code from various sources
`VisualVM`:: visual tool integrating several command-line JDK tools and lightweight clarification needed] performance and memory profiling capabilities
`wsimport`:: generates portable JAX-WS artifacts for invoking a web service.
`xjc`:: Part of the Java API for XML Binding (JAXB) API. It accepts an XML schema and generates Java classes.
The JDK also comes with a complete Java Runtime Environment, usually called a private runtime, due to the fact that it is separated from the "regular" JRE and has extra contents. It consists of a Java Virtual Machine and all of the class libraries present in the production environment, as well as additional libraries only useful to developers, such as the internationalization libraries and the IDL libraries.
== Additional resources
For Java in Fedora, see:
* link:https://admin.fedoraproject.org/mailman/listinfo/java-devel[java-devel mailing list]
* Freenode IRC channel link:irc://irc.freenode.net/fedora-java[#fedora-java]
* link:https://ask.fedoraproject.org/tags/java[Ask Fedora about Java]
For more information about Java in general, see:
* link:https://en.wikipedia.org/wiki/Java_(programming_language)[Wikipedia page for Java]
* link:https://openjdk.java.net/[OpenJDK homepage]
* link:https://oracle.com/java/[Oracle homepage for Java]
To develop Java applications, consider the following open-source IDEs:
* link:https://netbeans.org/[NetBeans]
* link:https://eclipse.org/[Eclipse]
* link:https://www.jetbrains.com/idea/[IntelliJ IDEA]