Overview of Java

Published 2026-07-29 08:17 Updated 2026-10-13 17:14 1196 words 6 min read ... Page views AI-reviewed An AI proof-read this post, but it still deserves a careful read. AI-rewritten Someone else wrote the original; AI helped me rewrite and polish it.

AI-reviewed An AI proof-read this post, but it still deserves a careful read.

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 explains in detail the Java code structure, naming convention, main method, output statements, binary representation, data storage method, character encoding and annotations, etc., and introduces the project creation, directory structure and common shortcut keys in IntelliJ IDEA, providing beginners with systematic guidance from environment configuration to basic programming.

Overview of Java

Configure environment variables

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

image-001
image-001

of the system Path Add JDK’s to environment variables bin Directory 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 in the specified directory HelloWorld.java Documents.

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 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 class names at runtime HelloWorld, don’t write HelloWorld.class。java The command launches the class rather than directly executing the class file name on disk.

Code structure description

class definition

public class HelloWorld {
}

public Is an access permission modifier that means that the class can be accessed from other locations.class Used to define classes,HelloWorld Is the class name.

note: By public The top-level class of the decoration must be consistent with the source file name.

A source file can define multiple top-level classes, but there can only be one at most public Top category. 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, for example HelloWorld; Variable names and method names usually use the little hump nomenclature, for example 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) {
}

main Methods are entrances to ordinary Java applications. Only classes that need to be started directly must be defined main Method, not every class has to write it.

output statements

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

System.out Represents the standard output stream, which is output to the console by default.println() After the output content, wrap the line,print() No line breaks after output.

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 be used as uniformly as possible UTF-8 Code to avoid Chinese garbled code.

image-007
image-007

binary

Common decimal system

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

In Java integer literals:

  • binary to 0b or 0B beginning.
  • Octal is based on 0 beginning.
  • hexadecimal in 0x or 0X beginning.
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 Corresponding:

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 equal to 8 bit。
  • 1 KB generally represents 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 Uses 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 and other scenarios requiring accurate decimal calculation should be used BigDecimal, rather than relying directly on it 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 assigns unified code points to characters around the world;UTF-8 Is a variable-length encoding method for Unicode. GBK is mainly used for Chinese character encoding.

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

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

Java annotations

single-line comments

// 单行注释

multiline comments

/*
 * 多行注释
 */

documentation comments

/**
 * 文档注释
 */

Document comments can be javadoc Tool extracts and generates API documents.

IntelliJ IDEA Basic Operations

new construction

Java source files are usually created in the project. can File、New、Project New construction.

Common contents in the project catalog are as follows:

  • .idea The directory holds the project configuration of IntelliJ IDEA.
  • src Directories are usually used as source code directories.
  • Compilation results are usually output to out Directory or 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

by File、Settings You can modify global settings such as themes and fonts.

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

project sets

by File、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 a list of recently used files.

Written by AI-rewritten

If you enjoyed this, leave a comment~

Loading...