Tag:java bitwise operator java heap size
First question: Class bindemo{ public static void main (String[] args) { //left: The first sign bit must be moved off, so there is no (have | no) sign bit move one said. byte plus_left = 9; byte minus_left = -9; System.out.println (plus_left << 2);//0000 1001 => 0010 0100 = 36 system.out.println (minus_left << 2);// 11111 0111 Mobile complement => 1101 1100 complement => 1010 0100 original code = -36 //sign right Shift: Positive 0, negative 1, sign bit normal movement. byte plus_right = 9; byte minus_right = -9; &nbsP; system.out.println (plus_right >> 2);//0000 1001 => 0000 0010 = 2 system.out.println (Minus_ RIGHT&NBSP;>>&NBSP;2);//1111 0111 Mobile complement => 1111 1101 complement => 1000 0011 Original code = -3 //unsigned Right Shift: positive 0, negative 1, sign bit does not move. byte unsigned_plus_right = 9; byte unsigned_minus_right = -9; system.out.println (unsigned_plus_right >>> 2);//0000 1001 => 0000 0010 = 2 system.out.println ((Byte) ( UNSIGNED_MINUS_RIGHT&NBSP;>>>&NBSP;2));//1111 0111 Mobile complement => 1111 1101 Complement => 1000 0011 Original Code = -3 byte unsigned_minus_right2 = -5; system.out.println ((Byte) (unsigned_minus_right2 >>> 2));//1111 1011 Mobile complement =>1111 1110 complement => 1000 0010 original code = -2 } } second question: Class bindemo{ public static void main (String[] args) { string hex_value = changehex (one); system.out.println (Hex_value); } public static string changehex (INT&NBSP;V) { int lower = v & 0x0f; int upper = (v >>&NBSP;4) & 0x0f; char[] arr = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E '}; return "0x" + arr[upper] + arr[lower]; }} Third question: Class bindemo{ public static void main (String[] args) { int sum_value = getsum (new int[]{ 1,5,7,9}); system.out.println (Sum_value); } public static int getsum (Int[] arr) { int length = arr.length; int total = 0; for (int i=0;i <length;i++) { total += arr[i]; } return total; }} Question Fourth:import java.util.arrays;class bindemo{ public static void Main (String[] args) { int[] copy_value = Copyarr (new int[]{1,5,7,9}); system.out.println ( Arrays.tostring (Copy_value)); } public static int[] copyarr (Int[] arr) { int length = arr.length; int[] new_arr = new int[ Arr.length]; for (int i=0;i<length;i++) { new_arr[i] = arr[i]; } return new_arr; }} The fifth question:class bindemo{ public static void main (String[] args) { while (True) { System.out.println ("execute"); } }} First step: Write a dead loop to perform the second step: JPS gets the PID of the execution third step:jmap -heap 14396 view the process information executed. heap configuration: minheapfreeratio = 0 MaxHeapFreeRatio = 100 maxheapsize = 2122317824 (2024.0MB) newsize = 44564480 (42.5MB) MaxNewSize = 707264512 (674.5MB) OldSize = 89653248 ( 85.5MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) compressedclassspacesize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 mb g1heapregionsize = 0 (0.0MB) Fourth step: Java -xms<size>: Sets the initial Java heap size. java -xmx<size>: Sets the maximum Java heap size.
This article from "Do Not Tang donation" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1770371
Big Data Java Foundation fourth day job