Data type, Java basic rules, operators

1. Variable size and byte valid range

byte occupies one byte, -2 ^ 7 ~ (2 ^ 7) -1 (byte char required to cast)
 Short occupies two bytes, 15 ~ -2 ^ (2 ^ 15) -1
 int occupies four byte, 31 is ~ -2 ^ (2 ^ 31 is) -1
 Long occupy eight bytes, 63 is ~ -2 ^ (2 ^ 62 is) -1 5L
 a float occupies four bytes, f / F, such as 11f 
 Double occupancy eight bytes 5.2d
 char occupies two bytes
 boolean occupies four bytes

byte (short) add, subtract byte (short) will increase the value of the type to be int, not when cross-border assignments. byte type can not b = b + 1, but using b ++.

a byte addition, subtraction result is short short

string s = a + b + c + "abc" + a + b; // string before count-value type, then counted as strings, behind the brackets can change the priority.


2. Naming

Class name capitalized;
and the circumstances under more than one word, capitalize the first letter of each word;
public class name must be the same file name

3. basic operations: +, -, *, /,%, +, -

Modulo operation with the symbol of the symbol number modulo consistent (not integer [given] modulo 0, the result is non float may [not know])
 increment and decrement variables can only operate, the operation can not be constant. Error: + 5,5 +
 ^ operator: the same is false, as different to true
 ||, &&: and with & | short compared with characteristic
 /: Division: int / int = int, an integer of 0 can not be removed; floating point divide by zero, the result is infinite
 s = 6 + b + "abc " + x + y; // compiler error because the addition is left binding.
 float f = 5 * 2.0; // compile error, a float (2.0) unless otherwise default to double emphasis
adder and connects to a digital strings, the assignment should be a string constant

And any type can be connected in series string (+)
---------------------------------------- -----------------------------
logical operators:
Boolean && B1 = F (X ++> 10); // * &&, || and & and | have the characteristics of a short circuit compared to that x ++ is not executed.
-------------------------------------------------- -------------------
 bitwise operators: &, |, ^, ~ : after the digital conversion into the corresponding binary bit operations
  & 1 are only two 1
  two are only 0 0
  ^ 0 is the same
  - the inverse
  of the original code is positive, the inverted, complementary codes are the same
  negative inverted: the same as the sign bit, the remaining bits inverted
  negative complement: plus-minus 1
    
---------------------------------------------- --------------------------
   shift operator :( arithmetic shift left) <<, >>, (unsigned right shift) >> >
  << 1 except 2 corresponds to (int type constant results << 32)
   >> 1 by 2 corresponds
   >>> 1 high bit 0, the low discarded.

Published 45 original articles · won praise 7 · views 7786

Guess you like

Origin blog.csdn.net/qq_42712280/article/details/105230397