文档介绍:Java语言程序设计—Java语言基础
王卓峥
******@bjut.
1
Java语言基础
标识符与数据类型
表达式与语句
程序控制语句
数组
2
标识符与数据类型
注释
分号、块和空白
标识符
基本java类型
3
注释
三种允许的Java技术程序注释风格
//comment on one line
/* comment on one
or more line */
/** ment */
4
分号、块和空白
一个语句是一行用分号(;) 终止的代码
totals=a+b+c+d+e+f;
一个块是以上括号和下括号为边界的语句集合
{
x=y+1;
y=x+1;
}
一个块可被用在一个类的定义中
public class Date{
int day;
int month;
int year;
}
块语句可被嵌套
Java程序中允许任意多的空白
5
区块的形式
// a block statement
{
x = y + 1;
y = x + 1;
}
// a block used in a class definition
public class MyDate {
int day;
int month;
int year;
}
// an example of a block statement nested within
// another block statement
while ( i < large ) {
a = a + i;
if ( a == max ) {
b = b + a; // nested block is here
a = 0;
}
}
6
空白
在源代码元素之间允许空白,空白的数量不限。空白(包括空格、tabs和新行)可以改善你的对源代码的视觉感受。
{
int x;
x = 23 * 54;
}
int x;
x = 23 + 54;
}
7
标识符
是赋予变量、类和方法的名称
可从一个字母、下划线(_)或美元符号($)开始
是大小写区别对待的, 且无最大长度
[举例]
identifier
userName
User_name
_sys_varl
$change
8
Java关键字
abstract do implements private throw
boolean double import protected throws
break else instanceof public transient
byte extends int return true
case false interface short try
catch final long static void
char finally native super volatile
class float new switch while
continue for null synchronized
default if package this
9
关键字—几点注意
true、false和null为小写
无sizeof运算符
goto和const不是Java编程语言中使用的关键字
10