JavaJDK6學(xué)習(xí)筆記-ppt簡(jiǎn)體版第21章.ppt_第1頁
JavaJDK6學(xué)習(xí)筆記-ppt簡(jiǎn)體版第21章.ppt_第2頁
JavaJDK6學(xué)習(xí)筆記-ppt簡(jiǎn)體版第21章.ppt_第3頁
JavaJDK6學(xué)習(xí)筆記-ppt簡(jiǎn)體版第21章.ppt_第4頁
JavaJDK6學(xué)習(xí)筆記-ppt簡(jiǎn)體版第21章.ppt_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第21章,Java SE6新功能簡(jiǎn)介 Java SE6基本新功能 Apache Derby、JDBC 4.0,java.lang套件,在Java SE 6中,String類別上新增了isEmpty()方法,String str = ; if(str.isEmpty() ,java.util套件,在Java SE 6中,Arrays類別新增了copyOf()方法,int arr1 = 1, 2, 3, 4, 5; int arr2 = Arrays.copyOf(arr1, arr1.length); for(int i = 0; i arr2.length; i+) System.out.pr

2、int(arr2i + ); System.out.println();,int arr1 = 1, 2, 3, 4, 5; int arr2 = Arrays.copyOf(arr1, 10); for(int i = 0; i arr2.length; i+) System.out.print(arr2i + ); System.out.println();,java.util套件,copyOfRange()方法 binarySearch()方法,int arr1 = 1, 2, 3, 4, 5; int arr2 = Arrays.copyOf(arr1, 1, 4);,int arr1

3、 = 10, 20, 30, 40, 50, 60, 70, 80, 90; int result = Arrays.binarySearch(arr1, 6, 9, 85); if(result -1) System.out.printf(索引%d處找到數(shù)據(jù)%n, result); else System.out.printf(插入點(diǎn)%d %n, (result + 1) * -1); ,java.util套件,在Java SE 6中,您可以直接使用getDisplayNames()或getDisplayName()方法取得區(qū)域化的日期格式顯示,Calendar rightNow = Cal

4、endar.getInstance(); Locale locale = Locale.getDefault(); System.out.println(現(xiàn)在時(shí)間是:); System.out.printf(%s:%d %n, rightNow.getDisplayName(ERA, LONG, locale), rightNow.get(YEAR); System.out.println( rightNow.getDisplayName(MONTH, LONG, locale); System.out.printf(%d日%n, rightNow.get(DAY_OF_MONTH); Sys

5、tem.out.println( rightNow.getDisplayName(DAY_OF_WEEK, LONG, locale);,java.io套件,使用System類別上新增的console()方法 使用Console物件的readLine()方法,System.out.print(輸入名稱:); String name = System.console().readLine(); System.out.print(輸入密碼:); char passwd = System.console().readPassword(); String password = new String(p

6、asswd); if(caterpillar.equals(name) ,java.io套件,String name = console.readLine(%s ,輸入名稱); char passwd = console.readPassword(%s,輸入密碼); String password = new String(passwd); if(caterpillar.equals(name) ,java.io套件,在Java SE6中,對(duì)于File類別新增了幾個(gè)方法,File roots = File.listRoots(); for(File root : roots) System.o

7、ut.printf(%s總?cè)萘?d,可用容量%d %n, root.getPath(), root.getTotalSpace(), root.getUsableSpace(); ,java.awt套件,指定啟動(dòng)屏幕的圖片 manifest檔案的寫法,java-splash:caterpillar.jpg -jar JNotePad.jar,Manifest-Version: 1.0 Main-Class: onlyfun.caterpillar.JNotePad SplashScreen-Image: caterpillar.jpg,java.awt套件,系統(tǒng)工具欄圖標(biāo)的支持,if(Syst

8、emTray.isSupported() SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit() .getImage(musical_note_smile.gif); TrayIcon trayIcon = new TrayIcon(image, JNotePad 1.0); try tray.add(trayIcon); catch (AWTException e) System.err.println(無法加入系統(tǒng)工具欄圖標(biāo)); e.printStackTrace();

9、else System.err.println(無法取得系統(tǒng)工具欄); ,java.awt套件,系統(tǒng)工具欄圖標(biāo)的支持,if(SystemTray.isSupported() SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit() .getImage(musical_note_smile.gif); PopupMenu popup = new PopupMenu(); MenuItem item = new MenuItem(開啟JNotePad 1.0); popup.add

10、(item); TrayIcon trayIcon = new TrayIcon(image, JNotePad 1.0, popup); try tray.add(trayIcon); catch (AWTException e) System.err.println(無法加入系統(tǒng)工具欄圖標(biāo)); e.printStackTrace(); else System.err.println(無法取得系統(tǒng)工具欄); ,java.awt套件,系統(tǒng)工具欄圖標(biāo)上主動(dòng)顯示訊息 移除系統(tǒng)工具欄中的圖標(biāo),trayIcon.displayMessage(哈囉,該休息了嗎?, TrayIcon.MessageTyp

11、e.WARNING);,tray.remove(trayIcon);,Classpath簡(jiǎn)化設(shè)定,在Java SE 6中,您可以使用*來指定某個(gè)目錄下的所有.jar檔案,java cp .;c:jars* onlyfun.caterpillar.JNotePad,使用Apache Derby,在JDK6中捆綁了ApacheDerby數(shù)據(jù)庫(/derby/) 純Java撰寫的數(shù)據(jù)庫,支援JDBC 4.0 可以在JDK6包裝目錄的db目錄下找到ApacheDerby的相關(guān)檔案,加載驅(qū)動(dòng)程序,JDBC 4.0之中,不需要再呼叫Class.forName()并指定

12、驅(qū)動(dòng)程序 JVM會(huì)自動(dòng)在Classpath中尋找適當(dāng)?shù)尿?qū)動(dòng)程序 在包裝有JDBC驅(qū)動(dòng)程序的JAR檔案中,必須有一個(gè)META-INF/services/java.sql.Driver檔案,當(dāng)中撰寫驅(qū)動(dòng)程序類別名稱,Connection conn = DriverManager.getConnection( url, username, password);,改進(jìn)的例外處理,在JDBC 4.0之中,SQLException新增了幾個(gè)建構(gòu)函式,可以接受Throwable實(shí)例進(jìn)行SQLException的建構(gòu) SQLException并實(shí)作了Iterable界面,改進(jìn)的例外處理,try catch(SQLException ex) for(Throwable t : ex) System.err.println(t); Throwable cause = t.getCause(); while(cause != null) System.err.println(Cause: + cause); cause = cause.get

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論