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.

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.

You can check whether the configuration was successful by executing the following command:
java -version
javac -versionWriting 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
You can also write out the full path to the source file in the command.

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

Step 4: Run the program
Execution after successful compilation:
java HelloWorld
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.

binary
Common decimal system
Common bases in computers include binary, octal, decimal and hexadecimal.
In Java integer literals:
- binary to
0bor0Bbeginning. - Octal is based on
0beginning. - hexadecimal in
0xor0Xbeginning.
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 = 25Storage of data in memory
Data in memory is ultimately stored in binary form. Common storage units are as follows:
1 bitRepresents a binary bit.1 byteequal to8 bit。1 KBgenerally represents1024 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:
.ideaThe directory holds the project configuration of IntelliJ IDEA.srcDirectories are usually used as source code directories.- Compilation results are usually output to
outDirectory or directory specified by the build tool.

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.

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


project sets
by File、Project Structure You can set the JDK, language level, and output directory used by the project.

Common shortcut keys
Alt + Enter: View error fixes or code operation suggestions.Ctrl + E: Open a list of recently used files.
If you enjoyed this, leave a comment~