Java
lastmod 2026-09-04created 2014-01-05115 edits
|
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.
- Register the folder where the JDK is installed as the
JAVA_HOMEenvironment variable. - Add
$(JAVA_HOME)/binto thePATHenvironment variable. (On Windows, add%JAVA_HOME%\bin.) - If there are
*.jarfiles to register, add them to theCLASSPATHenvironment 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
- CodingGuidelines:Java: Java coding guidelines.
- Java:Enumeration
- Java:Annotation
- Java:Exceptions
- Java:StackTrace
- Java:Volatile
- Java:InstanceOf
- Java:ThreadPool
- Java:Timestamp
- Java:Serialization
- Java:CLASSPATH
- Java:VirtualThreads
- Java bytecode
- Java Collection Framework (JCF)
- Java Virtual Machine (JVM)
- Java applet
- OpenJDK
- Java Development Kit (JDK)
- Scala
- Java class file
Libraries
Java Decompiler
Examples
- Android:Example: simple Android example.
- Java:Example: simple Java example.
- Java:Example:GlobalSetting: manages setting variables to be used globally.
- Android.opengl.GLSurfaceView#Example: Android GLSurfaceView Sample.
- Android:Example:DipCalc: converts between Android dip and pixel units.
- Android:Example:DisplayInfo: obtains Android display device information.
- Android.content.SharedPreferences:Example: saves/loads Android user information (Preference).
- Android:Example:SpinnerDialog: how to display an Android SPINNER-TYPE dialog box.
- Android:Example:Png2Mp4: sample program that converts png images to mp4.
- Android:Example:MusicInfo: sample class for obtaining music information on Android.
- Android:Example:DirectoryManager: helps obtain the list of predefined directories available on Android.
- Android:Example:SocketServer: sample example of creating a Socket Server and Socket Client on Android.
- Java.lang.String:InitialConsonant: example Hangul initial consonant search class (InitialConsonant)
- Android:Example:ImageAdapter: (Geosoft Roadie Android) selectable image + string list box class (items can be selected).
- Android:Example:SpinnerBox: (Geosoft Roadie Android) class that displays a spinner (Spinner) progress icon dialog box.
- Android:Example:NdkOpenGLESGeometry: (Geosoft Roadie Android) geometry rendering using OpenGLES on the NDK side.
- SMS-Forward: forwards incoming text messages to another phone, Telegram, or a webhook.
Classes
Build tools
Java Version Manager
- [Recommended] Installing multiple JDKs and choosing which one to use - Gaebal Suyangnok
- IDE (e.g. IntelliJ)
- APT/YUM
- update-alternatives / alternatives
- Homebrew
- Chocolatey
- direnv
- jEnv
- SDKMAN
- jabba
- jvms
How to install
- How to Install JAVA 8 (JDK 8u40) on CentOS/RHEL 7/6/5 and Fedora
- Manually installing Oracle Java on Ubuntu
- Manually installing JAVA (JDK) on Linux (CentOS 5.2)
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.
(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.
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
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
- LINE's OpenJDK adoption: from compatibility checks to caveats
- Java SE versions history
- Java version history - Wikipedia
- OpenJDK JDK 20.0.2 GA Release
- Java/OpenJDK | endoflife.date
| 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.
Change USER
You can override this value, the same as any other system property with:
OR,
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.
Or you can add CLASSPATH as shown below.
Directory
Current Working Directory
User Home Directory.
Line separator
The OS-specific newline character (Line separator) can be obtained as follows.
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):
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)
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.
- Stackoverflow: Is this a memory leak or a false positive?
- Stackoverflow: Eclipse Juno : unassigned closeable value
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
- Eclipse
- Scala
- JVM
- kotlin
- Rawdrawandroid – developing Android apps with C and Make, without Java
- Javet - embedding Node.js and V8 in Java
Favorite site
- Oracle JAVA homepage
- Java™ Platform, Standard Edition 7 API Specification
- Wikipedia (en) JAVA
- Java memory model and threads 1
- Java - Annotation (Custom Annotation)
- [Recommended] winapi.co.kr: JAVA course for C++ developers 2
- [Recommended] JavaTM Platform, Standard Edition 6 API specification 3
- [Recommended] Korean index of classes and interfaces (JDK) 4
Guide
- Stackoverflow: Why const keyword is not used in Java?
- 13 Decks Java Developers Must See to Stay Updated (13 slide decks Java developers should see so they don't fall behind)
- Ways to handle multiple tasks (Multi Task) effectively in Java (Executor, CountDownLatch, CyclicBarrier, ForkJoin)
Tip
- Understanding Java's hidden costs and improving app performance 5 (caveats when using Java8)
- Useful things to know when operating Java systems
- Java obfuscation techniques (Java Obfuscation Techniques)
Syntax: synchronized
- About Java synchronized
- Java Concurrency: Java Synchronized Blocks
- Synchronization using Java synchronized
References
- Akka
- Akka:Http
- Alternatives
- Android
- Android.content.SharedPreferences:Example
- Android:Example:DipCalc
- Android:Example:DisplayInfo
- Android:Example:ImageAdapter
- Android:Example:NdkOpenGLESGeometry
- Android:Example:Png2Mp4
- Android:Example:SpinnerBox
- Android:Example:SpinnerDialog
- Android:NDK:Sample
- Apache Ant
- Apache Maven
- Application.properties
- ArchLinux:Setup
- Bazel
- Bytecode
- C++
- CodingGuidelines:Java
- Com.typesafe.config.ConfigFactory
- Communication protocol
- Computer Language
- Computer Sciences
- Continuous Integration
- Data Structures
- Documentation generator
- Formal language
- Google Chrome
- Google Java Developer Tools
- Gradle
- Graphical user interface
- Groovy
- HashMap
- JAD
- Java applet
- Java Audio Video Encoder
- Java bytecode
- Java class file
- Java Collection Framework
- Java Development Kit
- Java Virtual Machine
- Java.io.Serializable
- Java.lang.StackTraceElement
- Java.lang.Thread
- Java.lang.UnsupportedOperationException
- Java.net.URLClassLoader
- Java.nio
- Java.nio.Buffer
- Java.text.SimpleDateFormat
- Java.util.ArrayList
- Java.util.Calendar
- Java.util.concurrent.ExecutorService
- Java.util.HashSet
- Java.util.Queue
- Java:Annotation
- Java:CLASSPATH
- Java:Enumeration
- Java:Example:GlobalSetting
and 47 more