标签:
package self.learn.basicdata; import java.io.PrintStream; import java.util.Properties; public class BasicData { public static void main(String[] args) {
//问题1: 类似整形变量的取值范围是什么?
//Integer rage
//- 2E31~ 2E31-1
// ........ , ........ , ........ , ........
// 0,1
// 正确的解法如上点表示位数,所以除去符号(次方-1),除去0,(正范围-1—)
//计算得到 Int的取值范围如下//- 2E(32位-1)~ 2E(32位-1)-1
// 顺便列举一下基本数据类型占据的位宽
//byte,boolean 1
// int, float 4
// short,char 2
// long,double 8 System.out.println(Integer.MIN_VALUE); System.out.println(Integer.MAX_VALUE); //不好意思,大哥System Properties 给大家看看,也就是顺便想到 Properties p = System.getProperties();
p.list(new PrintStream(System.out)); // 问题2: 左右移位运算举例考察
//左移 =》 左边丢弃,尾部补0
//安装2进制到10进制转换,移动的位置是2进制值(0,1)*2E‘N’(N代表位位置),相当于讲数字本身乘以2的N次方
// 酱油男又开始咧咧了,你写个(0,1)这算怎么回事?我只想说,你把0移动几位他的值是多少? int i = 2; System.out.println(i<< 2);//2*2*2或者说2* 2EN //右移=》 右边丢弃,原来最左边是0补0,是1补1 int j =-8; System.out.println(j >> 2);//相当于8/2/2 或者说-8/2E2 (取整) System.out.println(j >>> 2);// 无符号为右移,表示无论如何最边都补0 (即无符号位位移)
//顺便提下 逻辑运算 与 位运算
//&&,||,! VS &,|,^(异或),~(补码)
//解释:补码表示0变1,1变0
// 送你的 -> 自动装箱,拆箱的注意事项
// 不用直接比较自动被装箱的两个对象相等(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());
//因为-128~127 这种数字是在内存中被缓存了。(这是100与200的差异) //问题3: 数组,记得正确的申明与初始化的方式 int[] a1 = {1, 2,3}; int[] a2 = new int[10]; int[] a3 = new int[]{1,2,3};
//问题4: 考考你String内存复用的问题 //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
//关于正则,则每种语言都差不多啦 //Regular Expression: Nothing to say. //String.matches() //Compile Pattern with "Pattern.compile("regular expression")" //Reuse pattern_compiled.matcher(String) with Matcher Object. //If matcher and matcher.find(): //matcher with group([index]) } }
<未完待续>
标签:
原文地址:http://www.cnblogs.com/velly/p/4722863.html