Overview of Java

Published 2026-07-29 08:17 Updated 2026-07-29 08:25 1237 words 7 min read ... Page views

This article introduces the basic configuration and development environment of Java, including how to set environment variables so that the command line can access Java commands, and the complete process of writing the first Java program. It focuses on explaining Java code structure, naming convention, main method, output statements, binary representation, data storage method and character encoding, etc., and introduces Java annotation types and basic operations and settings in IntelliJ IDEA.

Overview of Java

Configure environment variables

The purpose of configuring environment variables is to allow command lines and development tools to find java, javac and other commands in the JDK bin directory. After configuration is complete, you can execute these commands in any directory.

image-001
image-001

Add the JDK’s bin directory to the system’s Path environment variable and move it to the appropriate location. After saving the configuration, you need to reopen the command-line window.

image-002
image-002

You can check whether the configuration was successful by executing the following command:

java -version
javac -version

Writing the first Java program

Step 1: Create source files

Create a HelloWorld.java file in the specified directory.

Step 2: Write code

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

Step 3: Compile the source file

Go to the directory where the source file is located on the command line, and then execute:

javac HelloWorld.java
image-003
image-003

You can also write out the full path to the source file in the command.

image-005
image-005

If there is a problem with the file name, path, environment variables, or source code, the compiler will output an error message.

image-004
image-004

Step 4: Run the program

Execution after successful compilation:

java HelloWorld
image-006
image-006

Write the class name HelloWorld at runtime, not HelloWorld.class. The java command launches the class rather than directly executing the class file name on the disk.

Code structure description

class definition

public class HelloWorld {
}

public is an access permission modifier that means that this class can be accessed from other locations. class is used to define classes, and HelloWorld is the class name.

Note: For top-level classes modified by public, the class name must be consistent with the source file name.

A source file can define multiple top-level classes, but there can only be one public top-level class at most. In actual development, usually only one main class is defined in a file, which is easy to maintain.

identifier naming

Class names usually use the big hump nomenclature, such as HelloWorld; variable names and method names usually use the small hump nomenclature, such as studentName and getName().

Java identifiers can consist of letters, numbers, underscores, and dollar signs, but they cannot start with a number or be the same as keywords. Meaningful English names should be used first in actual development, and the dollar sign is not recommended at will.

main method

public static void main(String[] args) {
}

The main method is the entry point for ordinary Java applications. Only classes that need to be started directly must define the main method, and not every class must write it.

output statements

System.out.println("Hello World");

System.out represents the standard output stream and is output to the console by default. println() outputs the content and breaks the line, and print() does not break the line after outputting it.

The content in double quotes is a string. When using a plus sign, if both sides are numeric values, addition is performed; if either side is a string, string splicing is performed.

System.out.println(1 + 2);
System.out.println("结果:" + 1 + 2);
System.out.println("结果:" + (1 + 2));

Source files, compilers and editors should use UTF-8 coding uniformly as much as possible to avoid Chinese garbled coding.

image-007
image-007

binary

Common decimal system

Common bases in computers include binary, octal, decimal and hexadecimal.

In Java integer literals:

  • Binary begins with 0b or 0B.
  • Octal begins with 0.
  • Hexadecimal begins with 0x or 0X.
int binary = 0b111001;
int octal = 071;
int decimal = 57;
int hexadecimal = 0x39;

The values stored in the above four variables are all decimal 57.

hexadecimal conversion

When a decimal integer is converted to another base, you can divide it continuously by the target base and record the remainder, and then arrange the remainder in reverse order.

When other decimal units are converted to decimal units, each digit can be multiplied by the corresponding weight and summed. For example, binary 00011001 corresponds to:

1 × 2^4 + 1 × 2^3 + 1 × 2^0 = 25

Storage of data in memory

Data in memory is ultimately stored in binary form. Common storage units are as follows:

  • 1 bit represents a binary bit.
  • 1 byte equals 8 bit.
  • 1 KB usually stands for 1024 byte.

Storage of integers

Java signed integers are represented in two’s complement. Complement’s complement allows addition and subtraction to use unified hardware arithmetic rules.

Taking one byte as an example, the range that can be represented is -128 to 127; the signed integer range of two bytes is -2^15 to 2^15 - 1.

Storage of floating point numbers

Java’s float and double use the IEEE 754 floating point format. Floating-point numbers are represented by symbols, exponents, and significant digits, so the range is wide, but many decimal fractions cannot be accurately represented in binary.

System.out.println(0.1 + 0.2);

Scenarios involving amounts that require accurate decimal calculation, such as amounts, should use BigDecimal instead of relying directly on float or double.

Pictures, audio and video

Pictures, audio and video are also stored in binary form. The encoder converts the original information into byte data in a specific format, and the decoder restores the content in the same format.

Character sets and character encoding

Unicode allocates unified code points to characters around the world; UTF-8 is a variable-length encoding method of Unicode. GBK is mainly used for Chinese character encoding.

The ASCII standard defines 128 characters, of which the encoded value of character A is 65, and the encoded value of character a is 97. Common encodings such as UTF-8 and GBK are compatible with the basic character range of ASCII.

Garbled code may occur when encoding and decoding use different character sets. The source files, configuration files and data transmission in the project should be as clear as possible and use UTF-8 uniformly.

Java annotations

single-line comments

// 单行注释

multiline comments

/*
 * 多行注释
 */

documentation comments

/**
 * 文档注释
 */

Document comments can be extracted by the javadoc tool and generated API documents.

IntelliJ IDEA Basic Operations

new construction

Java source files are usually created in the project. New projects can be built through File, New, and Project.

Common contents in the project catalog are as follows:

  • The .idea directory holds the engineering configuration of IntelliJ IDEA.
  • The src directory is usually used as the source code directory.
  • Compilation results are usually output to the out directory or to the directory specified by the build tool.
image-008
image-008

In a simple IDEA project, the directory labeled Sources Root is used to hold the source code. The compiled class file is located in the output directory.

image-009
image-009

global settings

Through File and Settings, you can modify global settings such as themes and fonts.

image-010
image-010
image-011
image-011

project sets

Through File and Project Structure, you can set the JDK, language level and output directory used by the project.

image-012
image-012

Common shortcut keys

  • Alt + Enter: View error fixes or code operation suggestions.
  • Ctrl + E: Open the list of recently used files.

If you enjoyed this, leave a comment~

... Page views
© 2026 跨越星轨的客 @Hoshiumi
Powered by theme astro-koharu · Inspired by Shoka