Fedora ships with reference implementation of Java Standard Edition
called http://openjdk.java.net/OpenJDK[OpenJDK]. OpenJDK provides Java
Runtime Environment for Java applications and set of development tools
for Java developers.

From users point of view, `java` command is probably most interesting.
It's a Java application launcher which spawns Java Virtual Machine
(JVM), loads specified `.class` file and executes its main method.

Here is an example how to run sample Java project from section 1.1.1:

[source,java]
--------
$ java org/fedoraproject/helloworld/HelloWorld.class
--------

For developers, `javac` command is probably one of the most important
tools from OpenJDK. It's a Java compiler which tranaslates source files
to Java bytecode, which can be later interpreted by JVM. Other
interesting tools are `javadoc` and `javap`. `javadoc` is a tool for
generating Javadoc documentation and `javap` can be used for
disassembling Java class files.

Users and developers may want to have multiple Java environments
installed at the same time. It is possible in Fedora, but only one of
them can be default Java environment in system. Fedora uses
`alternatives` for switching between different installed JREs/JDKs.

[source,shell]
--------
# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
  -----------------------------------------------
   1           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
*+ 2           /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.3.1.fc21.x86_64/jre/bin/java
   3           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number:
-------

Example above shows how to chose default Java environments from all
environments currently available on the system. All Java applications
will start using this chosen environment from now on.

[TIP]
========
See `man alternatives` for more information on how to use
`alternatives`.
========

Developers may want to use Java compiler from different JDK. This can be
also achieved with `alternatives --config javac`.

Most of the Java application needs to specify classpath in order to work
correctly. Fedora contains several tools which make working with
classpaths easier.

`build-classpath` - this tool takes JAR filenames or artifact
coordinates as arguments and translates them to classpath-like string.
See following example:

[source,shell]
--------
$ build-classpath log4j junit org.ow2.asm:asm
/usr/share/java/log4j.jar:/usr/share/java/junit.jar:/usr/share/java/objectweb-asm4/asm.jar
--------

`log4j` corresponds to `log4j.jar` stored in %{_javadir}. If the JAR
file is stored in subdirectory under `%{_javadir}`, it's neccessary to
pass `subdirectory/jarname` as an argument to `build-classpath`.
Example:

[source,shell]
--------
$ build-classpath httpcomponents/httpclient.jar
/usr/share/java/httpcomponents/httpclient.jar
--------

Another tool is `build-jar-repository`. It can fill specified directory
with symbolic/hard links to specified JAR files.Similarly to
`build-classpath`, JARs can be identified by their names or artifact
coordintes.

[source,shell]
--------
$ build-jar-repository my-repo log4j httpcomponents/httpclient junit:junit
$ ls -l my-repo/
total 0
lrwxrwxrwx. 1 msrb msrb 45 Oct 29 10:39 [httpcomponents][httpclient].jar -> /usr/share/java/httpcomponents/httpclient.jar
lrwxrwxrwx. 1 msrb msrb 25 Oct 29 10:39 [junit:junit].jar -> /usr/share/java/junit.jar
lrwxrwxrwx. 1 msrb msrb 25 Oct 29 10:39 [log4j].jar -> /usr/share/java/log4j.jar
--------

Similar command `rebuild-jar-repository` can be used to rebuild JAR
repository previously built by `build-jar-repository`. See `man
rebuild-jar-repository` for more information.

build-classpath-directory is a small tool which can be used to build
classpath string from specified directory.

[source,shell]
--------
$ build-classpath-directory /usr/share/java/xstream
/usr/share/java/xstream/xstream-benchmark.jar:/usr/share/java/xstream/xstream.jar
:/usr/share/java/xstream/xstream-hibernate.jar
--------

