Basic Java syntax and basic java syntax

Source: Internet
Author: User

Basic Java syntax and basic java syntax

I. Cross-row

Java variables cannot be cross-row, such as: String na

Me = "James ";

The String cannot be a cross-line String, for example, String a = "xxxxxxxxxx

Yyyyyyyy ";

 

Ii. identifier rules

Java identifiers refer to the names of variables, classes, and methods. The Java language is case sensitive. An identifier can consist of letters, numbers, underscores, and dollar signs ($). A digit cannot start. The identifier cannot contain spaces.

  

Iii. Data Type Classification

Java supports two types: basic type and reference type.

Basic Type:

  • Boolean Type:
  • Numeric type: Integer type (byte, short, int, long, char), floating point type (float, double)

Reference Type: Class, interface, array, null type

4. Note the following types:

Java integers are of the int type by default, for example, byte a = 56; (the system will assign 56 to a byte variable), long bigValue = 9999999999999999; (at this time, the system will not assign a value to the long variable, but assign a value to the int variable because it cannot store the variable and reports an error.) long bigValue = 999999999999999L can only be stored in this way;

The Unicode character set used by Java is used as the encoding method. A char variable in Java is a 16-bit unsigned integer, which is different from the Char in C language.

The Java floating point type is double by default. If you want to treat a floating point value as a float type, write float f = 5.12f;

The Java language also provides three special floating point values: POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN ); if a positive number is divided by 0, positive infinity is obtained. If a negative number is divided by 0, negative infinity is obtained. If a negative number is divided by 0.0, a non-number is obtained.

V. New Features of Java 7

Add a binary integer, which is expressed as 0B. If the binary number has 32 bits, the highest bits represent the symbol bits, for example, int val = 0b000000000000000000000000000000000000011. The highest bits represent the symbol bits. A value of 1 indicates a negative number, and a negative number indicates a supplemental code for storage. You must convert it to the original code to see its value. If you want to represent 64-bit binary, add l or L after the binary;

The underline function is added in Java 7, such as double pi = 3.14 _ 15_92_65_36;

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.