First, the key words
Keywords: words that are given meaning by the Java language. The letters that make up the keyword are all lowercase. Note: Goto and const exist as reserved words and are not currently used. Main is not a keyword.
Second, identifiers
Identifiers: A sequence of characters used to name classes, interfaces, methods, and variables.
Composition rule: English uppercase and lowercase letters, numeric characters, $ and _
Note: cannot start with a number, cannot be a keyword in Java, case-sensitive
We usually have an identifier for these things:
Packages, classes, or interfaces, methods, and variables, constants
Third, note
Format for Single-line comments://Comment text
Multi-line annotation format:/* Comment text/*
Format of document comments:/** annotation Text * *
Note: Multiline comments cannot be nested, and a single line is OK.
Documentation Comments: The Javadoc tool is parsed into a specification that is used in the knowledge of object-oriented parts.
Iv. constants, feed and feed conversions
Constants: Their values cannot be changed during program execution
Constants in Java categories:
Literal constants Custom Constants (in object-oriented section)
1. Common constants:
String constants: Content enclosed in double quotes
Integer constants,
Decimal constants,
Character constants: Content enclosed in single quotes
Boolean constants: More specific, only true and false
Null constants: null (array part explained)
2, in the system and conversion:
Java provides 4 representations of integer constants: binary, octal, decimal, hexadecimal.
The octal integer begins with 0, and the hexadecimal integer begins with a 0x.
Note: Today's computer systems are rarely used in octal. Binary notation is too verbose, so it is generally preferred to use hexadecimal in the program
Binary and Octal conversions:
Binary vs. hexadecimal conversions:
3. Signed Data notation:
Within a computer, there are 3 representations of signed numbers: The original code, the inverse code, and the complement. All data operations are performed using the complement.
The original code: is the binary fixed-point notation, that is, the highest bit for the symbol bit, "0" means positive, "1" means negative, the remaining bits represent the size of the value. Inverse code: The inverse code of a positive number is the same as its original code; the inverse of a negative number is the reverse of its original code, but the sign bit (the highest bit) does not change. Complement: The complement of a positive number is the same as its original code; the complement of a negative number is at the bottom of its inverse code plus 1.
The main reason: the use of complement, can be the symbol bit and other bits unified processing, while subtraction can also be processed by addition.
In addition, when the number of two digits is added, the carry is discarded if the highest bit (sign bit) has a carry.
Five, variable
Variable Overview: The amount of value that can be changed in a range during the execution of a program
Variable definition Format: Data type variable name = initialization value;
Note: The Java language is a strongly typed language that defines specific data types for each type of data and allocates memory space of different sizes in total memory
Variables are divided by data type:
Note: There is also a special type of NULL in the reference type. A reference data type is a reference to an object, which includes instances and arrays of two kinds. In fact, a reference type variable is a pointer, except that there is no pointer in Java.
Variables are divided according to the position declared:
Local variables: variable member variables defined internally by a method or statement block: External to the method, internally defined variables of the class
Six or eight basic data types and type conversions
1, the basic unit of computer storage data:
Byte is the basic unit of calculation for the size of a computer file.
1 bytes (byte) = 8 bit (bit)
Bit means "bit" or "bit", which is the basis of computer operation, and one in binary system is binary smallest information unit. Binary can be used to indicate a simple positive/negative judgment, with two states of the switch (such as a light switch).
Description
In the memory calculation process, the byte data operation speed is faster, in the hard disk storage, the byte data type can also fully deposit more data.
2, eight basic types of data:
Note:
(1) integer default: Int. Declaring a long constant must be appended to the number with ' l ' or ' l ', such as: long L1 = 88888888888L; You have to add L or you'll make mistakes.
(2) floating-point Constants (decimal) Default: Double. Declaring a float constant, you need to add F or F to the number, such as double d = 12345.6; correct float f = 12.3f; You must add f, or you'll make mistakes.
(3) Java characters are encoded in Unicode, each with two bytes, and are thus represented as hexadecimal encodings. Note: Unicode is a global language unified encoding. Character Char in the Java language can store one Chinese character because the characters in the Java language occupy two bytes.
(4) Boolean types are suitable for logical operations and are generally used in program flow control.
Boolean-type data allows only true or false, not 0 or 0 integers to replace true and false, which differs from the C language.
(5) Byte, short when defined, they are actually receiving a value of type int. This is done by themselves a data detection, if no longer within their range, the error.
128:10 million
-128:10000000 (1 Here is the sign bit, also the numerical bit)
Use variable considerations:
Scope: The scope of which curly braces are scoped by which variable is defined at the level of braces. Two variables with the same name cannot be defined in the same scope. Initialization value: No initialization value cannot be directly used on one line suggests defining only a variable: multiple can be defined, but not recommended
3. Data type conversion:
Note: Boolean type cannot be converted to another data type
Default conversions: (Conversions from small to large)
Byte,short,char-int-long-float-double
Byte,short,char conversion between each other, they participate in the operation first converted to type int
Cast:
The target type variable name = (target type) (converted data);
Summary: So, what kind of conversion do we use?
Generally recommended, it is best not to arbitrarily use mandatory type conversion, easily resulting in loss of data accuracy.
(1) When a large capacity data type is converted to a data type with a small capacity, a mandatory conversion is added, but may cause precision degradation or overflow;
(2) There are many types of data mixing operations, the system first automatically converts all the data into the largest capacity of the data type, and then the calculation.
Interview questions:
A: Is there any difference in the following two ways?
float f1 = 12.345f;
float F2 = (float) 12.345;
The answer: There is a difference: F1 is actually converted by a double type, while the F2 itself is a float type.
B: Is there a problem with the following procedure, if so, where?
BYTE B1 = 3;
byte b2 = 4;
BYTE B3 = b1 + b2;
byte B4 = 3 + 4;
Answer: Byte B3 = b1 + b2; There is a problem. Because the variables are added, you will see the type problem first, and the final assignment will also consider the type problem.
The constants are added, the results are calculated first, and then see if they are in byte range, and if they are not, the error is made.
C: What is the result of the following operation?
byte B = (byte) 130;
System.out.println (b);
Answer:-126
D: Character participation operation: is to find the value in ASCII
' A ' 97
' A ' 65
' 0 ' 48
System.out.println (' a ');
System.out.println (' a ' + 1);
E: String participation operation: This is actually a concatenation of strings
System.out.println ("Hello" + ' a ' + 1);
System.out.println (' A ' +1+ "Hello");
System.out.println ("5+5=" +5+5);
System.out.println (5+5+ "=5+5");
Note: here the + is not an addition operation, but a string connector.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.