The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
You use one of the wrapper classes – 您可以使用其中一个包装类–Byte
, Double
, Float
, Integer
, Long
, or Short
– to wrap a number of primitive type in an object.Byte
、Double
、Float
、Integer
、Long
或Short
–在对象中封装多个基元类型。The Java compiler automatically wraps (boxes) primitives for you when necessary and unboxes them, again when necessary.Java编译器会在必要时自动为您包装(装箱)原语,并在必要时再次拆箱。
The Number
classes include constants and useful class methods.Number
类包括常量和有用的类方法。The 常量MIN_VALUE
and MAX_VALUE
constants contain the smallest and largest values that can be contained by an object of that type.MIN_VALUE
和MAX_VALUE
包含该类型对象可以包含的最小值和最大值。The byteValue
, shortValue
, and similar methods convert one numeric type to another.byteValue
、shortValue
和类似的方法将一种数字类型转换为另一种。The valueOf
method converts a string to a number, and the toString
method converts a number to a string.valueOf
方法将字符串转换为数字,toString
方法将数字转换为字符串。
To format a string containing numbers for output, you can use the 要格式化包含输出数字的字符串,可以使用printf()
or format()
methods in the PrintStream
class.PrintStream
类中的printf()
或format()
方法。Alternatively, you can use the 或者,您可以使用NumberFormat
class to customize numerical formats using patterns.NumberFormat
类使用模式自定义数字格式。
The Math
class contains a variety of class methods for performing mathematical functions, including exponential, logarithmic, and trigonometric methods.Math
类包含用于执行数学函数的各种类方法,包括指数法、对数法和三角法。Math
also includes basic arithmetic functions, such as absolute value and rounding, and a method, random()
, for generating random numbers.Math
还包括基本的算术函数,如绝对值和舍入,以及生成随机数的方法random()
。