绿色版jdk1.5.0 绿色版,直接解压就行(háng).给(gěi)自己mark使用.
自动实现装箱和解(jiě)箱操作(Boxing/Unboxing Conversions)
说明:实(shí)现了(le)基(jī)本类型与(yǔ)外覆类之间的隐(yǐn)式转换。基本(běn)类(lèi)型至外覆类的转换称为装箱,外覆类至基本类型(xíng)的转换为解箱(xiāng)。这些(xiē)类包括(kuò)
Primitive Type Reference Type
boolean Boolean
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double
例如,旧的实(shí)现(xiàn)方式
Integer intObject;
int intPrimitive;
ArrayList arrayList = new ArrayList();
intPrimitive = 11;
intObject = new Integer(intPrimitive);
arrayList.put(intObject); // 不能放入int类型,只能使Integer
新的实(shí)现方式
int intPrimitive;
ArrayList arrayList = new ArrayList();
intPrimitive = 11;
//在这里intPrimitive被自动(dòng)的转换为Integer类型
arrayList.put(intPrimitive);
5静态导入(rù)(Static Imports)
很简单(dān)的东西(xī),看一个例子:
没有(yǒu)静(jìng)态(tài)导入(rù)
Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
有了静态(tài)导入
import static java.lang.Math.*;
sqrt(pow(x, 2) + pow(y, 2));
其(qí)中import static java.lang.Math.*;就是静态导入的语法,它的意思是导(dǎo)入Math类中的(de)所有static方法和属(shǔ)性。这(zhè)样我们在(zài)使用这些方法和属(shǔ)性时就不必写类名(míng)。
需(xū)要注意(yì)的是默认(rèn)包无法用静(jìng)态导入,另外如果(guǒ)导(dǎo)入的类中有重复的方法(fǎ)和属性则需要写出类名(míng),否则编译时无法通过。
6枚举类(Enumeration Classes)
用法:public enum Name {types, ….}
简单的例子:
public enum Colors {Red, Yellow, Blue, Orange, Green, Purple, Brown, Black}
public static void main(String[] args){
Colors myColor = Colors.Red;
System.out.println(myColor);
}
又一个简单例(lì)子:
import java.util.*;
enum OperatingSystems {windows, unix, linux, macintosh}
public class EnumExample1 {
public static void main(String args[]) {
OperatingSystems os;
os = OperatingSystems.windows;
switch(os) {
case windows:
System.out.println(“You chose Windows!”);
break;
case unix:
System.out.println(“You chose Unix!”);
break;
case linux:
System.out.println(“You chose Linux!”);
break;
case macintosh:
System.out.println(“You chose Macintosh!”);
break;
default:
System.out.println(“I don’t know your OS.”);
break;
}
}
}
应运(yùn)enum简(jiǎn)写的例子:
import java.util.*;
public class EnumTest
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
String input = in.next().toUpperCase();
Size size = Enum.valueOf(Size.class, input);
System.out.println("size=" + size);
System.out.println("abbreviation=" + size.getAbbreviation());
if (size == Size.EXTRA_LARGE)
System.out.println("Good job--you paid attention to the _.");
}
}
enum Size
{
SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
private Size(String abbreviation) { this.abbreviation = abbreviation; }
public String getAbbreviation() { return abbreviation; }
private String abbreviation;
}
enum类中(zhōng)拥(yōng)有方法的一个例子:
enum ProgramFlags {
showErrors(0x01),
includeFileOutput(0x02),
useAlternateProcessor(0x04);
private int bit;
ProgramFlags(int bitNumber) {
bit = bitNumber;
}
public int getBitNumber() {
return(bit);
}
}
public class EnumBitmapExample {
public static void main(String args[]) {
ProgramFlags flag = ProgramFlags.showErrors;
System.out.println(“Flag selected is: “ +
flag.ordinal() +
“ which is “ +
flag.name());
}
}
7元(yuán)数据(Meta data)
请(qǐng)参考
http://www-900.ibm.com/developerWorks/cn/java/j-annotate1/
http://www-900.ibm.com/developerworks/cn/java/j-annotate2.shtml
8Building Strings(StringBuilder类(lèi))
在JDK5.0中引入了StringBuilder类,该类的方法不(bú)是同(tóng)步(synchronized)的,这使得它比StringBuffer更加轻量(liàng)级和有效(xiào)。
9控制台输入(Console Input)
在JDK5.0之前我(wǒ)们只能通过JOptionPane.showInputDialog进行输(shū)入,但在5.0中我们可以通过类Scanner在控制台(tái)进行(háng)输入操作
例(lì)如在1.4中的输入
String input = JOptionPane.showInputDialog(prompt);
int n = Integer.parseInt(input);
double x = Double.parseDouble(input);
s = input;
在5.0中我们可以
Scanner in = new Scanner(System.in);
System.out.print(prompt);
int n = in.nextInt();
double x = in.nextDouble();
String s = in.nextLine();
10Covariant Return Types(不(bú)晓得(dé)怎么翻(fān)译,大概是 改变返回类型)
JDK5之前我们(men)覆盖一个方法(fǎ)时我们无法改变被方法(fǎ)的(de)返回类(lèi)型,但(dàn)在JDK5中我们(men)可以改变它
例如1.4中我们(men)只(zhī)能(néng)
public Object clone() { ... }
...
Employee cloned = (Employee) e.clone();
但是在5.0中我们可以改变返回类型为Employee
public Employee clone() { ... }
...
Employee cloned = e.clone();
11格式化I/O(Formatted I/O)
增加了类似C的格(gé)式化输入输(shū)出,简单的例(lì)子:
public class TestFormat{
public static void main(String[] args){
int a = 150000, b = 10;
float c = 5.0101f, d = 3.14f;
System.out.printf("%4d %4d%n", a, b);
System.out.printf("%x %x%n", a, b);
System.out.printf("%3.2f %1.1f%n", c, d);
System.out.printf("%1.3e %1.3e%n", c, d*100);
}
}
输出(chū)结果为(wéi):
150000 10
249f0 a
5.01 3.1
5.010e+00 3.140e+02
