自如
A. int i = 0xFFFFFFFF;
B. char c = 'u0571';
C. byte b = 01;
D. int i = 'a';
E. long l = 45555566666L;
复制代码
A. String s = new String();
B. String s = new String("A");
C. String s = "";
D. String s = "A".intern();
E. String s = (String)wInstance();
复制代码
public class Demo {void change(String s){s = s.replace('A','E');s = s.toLowerCase();}public static void main(String[] args){Demo d = new Demo();String str = "BEA";d.change(str);System.out.println(str);}}
复制代码
1). 堆内存溢出
/*** VM Args: -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError* */public class HeapOOM {static class OOMObjetct{}public static void main(String[] args){List<OOMObjetct> list = new ArrayList<>();while (true){list.add(new OOMObjetct());}}
}
复制代码
2). 虚拟机栈和本地方法栈OOM
/*** VM Args : -Xss128k* */public class JavaVMStackSOF {private int stackLength = 1;public void stackLeak(){stackLength ++;stackLeak();}public static void main(String[] args){JavaVMStackSOF oom = new JavaVMStackSOF();try {oom.stackLeak();}catch (Exception e){System.out.println("stack length : " + oom.stackLength);throw e;}}
}
复制代码
3). 运行时常量池导致的内存溢出异常
/*** VM Args : -XX:PermSize=10M -XX:MaxPermSize=10M* */public class RuntimeConstantPoolOOM {public static void main(String[] args){List<String> list = new ArrayList<>();int i = 0;while(true){list.add(String.valueOf(i++).intern());}}
}复制代码
由于PermSize在JDK 8.0已经被移除了
4). 本机直接内存溢出
/***VM Args : -Xmx20m -XX:MaxDirectMemorySize=10M* */public class DirectMemoryOOM {private static final int _1MB = 1024*1024;public static void main(String[] args) throws IllegalAccessException {Field unsafeField = DeclaredFields()[0];unsafeField.setAccessible(true);Unsafe unsafe = ((null);while (true){unsafe.allocateMemory(_1MB);}}}
复制代码
public static boolean equals(String a,String b){byte[] arr1 = a.getBytes();byte[] arr2 = b.getBytes();Arrays.sort(arr1);Arrays.sort(arr2);return Arrays.equals(arr1,arr2);}复制代码
详细可参考: 假设字符串类似这样的aba和aab就相等,现在随便给你二组字符串,请编程比较他们看是否相等
1). 常见的网络协议有哪些?
2). 简述TCP的三次握手
3). 网络传输数据的格式有哪些?
4). Jason的数据类型有哪些?
5). JacksonJason和FastJason的区别有哪些?
1). Spring 和 Spring MVC的区别有哪些?
2). 常用的标注在类上的Spring标签有哪些?
3). Spring事务是如何配置的?
1). 谈一下数据库连接池的相关配置有哪些?
2). 谈一下水平分表和垂直分表?
1). Hive和Hbase的区别有哪些?
2). UTF-8和UTF-8mb4的区别有哪些?
发布时间 : 2018年8月22
本文发布于:2024-02-04 06:02:42,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170700597852916.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |