您的位置:首页 > 编程语言 > Java开发

java基础整理7

2011-04-13 21:48 274 查看
Java API:
API的概念:(Application Programming Interface)应用程序编程接口。
Windows API:
就是Windows操作系统提供的各种函数,例如,CreateWindow。
Java API:
就是JDK中提供的各种Java类,例如,System类。

String类和StringBuffer类:
位于java.lang包中。
String类对象中的内容一旦被初始化就不能再改变。
StringBuffer类用于封装内容可以改变的字符串。
用toString方法转换成String类型
String x = "a"+4+"c";编译时等效于:
Stringx=new StringBuffer().append("a").append(4).append("c").toString();
字符串常量(如“hello”)实际上是一种特殊的匿名String对象。比较下面两种情况的差异:
String s1="hello";String s2="hello";
String s1=new String("hello");String s2=new String("hello");

String类的常用成员方法:
构造方法:
String(byte[]bytes,int offset,int length)
equalsIgnoreCase方法
indexOf(int ch)方法
substring(int beginIndex)方法
substring(int beginIndex,int endIndex)

集合类:
集合类用于存储一组对象,其中的每个对象称之为元素,经常会用到的额有Vector、Enumeration、ArrayList、Collection、Iterator、Set、List等集合类和接口。
Vector类与Enumeration接口。
Collection接口与Iterator接口。
Collection、Set、List的区别如下:
Collection各元素对象之间没有指定的顺序,允许有重复元素和多个null元素对象。
Set各元素对象之间没有指定的顺序,不允许有重复元素,最多允许有一个null元素对象。
List各元素对象之间有指定的顺序,允许有重复元素和多个null元素对象。

Hashtable类:
Hashtable不仅可以像Vector一样动态存储一系列的对象,而且对存储的每一个对象(称为值)都要安排另一个对象(称为关键字)与之相关联。
Hashtable numbers=new Hashtable();
numbers.put("one",new Integer(1));
numbers.put("two",new Integer(2));
numbers.put("three",new Integer(3));
Integer n = (Integer)numbers get("two");
if(n!=null)
{
System.out.println("two ="+n);
}
用作关键字的类必须覆盖Object.hashCode方法和Object.equals方法。

Properties类:
Properties类是Hashtable的子类
增加了将Hashtable对象中的关键字和值保存到文件和从文件中读取关键字和值到Hashtable对象中的方法。
如果要用Properties.store方法存储Properties对象中的内容,每个属性的关键字和值都必须是String类型。

System与Runtime类:
System类:
exit方法
currentTimeMillis方法
Java虚拟机的系统属性
getProperties和setProperties方法
Runtime类:
Runtime.getRuntime静态方法

与日期和事件有关的类:
最常用的几个类:Date、DateFormat、Calendar
Calender类:
Calendar.add方法
Calendar.get方法
Calendar.getInstance静态方法
GregorianCalendar子类
Date类:
java.text.DateFormat与java.text.SimpleDateFormat子类

Timer与TimerTask类
schedule方法主要有如下几种重载形式:
schedule(TimerTask task,long delay)
schedule(TimerTask task,Date time)
schedule(TimerTask task,long delay,long period)
schedule(TimerTask task,Date firstTimer,long period)
Timer类实现了Runnable接口,要执行的任务由它里面实现的run方法来完成。

Math与Random类:
Math类包含了所有用于几何和三角运算的方法
Random类是一个伪随机数产生器
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: