程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA編程入門知識 >> 試試jdk1.5

試試jdk1.5

編輯:JAVA編程入門知識

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 {
  }
  


 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved