java keywords 关键字

Java Language Specification 中的关键字列表:
[url]http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.9[/url][quote]3.9 Keywords
[color=red][b]50[/b][/color] character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (§3.8).:
Keyword: one of
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

[color=red]The keywords [b]const[/b] and [b]goto[/b] are reserved, even though they are not currently used[/color]. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.

[color=red]While [b]true[/b] and [b]false[/b] might appear to be keywords, they are technically[b] Boolean literals[/b][/color] (§3.10.3). Similarly, [color=red]while [b]null[/b] might appear to be a keyword, it is technically the [b]null literal[/b][/color] (§3.10.7).[/quote]


transient,volatile:
[url]http://stackoverflow.com/questions/106591/do-you-ever-use-the-volatile-keyword-in-java?rq=1[/url]
[quote]When is volatile enough?

If two threads are both reading and writing to a shared variable, then using the volatile keyword for that is not enough. You need to use synchronization in that case to guarantee that the reading and writing of the variable is atomic.

But in case one thread reads and writes the value of a volatile variable, and other threads only read the variable, then the reading threads are guaranteed to see the latest value written to the volatile variable. Without making the variable volatile, this would not be guaranteed.

Performance considerations of using volatile:

Reading and writing of volatile variables causes the variable to be read or written to main memory. Reading from and writing to main memory is more expensive than accessing the CPU cache. Accessing volatile variables also prevent instruction reordering which is a normal performance enhancement technique. Thus, you should only use volatile variables when you really need to enforce visibility of variables.[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值