Skip to content
Search

Java

lastmod 2026-09-04created 2014-01-05115 edits

Java Packages (list)

  • java.applet
  • java.awt
  • java.awt.color
  • java.awt.datatransfer
  • java.awt.dnd
  • java.awt.event
  • java.awt.font
  • java.awt.geom
  • java.awt.im
  • java.awt.im.spi
  • java.awt.image
  • java.awt.image.renderable
  • java.awt.print
  • java.beans
  • java.beans.beancontext
  • java.io
  • java.lang
  • java.lang.annotation
  • java.lang.instrument
  • java.lang.invoke
  • java.lang.management
  • java.lang.ref
  • java.lang.reflect
  • java.math
  • java.net
  • java.util.concurrent
  • java.nio
  • java.nio.channels
  • java.nio.channels.spi
  • java.nio.charset
  • java.nio.charset.spi
  • java.nio.file
  • java.nio.file.attribute
  • java.nio.file.spi
  • java.rmi
  • java.rmi.activation
  • java.rmi.dgc
  • java.rmi.registry
  • java.rmi.server
  • java.security
  • java.security.acl
  • java.security.cert
  • java.security.interfaces
  • java.security.spec
  • java.sql
  • java.text
  • java.text.spi
  • java.util
  • java.util.concurrent
  • java.util.concurrent.atomic
  • java.util.concurrent.locks
  • java.util.jar
  • java.util.logging
  • java.util.prefs
  • java.util.regex
  • java.util.spi
  • java.util.zip
  • javax.accessibility
  • javax.activation
  • javax.activity
  • javax.annotation
  • javax.annotation.processing
  • javax.crypto
  • javax.crypto.interfaces
  • javax.crypto.spec
  • javax.imageio
  • javax.imageio.event
  • javax.imageio.metadata
  • javax.imageio.plugins.bmp
  • javax.imageio.plugins.jpeg
  • javax.imageio.spi
  • javax.imageio.stream
  • javax.jws
  • javax.jws.soap
  • javax.lang.model
  • javax.lang.model.element
  • javax.lang.model.type
  • javax.lang.model.util
  • javax.management
  • javax.management.loading
  • javax.management.modelmbean
  • javax.management.monitor
  • javax.management.openmbean
  • javax.management.relation
  • javax.management.remote
  • javax.management.remote.rmi
  • javax.management.timer
  • javax.naming
  • javax.naming.directory
  • javax.naming.event
  • javax.naming.ldap
  • javax.naming.spi
  • javax.net
  • javax.net.ssl
  • javax.print
  • javax.print.attribute
  • javax.print.attribute.standard
  • javax.print.event
  • javax.rmi
  • javax.rmi.CORBA
  • javax.rmi.ssl
  • javax.script
  • javax.security.auth
  • javax.security.auth.callback
  • javax.security.auth.kerberos
  • javax.security.auth.login
  • javax.security.auth.spi
  • javax.security.auth.x500
  • javax.security.cert
  • javax.security.sasl
  • javax.sound.midi
  • javax.sound.midi.spi
  • javax.sound.sampled
  • javax.sound.sampled.spi
  • javax.sql
  • javax.sql.rowset
  • javax.sql.rowset.serial
  • javax.sql.rowset.spi
  • javax.swing
  • javax.swing.border
  • javax.swing.colorchooser
  • javax.swing.event
  • javax.swing.filechooser
  • javax.swing.plaf
  • javax.swing.plaf.basic
  • javax.swing.plaf.metal
  • javax.swing.plaf.multi
  • javax.swing.plaf.nimbus
  • javax.swing.plaf.synth
  • javax.swing.table
  • javax.swing.text
  • javax.swing.text.html
  • javax.swing.text.html.parser
  • javax.swing.text.rtf
  • javax.swing.tree
  • javax.swing.undo
  • javax.tools
  • javax.transaction
  • javax.transaction.xa
  • javax.xml
  • javax.xml.bind
  • javax.xml.bind.annotation
  • javax.xml.bind.annotation.adapters
  • javax.xml.bind.attachment
  • javax.xml.bind.helpers
  • javax.xml.bind.util
  • javax.xml.crypto
  • javax.xml.crypto.dom
  • javax.xml.crypto.dsig
  • javax.xml.crypto.dsig.dom
  • javax.xml.crypto.dsig.keyinfo
  • javax.xml.crypto.dsig.spec
  • javax.xml.datatype
  • javax.xml.namespace
  • javax.xml.parsers
  • javax.xml.soap
  • javax.xml.stream
  • javax.xml.stream.events
  • javax.xml.stream.util
  • javax.xml.transform
  • javax.xml.transform.dom
  • javax.xml.transform.sax
  • javax.xml.transform.stax
  • javax.xml.transform.stream
  • javax.xml.validation
  • javax.xml.ws
  • javax.xml.ws.handler
  • javax.xml.ws.handler.soap
  • javax.xml.ws.http
  • javax.xml.ws.soap
  • javax.xml.ws.spi
  • javax.xml.ws.spi.http
  • javax.xml.ws.wsaddressing
  • javax.xml.xpath
  • org.ietf.jgss
  • org.omg.CORBA
  • org.omg.CORBA_2_3
  • org.omg.CORBA_2_3.portable
  • org.omg.CORBA.DynAnyPackage
  • org.omg.CORBA.ORBPackage
  • org.omg.CORBA.portable
  • org.omg.CORBA.TypeCodePackage
  • org.omg.CosNaming
  • org.omg.CosNaming.NamingContextExtPackage
  • org.omg.CosNaming.NamingContextPackage
  • org.omg.Dynamic
  • org.omg.DynamicAny
  • org.omg.DynamicAny.DynAnyFactoryPackage
  • org.omg.DynamicAny.DynAnyPackage
  • org.omg.IOP
  • org.omg.IOP.CodecFactoryPackage
  • org.omg.IOP.CodecPackage
  • org.omg.Messaging
  • org.omg.PortableInterceptor
  • org.omg.PortableInterceptor.ORBInitInfoPackage
  • org.omg.PortableServer
  • org.omg.PortableServer.CurrentPackage
  • org.omg.PortableServer.POAManagerPackage
  • org.omg.PortableServer.POAPackage
  • org.omg.PortableServer.portable
  • org.omg.PortableServer.ServantLocatorPackage
  • org.omg.SendingContext
  • org.omg.stub.java.rmi
  • org.w3c.dom
  • org.w3c.dom.bootstrap
  • org.w3c.dom.events
  • org.w3c.dom.ls
  • org.xml.sax
  • org.xml.sax.ext
  • org.xml.sax.helpers

Java (North Korean standard language: Jyaba) is an object-oriented programming language developed by James Gosling and other researchers at Sun Microsystems, and Sun Microsystems provides it free of charge. It began in 1991 under the name Green Project and was released in 1995. It was originally developed for programs embedded in and running on home appliances, but it is now one of the most widely used languages for web application development, and it is also widely used for developing software for mobile devices.

Because Java's developers had a Unix background, its syntax resembles C, the ancestor of C++, rather than Pascal. The biggest feature that sets Java apart from other compiled languages is that compiled code is platform-independent. The Java compiler converts programs written in the Java language into a special binary form called bytecode. Running bytecode requires a special virtual machine called the JVM (Java Virtual Machine), and this virtual machine runs Java bytecode the same way on any platform. As a result, programs developed in Java can run on any system where a JVM can be installed, regardless of CPU or operating system type, and because this fit the nature of web applications well, Java became explosively popular.

History

The Java language was created by James Gosling in June 1991 for a set-top project. The language was originally called Oak, after an oak tree outside James Gosling's office, or Green, but Java, picked at random from a list of words, was chosen. Gosling's goal was to implement a C/C++-style language and a virtual machine. The first public version of Java was Java 1.0 in 1995. It promised "Write Once, Run Anywhere" and provided free runtimes on popular platforms. The platform was fairly stable, and its security system could control network and file access through various settings. Most browsers soon became able to run Java Applets inside web pages, and Java's popularity soared. With the arrival of Java 2 (JDK 1.2 ~ 1.4), configurations usable on a variety of platforms were created. For example, J2EE can run enterprise applications and J2ME can run mobile applications. J2SE was designated the Standard Edition. In 2006, for marketing purposes, these were renamed Java EE, Java ME, and Java SE, respectively.

In 1997, Sun Microsystems approached the ISO/IEC JTC1 standards group, and later the ECMA International group, seeking formal approval, but soon withdrew from the process. Java is a de facto standard and is managed through the Java Community Process. Sun Microsystems distributed most of Java free of charge, but it was proprietary software, not open. Sun Microsystems earned revenue by selling specific licenses such as the Java Enterprise System. Sun distinguishes between its development kit (Software Development Kit (SDK)) and the runtime that is part of the development kit (Java Runtime Environment, JRE). The runtime does not include the compiler, utilities, or the various development header files.

On November 13, 2006, Sun Microsystems open-sourced most of Java under the GPL license, and it completed this process on May 8, 2007. It opened most of the core parts to which Sun Microsystems did not hold the rights.

On April 20, 2009, as its maker Sun Microsystems was acquired by and merged into Oracle, the rights to and maintenance of Java also passed to Oracle.

Install Java Developer Kit

To install the JDK (Java Developer Kit), proceed as follows.

  1. Register the folder where the JDK is installed as the JAVA_HOME environment variable.
  2. Add $(JAVA_HOME)/bin to the PATH environment variable. (On Windows, add %JAVA_HOME%\bin.)
  3. If there are *.jar files to register, add them to the CLASSPATH environment variable.

Java Runtime Interpreter

The Java Runtime Interpreter.

To run a JAR file (*.jar), enter java -jar [JAR_PATH].

  • appletviewer: applet viewer.
  • java: runtime interpreter.
  • javac: compiler.
  • jdb: debugger.
  • javap: class file disassembler.
  • javah: C header file generator.
  • javadoc: documentation tool.
  • jar: description of the Java™ Archive (JAR) file format.

Tools

Category

Libraries

Java Decompiler

Examples

Classes

Build tools

Java Version Manager

How to install

Download Java from the Oracle homepage and extract it.

## Login root
$ sudo -s
$ cd /usr/local
## Download: jdk-8u66-linux-x64.tar.gz
$ tar vxzf jdk-8u66-linux-x64.tar.gz
$ ln -s jdk1.8.0_66 java

Check that the executables have rwxr-xr-x permissions.

Then open the /etc/profile.d/java.sh file and enter the following.

export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin

(Note that the file above is loaded automatically by /etc/profile.

Use alternatives

Use alternatives to apply the java to be used on the system.

$ /usr/sbin/alternatives --install /usr/bin/java java /opt/jdk1.6.0_24/jre/bin/java 2
$ /usr/sbin/alternatives --config java

Among the selectable java entries, enter the number of the path you just installed. It is usually the last one.

Confirm that it has changed and check the version, and the installation is complete.

$ /usr/sbin/alternatives --display java
$ java -version

Oracle JAVA SE License

Major version releases (every 6 months / after version 8)
Adds or changes specifications that require JCP (Java Community Process) approval
Update cycle
The major patch update cycle is 3 months
Bug fixes including vulnerability protection
For Oracle customers only, Bundle Patch Releases are issued and provided irregularly when serious security issues occur
LTS versions (stable, long-term support)
The LTS versions Java 7, 8, 11, and 17 provide long-term support, so they can be considered the major versions

Java SE policy change: Java SE 17 (2021.10)

  • LTS releases every 2 years (previously 3 years)
  • New terms of use: Oracle No-Fee Terms and Conditions (NFTC)*
    • The JDK 17 NFTC license is a new license that follows Oracle Java 17's policy change; Oracle Java 17 can be used free of charge under the license terms and Oracle's Java usage policy
  • Public updates provided for 3 years (next LTS release + 1 year)
  • Updates after that require a Java SE subscription and are published under the OTN license
  • Commercial use allowed (no license fees during the public update period)

NFTC: https://www.oracle.com/downloads/licenses/no-fee-license.html

Java SE policy: servers

  • Java SE Subscription server licenses are billed per Processor
  • Oracle applies licenses to all processes that are installed and/or running, regardless of whether they are used
  • Oracle software virtualization and cloud policy
    • A license is required for every process on which Oracle Java SE is installed and/or running
    • Applies equally to physical, virtual, and cloud computing environments

Java SE policy: desktops

  • Java SE Subscription desktop licenses are billed per user (Named User Plus)
  • A license is required if it is installed (Installed), regardless of whether it is used
  • If you use Java SE 6, 7, or 8 and need a separate JRE (JVM) license, purchase a Java SE Subscription desktop license

Oracle JDK free version vs paid version

Free version

Paid version

6u45 and earlier

6u51 and later (latest: 6u211)

7u80 and earlier

7u85 and later (latest: 7u361)

8u202 and earlier

8u211 and later (latest: 8u351)

-

All versions from 11 onward

  • All versions of OpenJDK are free to use
  • Free versions do not receive the latest security updates, feature updates, or bug fix updates

Version Compatibility Matrix

Java SE version

Version number

Release date

LTS

Notes

JDK 1.0 (Oak)

1.0

January 1996

JDK 1.1

1.1

February 1997

J2SE 1.2 (Playground)

1.2

December 1998

J2SE 1.3 (Kestrel)

1.3

May 2000

J2SE 1.4 (Merlin)

1.4

February 2002

J2SE 5.0 (Tiger)

1.5

September 2004

Java SE 6 (Mustang)

1.6

December 2006

Java SE 7 (Dolphin)

1.7

July 2011

Java SE 8

1.8

March 2014

LTS

If someone elsewhere asks you to download JDK 1.8, it means the Oracle Java SE 8 version.

Java SE 9

9

September 21, 2017

Java SE 10

10

March 20, 2018

Java SE 11

11

September 25, 2018

LTS

Java SE 12

12

March 19, 2019

Java SE 13

13

September 17, 2019

Java SE 14

14

March 17, 2020

Java SE 15

15

September 15, 2020

Java SE 16

16

March 16, 2021

Java SE 17

17

September 14, 2021

LTS

Java SE 18

18

March 22, 2022

Java SE 19

19

September 20, 2022

Java SE 20

20

March 21, 2023

  • Versions 1.0 and 1.1 are named JDK (Java Development Kit).
  • From version 1.2 through 1.4, the platform name is J2SE (Java 2 Standard Edition).
  • Starting with version 1.5, Sun introduced internal and external versions.
    • The internal version continues from the previous one (1.5 after 1.4), but the external version jumped significantly (from 1.5 to 5.0).
    • This may confuse some people, so keep in mind that version 1.5 and version 5.0 are just different version names for the same thing.
  • Starting with Java 6, the version name is Java SE X.

Change USER

System.getProperty("user.name");

You can override this value, the same as any other system property with:

$ java -Duser.name=my-new-user

OR,

System.setProperty("user.name", "my-new-user"); 

Hello, World!

Create a Main.java file as shown below. The file name and the class name must be the same.

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

Compile it and run it as shown below.

$ javac Main.java
$ java Main

Or you can add CLASSPATH as shown below.

$ java -cp . Main

Directory

Current Working Directory

String workingDir = System.getProperty("user.dir");

User Home Directory.

String userDir = System.getProperty("user.home");

Line separator

The OS-specific newline character (Line separator) can be obtained as follows.

String lineSeparator = System.getProperty("line.separator");

Variable Arguments

Use variable arguments like an array, as shown below.

public static void foo(int ... nums) {
    for(int num : nums) {
        System.out.print(num);
    }
    System.out.printf("The last number of list is %d\n", nums[nums.length - 1]);
}

Byte Array to HEX String

To convert a byte[] to a HEX string:

public static String byteArrayToString(byte[] data) {
    if (data != null && data.length > 0) {
        StringBuilder builder = new StringBuilder();
        for (byte cursor : data) {
            String hex = Integer.toHexString(0xFF & cursor);
            builder.append("0x");
            if (hex.length() == 1) {
                builder.append('0');
            }
            builder.append(hex.toUpperCase() + " ");
        }
        return builder.toString();
    }
    return "";
}

The reverse is as follows.

public static byte[] stringToByteArray(String byteString) {
    String[] byteStringArray = byteString.split(" ");
    if (byteStringArray != null && byteStringArray.length > 0) {
        byte[] byteArray = new byte[byteStringArray.length];
        for (int cursor = 0; cursor < byteStringArray.length; cursor++) {
            byteArray[cursor] = (byte) (Integer.decode(byteStringArray[cursor].trim()) & 0xFF);
        }
        return byteArray;
    }
    return null;
}

Static import

Code without Static import (Math):

int i = Math.abs(-20);
double d = Math.acos(Math.PI) * Math.E;

The most basic usage is to add static after the import statement and write {패키지.클래스.*} or {패키지.클래스.멤버}. The code above written with static import looks like this.

Basic use of static import (not recommended)

import static java.lang.Math.*;

...

int i = abs(-20);
double d = acos(PI) * E;

Troubleshooting

A summary of troubleshooting methods.

No enclosing instance of type

You may get an error saying that the instance of the class you are trying to access is not enclosed.

No enclosing instance of type 클래스이름 is accessible. Must qualify the allocation with an enclosing instance of type 클래스이름 (e.g. x.new A() where x is an instance of 클래스이름)

Check whether the class is static.

Class loading exception

Resource leak

You may get a Warning message like the following.

Resource leak: '<unassigned Closeable value>' is never closed.

This warning occurs because a memory-releasing method such as close() was not called. After using the resource, add a release call such as close().
Alternatively, if you are using Java 7, you can solve it with try-with-resources blocks:

public static boolean copyFile(String fileSource, String fileDestination) {
    try (FileInputStream srcStream = new FileInputStream(fileSource); 
            FileOutputStream dstStream = new FileOutputStream(fileDestination)) {
        dstStream.getChannel().transferFrom(srcStream.getChannel(), 0, srcStream.getChannel().size());
        return true;
    } catch (IOException e) {
        return false;
    } 
}

java.lang.Object cannot be resolved

You may get an error message like the following.

The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

In this case, fix it in Eclipse as follows.

  • Properties -> Java Build Path -> Libraries -> add JRE System Library

Could not create the Java Virtual Machine

Running it in the console as below causes an error.

$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

In this case, try -version instead of --version.

Documentation

Easy-to-Follow Java Web Development - Java Web Development, 2nd edition
https://github.com/keesun/study/tree/master/book
Java_Web_Development_to_Easily_Follow_-Java_Web_Development-_2nd.pdf

See also

Favorite site

Guide

Tip

Syntax: synchronized

References


  1. Tech_column_-_Java_memory_model.pdf ↩

  2. Soenlab_com.7z ↩

  3. Xrath_com-java-spec.zip (see /javase/ko/6/docs/ko/api/overview-summary.html) ↩

  4. Www.javacool.net.zip (see _cool/api_doc/kor_jdk11api/AllClasses.htm) ↩

  5. Andev-jake-wharton-java-hidden-costs-android.pdf ↩

author Zer0 sitemap