找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 15|回复: 0

jdk1.5.0

[复制链接]

32万

主题

0

回帖

96万

积分

超级版主

积分
964681
发表于 2025-3-14 11:36:34 | 显示全部楼层 |阅读模式
软件标签:  jdk
jdk1.5.0是一款java最原始的软件开发工具包,java jdk是java运行的核心,一些开发的应用都需要安装java jdk环境的应用软件。赶快下载吧!!!
jdk1.5.0的11个主要新特征
自动实现装箱和解箱操作(boxing/unboxing conversions)

说明:实现了基本类型与外覆类之间的隐式转换。基本类型至外覆类的转换称为装箱,外覆类至基本类型的转换为解箱。这些类包括

primitive type ? ? reference type

boolean ? ? ? ? ? boolean

byte ? ? ? ? ? ? ?byte

char ? ? ? ? ? ? ?character

short ? ? ? ? ? ? short

int ? ? ? ? ? ? ? integer

long ? ? ? ? ? ? ?long

float ? ? ? ? ? ? ?float

double ? ? ? ? ? ?double

例如,旧的实现方式

integer intobject;

int intprimitive;

arraylist arraylist = new arraylist();

intprimitive = 11;

intobject = new integer(intprimitive);

arraylist.put(intobject); // 不能放入int类型,只能使integer

新的实现方式

int intprimitive;

arraylist arraylist = new arraylist();

intprimitive = 11;

//在这里intprimitive被自动的转换为integer类型

arraylist.put(intprimitive);

5静态导入(static imports)

很简单的东西,看一个例子:

没有静态导入

math.sqrt(math.pow(x, 2) + math.pow(y, 2));

有了静态导入

import static java.lang.math.*;

sqrt(pow(x, 2) + pow(y, 2));

其中import static java.lang.math.*;就是静态导入的语法,它的意思是导入math类中的所有static方法和属性。这样我们在使用这些方法和属性时就不必写类名。

需要注意的是默认包无法用静态导入,另外如果导入的类中有重复的方法和属性则需要写出类名,否则编译时无法通过。

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);

}

又一个简单例子:

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;

}

}

}

应运enum简写的例子:

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类中拥有方法的一个例子:

enum programflags {

showerrors(0x01),

includefileou
tput(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元数据(meta data)

请参考

http://www-900.ibm.com/developerworks/cn/java/j-annotate1/

http://www-900.ibm.com/developerworks/cn/java/j-annotate2.shtml

8building strings(stringbuilder类)

在jdk5.0中引入了stringbuilder类,该类的方法不是同步(synchronized)的,这使得它比stringbuffer更加轻量级和有效。

9控制台输入(console input)

在jdk5.0之前我们只能通过joptionpane.showinputdialog进行输入,但在5.0中我们可以通过类scanner在控制台进行输入操作

例如在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(不晓得怎么翻译,大概是 改变返回类型)

jdk5之前我们覆盖一个方法时我们无法改变被方法的返回类型,但在jdk5中我们可以改变它

例如1.4中我们只能

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的格式化输入输出,简单的例子:

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);

}

}

输出结果为:

150000 ? 10

249f0 a

5.01 3.1

5.010e+00 3.140e+02


aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|ziyuan80.com

GMT+8, 2025-8-14 21:13 , Processed in 0.065437 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表