Article directory
JAVA development kit JDK
Java Development Kit , Java Development Kit, referred to as JDK
javac : Java compiler
java : Java virtual machine
javadoc : Java document generator
jar : Java archive packager
appletviewer : Java applet viewer
When a source program file contains multiple classes, pay attention to the following issues:
- Only one class can be declared public.
- The file name must match the public class name exactly, including letter case.
- public static void main(String[] args) can only be defined in public classes.
identifier - indentifer
An identifier is a name assigned by a programmer to a variable, constant, method, enumeration, class, interface, etc. The characters that make up an identifier have certain specifications. The naming rules of identifiers in the Java language:
- Case sensitivity : My and my are two different identifiers;
- The first character , which can be an underscore or a dollar sign or a letter, but not a number;
- Characters other than the first character , which can be underscores, dollar signs, letters and numbers;
- keywords cannot be used as identifiers
The letters in the Java language use double-byte Unicode encoding. Unicode is a unified encoding system, which includes Asian character encodings, such as Chinese, Japanese, Korean and other characters.
keywords
There are almost fifty keywords in Java, as shown in the figure: (all keywords are lowercase letters)
delimiter
The main delimiters are: semicolon (;), left and right braces ({}) and blank.
Semicolon : indicates the end of a statement
Braces : used for nesting of statements, etc.
Blank : Blanks are allowed between elements in Java source code, and the number of blanks is not limited. Blanks include spaces, tabs (Tab key input) and line breaks (Enter key input), and appropriate blanks can improve the readability of the source code.
variable
Variables and constants are an important part of expressions, and the internals of variables can be modified. Variables include variable names and variable values, variable declaration format:
数据类型 变量名 [=初始值];
The variable name must comply with the identifier naming convention, and there cannot be repeated variable names in the relevant scope.
The variable scope is the scope of use of the variable . The variable can be used within this scope. When the scope is exceeded, the variable content will be released. According to different scopes, variables are divided into member variables and local variables .
constant
Constants are variables that cannot be modified. Constants also need to be declared, and an initial value needs to be assigned when declaring. Constants cannot be modified once initialized . The format is as follows:
final 数据类型 变量名 = 初始值;
Constants are divided into three categories: static constants , member constants , and local constants .
public class Hello {
public static final double PI = 3.1415;
// 静态常量,可当作const使用
final int y = 10;
//声明成员变量
public static void main(String[] args) {
// 声明局部变量
final int k = 4;
}
}
The constant modified by public static is a static constant. Its scope is global and can be accessed without creating an object. The access form outside the class: Hello
type of data
There are 8 basic data types in the Java language.
Different data types have different ways of writing:
integer constants:
decimal : 20, -20;
octal : 020, -020;
hexadecimal : 0x20, -0x20;
binary : 0b10100, -0B10100
Real number constant:
with decimal point : 20.5, -20.0
scientific notation : 2.05E1, etc.
You can add the suffix "L" (both uppercase and lowercase) to convert it into a long type, for example: 20L, -20l;
There are a few points I haven't seen in C++, as follows:
- Java language integer types are all signed forms (signed)
- The single-byte integer in the Java language is byte, and in C++ it is char
- The Java long integer long occupies 8 bytes, which is twice that of int
- The character type char occupies 2 bytes in Java and 1 byte in C++
- There are no pointers in Java
Regarding the encoding method, I don’t know much about it. Let’s post a screenshot:
escape character
read-only variable
If a certain data processed by the program is constant and does not need to be changed during the running of the program, you can define a read-only variable (read-only) to save the data.
- A read-only variable is essentially a variable, and from a functional point of view, it uses variables to realize the function of constants
- Read-only variables are sometimes simply called constants
- Compared with literal constants, read-only variables can improve program readability and facilitate adjustment of constant values. Definition
method:
final 数据类型 常变量名=初始值;
Grammar description :
- Use the keyword final to define read-only variables;
- Read-only variables can only be assigned a value once . After the read-only variable obtains the initial value, it can only be read, and cannot be written (such as reassignment).
- Read-only variables are usually initialized when they are defined.
operator
data coercion
Algorithm Basic Structure
- sequential structure
- select structure
- loop structure
If else, switch, while, for, continue, break, and other statements are the same as in C++.