1、classpath不用再定義.;***\lib\tools.jar;***\lib\rt.jar,因為jre會自動尋找lib目錄
2、如果想要用jdk5.0編譯出jdk1.4可運行的class文件需要帶-source和-target兩個參數
eg: javac -source 1.4 -target 1.4 Hello.java
3、命令行讀入int i = System.in.read();//讀入輸入字符串的第一個字符的int值;
讀整個字符串時:
public class Test{
?public static void main(String[] args){
??byte[] a = new byte[100];
??try {
???System.in.read(a);
??} catch (IOException e) {
???e.printStackTrace();
??}
??System.out.println(new String(a));
?}
}
jdk5.0中命令行讀入的方法更好,可以讀成不同類型的數據:
//Scanner取得輸入的依據是:空格鍵、Tab鍵或Enter鍵
import java.util.Scanner;
public class ScannerDemo{
?public static void main(String[] args){
??Scanner scanner = new Scanner(System.in);
??System.out.print("請輸入姓名");
??System.out.printf("您好%s!\n", scanner.next());
??System.out.print("請輸入年齡");
??System.out.printf("您好%d!\n", scanner.nextInt());
??//還有scanner.nextFloat(),scanner.nextBoolean();
?}
}
//BufferReader取得輸入的依據是:Enter鍵
import java.io.*;
public class BufferReaderDemo{
?public static void main(String[] args){
??BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
??System.out.print("請輸入一系列文字");
??String text = bufferedReader.readLine();
??System.out.print("您輸入的是:" + text);
?}
?}
}
4、aotuboxing和unboxing,jdk5.0可以自動對基本類型和它們的包裝類型自動轉換。
5、數組
數組的索引值:由0開始的原因:索引值表示偏移量,第一個值的偏移為0.
數組的初始化:byte/short/int = 0; long = ol; float = o.0f; double = 0.0d; char = \u0000; boolean = false; Objective = null;
一維數組:
法一:int[] i = {1,2,3};
法二:int[] i = new int[]{1,2,3};
法三:int[] i = new int[3]; i[0] = 1; i[1] = 2; i[2] = 3;
多維數組:
法一:int[][] i = {{...},...,{...}};
法二:int[][] i = int[][]{{...},...,{...}};
法三:int[][] i = int[3][]; i[0] = {1,2,3}; i[0] = {1,2,3}; i[0] = {1,2,3};
法四:int[][] i = int[3][3];
不規則數組:行列不等
數組的常用方法:都是java.util.Arrays類的方法
sort()//制定數組快速排序
binarySearch()//對已排序的數組搜索,找到返回索引,否則返回負值
fill()//根據數組的數據類型填默認值
equals()//比較兩數組
jdk1.5中新增:
deepEquals()//深度比較
deepToString()//深度輸出
foreach與數組:
String[] a = {"asd","efge","efg"};
for(String s : a)
?System.out.println(s);
5、字符串
java.lang.StringBuilder是jdk5.0新增的類,它與StringBuffer具有相同接口,只是單機非多線程情況下用StringBuilder效率較高,因為StringBuilder沒處理同步問題;多線程下用StringBuffer好。
字符串分離:
?String s = "23/twomen/tlai/t jeje";
?String[] a = s.split("/t");
?for(int i = 0; i < a.length; i++){
??System.out.print(a[i] + " ");
?}
輸出結構:23 women lai? jeje
由于工作關系學習jdk5.0的步伐暫時停止,以后有機會繼續看《jdk5.0學習筆記》,回來寫我的總結。
posted on 2007-03-08 15:06
保爾任 閱讀(457)
評論(0) 編輯 收藏 所屬分類:
J2SE