netbeans4.0beta2,手裡的工具只有這個可以試試1.5了,1.5的concurrent也很強悍啊,很方便.
package jdk5;
import Java.util.*;
import java.util.concurrent.*;
import static test.Constants.FIRST;
/** @author zzzhc
*/
public class Main {
public static enum firstEnum {one,two};
/** Creates a new instance of Main * */
private Main() {
}
static int count = 0;
static Object lock = new Object();
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
List<String> list = new ArrayList<String>();//泛型
list.add("1");
list.add("first");
list.add("second");
for (String s:list) {//循環
System.out.println(s);
}
Vector v = new Vector();
v.add(23);//自動裝箱
v.add(32);
v.add(680);
for (int i:v) {//自動拆箱
System.out.println(i);
}
HashMap map = new HashMap();
map.put("key1",23);
System.out.println(map.get("key1"));
for (String i:map.keySet()) {
System.out.println(i);
}
System.out.println(FIRST);//靜態導入
System.out.printf("%2$s %1$d
",new Integer(1),"str");//printf
for (firstEnum fe:firstEnum.values()) {
System.out.println(fe);
} //並發
Executor exec = Executors.newFixedThreadPool(5);
for (int i=0;
i<50;
i++) {
exec.execute(new Runnable() {
public void run() {
int cur;
synchronized (lock) {
cur = count++;
}
System.out.println(cur+"running...");
try {
Thread.sleep(2000);
}catch (Exception e) {
e.printStackTrace();
}
System.out.println(cur+"end...");
if (cur==49) {
System.exit(0);//else program can't exit
}
}
});
}
System.out.println("all started");
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println("program end.");
}
});
}
}
@interface Enum {
}