Java basic grammar (a)

Keywords and identifiers

Use the keyword 1.java

Definition: The Java language is given a special meaning, with special purposes string (word)
Features: keywords are lowercase letters
exactly which keywords:

 

2. Reserved words : now Java version has not been used, but later versions may use as keywords.
  What specific reserved words: goto, const
  Note: When naming their own identifier to avoid using these reserved words

3. Use of identifiers
  defined: those who own place from the name of the call identifier.
  Related to the structure:
  the package name, class name, interface name, variable names, method names, constant names,
rules must be observed :( Otherwise, the compiler does not pass).


:( can not comply with specifications, does not affect compile and run, but ask you to follow )

  Note the point:
  when a name in order to improve readability, as far as possible sense, "see the name to know Italian."

 


 

Use variables

1.1 by data type

Detailed Description:
1. Integer: byte (byte. 1 = 8bit) \ short (2 bytes) \ int (4 bytes) \ long (. 8 bytes)
  ① byte range: -128 ~ 127
  ② long variable declarations , must be "l" or "L" end
  ③ typically, the definition of an integer variable, using an int.
  ④ integer constant, the default type is: int type


2. Float : float (4 bytes) \ double (8 bytes)
  ① float, a numerical value with decimal
  ② float represents a range of values larger than the long
  time ③ defined float type variables, variables to " f "or" F "end
  ④ typically, when the float variable is defined, using double.
  ⑤ floating-point constants, default type is: double


3. Character : char (2 bytes = 1 character)
  ① char type variable is defined, a pair of generally '', only the internal write a character
  ② representation: 1. Declare a character escape character 2. 3. Direct use Unicode character values to represent constants


4 Boolean: Boolean
  ① can only take one of two values: to true, to false
  ② often conditional, loop structure used


1.2 Classification of statement by location


2. The definition of a variable format:
  Data type variable name = variable value;
  or
  data type variable name;
  variable name = variable value;

3.变量使用的注意点:
  ① 变量必须先声明,后使用
  ② 变量都定义在其作用域内。在作用域内,它是有效的。换句话说,出了作用域,就失效了
  ③ 同一个作用域内,不可以声明两个同名的变量
4.基本数据类型变量间运算规则
4.1 涉及到的基本数据类型:除了boolean之外的其他7种
4.2 自动类型转换(只涉及7种基本数据类型)
  结论:当容量小的数据类型的变量与容量大的数据类型的变量做运算时,结果自动提升为容量大的数据类型。
    byte 、char 、short --> int --> long --> float --> double
  特别的:当byte、char、short三种类型的变量做运算时,结果为int型
  说明:此时的容量大小指的是,表示数的范围的大和小。比如:float容量要大于long的容量

4.3 强制类型转换(只涉及7种基本数据类型):自动类型提升运算的逆运算。
  1.需要使用强转符:()
  2.注意点:强制类型转换,可能导致精度损失。
4.4 String与8种基本数据类型间的运算
  1. String属于引用数据类型,翻译为:字符串
  2. 声明String类型变量时,使用一对""
  3. String可以和8种基本数据类型变量做运算,且运算只能是连接运算:+
  4. 运算的结果仍然是String类型

 


 

Guess you like

Origin www.cnblogs.com/qykk/p/12513825.html