Java series (3)-basic syntax and java syntax

Source: Internet
Author: User

Java series (3)-basic syntax and java syntax

1. Keywords

Features: All lowercase letters

2. identifier

(1) It is the character sequence that names such as class, interface, and method.

(2) composition rules:

   

A: uppercase/lowercase letters

B: Number

C: $ and _

 

(3) considerations:

   

A: it cannot start with A number.

B: it cannot be a keyword in java.

C: Case Sensitive

(4) common naming rules

   

A: The packages are all in lower case and are separated by multi-level packages.

B: class or interface: uppercase letters of each word

C: method or variable: lowercase for the first letter, and uppercase for the second word

D: constant: all uppercase. Multiple words must be separated by _ (STUDENT_MAX_AGE)

3. Notes

(1) category:

   

A: When the line comment ://

B: multi-line comment :/**/

C: document notes:

(2) functions of Annotations:

   

A: Explain the program and improve the code reading.

B: It can help us debug the program.

4. Constants

(1) The value of the program remains unchanged during execution.

(2) category:

   

A: literal value constant

B: Custom Constants

(3) literal Constants

   

A: String constant

B: integer constant

C: decimal constant

D: character constant

E: Boolean constant

F: null constant, null

(4) java provides four representations for Integer constants

   

A: binary (starting with 0 B)

B: octal (starting with 0)

C: decimal (the default integer is decimal)

D: hexadecimal (starting with 0x)

5. hexadecimal conversion

(1) convert others to decimal

(2) convert decimal to other hexadecimal

(3) Fast Conversion Method of hexadecimal conversion

   

A: The conversion between decimal and binary. The code is 8421.

B: Binary and octal, hexadecimal conversion

6. Variables

(1) amount of changes that can occur within a certain range during Program Execution

(2) Definition Format of variables:

   

A: data type variable name = initialization value

B: data type variable name;

Variable name = initial value

 

7. Data Type

(1) java is a strong type language that provides a corresponding data type for each type of data

(2) category:

   

A: basic data types: 4 categories, 8 Types

B: Reference Data Type: Class, interface, array

(3) Basic Data Types

   

A: integer

[Byte: 1]

[Short: 2]

[Int: 4] [Default]

[Long: 8]

B: Floating Point Number

[Float: 4]

[Double: 8] [Default]

C: character

[Char: 2]

D: Boolean

[Boolean: 1]

8. Data Type Conversion

(1) The boolean type is not involved in conversion.

(2) Default conversion:

   

A: from small to big

B: byte, short, char → int → long → float → double

C: byte, short, and char are not converted to each other and are directly converted to the int type during calculation.

(3) forced conversion:

   

A: from big to small

B: It may cause loss of precision. It is generally not recommended.

C: Format: Target data type variable name = (target data type) (converted data)

[Example]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.