Concept of identifier
* Java For various variables , The character sequences used in naming methods and classes are called identifiers
* Any place where you can name yourself is called an identifier int num1 = 99;
Naming rules for identifiers ( Must be observed )
* from 26 English letters case ,0-9,_ or $ form
* Number cannot begin .int 5abc = 1;// error
* Keywords and reserved words cannot be used , But it can contain keywords and reserved words
* Java Strictly case sensitive in , Unlimited length .
* Identifier cannot contain spaces .int a b = 99;// error
Identifier naming conventions [ More professional ]
(1) Package name : All letters are lowercase when composed of multiple words :aaa.bbb.ccc // such as com.xjs.com
(2) Class name , Interface name : Multi word composition , Capitalize all words :XxxYyyZzz [ Large hump ] such as : TankShotGame
(3) Variable name , Method name : Multi word composition , First word initial lowercase , Start with the second word and capitalize each word :xxxYyyZzz [ Small hump , abbreviation Hump method ] such as :
tankShotGam
(4) Constant name : All letters are capitalized . When there are multiple words, each word is underlined :XXX_YYY_ZZZ
keyword
definition : cover Java Language gives special meaning , A string used for special purposes ( word )
characteristic : All letters in the keyword are lowercase .
Reserved word
Java Reserved word : existing Java Version not used , But later versions may be used as keywords . Avoid these reservations when naming identifiers yourself word
byValue,cast,future, generic, inner, operator, outer, rest, var , goto ,const
Base ( Basic skills of programmers )
Hexadecimal introduction
For integers , There are four representations :
* Binary :0,1 , full 2 enter 1. with 0b or 0B start .
* decimal system :0-9 , full 10 enter 1.
* octal number system :0-7 , full 8 enter 1. In numbers 0 Opening indication .
* hexadecimal :0-9 and A(10)-F(15), full 16 enter 1. with 0x or 0X Opening indication . Here A-F Case insensitive . // Demo Quad //
public class BinaryTest { // Write a main method public static void main(String[] args) {
//n1 Binary int n1 = 0b1010; //n2 10 Base int n2 = 1010; //n3 8 Base int n3 = 01010;
//n4 16 Base int n4 = 0X10101; System.out.println("n1=" + n1);
System.out.println("n2=" + n2); System.out.println("n3=" + n3);
System.out.println("n4=" + n4); System.out.println(0x23A); } }
Binary conversion ( basic skill )
Example of binary to decimal conversion :
Octal to decimal example :
Hexadecimal to decimal :
rule : From lowest order ( right ) start , Extract the number on each bit , multiply 16 of ( digit -1) Power , Then sum .
case : Please 0x23A Number converted to decimal 0x23A = 10 * 16^0 + 3 * 16 ^ 1 + 2 * 16^2 = 10 + 48 + 512
= 570
Convert decimal to binary :
rule : Divide the number by 2, Until Shang Wei 0 until , Then reverse the remainder from each step , Is the corresponding binary . case : Please 34 Convert to binary = 0B00100010
Convert decimal to octal :
rule : Divide the number by 8, Until Shang Wei 0 until , Then reverse the remainder from each step , Is the corresponding octal . case : Please 131 Convert to octal => 0203
Convert decimal to hexadecimal :
rule : Divide the number by 16, Until Shang Wei 0 until , Then reverse the remainder from each step , Is the corresponding hexadecimal .
case : Please 237 Convert to hex => 0xED
Binary to octal :
rule : Start low , Group binary numbers by three bits , Convert to the corresponding octal number .
case : Please ob11010101 Convert to octal ob11(3)010(2)101(5) => 0325
Binary to hexadecimal :
rule : Start low , Group binary numbers every four bits , Convert to the corresponding hexadecimal number .
case : Please ob11010101 Convert to hex ob1101(D)0101(5) = 0xD5
Octal to binary :
rule : Convert octal numbers every 1 position , Convert to the corresponding one 3 Binary number of bits .
case : Please 0237 Convert to binary 02(010)3(011)7(111) = 0b10011111
Hex to binary :
rule : Convert hexadecimal numbers every 1 position , Convert to corresponding 4 A binary number of bits .
case : Please 0x23B Convert to binary 0x2(0010)3(0011)B(1011) = 0b001000111011
Description of binary in operation
(1) Binary is every 2 Carry system of carry ,0,1 Is a basic operator .
(2) Modern computer technology is all binary , Because it only uses 0,1 Two numbers match , Very simple and convenient , Easy to implement electronically . Information processed inside the computer , Are represented by binary numbers . Binary (binary) Numerical use 0 and 1 Two numbers and their combinations represent any number . Carry rule is “ Meet 2 enter 1”,
number 1 Represent different values on different bits , In right to left order , This value is multiplied by two .
Original code , Inverse code , Complement ( a key difficulty )
Bitwise Operators
java There are 7 Bit operation (&,|, ^ ,~,>>,<< and >>>)
also 3 Bitwise operators >>,>> , Operation rules :
(1) Arithmetic shift right >>: Low overflow , Sign bit invariant , And fill the overflow high bit with the sign bit
(2) Arithmetic shift left <<: Sign bit invariant , Low complement 0
(3)>>> Logical shift right is also called unsigned shift right , The operation rule is : Low overflow , High complement 0
(4) Special notes : No, <<< Symbol
Operation in this chapter
Technology