JavaSE----02.Java basic grammar

02.Java basic grammar

1 keyword

    Java is a computer language keywords previously defined, have special meaning to an identifier, sometimes called reserved words, there is special significance of variables. Java keywords are for Java compiler special meaning, they are used to represent a data type, or shows the structure of a program like keyword can not be used as variable names, method names, class name, package name and parameter name.

java keyword table

Keyword meaning
abstract Members of the class or method show abstract properties
assert Assertions, used for debugging
boolean One of the basic data types, declare Boolean types of keywords
break Advance out of a block
byte One of the basic data types, Type Byte
case Represents a branch which is used in the switch statement,
catch In exception processing for capturing an abnormal
char One of the basic data types, character types
class Declare a class
const Reserved keywords, there is no specific meaning
continue Back to the beginning of a block
default By default, for example, used in a switch statement, indicating that a default branch. In Java8 also act on the declaration of default implementation of the interface functions
do Used in the do-while loop structure
double One of the basic data types, double precision floating point type
else Used in a conditional statement, indicating that the time when the branch condition is not satisfied
enum enumerate
extends It indicates that a type is a subtype of another type. For a class, or it may be another class abstract class; For an interface, the interface may be another
final Used to describe the final attribute that identifies a class can not derive subclasses or members of the method can not be covered, or the value of the member of the domain can not be changed, the constants used to define
finally Statement block for processing exceptions, to declare a substantially certain to be performed to
float One of the basic data types, single precision floating point type
for An endless guide word structure
goto Reserved keywords, there is no specific meaning
if Guide word conditional statement
implements Showed that a class implements the given interface
import To access the show specified class or package
instanceof It used to test whether an object instance of the object type is designated
int One of the basic data types, integer type
interface interface
long One of the basic data types, long integer type
native Is used to declare a method implemented by the language associated with the computer (e.g., C / C ++ / FORTRAN language)
new 用来创建新实例对象
package
private 一种访问控制方式:私用模式
protected 一种访问控制方式:保护模式
public 一种访问控制方式:共用模式
return 从成员方法中返回数据
short 基本数据类型之一,短整数类型
static 表明具有静态属性
strictfp 用来声明FP_strict(单精度或双精度浮点数)表达式遵循 IEEE754 算术规范
super 表明当前对象的父类型的引用或者父类型的构造方法
switch 分支语句结构的引导词
synchronized 表明一段代码需要同步执行
this 指向当前实例对象的引用
throw 抛出一个异常
throws 声明在当前定义的成员方法中所有需要抛出的异常
transient 声明不用序列化的成员域
try 尝试一个可能抛出异常的程序块
void 声明当前成员方法没有返回值
volatile 表明两个或者多个变量必须同步地发生变化
while 用在循环结构中

2、标识符

    Java语言中的类名、对象名、方法名、常量名和变量名我们统称之为Java标识符。简单来说标识符就是用来给类、对象、方法、变量、接口和自定义数据类型命名的。
标识符其命名规则为:

  1. 一个标识符可以由多个单词连接而成,以表明它的意思。
  2. 所有的标识符都应该以字母(A-Z 或者 a-z),美元符($)、或者下划线(_)开始,不能以数字开头
  3. 首字符之后可以是字母(A-Z 或者 a-z),美元符($)、下划线(_)或数字的任何字符组合。
  4. 标识符不能是关键字,标识符区分大小写。
  5. 标识符不能是true、false和null。
  6. 对于类名,每个单词的首字母必须大写,其他字母小写(如:MyFirstApplication)。
  7. 对于方法名和变量名,第一个单词首字母小写,其他单词首字母大写(如:readMyArticle)。
  8. 对于常量名,每个单词要大写,如果有多个单词组成,则单词之间用(_)连接(如:MAX_VALUE)。
  9. 对于包名,每个单词的每个字母都有小写(如:com.cnblogs.zhang)。

3、常量与变量

  • 常量:常量就是永远不会改变的量。如果要声明一个常量就必须用关键字final来修饰。格式为:
格式: final 常量类型 常量标识符 = 常量值;
例如: final float PI = 3.14F;         //声明一个float类型常量,初始化值为3.14
例如: final int MY_AGE = 18;         //声明一个int类型常量,初始化值为18
  • 变量:变量就是可以被改变的量。在声明变量时,可以先不赋值,也可以立即赋值。格式为:
格式:变量类型 变量标识符 = 变量值;
例如:double price = 2.13;       //声明一个double类型变量,初始化值为2.13
例如:int age = 18;             //声明一个int类型变量,初始化值为18

4、注释

    Java注释:编写程序时总需要为程序添加一些注释,用以说明某段代码的作用,或者说明某个类的用途、某个方法的功能,以及该方法的参数和返回值的数据类型及意义等。对于Java注释我们主要了解三种:

  • // 单行注释
  • /* ...... */ 多行注释
  • /** ...... */ 文档注释

Guess you like

Origin www.cnblogs.com/zhangliuping/p/11603463.html