I. Chapter II Analysis of Knowledge point context
The second chapter of the topic is called "Java Language Foundation", first introduced the Java language, the common basic knowledge point nouns: keywords, identifiers, annotations, constants and variables, functions and arrays. So far, we have not finished all the studies. In the existing learning process, we do a knowledge point of the context analysis.
The first three basic knowledge points, keywords, identifiers and comments, just introduce the rules of writing. The constants and variables that follow are a focus, and the functions and arrays are not introduced at all. In the key points of knowledge of constants and variables, both constants and variables are data, so when we define and use variables, we involve different types of data, which requires careful analysis of the types of data. The analysis of data types is also focused on the operation of basic data types and variables. First understand the type of data, provide a basis for the definition of variables, and then the different types of variables to operate.
In the previous section we discussed mainly the operations between the numeric variables, and now we discuss the remaining types of operations in the basic data types.
Two. Character type operation
Here are two types, character and Boolean, ch and Boolean. And listen to the meaning, it is also the two types and numerical type of operation. For Boolean types, it is not possible to operate with a numeric type.
When explained here, there are some incomprehensible points of knowledge, as follows:
It says here that a in the output statement is neither a constant nor a variable, so what is the composition of the constant ?
Here is talking about the character and numerical operation, behind the design of a knowledge point, that is, the character type at the bottom is actually binary encoding, can also act as a numerical value.
Shows that the output of ' a ' +1 is a numeric value of 98, which explains the problem, which is related to the coding knowledge point. The character type occupies two bytes of memory space , 1 is of type int and occupies four bytes. There is an automatic type promotion at the time of the operation.
The principle of the explanation: the computer only know the binary, at first, we put the binary code and the value of the relationship, so that the computer can recognize the number of life, is currently encoded through the binary number of life. Thinking out of the way, is to make the computer to recognize the text in life, the specific operation is to use binary coding to represent letters, symbols and so on. Because numbers, letters, and so on are linked to binary encodings, natural computers can operate on both. (in the sense that the Boolean type is also a binary encoding, why not and the numerical type to calculate?) → The only explanation is that the code table did not put true and false in the original, or not in a coding system? At least the numbers and letters in the ASC codes in the United States are in a single table . )
Statement System.out.println (' a ' + 1); The output is 97, if you want to output letters, you must force the type conversion, SYSTEM.OUT.PRINTLN ((char) (' a ' + 1)); So the output is B.
Here you need to remember, ' a ', ' a ', and 0 behind the coded values, respectively, are 65,97,48.
Java-Preliminary Understanding-Chapter II-operation of character types