Article From:

***********************Identifiers, keywords, reserved words ***********************************


Every place that can be named is an identifier.

Class name HelloWorld

Method name testString

The variable int a = 10; //a is also an identifier


Identifier naming rules

1. It can be made up of and $, letters and numbers.

2. You can’t start with numbers, you can only start with and $, letters.

3. Case-sensitive (case-sensitive), unlimited length

4. Knowing by name, identifier cannot be synonymous with keyword


2. Keyword

Special meaning of the identifier, has the function of..

class Is a keyword public static void main (String)

In general, keywords will be highlighted

javaKeyword in language is lowercase


III. Retention Words


javaIs goto the key word in language?????

gotoIt’s not a keyword. Goto is called a reserved word.

Retained Words: Although not a keyword, the identifier can not be named after it, which is equivalent to retaining it first, and may be upgraded to a keyword later.

*************************************Variables and constants************************************************************************************

I. variables

After assignment, the value can be changed at any time called variable.

How to define variables

Data type variable name=[initial value];

For example:


public class TestVariable{

public static void main(String[] args){

//Definition of variables
//int a = 10;
//Equivalent to two steps
int a;//statement
a = 10;//Initialization of variables (the first assignment is called initialization)

a = 20;//assignment



Note: Do not define multiple variables in one row

double d1,d2,d3 = 0.1;// Although it is possible, it is easy to misunderstand that assigning 0.1 to d1, D2 and D3 is actually only assigning 0.1 to d3.

Two. Constant.

Once assigned, you can’t modify it as a constant at will. It can only be assigned once!

javaThe final keyword is required to define constants in

Constant names should be capitalized

public class TestFinalVariable{

public static void main(String[] args){

final double PI;//The final variable represents a constant

PI = 3.14;//Compilation errors cannot assign values to final variables



*************************************Classification of variables ************************************************************************************

1. According to the position of the declaration

1.Member variables

Defined in the class body, the variables outside the method are called member variables.

public class HelloWorld{

//1.Member variables
int a = 10;

public static void main(String[] args){

//2.local variable
int b = 20;


2.local variable

Variables defined in the method body


II. Data Type Classification

1.Basic types

2.reference type


*************************************Local Variables and Scope Issues************************************************************************************************

Local variables: The variables defined in the method body are called local variables.

Scope: Where does a variable work, and where can we use a scope called a variable uuuuuuuuuuu

I. Formal parameters of the method

Formal parameters: The parameters that follow the method name are called formal parameters.

Actual parameters: When the method is executed, the parameters actually passed in to the method are called actual parameters.

public static void main(String[] args){


For example: String [] args


Interview Question: How to pass on the main method

java TestXingCan aaa bbb ccc

Spacing between multiple parameters

Scope: The whole methodology


2. Local Variables in Method

Scope: The location of the declaration begins at the end of the method body

3. Local variables in code blocks

Scope: From the position declared in the code block to the end of the code block (block scope)

Life cycle: Focus on memory allocation from the beginning – & gt; variable memory is recycled to the end



code block


Statement 1;
Statement 2;
Statement 3;


*************************************Duplicate Definition of Variables******************************************************************************************************



*******************************Local variables must display initialization *************************************


Link of this Article: Java Basic Grammar (2)

Leave a Reply

Your email address will not be published. Required fields are marked *