第一题: class BinDemo{ public static void main(String[] args){ //左移:首位符号位 一定会移动掉,因此没有(有|无)符号位移动一说。 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 移动补码 => 1101 1100 补码 => 1010 0100原码 = -36 //有符号右移:正数补0,负数补1,符号位正常移动。 byte plus_right = 9; byte minus_right = -9; System.out.println(plus_right >> 2);//0000 1001 => 0000 0010 = 2 System.out.println(minus_right >> 2);//1111 0111 移动补码 => 1111 1101 补码 => 1000 0011原码 = -3 //无符号右移:正数补0,负数补1,符号位不移动。 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 >>> 2));//1111 0111 移动补码 => 1111 1101 补码 => 1000 0011原码 = -3 byte unsigned_minus_right2 = -5; System.out.println((byte)(unsigned_minus_right2 >>> 2));//1111 1011 移动补码 =>1111 1110 补码 => 1000 0010原码 = -2 } } 第二题: class BinDemo{ public static void main(String[] args){ String hex_value = changeHex(11); System.out.println(hex_value); } public static String changeHex(int v){ int lower = v & 0x0F; int upper = (v >> 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]; } } 第三题: 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; } } 第四题: 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; } } 第五题: class BinDemo{ public static void main(String[] args){ while(true){ System.out.println("execute"); } } } 第一步:先写一个死循环执行 第二步:jps获取该执行的pid 第三步:jmap -heap 14396 查看执行的进程信息。 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) 第四步:java -Xms<size>:设置初始java堆大小。 java -Xmx<size>:设置最大java堆大小。
本文出自 “功不唐捐” 博客,请务必保留此出处http://senlinmin.blog.51cto.com/6400386/1770371
原文地址:http://senlinmin.blog.51cto.com/6400386/1770371