Summary of Java Basic syntax

Source: Internet
Author: User

1. Choose the rules in Java: A, cannot be a keyword, B, can only be numbers, letters, underscores or dollar sign; C, can only start with a letter, underscore or dollar sign; d, see the name of the meaning; E, case-sensitive, unlimited length.

2. Comparison of data types in Java with data types in C:

Data types in Java:

Key words

The amount of space occupied

Byte

1 bytes

Short

2 bytes

Int

4 bytes

Long

8 bytes

Float

4 bytes

Double

8 bytes

Char

2 bytes

Boolean

Not sure, there is a JVM decision

Data types in the C language:

Key words

The amount of space occupied

signed/unsigned Char

1 bytes

signed/unsigned Short

2 bytes

signed/unsigned int

2F bytes or 4 bytes , determined by the compiler

signed/unsigned Long

8 bytes

3. Automatic type promotion rules when performing mathematical expression operations in Java:

A, all byte, short, and char types are automatically promoted to int.

b, if there is an operand of type long, n then the result of the calculation will be promoted to a long type.

C, if one of the operands is a float type, n then the calculation result will be promoted to float type.

D, if one operand is a double type, n then the result of the calculation will be promoted to double type. (That is, when you perform a mathematical expression operation, the variable type is different, and the small amount of space is automatically converted to that type that occupies a large space)

4. In Java, you must use the final keyword when defining constants .

5. Operators and Expressions in Java:

Operator

Meaning of the operator

+ +,--

Self-increment, decrement operator

+,-,*,/,%

Arithmetic operators: Add, subtract, multiply, divide, modulo

>,<,>=,<=,==,!=

Relational operator: greater than, less than, greater than or equal to, less than equals, equal to, not equal to

!,&&,| |                 

  logical Operator: logical non, logical and logical, or

&,|,^,~,>>, <<,>>>

Bitwise operators: Bit-and-bit or,-XOR, non- signed, right -shifted (the power to shift the original 2 to a smaller scale), left (to the power of the original 2 shift), unsigned right shift (whatever the sign bit is, Always set the highest bit to 0)

=

Assignment operators

+=,-=,*=,/=,%=, <<=, >>=, >>>=, &=, |=, ^=

Extended assignment operators

?:

Conditional trinocular operation symbol: Before the question mark is true, take the value before the colon, and vice versa, take the value after the colon

Note: A, in Java,,& and | can also be used for logical relationships, regardless of whether the expression on the left is true or false, he must calculate the expression on the right. In the C language, these two operators are used only for bitwise operations.

b, whether in C or Java,&& and | | There will be a short-circuit condition. For &&, when the left expression is false, the expression on the right will not be evaluated; for | |, when the expression on the left is true, the expression on the right will not be evaluated.

Summary of Java Basic syntax

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.