Overview and use of constants
What is a constant?
Its value cannot be changed during program execution
classConstant { Public Static voidMain (string[] args) {System.out.println ("Hello world!");//string ConstantsSYSTEM.OUT.PRINTLN (123);//Integer ConstantsSystem.out.println (12.3);//Decimal ConstantsSystem.out.println (' 1 ');//a single character must be stored in the character constant 'System.out.println (true);//Boolean constantSystem.out.println (false);//Boolean constantSystem.out.println ("");//Empty Constants }}Variable
When are the variables?
The amount of the value that can change within a range during the execution of a program
The format of the variable definition
Data type variable name = variable value;
Why do you define variables
Used to keep constant of the same type, and can be reused
Overview and classification of data types
Why do you have data types?
Java Yu Yuan is a strongly typed language that defines specific data types for each data type and allocates a different size of memory space in memory
Classification of data types in Java
1. Integer type:
*byte 占1个字节 -128 到127 *short 占2个字节 -2^15 到2^15-1 *int 占4个字节 -2^31 到2^31-1 *long 占8个字节 -2^63 到2^63-1
2. Float Type:
*float 占4个字节 -3.403E38到3.403E38 *double 占8个字节 -1.798W408到1.798W408
3. Character Type:
*char 占2个字节 0到 65535
4. Boolean type:
*boolean 理论上占八分之一个字节,因为一个开关就可以决定是true和false了,但是java中的boolean 并没有明确的指定其大小
Java Basics-Data types & variables