OpenJDK: Difference between revisions

From Rosetta Code
Content added Content deleted
(Briefly describe OpenJDK; show how to use 'javac' and 'java'.)
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{implementation|Java}}
{{implementation|Java}}


[http://openjdk.java.net/ OpenJDK] is an [[open source|free]] implementation of Java for [[Linux]], [[Solaris]] and [[Windows]].<ref>[http://hg.openjdk.java.net/jdk7/build/raw-file/tip/README-builds.html#MBE OpenJDK Build README: Minimum Build Environments]</ref> There is also OpenJDK for [[BSD]]<ref>[http://openjdk.java.net/projects/bsd-port/ OpenJDK: BSD Port Project]</ref>. Several BSD and Linux distros carry packages of OpenJDK.
'''[http://openjdk.java.net/ OpenJDK]''' is an [[open source|free]] implementation of [[:Category:Java|Java]] for [[Linux]], [[Solaris]] and [[Windows]].<ref>[http://hg.openjdk.java.net/jdk7/build/raw-file/tip/README-builds.html#MBE OpenJDK Build README: Minimum Build Environments]</ref>
There is also OpenJDK for [[BSD]]<ref>[http://openjdk.java.net/projects/bsd-port/ OpenJDK: BSD Port Project]</ref>.
Several BSD and Linux distros carry packages of OpenJDK.


OpenJDK can compile and run Java programs. OpenJDK 6 implements Java 6, while OpenJDK 7 is a preview of future Java 7.
OpenJDK can compile and run Java programs.
OpenJDK 6 implements Java 6, while OpenJDK 7 is a preview of future Java 7.


== Usage ==
== Usage ==
OpenJDK is a set of command-line tools.
OpenJDK is a set of command-line tools. I have OpenJDK in <tt>/usr/local/jdk-1.7.0</tt>, so I added <tt>/usr/local/jdk-1.7.0/bin</tt> to my PATH. Now I can use the tools. The two most important tools are the [[javac]] compiler, and the java runner.
If OpenJDK is installed in <kbd>/usr/local/jdk-1.7.0</kbd>, then <kbd>/usr/local/jdk-1.7.0/bin</kbd> needs to be added to the <kbd>PATH</kbd> environment variable.
The two most important tools are the [[javac]] compiler, and the java runner.


This example program would compute 12 - 4.
This example program would compute 12 - 4.


<syntaxhighlight lang="java">
<lang java>/* TwelveMinusFour.java */
/* TwelveMinusFour.java */
public class TwelveMinusFour {
public class TwelveMinusFour {
public static void main(String[] args) {
public static void main(String[] args) {
System.out.println(12 - 4);
System.out.println(12 - 4);
}
}
}
}</lang>
</syntaxhighlight>


One can compile this program with javac, and run it with java.
One can compile this program with <kbd>javac</kbd>, and run it with <kbd>java</kbd>.


<syntaxhighlight lang="bash">
<lang bash>$ javac TwelveMinusFour.java
$ java TwelveMinusFour
$ javac TwelveMinusFour.java
$ java TwelveMinusFour
8</lang>
8
</syntaxhighlight>


== References ==
== References ==

Latest revision as of 08:34, 21 July 2023

OpenJDK is an implementation of Java. Other implementations of Java.

OpenJDK is an free implementation of Java for Linux, Solaris and Windows.[1] There is also OpenJDK for BSD[2]. Several BSD and Linux distros carry packages of OpenJDK.

OpenJDK can compile and run Java programs. OpenJDK 6 implements Java 6, while OpenJDK 7 is a preview of future Java 7.

Usage

OpenJDK is a set of command-line tools. If OpenJDK is installed in /usr/local/jdk-1.7.0, then /usr/local/jdk-1.7.0/bin needs to be added to the PATH environment variable. The two most important tools are the javac compiler, and the java runner.

This example program would compute 12 - 4.

/* TwelveMinusFour.java */
public class TwelveMinusFour {
	public static void main(String[] args) {
		System.out.println(12 - 4);
	}
}

One can compile this program with javac, and run it with java.

$ javac TwelveMinusFour.java
$ java TwelveMinusFour
8

References