JAVA认证考试(SCJP)笔记之第十章基础包

  • 考点01 Object类
    • 规则01:Object类是所有java类的顶层类,即类继承树的根。如果一个类没有使用extends关键字扩展任何类,则编译期自动将创建的类视为Object类的子类。
    • 规则02:Object类的所有方法都被每个类继承,其定义的所有方法如下。
      • 方法列表:
        • protected Object clone() //获得此对象的一个拷贝
        • public boolean equals(Object obj) //判断参数对象和此对象是否相等
        • protected void finalize() //当垃圾回收器认为此对象不会被引用,垃圾回收器就调用此方法
        • public final Class getClass() //获得一个此对象对应的哈希码
        • public final void notfy() //唤醒一个等待此对象监视器的线程
        • public final void notifyAll() //唤醒一个等待对象此对象监视器的线程
        • public String toString() //获得一个代表此对象的字符串
        • public final void wait() //挂起当线程,直到其他线程通过调用此对象的notify()或notifyAll()方法
        • public final void wait(long timeout) //挂起当前线程,直到其他线程通过调用此对象的notify()或notifyAll()方法,或指定时间段已过
        • public final void wait(long timeout,int nanos) //挂起当前线程,直到其他线程通过调用此对象的notify()或notifyAll()方法,或指定时间段已过。注意此方法类似于wait(long timeout)方法,只不过允许对时间更精准的控制。时间段应为1000000*timeout+nanos。参数nanos的取值范围为0.999999
  • 考点02 Math类
    • 规则01:java.lang.Math类是final类,因此不能被其他类继承。
    • 规则02:java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个java.lang.Math类。
    • 规则03:java.lang.Math类上定义的所有常量和方法均是public的和static的,因此可以直接通过类名调用。
      • 在java.lang包的Math类中定义的属性如下。
        • 属性列表:
          • public static final double E
          • public static final double PI
      • 在java.lang包的Math类中定义的方法如下。
        • 方法列表:
          • public static double abs(double a) //获得一个双精度型对应的绝对值
          • public static float abs(float a) //获得一个单精度型对应的绝对值
          • public static int abs(int a) //获得一个整数型对应的绝对值
          • public static long abs(long a) //获得一个长整数型对应的绝对值
          • public static double sin(double a) //获得 一个正弦值
          • public static double cos(double a) //获得一个余弦值
          • public static double tan(double a) //获得一个正切值
          • public static double asin(double a) //获得一个反正弦值
          • public static double acos(double a) //获得一个反余弦值
          • public static double atan(double a) //获得一个反正切值
          • public static double ceil(double a) //获得最接近,但并不小于参数的一个双精度型整数
          • public static double floor(double a) //获得最接近,但并不大于参数的一个双精度型整数
          • public static long round(double a) //获得一个四舍五入的长整数型值
          • public static int round(float a) //获得一个四舍五入的整数型值
          • public static double max(double a,double b) //获得两个双精度型数之中的较大数
          • public static float max(float a, float b) //获得两个单精度型数之中的较大数
          • public static long max(long a,long b) //获得两个长整数型数之中的较大数
          • public static int max(int a,int b) //获得两个整数型数之中的较大数
          • public static double min(double a,double b) //获得两个双精度型数之中的较小数
          • public static float min(float a, float b) //获得两个单精度型数之中的较小数
          • public static long min(long a,long b) //获得两个长整数型数之中的较小数
          • public static int min(int a,int b) //获得两个整数型数之中的较小数
          • public static double random() // 获得一个双值范围为[0.0~1.0]的随机数
          • public static double sqrt(double a) //获得一个平方根值
    • 规则04:Math.min(-0.0,+0.0)的返回值为-0.0,Math.max(-0.0,+0.0)的返回值为0.0,代表-0.0=+0.0的返回值为true。
    • 规则05:min()和max()方法的参数之一,只要存在一个NaN值,则它们的返回值就为NaN。
  • 考点03 封装类
    • 规则01:Java语言中每个基本数据类型都有一个对应的封装类。
      • 基本数据类型/封装类
        • boolean/Boolean
        • byte/Byte
        • char/Character
        • short/Short
        • int/Integer
        • long/Long
        • float/Float
        • double/Double
    • 规则02:所有的封装类都可以直接以对应的基本类型数据作为构造器参数构造实例,除了Character封装类外,其他封装类都可以字符串作为构造器参数构造实例。
    • 规则03:封装类中包含的数值,可以通过equals()方法进行比较。
    • 规则04:封装类中包含的数值,可以通过xxxValue()方法来提取。
    • 规则05:6个数值型封装类Byte、Short、Integer、Long、Float和Double,它们都定义有byteVlaue(),shortValue(),intValue(),longValue(),floatValue()和doubleValue()转换数据类型的方法。
    • 规则06:封装类均是不可变类。
  • 考点04 String和StringBuffer类
    • 在java.lang包的String类中定义的常用方法如下。
      • 构造器列表:
        • public String()
        • public String(byte[] bytes)
        • public String(byte[] bytes,int offset,int length)
        • public String(byte[] bytes,int offset,int length,String cbarsetName)
        • public String(byte[] bytes,String eharsetName)
        • public String(char[] value)
        • public String(char[] value,int offset,int count)
        • public String(String original)
        • public String(StringBuffer buffer)
      • 方法列表:
        • public String concat(String str) //将指定字符串连接到此字符串的末尾
        • public int compareTo(String anotherString) //按字典孙晓比较两个字符串
        • public int compareToIgnoreCase(Sring str) //按字典顺序,忽略大小写,比较两个字符串
        • public boolean qeuals(Object anOject) //和指定对象作比较
        • public boolean equalsIgnoreCase(String anotherString) //忽略大小写,比较两个字符串
        • public boolean startsWith(String prefix) //判断字符串头部是否以指定字符串作为前缀
        • public boolean endsWith(String suffix) //判断字符串末尾是否以指定字符串作为后缀
        • public char charAt(int index) //获得指定索引处的字符
        • public int indexOf(int ch) //获得指定字符在字符串中首次出现的位置索引
        • public int indexOf(int ch,int formIndex) //获得指定字符在字符串中从指定搜索位置开始,首次出现的位置索引
        • public int indexOf(String str) //获得指定字符串在字符串中首次出现的位置索引
        • public int indexOf(Srting str,int fromIndex) //获得指定字符串在字符串中从指定搜索位置开始,首次出现的位置索引
        • public int lastIndexOf(int ch) //获得指定字符串在字符串中最后出现的位置索引
        • public int lastIndexOf(String str,int formIndex) //获得指定字符串在字符串中从指定搜索位置开始的最后出现的位置索引
        • public int length() //获得字符串的长度
        • public String replace(char oldChar,char newChar) //使用新字符替换就字符
        • public String substring(int beginIndex) //获得一个子串,存储在一个新字符串对象中
        • public String substring(int beginIndex,int endIndex) //获得一个子串,存储在一个新字符串对象中
        • public String toLowerCase() //把字符串中所有字符串转换为小写字符
        • public String toUpperCase() //把字符串中所有字符串转换为大写字符
        • public String trim() //截掉字符串头尾空格
        • public String toString() //返回该字符串自身
      • 规则01:String类是final类,不可以被子类继承。
      • 规则02:String类是不可变类。
      • 规则03:可以通过一个字符数组构造一个String类实例。
        • char data[]=['a','b','c'];
        • String str = new String(data);
      • 规则04:由于Java中存在字符串对象池,因此采用下面方式创建两个字符串变量,它们指向的是同一个字符串对象。
        • String str1 = "aa";
        • String str2 = "aa";
      • 规则05:采用new语句方式创建两个字符串变量,即使字符串内容相同,指向的也不是同一个字符串对象。
        • String str1 = new String("aa");
        • String str2 = new String("aa");
      • 规则06:调用字符串上定义的可改变字符串内容,返回值都是一个新字符串,而原有字符串内容不变。
      • 规则07:调用replace(char oldChar,char newChar)方法,当参数oldChar为空时,则返回原有字符串。
      • 规则08:调用toUppertCase()和toLowerCase()方法,当未进行大小写转换时,则返回原有字符串。
      • 规则09:reverse()、append()和insert()方法,在String类中未定义。
    • 在java.lang包的StringBuffer类中定义的常用方法如下:
      • 构造器列表
        • public StringBuffer() //构造一个为空的字符串缓冲对象,其初始容量为16个字符
        • public StringBuffer(int length) //构造一个空的字符串缓冲对象,其容量由参数length指定
        • public StringBuffer(String str) //构造一个新的字符串缓冲对象,其初始内容由参数str指定
      • 方法列表:
        • public int capacity() //获得此字符串缓冲的当前容量
        • public void setLength(int newLength) //设置此字符串缓冲的长度
        • public int length() //获得此字符串缓冲的长度,即包含的字符数
        • public StringBuffer append(Object obj) //将对象参数的字符串标识追加到此字符串缓冲中
        • public StringBuffer append(String str) //将给定的字符串追加到字符串缓冲中
        • public StringBuffer append(StringBuffer sb) //将给定的字符串缓冲对象追加到字符串缓冲中
        • public StringBuffer insert(int offset,Object obj) //将参数对象的字符串标识插入到字符串缓冲中
        • public StringBuffer insert(int offset,String str) //将一个字符串插入到字符串缓冲中
        • public StringBuffer delete(int start,int end) //删除掉字符串缓冲中的部分字符
        • public StringBuffer deleteCharAt(int index) //删除掉指定索引的位置处
        • public void setCharAt(int index,char ch) //将给定字符插入指定索引的位置处
        • public char charAt(int index,char ch) //获得指定索引指向的字符
        • public int indexOf(String str,int fromIndex) //获得指定字符串在原字符串中从指定位置搜索开始,最后出现的位置索引
        • public int lastIndexOf(String str) //获得指定字符串在字符串中最后出现的位置索引
        • public int lastIndexOf(String str,int fromIndex) //获得指定字符串在原字符串中从指定搜索位置开始的首次出现的位置索引
        • public StringBuffer replace(int start,int end,String str) //用新字符串替换掉指定的子字符串
        • public StringBuffer reverse() //将一个字符串中字符的序列反转
        • public String substring(int start) //获得一个子串,从指定处开始,到字符串缓冲对象结束处,并将其存储在一个新字符串对象中
        • public String substring(int start,int end) //获得一个指定子串,并将其存储在一个新字符串对象中
        • public String toString() //获得一个字符串来代表此字符串缓冲中的数据
      • 规则10:StringBuffer类是final类,不可以被子类继承。
      • 规则11:StringBuffer类是可变类。
      • 规则12:可以创建一个空的StringBuffer类实例,其默认容量是16个字符。
      • 规则13:setLength()方法用于设置StringBuffer的长度。当字符串内容长于指定长度时,则字符串内容被截取名单此方法不会对容量产生影响。
      • 规则14:用于String类的连接运算符+不能用于StringBuffer类。
      • 规则15:String类重载了Object的equals()方法,对于比较对象的内容作比较。String类并未重载Object的equals()方法,所以调用StringBuffer类的equals()方法,实质是调用了Object的equals()方法,因此是对比较对象的句柄做一个比较。
  • 考点05 集合类
    • java.util包中接口的继承树和特性描述如下:
      • interface java.util.Collection:最基本的接口,定义了集合操作的方法
      • interface java.util.List:一个有顺序、允许重复项的集合接口
      • interface java.util.Set:一个无顺序,不支持重复项的集合接口
      • interface java.util.SortedSet:一个有顺序,不支持重复项的集合接口
      • interface java.util.Map:一个支持按关键字检索的集合接口,但关键字必须唯一
      • interface java.util.SortedMap:一个支持有顺序的值、键映射接口
    • Collection接口方法描述如下:
      • 方法列表:
        • public boolean add(Object o) //确保此Collection接口指定的元素
        • public Boolean addAll(Collection c) //将指定Collection接口中的所有元素添加到此Collection接口中
        • public void clear() //删除掉此Collection接口中的所有元素
        • public boolean contains(Object o) //判断此Collection接口是否包含指定Collection接口中的所有元素
        • public boolean containsAll(Collection c) //判断此Collection接口是否包含指定Collection接口中的所有元素
        • public boolean equals(Object o) //判断制定对象和此Collection接口进行比较
        • public int hashCode() //获取此Collection接口的哈希码
        • public boolean isEmpty() //判断此Collection接口是否不包含任何元素
        • public Iterator iterator() //判断此Collection接口反应的反复器
        • public boolean remove(Object o) //从此Collection接口中删除指定元素
        • public boolean remove(Collection c) //从此Collection接口中删除指定的Collection接口中的所有元素
        • public boolean retainAll(Collection c) //只保留此Collection接口中指定Collection接口中的所有元素,即从此Collection接口中删除掉指定Collection接口中的所有元素之外的元素
        • public int toArray() //获取包含此Collection接口中元素个数
        • public Object[] toArray() //获取包含此Collection接口中所有元素的一个数组
        • public Object[] toArray(Object[] a) //获取包含此Collection接口中所有元素的一个数组,该数组运行期类型由指定组类决定
    • 规则01:List接口的重要特性是顺序性,它可以保证元素按照规定的顺序排列。List除了继承Collection的方法外,还添加了大量方法,以便在List中插入和删除元素。List也会生成一个ListIterator。利用它可在一个列表里实现像两个方向遍历,同时插入和删除位子列表中部的元素。
      • ArrayList实现了list接口,作为一个常规用途的对象容器,用于替换原先的Vector。允许快速访问元素,但在从列表中部插入和删除元素时,速度较慢。一般只应该应用ListItcrator对一个ArrayList进行向前或向后遍历,不要它删除和插入元素,与LinkedList相比,其效率要低许多。
      • LinkedList提供优化的顺序访问性能,同时可以高效率地在列表中部进行插入和删除操作,但在进行随机访问时,速度却相当慢,此时应换用ArrayList。该类也提供了addFirst(),addlast(),getFirst(),getLast(),removeFirst()以及removeLast()方法,以便将其作为一个队列或双向队列使用。
    • 规则02:添加到Set接口中的每个元素都必须是唯一的,否则Set皆苦不会添加重复元素。添加到Set接口的对象必须定义equals()方法,从而建立对象的唯一性。Set接口拥有与Collection接口完全相同的接口,一个Set接口不能保证自己可以按任何特定的顺序维持自己的元素。
      • HashSet实现了Set接口,用于面向非常小的Set,特别是需要频繁创建和删除操作的。对于小set,与HashSet相比,ArraySet创建和遍历所需付出的代价都要小的多。随着Set的增大,它的性能也会大打折扣。该类不需要包含的对象,必须定义有hashCode()方法。
      • TreeSet基于“红-黑树”机制,这样可以获得一个顺序集合。
    • 规则03:Map接口支持键-值对应关系,以便通过一个键查找对应的值。
      • HashMap实现了Map接口,构成一个散列表。针对键-值映射进行插入和检索,具有最稳定的性能,可遍过设置散列表构造器的容量和装载因子对这一性能进行调整。
      • TreeMap基于“红-黑树”机制。查看键或者键-值对时,它们会按固定的顺序排列。TreeMap最大的好处,就是我们得到的是已排好序的结果。TreeMap是含有subMap()方法唯一Map,利用它可以返回树的一部分。
    • Vector类方法的描述如下:
      • 构造器列表:
        • public Vector() //构造一个大小为10,容量增长步长为0的空向量对象
        • public Vector(Collection c) //构造一个包含指定Collection接口中所有元素的向量对象
        • public Vector(int initialCapacity) //构造一个指定大小,容量增长步长为0的空向量对象
        • public Vector(int initialCapacity, int capacityIncrement) //构造一个指定大小和容量增长步长的空向量对象
      • 方法列表:
        • public void add(int index, Object element) //向此向量中指定位置处插入一个指定元素
        • public boolean add(Object o) //向此向量末尾位置处添加一个指定元素
        • public boolean addAll(Collection c) //将制定Collection接口中所有元素添加到此向量末尾位置处
        • public boolean addAll(int index, Collection c) //向此向量中指定位置处插入指定Collection接口中所有元素
        • public void addElement(Object obj) //向此向量末尾位置处添加一个指定元素,向量大小增一
        • public int capacity() //获取向量的当前容量
        • public void clear() //删除掉此向量中的所有元素
        • public Object clone() //获取此向量的一份拷贝
        • public boolean contains(Object elem) //判断向量是否包含指定对象
        • public boolean containsAll(Collection c) //判断此向量中是否包含指定Collection接口中的所有元素
        • public void copyInto(Object[] anArray) //拷贝此向量中的所有元素至指定数组中
        • public Object elementAt(int index) //获取指定位置处的元素
        • public Enumentation elements() //获取此向量对应的枚举器
        • public void ensureCapacity(int minCapacity) //确保此向量的容量值满足包含指定的元素数量。如果当前向量容量小于元素数量,则增加容量以满足需要。
        • public boolean equals(Object o) //将指定对象和此向量进行比较
        • public Object firstElement() //获取向量中的第一个元素,即索引为0的元素
        • public Object get(int index) //获取指定位置处的元素
        • public int hashCode() //获取向量的哈希码
        • public int indexOf(Object elem) //获取向量中第一个出现的指定对象的元素索引
        • public int indexOf(Object elem,int index) //获取从指定位置开始的向量中第一个出现的指定对象的元素索引
        • public void insertElementAt(Object obj, int index) //向此向量中指定位置处插入一个指定元素
        • public boolean isEmpty() //判断此向量是否不包含有任何元素
        • public Object lastElement() //获取向量中的一个元素
        • public int lastIndexOf(Object elem) //获取向量中最后一个出现的指定对象的元素索引
        • public int lastIndexOf(Object elem, int index) //获取从指定位置开始的向量中最后一个出现的指定对象的元素索引
        • public Object remove(int index) //删除掉向量中指定位置处元素
        • public boolean remove(Object o) //删除掉向量中第一个出现的指定对象
        • public boolean removeAll(Collection c) //从向量中删除掉指定Collection接口中的所有元素
        • public void removeAllElements() //删除掉所有元素,并且将向量大小设置为0
        • public boolean removeElement(Object obj) //删除掉向量中第一个出现的指定对象
        • public void reoveElementAt(int index) //删除掉向量中指定位置处元素
        • protected void removeRange(int fromIndex,int toIndex) //删除掉指定索引范围内的所有元素
        • public boolean tetainAll(Collection c) //只保留向量中指定Collection接口中的所有元素,即从向量中删除掉指定Collection接口中的所有元素之外的元素
        • public Object set(int index, Object element) //用指定对象取代掉指定索引处元素
        • public void setElementAt(Object obj, int index) //用指定对象取代掉指定索引处元素
        • public void setSize(int newSize) //设置向量大小
        • public int size() //获取向量元素数量
        • public List subList(int formIndex, int toIndex) //获取包含向量中指定索引范围的元素列表对象
        • public Object[] toArray(Object[] a) //获取包含向量中所有元素的一个数组,该数组运行期类型由指定数组类型决定
        • public String toString() //获取向量的字符串标识
        • public void trimToSize() //设置向量大小以和元素数量保持一致
      • HashTable类方法的描述如下 :
        • 构造器列表:
          • public Hashtable() //构造一个初始容量为11、装载因子为0.75的空哈希表
          • public Hashtable(int initialCapacity) //构造一个指定初始容量、装载因子为0.75的哈希表
          • public Hashtable(int initialCapacity, float loadFactor) //构造一个指定初始容量和装载因子的空哈希表
          • public Hashtable(Map t) //构造一个包含指定Map所有映射的哈希表
        • 方法列表:
          • public void clear() //清空哈希表
          • public Object clone() //获取一个此哈希表的拷贝
          • public boolean contains(Object value) //判断哈希表是否包含指定对象
          • public boolean containsKey(Object key) //判断哈希表是否包含指定键值
          • public boolean containsValue(Object value) //判断哈希表是否存在有指定独享的键值
          • public Enumeration elements() //获取此哈希对应的枚举器
          • public Set entrySet() //获取此哈希表对应的Set集合
          • public boolean equals(Object o) //获取指定对象和此哈希表进行比较
          • public Object get(Object o) //获取指定键值对应的对象
          • public int hashCode() //获取此哈希表的哈希码
          • public boolean isEmpty() //判断此哈希表中是否不包含有任何元素
          • public Enumeration keys() //判断此哈希表中是否不包含有任何元素
          • public Set keySet() //获取此哈希表中键值对应的枚举器
          • public Object put(Object key, Object value) //向哈希表中添加一对键-值
          • public void put(Map t) //将指定Map中的所有键-值对添加到哈希表中
          • protected void rehasb() //增加哈希表的容量,整理哈希表排序以提高访问效率
          • public Object remove(Object key) //删除掉指定的键值
          • public int size() //获取键值数
          • public String toString() //获取哈希表的字符串标识
          • public Collection values() 获取此哈希表对应的Collection接口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值