当前位置: 首页 > news >正文

什么东西可以做网站郑州高端网站定制建设

什么东西可以做网站,郑州高端网站定制建设,扁平化网站 psd,怎么建设境外网站本文主要大致思路为#xff1a;不管从工作中还是面试#xff0c;这篇文章都应该好好看完#xff0c;本人认为是非常有用的。案例Integer是基本类型int的封装类。平时不管是入坑多年的小伙伴还在入坑路上的小伙伴#xff0c;都应该知道的使用频率是相当高。下面模仿订单支付…本文主要大致思路为不管从工作中还是面试这篇文章都应该好好看完本人认为是非常有用的。案例Integer是基本类型int的封装类。平时不管是入坑多年的小伙伴还在入坑路上的小伙伴都应该知道的使用频率是相当高。下面模仿订单支付做了一个订单支付状态枚举类PayStatusEnumpublic class IntegerDemo {public static void main(String[] args) {Integer a new Integer(8);Integer b Integer.valueOf(8);Integer c 8;System.out.println(a.equals(b));System.out.println(a.equals(c));System.out.println(b.equals(c));System.out.println(a b);System.out.println(a c);System.out.println(b c);}}结果输出什么把上面代码中的8改成128后又输出什么public class IntegerDemo {public static void main(String[] args) {Integer a new Integer(128);Integer b Integer.valueOf(128);Integer c 128;System.out.println(a.equals(b));System.out.println(a.equals(c));System.out.println(b.equals(c));System.out.println(a b);System.out.println(a c);System.out.println(b c);}}答案慢慢道来。解析案例Integer整体阅览构造方法private final int value;public Integer(int value) {this.value value;}太简单了没什么可讲的。valueOf()方法public static Integer valueOf(String s) throws NumberFormatException {return Integer.valueOf(parseInt(s, 10));}//HotSpotIntrinsicCandidate 这个注解是JDK9才引入的//HotSpot 虚拟机将对标注了HotSpotIntrinsicCandidate注解的方法的调用//替换为直接使用基于特定 CPU 指令的高效实现。这些方法我们便称之为 intrinsic。public static Integer valueOf(int i) {//如果i在low和high之间就使用缓存if (i IntegerCache.low i IntegerCache.high){return IntegerCache.cache[i (-IntegerCache.low)];}return new Integer(i);}上面valueOf()方法中用到了IntegerCache下面我们来聊聊。IntegerCache下面是IntegerCache源码和部分注释/*** Cache to support the object identity semantics of autoboxing for values between* -128 and 127 (inclusive) as required by JLS.* JLS协议要求缓存在-128到127之间(包含边界值)** The cache is initialized on first usage.* 程序第一次使用Integer的时候* The size of the cache may be controlled by the {code -XX:AutoBoxCacheMax} option.* JVM 的启动参数 -XX:AutoBoxCacheMaxsize 修改最大值* During VM initialization, java.lang.Integer.IntegerCache.high property* may be set and saved in the private system properties in the* sun.misc.VM class.* 可以通过系统属性来获得-Djava.lang.Integer.IntegerCache.high*/private static class IntegerCache {static final int low -128;static final int high;//使用数组来缓存常量池static final Integer cache[];static {// high value may be configured by property//最大值是可以配置的int h 127;String integerCacheHighPropValue sun.misc.VM.getSavedProperty(java.lang.Integer.IntegerCache.high);//如果有配置-XX:AutoBoxCacheMaxif (integerCacheHighPropValue ! null) {try {int i parseInt(integerCacheHighPropValue);//和127进行比较谁大用谁i Math.max(i, 127);// Maximum array size is Integer.MAX_VALUE//再比较获取最小值h Math.min(i, Integer.MAX_VALUE - (-low) -1);} catch( NumberFormatException nfe) {// If the property cannot be parsed into an int, ignore it.// 如果该值配置错误则忽略该参数配置的值使用默认范围-128~127}}high h;cache new Integer[(high - low) 1];int j low;// 缓存通过for循环来实现创建范围内的整数对象并存储到cache数组中// 程序第一次使用Integer的时候需要一定的额外时间来初始化该缓存for(int k 0; k cache.length; k){cache[k] new Integer(j);}//无论如何缓存的最大值肯定是大于等于127assert IntegerCache.high 127;}//私有的构造方法因为所有的属性均属于类常量private IntegerCache() {}}整个静态块流程那么如何设置java.lang.Integer.IntegerCache.high的值呢The size of the cache may be controlled by the {code -XX:AutoBoxCacheMax} option.注释中已经说清楚可以使用-XX:AutoBoxCacheMax设置。写个demo来debug看看public class IntegerDemo {public static void main(String[] args) {Integer a 8;Integer b Integer.valueOf(8);System.out.println(a.equals(b));System.out.println(a b);}}设置-XX:AutoBoxCacheMax100开始debug看看high的值是127那就对了因为上面设置-XX:AutoBoxCacheMax130开启debug模式注意low-128是不会变的整个缓存初始化过程并没有对low进行修改再说low是常量。-XX:AutoBoxCacheMax最大能设置成多大因为Integer的最大值是2147483647 所以我们这里使用这个值试试开始debug直接报OOM了为什么会OOM呢如果-XX:AutoBoxCacheMax没有设置值那么对应数组是这样的。equals()方法上面的案例中有equals方法这里把这个方法也拿出来聊聊private final int value;public boolean equals(Object obj) {if (obj instanceof Integer) {//这里比较的是两个int类型的值return value ((Integer)obj).intValue();}//obj不是Integer类型直接返回falsereturn false;}回到上面的案例中当我们使用equals方法比较两个对象是否相等的时候其实就是比较他们的value值。所以不管是128还是8equals后肯定都是true。当引用类型使用进行比较的时候此时比较的是两个引用的对象的地址是不是同一个。public class IntegerDemo {public static void main(String[] args) {Integer a new Integer(8);Integer b Integer.valueOf(8);Integer c 8;System.out.println(a.equals(b));System.out.println(a.equals(c));System.out.println(b.equals(c));System.out.println(a b);System.out.println(a c);System.out.println(b c);}}我们看看器class文件中的字节码本地变量表每个本地变量赋值的过程这里我们可以得出一个结论Integer c 8;就是Integer c Integer.valueOf(8);上面Integer b Integer.valueOf(8);那就说明变量b和c都是使用Integer.valueOf()获取到的。valueOf方法中-XX:AutoBoxCacheMax不设置上面关于IntegerCache的low和high已经进行了说明,low永远是-128所以当我们没有设置-XX:AutoBoxCacheMax 的值的时候这时候 high127。当Integer.valueOf(8);的时候就会进入上面代码中的if中。然后从IntegerCache中的数组cache中获取。但是IntegerCache中的cache数组是个常量数组。言外之意就是一旦给这个数组cache赋值后就不会变了。Integer b Integer.valueOf(8);和Integer c8;b和c不就是都指向同一个引用地址吗所以 bc为true;但是Integer bInteger.valueOf(128);此时就不进入if中而是直接new一个Integer对象所以此时Integer bInnteger.valueOf(128) 和Integer c 128;都会各自new 一个Integer对象此时的bc为false。这里也就是网上很多文章也就说到这里就是比较当前int i 这个i是不是在-128到127范围之内。-XX:AutoBoxCacheMax设置为130如果我们把-XX:AutoBoxCacheMax设置为130。那么上面Integer bInnteger.valueOf(128) 和Integer c 128;也会进入if条件中。最后bc为true。如何避坑Integer是基本类型int的封装类那么在平常使用的时候需要注意几点1如果使用Integer注意Integer的默认是null容易引起空指针异常NullPointerException。2如果使用int类型注意int类型的初始值是0很多设计某某状态时很喜欢用0作为某个状态这里要小心使用。3另外从内存使用层面来讲int是基本数据类型只占用4个字节Integer是一个对象当表示一个值时Integer占用的内存空间要高于int类型从节省内存空间考虑建议使用int类型(建议了解一下Java对象内存布局)。4Integer使用的时候直接赋值Integer c 8不要new Integer(8)。因为直接赋值就是Integer.valueOf方法使用缓存没必要每次都new一个新对象有效提高内存使用。5如果系统中大量重复的使用比127大的数建议JVM启动的时候为-XX:AutoBoxCacheMaxsize 适当的大小提升内存使用效率(但是也不能太大上面我们已经演示了可能出现OOM)。面试题面试题1Integer num1 new Integer(10);Integer num2 new Integer(10);System.out.println(num1.equals(num2));System.out.println(num1 num2);面试题2Integer num3 100;Integer num4 100;System.out.println(num3.equals(num4));System.out.println(num3 num4);面试题3Integer num5 1000;Integer num6 1000;System.out.println(num5.equals(num6));System.out.println(num5 num6);把上面看完了在回头来看看这种面试题还难吗如果在面试中遇到面试题3可以适当反问一下面试官是否有对缓存范围进行调整或许某些面试官都会懵逼。赤裸裸的吊打面试官。总结1.引用类型的是比较对应的引用地址。2.Integer中使用的默认缓存是-128到127。但是可以在JVM启动的时候进行设置。3.Integer bInteger.valueOf(8);和Integer b8;是一样的效果。4.Integer.valueOf()方式比较是否在缓存范围之内在就直接从缓存中获取不在new一个Integer对象。5.每次使用new来创建Integer对象是用不到IntegerCache缓存的。6.Integer中的使用缓存的方式也可以理解为享元模式。欢迎关注我的公众号java后端技术全栈专业做Java相关技术分享的的公众号。一个纯粹的Java技术分享达人。
http://www.yutouwan.com/news/442466/

相关文章:

  • 钢结构东莞网站建设个人记账网站开发时长
  • 网站做管理员消息推送网站开发net
  • 北京建设网站的公司简介网站如何开发触屏版
  • 1000元做网站集约化网站建设情况经验材料
  • 微信怎么做网站的动图永久免费空间
  • 地名网站建设费用施工企业建言献策
  • 网站的三大标签企业 备案 网站服务内容
  • 网站标题的重要性如何整合wordpress博客
  • 网站图片做伪静态网站如何做担保交易平台
  • 网站设计 推广羽毛球最新赛事
  • 个人网站建设方案书模板百度推广个人怎么开户
  • 阳江网站设计商城网站开发项目文档
  • 网站建设备案计划书怎么在网上做装修网站
  • 重庆 做网站软件编程工具
  • 建设网站需要api吗dede被挂网站网站木马
  • 皮具网站建设策划书徐州app定制开发
  • 遵义网站山东百度推广
  • 江苏省招投标办法建设厅网站展示型网站建设
  • 房山营销型网站建设长沙优化网站分析
  • 做动态的网站的参考资料有哪些百家号排名
  • 对于网站建设的体会wordpress支付后可见
  • 网站开发和上传中错误的是阿里云做哪里查网站
  • 公司做网站推广要注意什么asp.net网站开发pdf
  • 济南建设公司网站网站一天要发多少外链
  • 分销系统网站门源县wap网站建设公司
  • 网站建设验收表网站收录后才可以做排名吗
  • 网站强制字体wordpress这个网站最近运转怎么样?安全性怎么样? 另外建设银行的网银能在这里存取款吗?
  • 网站建设高端定制设计方案万能模板
  • 海南网站建设推荐小程序做视频网站
  • 网站网络推广方法做网站备案是承诺书是啥