Java constants, variables, data types

Constants, variables, data types

constant

Refers to data whose value cannot change during program execution. For example, π= 3.1415 in mathematics... Another example: integer 123, decimal
1.23, character 'A', Boolean constant true, false, etc.

程序开发中,常量名一般规则全部大写,声明常量时必须赋值,以后只能使用,不能再赋值,java语言声明常量使用final。
package cn.qhk;
//静态导入 PI是常量.
import static java.lang.Math.PI;
public class V1 {

    //成员,属性
    final static int AGE = 99;
    public static void main(String[] args) {
//局部 常量
            final double pi = Math.PI;
            System.out.println(AGE);
            System.out.println(pi);
//使用常量
            System.out.println(PI);
        }
    }

insert image description here

variable

Variable: Refers to the quantity whose value can be changed during the running of the program. Variables are used to store information. It points to a certain unit of memory and indicates how big the memory is. Java is strongly typed, and variables must be declared and initialized before they can be used. In Java programs, variable names are case-sensitive.

//属性 成员 变量 属性 在实例化会自动初始化 int 0 、double float 0.0 、Object null、boolean false

type of data

The data types supported by Java are divided into two categories: primitive data types and reference data types.
There are 8 basic data types, which can be divided into three categories:
(1) Numerical type: integer type (byte, short, int, long) and floating point type (float, double) (
2) Character type: char
(3) Boolean type; boolean

insert image description here
insert image description here
The minimum and maximum values ​​of float and double are output in the form of scientific notation, and the "E+number" at the end indicates how many times the number before E is
multiplied by 10. For example, 3.14E3 is 3.14×1000=3140, and 3.14E-3 is 3.14/1000=0.00314.
Pay attention to a few points:
(1) The number of bytes of the eight basic data types of java: 1 byte (byte, boolean), 2 bytes (short, char), 4 bytes (int, float), 8 bytes (long, double) (2) The default type of floating point number is double (if you need to declare a constant as float type, you must add f or F at the end) (3) The default type of integer is int (declare Long type and add l or L at the end) ( 4) Packaging classes for eight basic data types: except for char which is Character and int which is Integer, the rest are capital letters (5) The char type is unsigned and cannot be negative, so
it
starts
with
0
(
6
)f F 、l L 、dD

Guess you like

Origin blog.csdn.net/qq_56015865/article/details/128944135