JAVA-basic syntax and java syntax

Source: Internet
Author: User

JAVA-basic syntax and java syntax

I. Data Types

Java has eight basic data types: byte, short, int, long, char, boolean, float, and double:

1. boolean: the data value is only true or false, applicable to logical computing.

2. char: char (character type) data in memoryOccupies 2 bytes. Char data is used to represent characters in the general sense. Each character occupies 2 bytes. Java characters are encoded in Unicode format. The first 128 bytes of Its Encoding and the storage range of ASCII-compatible characters are\ U0000 ~ \ UFFFFWhen defining data of the dense type, add ''. For example, '1' indicates the character '1' rather than the value 1,

3. byte: byte data is stored in the memory.1 byteIndicates the range of stored data:-128 ~ 127.

4. short: short Type (short integer) data is in the memoryOccupies 2 bytes.

5. int: the int type (integer) data is in the memory.4 bytes.

6. long: long (long integer) data in memoryTakes 8 bytes.

7. float: float Type (single-precision floating point type) data in memory4 bytes. (Float precision is 7-8 bits)

8. double: double type (double-precision floating point type) data in the memoryTakes 8 bytes.

All basic data types in Java have a fixed storage range and the size of memory space, which is not affected by the specific operating system to ensure the portability of Java programs.

 

II, Identifier

In Java, we need many elements in the identifier, including the class name, method, field, variable, and package name. The name we selected is called an identifier and must comply with the following rules:

1. The identifier cannot be a keyword, true, false, or null.

2. An identifier can contain letters, numbers 0-9, underscores (_), or dollar signs ($ ).

3. the first character of the identifier must be a letter, underscore (_), or dollar sign ($ ).

4. The identifiers are case-sensitive and do not specify the maximum length.

 

3., Data type conversion

1. The boolean type cannot be converted to any other data type.

2. Automatic type conversion: a data type with a small capacity can be automatically converted to a data type with a large capacity, such as byte-short-int-long-float-double. Byte, short, and int types are not converted to the int type during calculation.

3. Forced type conversion: when a data type with a large capacity is converted to a data type with a small capacity, a forced conversion character must be added. However, this may cause reduced precision or data overflow, be careful.

 

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.