Package Self.learn.basicdata;import Java.io.printstream;import Java.util.properties;public class Basicdata {public static void Main (string[] args) {
//Question 1: What is the range of values for similar shaping variables?
Integer Rage
-2e31~ 2e31-1
// ........ , ........ , ........ , ........
0,1
The correct solution as above indicates the number of digits, so remove the symbol (1), minus 0, (positive range--)
The computed value range of int is as follows//-2E (32-bit-1) ~ 2E (32-bit-1)-1
By the way, list the bit widths that the base data type occupies
Byte,boolean 1
int, float 4
Short,char 2
Long,double 8system.out.println (Integer.min_value); System.out.println (Integer.max_value);//Sorry, Big Brother System properties for everyone to see, that is, by the way think of Properties P = system.getproperties () ;
P.list (New PrintStream (System.out));//Question 2: an example of left and right shift operations
Left shift = Left discard, tail complement 0
Install 2-to-10 conversion, the position of the move is 2 binary value (0,1) *2e ' n ' (n represents the bit position), equivalent to the number itself multiplied by 2 of the N-th square
Soy sauce man started afterward again, you write a (0,1) this is what? I just want to say, what's the value of your 0 move? int i = 2; System.out.println (i<< 2)//2*2*2 or 2en//right shift = "right discard, the original leftmost is 0 complement 0, is 1 complement 1int J =-8; System.out.println (J >> 2);//equivalent to 8/2/2 or -8/2e2 (rounding) System.out.println (J >>> 2);//unsigned to the right, indicating that no matter what the edge is 0 (i.e., unsigned bit displacement)
By the way, the logical operation and the bitwise operation
&&,| |,! VS &,|,^ (XOR), ~ (complement)
Explanation: The complement means 0 changes to 0
For you, automatic packing, unpacking precautions
Without directly comparing the automatically boxed two objects equal (not useful) Integer II = 200;integer JJ = 200; System.out.println ("II = = JJ?") = = "+ (ii = = JJ?) "Yes,equal": "No,unqual"). toString ()); Integer Ii2 = 100;integer jj2 = 100; System.out.println ("Ii2 = = jj2?") = = "+ (Ii2 = = jj2?) "Yes,equal": "No,unqual"). toString ());
Because -128~127 this number is cached in memory. (This is the difference between 100 and 200)//Question 3: Array, remember the correct way to declare and initializeint[] A1 = {1, 2,3};int[] A2 = new int[10];int[] a3 = new int[]{1,2,3};
Question 4: Test your String memory reuse problem//string, immutable object. String str1 = "Hello"; String str2 = "velly"; String STR4 = "Hello velly"; String STR3 = (str1 + str2). Intern (); System.out.println ("STR3 = = STR4, if use intern () =" + (STR3 = = STR4?) "Yes,equal": "No,unqual");//ensure you know StringBuilder
About regular, then each language is almost the same.//regular expression:nothing to Say.//string.matches ()//compile the Pattern with "Pattern.compile (" Regular expression ")"//reuse Pattern_compiled.matcher (String) with Matcher object.//if Matcher and Matcher.find ():// Matcher with group ([index])}}
< to Be continued >
Send a cheat book for Java interview (Java beginner)