抽象(abstract)
- 抽象类 不能创建对象
- 抽象方法 没有方法体 有抽象方法一定是抽象类,反之不一定
- 接口 代表一种能力
- 接口中都是抽象方法,没有方法体,省略了abstract
- 类中实现(implements)接口的能力,可以多个
- 面向接口编程:接口的引用指向实现此接口的对象; 多态:父类的引用指向子类的对象
内部类
类中的类,如下:China类是Word类中的类
public class Word {
private String county;
private int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getCounty() {
return county;
}
public void setCounty(String county) {
this.county = county;
}
//外部方法
public void show(){
System.out.println("友好相处!");
}
class China{// 内部类
String city;
int num;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
//内部方法
public void play(){
System.out.println(Word.this.county+"爱好和平!");
}
}
Word word = new Word();//先创建外部类
word.show();
word.setCounty("中国");
China china =word.new China();//再创建内部类
china.play();
局部类 :
在方法体内写的类 只能在此方法中创建对象
匿名内部类 :
当只使用一次这个类的对象的时候使用,它没有名字,只能创建一次对象
Ink ink = new Ink(){//Ink是一个接口,不能创建对象,后面的相当于创建了一个类。 主要是在观察者模式,在Android中主要是事件。
@Override
public String getInk() {
// TODO Auto-generated method stub
return "蓝色";
}
};
常用的类
1、Date
类 Date 表示特定的瞬间,精确到毫秒。
Date.getTime()
返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
2、Calendar
Calendar SeeNow = Calendar.getInstance();
System.out.println(SeeNow.get(Calendar.YEAR));
System.out.println(SeeNow.get(Calendar.MONTH));
Calendar SeeNow = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyy年MM月dd日");
String time = format.format(SeeNow.getTime());
System.out.println(time);
String time ="2015年08月03日";
try {
Date date = format.parse(time);
System.out.println(date.getTime());
} catch (ParseException e) {
e.printStackTrace();
// TODO: handle exception
}
Exception
3、Pattern
- x 字符 x
- \d 数字:[0-9]
- \w 单词字符:[a-zA-Z_0-9]
- \p{Lower} 小写字母字符:[a-z]
- \p{Upper} 大写字母字符:[A-Z]
- X{n}? X,恰好 n 次
- X{n,}? X,至少 n 次
- X{n,m}? X,至少 n 次,但是不超过 m 次
(查API)
Pattern p = Pattern.compile("^\\d{17}(x|X|\\d{1})$");
Matcher m = p.matcher("37072519975632321x");
boolean b = m.matches();
System.out.println(b);
邮箱地址 xxx@xxx.com|cn|net
Pattern p = Pattern.compile("\\w{2,10}@\\w+(.com|.cn|.net)");
Matcher m = p.matcher("1763900@qq .com");
boolean b = m.matches();
System.out.println(b);
类 FileOutputStream
类 OutputStream
……