2: Constant
2.1 Overview
Constant: refers to the Java program in fixed data.
2.2 classification
Types of | meaning | Data example |
Integer constant | All integer | 0,1,2 |
Decimal constant | All decimals | 0.1,0.2,-0.1 |
Character constant | Single quotation marks, can only write a character, you must have content | 'A', '', 'good' |
String constant | Double quotation marks, you can write more than one character, you can not write | "A" ,"Hello" ,"你好" ,"" |
Boolean constants | Only two values (flow control to explain | true , false |
Constant air | Only one value (reference data types to explain | null |
2.3, output various types of constants
public class ConstantDemo { public static void main (String [] args) { // output integer constant System.out.println (123); // output decimal constant System.out.println (0.125); // output character constants System. Out.println ( 'A'); // output Boolean constants System.out.println (to true); // string literals System.out.println ( "Hello the Java"); } }
3, variable
Overview 3.1, variables
Variable: Constant data is fixed, then the amount of change in the program can be called variables.
3.2 Notes
Variable Name: braces in the same range, the variable name can not be the same.
Variable assignment: defined variables, no assignment can not be used.
3.3 definitions, variable
Data type variable name = data value
4 , the data type
4.1, the data type classification
Java data types are divided into two categories:
basic data types include: integers, floating point, character, Boolean.
Reference data types: a class, arrays, interfaces.
4.2, the basic data types
type of data | Keyword | Memory footprint | Ranges |
Byte | byte | 1 byte | -128-127 |
Short integer | short | 2 bytes | -32768-32767 |
Integer | int | 4 bytes | -231 th ~ 31 th power of 2 -1 |
Long integer | long | 8 bytes | -2 63 63 th power to 2 -1 |
Single-precision floating-point | float | 4 bytes | 1.4013E-45~3.4028E+38 |
Double-precision floating-point | double | 8 bytes | 4.9E-324 ~ 1.7977E + 308 |
Character | char | 2 bytes | 0-65535 |
Boolean | boolean | 1 byte | true,false |
Defines all the basic data types of variables, as follows: