while,for// 循环
定义数组的方法
int Array [] = {1,2,3,4};
int Array1 [] = new int[5];
int[] nums = new int[] { 61, 23, 4, 74, 13, 148, 20 };
Java方法定义
访问修饰符 返回值类型 方法名(参数列表){
方法体
}
方法的重载
1、 必须是在同一个类中
2、 方法名相同
3、 方法参数的个数、顺序或类型不同
4、 与方法的修饰符或返回值没有关系
try {
} catch (excption e) {
} catch (excption e) {
} finally{
}
多重:先子后父
throw
throws
自定义异常
public class DrunkException extends Exception{
public DrunkException(){
}
public DrunkException(String message){
super(message)
}
}
异常链 //
创建
String s1 = 'liubin'
String s2 = new String();
String s2 = new String('liubin');
不可变性
StringBuilder
StringBuffer
Integer m = new Integer('8');
// 定义double类型变量
double a = 91.5;
// 手动装箱
Double b = new Double(a);
// 自动装箱
Double c = a ;(Integer i = Integer.valueOf(100);)
System.out.println("装箱后的结果为:" + b + "和" + c);
// 定义一个Double包装类对象,值为8
Double d = new Double(87.0);
// 手动拆箱
double e = d.doubleValue() ;
// 自动拆箱
double f = d ;
-
使用包装类的 toString() 方法
-
使用String类的 valueOf() 方法
-
用一个空字符串加上基本类型,得到的就是基本类型数据对应的字符串
-
调用包装类的 parseXxx 静态方法
-
调用包装类的 valueOf() 方法转换为基本类型的包装类,会自动拆箱
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 创建Calendar对象
Calendar c = Calendar.getInstance();
// 获取Date对象
Date date = c.getTime();
// 获取当前毫秒数
Long time = c.getTimeInMillis();
// 0-10 的随机整型
int x = (int)Math.round(Math.random()*10);