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");
}