jdk1.5.0

43 MB/热门软件

简介 相关 评论

简介

绿色版jdk1.5.0 绿色版,直接解压就行.给自己mark使用.EOH红软基地

JDK1.5.0的11个主要新特征

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

jdk1.5.0截图

jdk1.5.0EOH红软基地

展开

同类推荐

相关文章