Java关键字
Java关键字是保留字,表示预定义的动作、内部进程等。因此,关键字不能用作变量、函数、对象等的名称。
关键字和标识符的主要区别在于,关键字是表示预定义动作的保留字,而标识符是变量、函数、对象等的名称。
一些Java关键字如下:
| abstract | assert | boolean | break |
| byte | case | catch | char |
| class | const | continue | default |
| do | double | else | enum |
| extends | final | finally | float |
| for | goto | if | implements |
| import | instanceof | int | interface |
| long | native | new | package |
| private | protected | public | return |
| short | static | strictfp | super |
| switch | synchronized | this | throw |
| throws | transient | try | void |
| volatile | while |
一个演示关键字的程序如下:
示例
public class Example {
public static void main(String[] args) {
int i = 5;
char c = 'A';
System.out.println("i = " + i);
System.out.println("c = " + c);
}
}输出
i = 5 c = A
现在让我们来理解上面的程序。
上面程序中的关键字是`int`和`char`,它们分别指定整型和字符型数据类型。`i`和`c`是标识符。
在上面的程序中,定义了`i`和`c`的值,然后打印它们。演示此代码片段的代码如下。
int i = 5;
char c = 'A';
System.out.println("i = " + i);
System.out.println("c = " + c);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP