Documentation

The Java™ Tutorials
Hide TOC
Summary of Variables变量的小结
Trail: Learning the Java Language
Lesson: Language Basics
Section: Variables

Summary of Variables变量的小结

The Java programming language uses both "fields" and "variables" as part of its terminology.Java编程语言使用“字段”和“变量”作为术语的一部分。Instance variables (non-static fields) are unique to each instance of a class.实例变量(非静态字段)对于类的每个实例都是唯一的。Class variables (static fields) are fields declared with the static modifier; there is exactly one copy of a class variable, regardless of how many times the class has been instantiated.类变量(静态字段)是使用静态修饰符声明的字段;不管类被实例化了多少次,类变量只有一个副本。Local variables store temporary state inside a method.局部变量在方法中存储临时状态。Parameters are variables that provide extra information to a method; both local variables and parameters are always classified as "variables" (not "fields").参数是为方法提供额外信息的变量;局部变量和参数始终分类为“变量”(而不是“字段”)。When naming your fields or variables, there are rules and conventions that you should (or must) follow.在命名字段或变量时,您应该(或必须)遵循一些规则和约定。

The eight primitive data types are: byte, short, int, long, float, double, boolean, and char.八种基本数据类型是:byteshortintlongfloatdoublebooleancharThe java.lang.String class represents character strings.java.lang.String类表示字符串。The compiler will assign a reasonable default value for fields of the above types; for local variables, a default value is never assigned.编译器将为上述类型的字段分配合理的默认值;对于局部变量,从不指定默认值。A literal is the source code representation of a fixed value.文本是固定值的源代码表示形式。An array is a container object that holds a fixed number of values of a single type.数组是一个容器对象,它包含固定数量的单一类型的值。The length of an array is established when the array is created.数组的长度是在创建数组时确定的。After creation, its length is fixed.创建后,其长度是固定的。


Previous page: Arrays
Next page: Questions and Exercises: Variables