Introduction to Java Syntax (i): The basic composition of the Java language

Source: Internet
Author: User
Tags character set number sign java keywords

The Java language consists mainly of the following five elements: identifiers, keywords, literals, operators, and delimiters. These five elements have different grammatical meanings and composition rules, and they work together to complete the semantic expression of the Java language. Let's explain them separately.

1: Identifiers

variables, classes, and methods require a certain name, which we call the identifier. There is a certain limit to identifiers in Java. First, the first character of all identifiers must be a letter (case), underscore _ or dollar sign ¥, followed by numbers (0--9), all from a--z uppercase letters, A--z lowercase and underscore _, dollar sign ¥ and all ASCII codes before hexadecimal 0xc0 Third note the notation cannot be marked with a system-reserved keyword.

The above is the basic rule for identifier naming, and here is a right and wrong comparison, which will have a better understanding of the naming rules for identifiers:

Legal identifier Illegal identifier

Try try# (Note: cannot use # as an indicator)

Group_7 7group (Note: Cannot start with a number sign)

Opendoor Open-door (Note: Can not use the next-as a sign)

Boolean_1 Boolean (Note: boolean is a keyword and cannot be marked with a keyword)

2: Key Words

The keyword is the identifier used by the Java language itself, and it has a specific grammatical meaning. All Java keywords will not be used as identifiers, and the Java keywords are:

Abstract, continue, for, new, switch, Boolean, default, goto, NULL, synchronized, break, do, if, package, this, byte, double, Implements, private, Threadsafe, byvalue, else, import, protected, throw, case, extends, instanceof, public, transient, Catch, False, int return, True, char, final, interface, short, try, class, finally, long, static, void, const, float, native, Super, while and so on.

3: Data type

Java has different data types, Java data types are: Integer, floating-point, Boolean, character, String type.

Integer data is the most common type of data, and it behaves in decimal, hexadecimal, and octal terms. A hexadecimal integer must begin with 0X.

Each integer data occupies 32-bit storage space, or four bytes. This means that the integer data indicates that the range is between 2,147,483,648 and 2,147,483,648, and if for some reason you have to represent a larger number, a 64-bit long integer should be sufficient. If you want to force an integer to be a long form, you can add the letter L after the number.

Floating-point data is used to represent a decimal number with decimals. For example 1.35 or 23.6. is a standard form of floating-point numbers, and it can be in the form of scientific notation, and here are some examples:

3.1415926 0.34.01234 9.999E8

A standard floating-point number is called a single-precision floating-point number, and its storage space is 32 bits, or four bytes. There are also 64-bit double-precision floating-point numbers. You can use the D suffix to make sure that you want this double-precision floating-point number.

A Boolean type is the simplest type of data, and Boolean data has only two states: true and false, usually with the keyword true and false to represent both states.

Character data is a single character enclosed by a pair of single quotes. It can be any character in the character set, such as: ´a´,´b´.

The string data type is a sequence of characters enclosed in double quotes, which are actually implemented by the string class (the concept of the class is explained in detail in subsequent chapters), rather than the character array used in the C language. Each string data will produce a new instance of the string class, readers do not have to worry about the notion that strings are related to the concept of a class, and because of the nature of classes, you don't have to worry about how to implement them, they take care of themselves, and what you need to say is that strings are used in Java as classes for security reasons only.

Here are a few examples of strings

"How are Your"

"I am Student

4: operator

Any language has its own operators, the Java language is no exception, such as +,-, *,/And so are operators, the operator's function is with a certain operation data composition expression to complete the corresponding operation. There are different operators for different data types.

5: Separator

Delimiters are used to make the compiler confirm where the code is delimited. '; ' is a separator of the Java language.

Related Article

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.