JAVA basic knowledge (1) to be continued~

JAVA basic knowledge

The key terms of the JAVA white paper: simplicity, object-oriented, distributed, robustness, security, neutral architecture, portability, interpretation, high performance, multithreading, dynamics.

Related terms

Term name abbreviation Explanation
Java Development Kit JDK Software development kit used by programs for writing Java programs
Java Runtime Environment JRE The operating environment required by the user to use the java program (specially provided for the user)
Server JRE Java program running on the server
Standard Edition I KNOW Java platform for desktop or simple server application development
Enterprise Edition EE Java platform (Enterprise Edition) for complex server application development
Micro Edition ME Java platform for the development of mobile phones and other small devices
NetBcans Oracle's integrated development environment
Update Oracle's terminology, indicating the revised version of the bug

Set JAVA environment variables

win version

setx -m JAVA_HOME "java所在路径"
setx -m CLASSPATH "%JAVA_HOME%/lib/tools.jar;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib"
setx -m PATH "%PATH%;%JAVA_HOME%/bin"

linux version

vim /etc/profile
export JAVA_HOME=java所在路径
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH

JAVA commands

再次之前需要设置好环境变量;

javac 编译

java  运行(直接输入文件名即可,不需要加后缀不然会出错误)

Basics of Java programming

A simple Java program

public class 类名
{
    
    
    public static void main(String[] args)
    {
    
    
        System.out.println("hello world");
    }
}

Pubilc (access modifier) controls the access level of this code.

class: All the contents of the Java program are contained in the class.

(Class name): The class keyword is followed by the class name, which can be any character, and the class name needs to be consistent with the created Java file name.

main: The program is executed from the main function. The main method must be of public type and must have a shell class.

System.out.println("hello world"): Use the println method of the System.out object to output the hello world string of characters to the screen. The period (.) is used to call the method.

Java programming specification

  • Java programs are case sensitive

  • Each statement ends with a semicolon

Comment

The statement in the comment area will not be executed.

**'' //''** stands for single-line comment.

'' / ****/''** stands for multi-line comments.

public class HelloWorld
{
    
    
    /**
    *多行注释:
    *这个程序用于向计算机屏幕打印一串字符串。
    *这里面的内容都不会被执行。
    *注:多行注释不可以嵌套使用
    **/
    public static void main(String[] args)
    {
    
    
        //System.out.println("hello world"); 这句代码将不会被执行
    }
}

Basic data type

Java is a strongly typed language , and a type must be declared for every variable.

Strongly typed language: A language that enforces type definitions, requires the use of variables to strictly conform to the definition, and all variables must be defined before use.

Plastic surgery

Integer is used to represent values ​​without a decimal part, and negative numbers are allowed. The int type is most commonly used.

Types of Storage requirements Ranges
byte 1 byte -128~127
short 2 bytes -32768~32767
int 4 bytes -2147483648~2147483647
long 8 bytes -9223372036854775808~9223372036854775807

Note:

Long (long integer) values ​​need to have the suffix l or L when used (such as 999999999L, 400000000000l).

When using hexadecimal values, the prefix 0x or 0X is required (if 0x125a, 0X521c).

When using octal values, the prefix 0 is required. It is recommended not to use octal.

(Supported only after java7) Binary values ​​need to be prefixed with 0b or 0B (such as 0b1_0001_1001).

There is no unsigned form of shaping in java.

Floating point

Floating point types are used to represent values ​​with fractional parts. The double type is most commonly used.

Types of Storage requirements Ranges
float (single precision) 4 bytes Approximately (plus or minus) 3.40282347E+38F (effective digits are 6-7 digits)
double (double precision) 8 bytes Approximately (plus or minus) 1.79769313486231570E+308 (15 effective digits)

Note:

The value of the float type needs to be suffixed with f or F (such as 3.14F) when using it. If it is not marked, the default is double type.

Hexadecimal can also represent floating-point values ​​(for example, 0.125 == 2^-3 == 0x1.0p-3 p is knowledge, the mantissa is in hexadecimal, and the exponent is in decimal).

Floating point numbers are not suitable for financial calculations where rounding errors cannot be accepted.

Floating point calculations all follow the IEEE 754 specification.

NaN represents an undefined or unrepresentable value. Often used in floating-point arithmetic.

char type

The char type in Java is used to describe Unicode characters.

Code point refers to the code value corresponding to a certain character in a code table.

Note: It is strongly advised not to use the char type in the program unless you really need to deal with UTF-16 unit codes.

boolean type

The boolean type has only two values, false and true, which are used to determine logical conditions.

There is no mutual conversion between plastic and boolean, and there is no concept of non-zero or true.

variable

Every variable in Java has a type, and the variable type is located before the variable name.

Variable naming rules

Must start with a letter, a sequence of letters and numbers. And you cannot use Java reserved words as variable names

Initialization of variables

类型 变量名 = 初始赋值;
如: int a = 5;
	double b = 5.21;
	......

Note:

The variable declaration is as close as possible to the first use.

The declaration and definition of variables are not distinguished in Java.

constant

The value of this variable can only be assigned once, and cannot be changed after the assignment.

Use the final keyword to define constants in Java

static final double Pi = 3.1415926;

Guess you like

Origin blog.csdn.net/DRAGON_ranhou/article/details/105536534