第21章 Java se6新功能简介 Java se6基本新功能 Apache Derby、JDBC4.0
第21章 • Java SE6新功能简介 – Java SE6基本新功能 – Apache Derby、JDBC 4.0
ava.lang套件 在 Java se6中, String类别上新增了 IsEmpty0方法 string str if(str isEmpty())
java.lang套件 • 在Java SE 6中,String类别上新增了 isEmpty()方法 String str = ""; if(str.isEmpty()) { … }
java uti套件 在 Java se6中, Arrays类别新增了 copyof0 方法 int[]arr1={1,2,3,4,5} int[] arr2 Arrays copyof(arrl, arrl. length)i for(int 1=0; i< arr2length i++) System. out.print(arr2[i] + " System. out. println()i int[]arr1={1,2,3,4,5}; int[] arr2 =Arrays. copyof(arrl, 10 for(int i=0, i< arr2 length; i++ System. out. print(arr2[i] + "" System. out. println()i
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.print(arr2[i] + " "); 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(arr2[i] + " "); System.out.println();
Java.uti i套件 copy ofRange0方法 int[]ayr1={1,2,3,4,5}; int[] arr2 Arrays copyof(arrl, 1,4)i binary Search0方法 int[]arr1={10,20,30,40,50,60,70,80,90}; int result Arrays binarySearch(arrl, 6, 9,85) if(result 1){ System.out. printf("索引器d处找到数据鹗n", result); else System.out. printf("插人点号d影n",(resu1t+1
java.util套件 • copyOfRange()方法 • binarySearch()方法 int[] arr1 = {1, 2, 3, 4, 5}; int[] arr2 = Arrays.copyOf(arr1, 1, 4); int[] arr1 = {10, 20, 30, 40, 50, 60, 70, 80, 90}; int result = Arrays.binarySearch(arr1, 6, 9, 85); if(result > -1) { System.out.printf("索引%d处找到数据%n", result); } else { System.out.printf("插入点%d %n", (result + 1) * -1); }
java.ut套件 在 Java se6中,您可以直接使用 getDisplaynames0或 getDisplay小 Nameo方 法取得区城仁的日期格式显示 Calendar rightNow Calendar getInstance ()i Localelocale Locale get Default()i System.out. print1n("现在时间是:" System. out. printf("s:d on", rightNow. getDisplayName(ERA, LONG, locale) rightNow. get(YEAR)) System.out. println( rightNow. getDisplayName(Month, LoNG, locale))i System.out. printf("号d日n", rightNow. get(DAY OF MONTH))i System. out. println( rightNow. getDisplayName(DAY OF WEEK, LonG, locale)
java.util套件 • 在Java SE 6中,您可以直接使用 getDisplayNames()或getDisplayName()方 法取得区域化的日期格式显示 Calendar rightNow = Calendar.getInstance(); Locale locale = Locale.getDefault(); System.out.println("现在时间是:"); 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)); System.out.println( rightNow.getDisplayName(DAY_OF_WEEK, LONG, locale));
Java. Io套件 使用 System类别上新增的 console0方法 °使用 Console物件的 breadline0方法 System.out. print("输人名称:"); string name System console(). readline()i System.out. print("输入密码:"); char [] passwd= System. console().readPasswordo)i String password new String(passwd) if( caterpillar .equals(name)&& 123456.equals(password))t System.out. println("欢迎 caterpi1lar"); break else i System.out. printf("号s’名称或密码错误’请重新输人!鹗n",name)
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(passwd); if("caterpillar".equals(name) && "123456".equals(password)) { System.out.println("欢迎caterpillar "); break; } else { System.out.printf("%s,名称或密码错误,请重新输入!%n", name); }
Java. Io套件 string name= console. readline("[s]","输入名称."); char[] passwd= console. readpassword("[s]","输人密码… string password new string (passwd)i if( caterpillar.equals(name)&& 123456 .equals(password))i System. out. print1n("欢迎 caterpl1lar"); break else System.out. printf("s,名称或密码错误’请重新输入!器n",name);
java.io套件 String name = console.readLine("[%s] ","输入名称…"); char[] passwd = console.readPassword("[%s]","输入密码…"); String password = new String(passwd); if("caterpillar".equals(name) && "123456".equals(password)) { System.out.println("欢迎caterpillar "); break; } else { System.out.printf("%s,名称或密码错误,请重新输入!%n", name); }
Java. Io套件 在 Java se6中,对于Fle类别新增了几个方 法 File[] roots File. listRootso)i for(File root roots) i System.out. printf("s总容量d,可用容量号dn root getPath(), root. getTotalSpace( root. getUsable space())i
java.io套件 • 在Java SE6中,对于File类别新增了几个方 法 File[] roots = File.listRoots(); for(File root : roots) { System.out.printf("%s总容量%d,可用容量%d %n", root.getPath(), root.getTotalSpace(), root.getUsableSpace()); }
Java. aw套件 指定动屏幕的图片 Gava-splash: caterpillar. jpg -jar JNotePad jar manifest档案的写法 Manifest-Version: 1.0 Main-Class: onlyfun. caterpillar. JNote Pad SplashScreen-Image: caterpillar. jpg
java.awt套件 • 指定启动屏幕的图片 • manifest档案的写法 java-splash:caterpillar.jpg -jar JNotePad.jar Manifest-Version: 1.0 Main-Class: onlyfun.caterpillar.JNotePad SplashScreen-Image: caterpillar.jpg
Java. aw套件 系统工具栏图标的支持 if(SystemTray is Supported())i SystemTray tray SystemTray. getSystemTray ()i Image image Toolkit get DefaultToolkit( get Image("musical note smile. gif")i TrayIcon trayIcon new TrayIcon(image,"JNotePad 1.0)i try tray. add(trayicon)i 3 catch (AWTException e) System.err. println("无法加入系统工具栏图标"); eprintstackTrace()i t else System.err, print1n("无法取得系统工具栏"); NOte Pad 1.0 否更⊕下午0253
java.awt套件 • 系统工具栏图标的支持 if(SystemTray.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("无法加入系统工具栏图标"); e.printStackTrace(); } } else { System.err.println("无法取得系统工具栏"); }