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发行说明。
Now that you've learned how to declare and initialize variables, you probably want to know how to do something with them.既然您已经学习了如何声明和初始化变量,您可能想知道如何使用它们。Learning the operators of the Java programming language is a good place to start.学习Java编程语言的操作符是一个很好的起点。Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.运算符是对一个、两个或三个操作数执行特定操作,然后返回结果的特殊符号。
As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence.在我们探索Java编程语言的运算符时,提前知道哪些运算符具有最高优先级可能会有所帮助。The operators in the following table are listed according to precedence order.下表中的运算符按优先顺序列出。The closer to the top of the table an operator appears, the higher its precedence.运算符越靠近表的顶部,其优先级越高。Operators with higher precedence are evaluated before operators with relatively lower precedence.优先级较高的运算符在优先级相对较低的运算符之前求值。Operators on the same line have equal precedence.同一行上的运算符具有相同的优先级。When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first.当同等优先级的运算符出现在同一表达式中时,必须有一条规则来控制首先求值的运算符。All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.除赋值运算符外,所有二进制运算符都从左到右求值;赋值运算符从右向左求值。
expr++ expr-- | |
++expr --expr +expr -expr ~ ! | |
* / % | |
+ - | |
<< >> >>> | |
< > <= >= instanceof | |
== != | |
& | |
^ | |
| | |
&& | |
|| | |
? : | |
= += -= *= /= %= &= ^= |= <<= >>= >>>= |
In general-purpose programming, certain operators tend to appear more frequently than others; for example, the assignment operator "在通用编程中,某些操作符往往比其他操作符出现得更频繁;例如,赋值运算符“=
" is far more common than the unsigned right shift operator ">>>
".=
”远比无符号右移运算符“>>>
”常见。With that in mind, the following discussion focuses first on the operators that you're most likely to use on a regular basis, and ends focusing on those that are less common.考虑到这一点,下面的讨论首先集中在您最有可能定期使用的操作符上,最后集中在那些不太常见的操作符上。Each discussion is accompanied by sample code that you can compile and run.每一次讨论都伴随着您可以编译和运行的示例代码。Studying its output will help reinforce what you've just learned.研究它的输出将有助于巩固你刚刚学到的东西。