1、堆的最小值:-Xms 如-Xms20m
堆的最大值 -Xmx 如果设为一样的则可避免堆自动扩展。
-Xss128k:设置每个线程的栈大小。JDK5.0以后每个线程栈大小为1M,以前每个线程栈大小为256K。更具应用的线程所需内存大小进行调整。在相同物理内存下,减小这个值能生成更多的线程。但是操作系统对一个进程内的线程数还是有限制的,不能无限生成,经验值在3000~5000左右。
StackOverflowError:栈溢出,压入线程对应栈中方法太多,比如递归。
OutOfMemoryError:内存溢出,栈内存溢出,堆内存溢出,方法区内存溢出。参考:http://super-sjh.iteye.com/blog/1855386
2、1024个字节=1KB byte 1个字节 short 2个字节 char 2个字节 int占4个字节,long占8个,float占8个,double占16个。
int为例,它的表示范围应当是-2的31次方到2的31次方再减1这个范围
System.out.println(Long.MAX_VALUE); //2的64次方-1,19位
System.out.println(Long.MIN_VALUE); //负的2的64次方
9223372036854775807
-9223372036854775808
int为例,它的表示范围应当是-2的31次方到2的31次方再减1这个范围
System.out.println(Long.MAX_VALUE); //2的64次方-1,19位
System.out.println(Long.MIN_VALUE); //负的2的64次方
9223372036854775807
-9223372036854775808
3、productSkuAttrvalDTO.setSizeSpecType((byte)0);
public void setSizeSpecType(Byte sizeSpecType)
productSale.setMaxBuyerPrice(new BigDecimal(1000.00));
java.math.BigDecimal类 http://jeelee.iteye.com/blog/652003
4、Exception IOException is not compatible with throws clause in
接口中没有抛出异常。子类抛出的异常类型不能比父类抛出的异常类型更宽泛!
5、获取键值对配置文件
/** * 获取Properties对象 * @param fileName * @return */ public static Properties loadConfig(String fileName){ Properties properties = new Properties(); try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if(classLoader == null){ classLoader = StringUtils.class.getClassLoader(); } InputStream is = classLoader.getResourceAsStream(fileName); properties.load(is); } catch (Exception e) { e.printStackTrace(); } return properties; } //取值 String value = properties.getProperty(params);
6、设计
demo-->封装-->接口,通用基础类实现接口,定制继承抽象类。不能写死的放配置文件,配置文件加载到常量类。
方法有太多参数可以用 map
通过重载简化参数,比如默认值,默认配置文件名
顺序: 静态代码块--> 非静态代码块--> 类构造方法。
成员变量用成员方法赋值:private int indexCount = getIndexCount();
接口,实现一个顶级类放通用的方法,继承根据类型扩展。
7、获得系统属性
//D:\workspace\projectname
System.out.println(System.getProperty("user.dir"));
其它变量参考: http://201111181922.iteye.com/blog/1335869
8、随机数
static void testRandom(){ //会输出负数 ,如:-928637957 System.out.println(new Random().nextInt()); // 0 <= val <100 System.out.println(new Random().nextInt(100)); }
9、编码转换
String str=URLEncoder.encode("字符串", "UTF-8");
10、自定义异常
//自定义异常类 public class AlreadyClosedException extends IllegalStateException { public AlreadyClosedException(String message) { super(message); } } //使用 if (analyzer.storedValue == null) { throw new AlreadyClosedException("this Analyzer is closed"); }