Java

From XennisWiki
Jump to: navigation, search

Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. (Wikipedia)

Setup

Installation

To develop programs in JAVA SE (Standard Edition), download the JDK (Java Development Kit) from the official site. The JDK already contains the JRE (Java Runtime Environment), which is sufficient for running a Java program only. You download maybe also the documentation JavaDoc.

Arch Linux

pacman -S jdk-openjdk

Debian

Installation OpenJDK via APT

apt-get install openjdk-10-jdk

On older operating systems first execute

add-apt-repository ppa:openjdk-r/ppa
apt-get update

Alternatively install OracleJDK

apt-add-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java10-installer

Add to PATH

  • Set the environment variable JAVA_HOME to the directory of the JDK
    • On Linux it is for instance: /usr/lib/jvm/java-10-openjdk-amd64
    • On Windows it is for instance: C:\Program Files\Java\jdk1.6.0_24
  • Append the environment variable PATH with the bin directory
    • On Linux: ${JAVA_HOME}/bin
    • On Windows: %JAVA_HOME%\bin

Example

HelloWorld.java

public class HalloWorld
{
    public static void main(String[] args)
    {
        System.out.println("Hallo World!");
    }
}

More

jar file

Execute jar file in console

java -jar NAME.jar

Mainfest

A very simple manifest. The file UTM.java has the main method. The manifast is in the jar file at the location: META-INF/MANIFEST.MF.

Manifest-Version: 1.0
Class-Path: .
Main-Class: UTM

See also

External links