First, Introduction
In the Java language, all variables must be declared before they are used. The basic format for declaring variables is as follows:
Type identifier [= value][, identifier [= value] ...];
Format Description: Type is a Java data type. Identifier is the variable name. You can declare multiple variables of the same type by separating them with commas.
The following is a list of the declaration instances for some variables. Note that some of the initialization procedures are included.
int A, b, C; // declares three integers of type int: A, B, C int // declares three integers and assigns an initial value byte z =; // declaring and Initializing Z string s = "Runoob" // declares and initializes the string sdouble// declares a dual-precision floating-point variable pi char x = ' x '; // the value of the declared variable x is the character ' X '.
Second, notes
PackageCom.hgd.study;/*** variable *@authorHutiger **/ Public classVariables { Public Static voidMain (string[] args) {inta=30;//"A" is the variable "30" is the literal value "=" is the assignment "int" Data type shaping intB=20; System.out.print (A+B);//and theSystem.out.print (A*B);//Product//--------------------------------- //defining rules for variables /** 1. Variable name must not be $ _ or the beginning of the letter, you can make $ _ number or character * 2. Variable name suggested first letter lowercase * 3. Variable name cannot use keyword * 4. For multiple English word variables Using the Hump naming method * 5. Variable names not recommended for use in Chinese*/String UserName= "Admin";//String class = "" Error definition }}
Java Learning notes: Variables for Java