First, the key word
Words that are given special meaning by the Java language are all lowercase letters that make up a keyword word.
class, public, static, void are keywords
class Keyworddemo
{ publicstaticvoid main (string[] args)
{ System.out.println ("Hello keyword");} }
Second, identifiers
A sequence of characters to use when naming classes, interfaces, methods, variables, etc.
Composition rule:
1, by the English case, the number of characters, $, _ Composition
2. Do not start with a number
3. Cannot be a Java keyword
4, case-sensitive.
class makenamedemo{ publicstaticvoid main (string[] args) { // Correct Practice int x = +; // cannot start with a number int 2y= ;// cannot be a Java keyword intclass = ;} }
Common naming conventions: see Names and meanings
Package: All lowercase
1, single-stage: Example
2, Multilevel: cn.edu.example
Class, Interface:
1. One word: Capitalize the first letter of a word, Student
2. Multiple words: The first letter of each word must be capitalized, HelloWorld
Methods, variables:
1, a word: The first letter of the word lowercase, main
2. Multiple words: Start with the second word, capitalize the first letter of each word, studentage,showallnames ()
Constant:
1, a word: all uppercase, PI
2, multiple words: Each letter is capitalized, separated by _, Student_max_age
Third, comments
Format: single-line comment//...
Multi-line Comment/*...*/
Document Comment/**...*/
Programming Habits: Write comments First, then write code
Function: Explain the procedure, improve the reading of the program, and help to debug the program.
Iv. Constants
1. Literal value Constants
(1) string constants, with the contents of "";
(2) Integer constants
A. Binary (0b start), octal (beginning with 0), decimal, hexadecimal (0x), console output defaults to decimal
B. Representation of signed data: original code, inverse code, complement
Example: 7--0b111
The original code: positive source code The highest bit is 0, negative number is 1, the other is the value bit.
+7--0 0000111;-7--1 000111
Anti-code: The inverse code of positive number is the same as the original code;
+7--0 0000111;-7--1 111000
Complement: The complement of positive numbers is the same as the original code; the complement of negative numbers is based on the inverse code plus 1.
+7--0 0000111;-7--1 111001
(3) Decimal constants;
(4) Character constants, the contents of which are enclosed;
(5) Boolean constant, True,false
(6) NULL constant, NULL
classconstantdemo{ Public Static voidMain (string[] args) {//string ConstantsSystem.out.println ("Hello"); //Numeric ConstantsSYSTEM.OUT.PRINTLN (100); //Decimal ConstantsSYSTEM.OUT.PRINTLN (1.1); //Character ConstantsSystem.out.println (' a '); //Boolean ConstantsSystem.out.println (true); }}
2. Custom Constants
A-2 Java language Basics