Name of the variable:
(1) The first letter is an English letter, a $ or an underscore, consisting of letters, numbers, and underscores.
(2) The name of the variable follows the principle of the known meaning.
(3) Java variable names are not recommended for Chinese.
(4) The first letter of the variable name is not capitalized.
(5) The name of a variable consisting of multiple words named by the Hump name method, for example: Sumscore.
Scope of the variable:
1. Java uses a pair of curly braces as a range of statement blocks, called scopes.
2. Variables in the scope cannot be defined repeatedly.
3. Out of scope, the allocated memory space of the variable will be reclaimed by the JVM.
Why
uses wrapper classes:
Java provides the corresponding classes for the base data types, which are called wrapper classes.
1, the wrapper class encapsulates some very useful methods and constants. For example: Byte.min_value is a constant in the byte class that holds the minimum value of the byte type data.
2, the wrapper class is used in the collection to define the type of the collection element. Common methods and constants for wrapper classes:
1, minimum value of type Integer.MIN_VALUE:int: -2^31
2, maximum value of Integer.MAX_VALUE:int type: 2^31-1
3, int integer.parseint (string sinteger);
function: Converts an integer of type string to data of type int.
4, string integer.tobinarystring (int value);
function: Converts the decimal number to binary, which returns the result string type.
5, Long.MIN_VALUE:long type minimum
6, Long.max_ Maximum value of Value:long type 7
7, long Long.parselong (string slong)
function: Converts an integer of type string to data of type long.
About complement:
1, in the computer system, the values are used in twos complement to store.
2. The highest bit of binary is the sign bit, 0 is a positive number, and 1 indicates negative number.
3, positive value is its own, negative value is the highest bit (sign bit) unchanged, the other bit-by-bit inverse, plus 1.
4, two number add, if the highest bit (sign bit) has carry, then carry is discarded.
Why use Complement:
1, the symbol bit and other bits can be unified processing.
2, the highest bit no longer represents the value, but as a sign bit, just the value binary, that is, half is 0 to positive, and half is negative.
3, subtraction can also be processed by addition.
The features of the complement operation:
1, the relationship between positive and negative numbers in the computer is to take the inverse plus one.
2. The complement operation is closed: The result of the operation is kept within the complement range, and the overrun range is overflow.
Java integer type:
1. Java has four types of integers: Byte, short, int, and long.
2. The result of the Java default integer calculation is the int type.
3, the literal of the integer is the int type.
4, if the literal exceeds the maximum value of type int, the literal is a long type, then L (or L) is used to indicate that the value is a long type.
Small types to large type conversions:
1, small type to large type of conversion will be done automatically, that is, the programmer does not need to write additional code, the JVM is responsible.
Tip: An automatic type conversion is also called an implicit type conversion.
2, Automatic conversion rules: The sign bit will automatically expand, negative 1, positive 0.
3. Automatic type conversion consists of the following:
(1) byte->short->int->long->float->double
(2) Data of int and char types can be converted to each other automatically in some cases.
Error type for Java:
Program errors are divided into compile-time syntax errors, run-time exception errors, and run-time logic errors.
1. Compile-time syntax errors can easily locate errors and modify them with the help of Eclipse.
2, the operating period is abnormal, the system will prompt the wrong type and the location of the error.
3, logic error refers to the program can compile and run, but the results of program execution is not the expected effect.
Changes and data types of Java programming fundamentals