注释
基本数据类型
Java与OOP有关的关键字
1 2 3 4 5 6 7 8 9 10 11 12 13 class Person { private Date birthDate; public Person (Date birthDate) { this .birthDate = birthDate; } boolean isBornBoomer () { Date startDate = Date.valueOf("1946" ); Date endDate = Date.valueOf("1964" ); return birthDate.compareTo(startDate)>=0 && birthDate.compareTo(endDate) < 0 ; } }
每次调用isBornBoomer,都会生成startDate和endDate两个对象,存储空间浪费
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Person { private Date birthDate; private static Date startDate,endDate; static { startDate = Date.valueOf("1946" ); endDate = Date.valueOf("1964" ); } public Person (Date birthDate) { this .birthDate = birthDate; } boolean isBornBoomer () { return birthDate.compareTo(startDate)>=0 && birthDate.compareTo(endDate) < 0 ; } }
final
用final修饰的类断子绝孙
abstract
抽象类,方法留给子类来实现
this,super
代指子类和父类
Java-OOP的一些说明
Java输入输出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.text.DecimalFormat;import java.util.Scanner;public class hello_world { public static void main (String[] args) { String message1; String message2; double double1; Scanner scan = new Scanner(System.in); message1 = scan.next(); message2 = scan.nextLine(); double1 = scan.nextDouble(); System.out.println(message1+"\n" +message2+"\n" +double1); DecimalFormat fmt = new DecimalFormat("0.###" ); System.out.println(fmt.format(double1)); } }
数组复制 1 System.arraycopy(src, srcPos, dest, destPos, length);
src表示源数组
srcPos表示源数组中拷贝元素的起始位置。
dest表示目标数组
destPos表示拷贝到目标数组的起始位置
length表示拷贝元素的个数
Vector类 四种构造方法:
1 2 3 4 Vector() Vector(int size) Vector(int size,int incr) Vector(Collection c)
方法:
1 2 3 4 5 6 7 8 9 10 void setElementAt(Object obj, int index) void removeElementAt(int index) boolean removeElement(Object obj) void removeAllElements() Object elementAt(int index) int indexOf(Object elem) int indexOf(Object elem, int index) int lastIndexOf(Object elem) int lastIndexOf(Object elem, int index) ...