Java constants:
The constant value of Java is represented by a string, distinguishing between different data types
Integer constant 123, floating-point constant 3.14, character constant ' a ', logical constant True, string constant "HelloWorld".
PS: This ' constant ' differs from the immutable variable that is modified by the final keyword.
Java variables:
The Java variable is the most basic storage unit in the program, its features include variable name, variable type and action.
Each variable in a Java program belongs to a specific data type that must be declared before it is used and must be assigned before it can be used.
int i = +; float f = 12.2fdouble//D1 and D2 not assigned, d3=0.123String s = "Hello World";
The difference between a local variable and a member variable:
Local variables, variables (including formal parameters) declared inside the method body.
A member variable, a variable declared within a class inside a method body.
4 Basic data types for Java:
Boolean (Boolean), character (char), Integer (Byte, short, int, long), floating-point (float, double)
Boolean (Boolean), which allows only values of true or false to be substituted for true and false for integers of 0 or not 0 (this is not the same as the C language)
character Type (char), 1, character constant is a single character enclosed in single quotation marks, 2, the escape character ' \ ' is allowed to convert subsequent characters to other meanings, 3, Java characters are Unicode encoded, Two bytes per character (Unicode is a unified Global language encoding)
integer type (byte, short, int, long), 1, Java each integer type has a fixed number representation range, not affected by the specific operating system, to ensure the portability of Java programs. 2, byte type 1 byte, short type 2 byte, int type 4 byte, long type 8 byte, no unsigned integer. 3, the normal value is a decimal integer, starting with a value of 0 is an octal integer, starting with a hexadecimal number of 0x. 4, the Java language of the integer constant is the default int type, the declaration of a long class constant value must be added ' l ' or ' l '.
int a1 = 600; // correct long a2 = 666666666666L; // must add l otherwise error
floating-point (float, double), 1, Java floating-point types have a fixed number representation range, not affected by the specific operating system. 2, Float type 4 byte, double type 8 bytes. 3. Two types of representations: decimal number and scientific counting method. 4, the Java language floating-point type constant is the default double type, declare the float class constant value must be added ' F ' or ' F '.
double d = 123.456; // correct float f = 12.34f; // must add f otherwise error
Java Learning 6--Basic data types and their transformations