scjp 第一篇 java 识别符  

Posted by Mindlern in

第一篇 JAVA 识别符

识别符用在变量名 函数名等地方。

有效的是英文字母 阿拉伯数字
还有货币符号(a currency character) 比如美元符号$ 欧元符号€等(货币符号 不常见 要注意哦
连接字符( a connecting character) 最常见的是"_"下划线
http://www.fileformat.info/info/unicode/category/Pc/list.htm (该处是所有的连接字符列表)
除以上的字符外 都是不允许的

规则
1、第一个字符不能是数字
2、第一个字符之后,可以追加以上说了任意有效字符
3、没有限制识别符的长度
4、不能使用JAVA 内定的关键字 作为识别符
5、识别符是大小写敏感的 foo 和 FOO 被看做是不同的识别符

下面是合法的识别符
int _a;
int $c;
int __________2_w;
int _$;
int this_is_a_very_detailed_name_for_an_identifier;
int £a = 1;
int €a = 1;

以下是非法的识别符
int :b;
int -d:
int e#;
int .f;
int 7g;

可能一些朋友有疑问 e# 为什么不是有效识别符?
e打头 这是没有错的
但是其后的# 并不包含在有效的识别符组成符号列表中
所以是非法的

一些论坛讨论的帖子
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=025630
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=046799
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=042127
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=042573

最后送上 JAVA 内定的关键字列表

abstract
char
double
for
int
private
strictfp (这个我还没有用到 不熟悉的要注意咯
throws
assert
boolean
class
else
goto
interface
protected
super
transient(这个也是 还没用到过
enum
break
const
extends
if
long
public
switch
try
byte
continue
final
implements
native(这个也没用到过
return
synchronized
void
case
default
finally
import
new
short
this
volatile (这个好像是多线程时候 用到的关键字
catch
do
float
instanceof
package
static
throw
while

This entry was posted on 2008年10月25日星期六 at 星期六, 十月 25, 2008 and is filed under . You can follow any responses to this entry through the comments feed .

0 评论

发表评论