Basic Java syntax and java syntax

Source: Internet
Author: User
Tags bitwise operators

Basic Java syntax and java syntax

Basic Java syntax

1. Close the key word

Boolean, break, byte, case, char, class, continue, default, do, double, else, final, float, for, goto, if, import, int, long, new, package, private, protected, public, return, short, static, switch, this, void, while, abstract, catch, const, extends, assert, finally, implements, instanceof, interface, native, strictfp, super, synchronized, throw, throws, transient, try, volatile

2. Reserved Words

True, false, null

3. Mark

Naming rules: a. an identifier can contain letters, numbers, underscores, and dollar signs.

B. The identifier cannot be a keyword or a reserved word.

C. The identifier cannot start with a number.

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

For example: identifier, User_name, _ sys_varl, $ change, etc.

Naming rules: a. "See the name and meaning" (select a concise English word as the identifier)

B. Each word starts with a lower-case letter, and the first letter of the second word is an upper-case letter or the first letter of each word is an upper-case letter)

For example, myStudentCount and DataBaseUser

C. Words are not separated by spaces or are connected by hyphens (-) and hyphens (_). The first letter of each word is capitalized (Pascal naming method)

Example: FirstName and UserName

4. Data Type

Basic data types: Numeric (byte, short, int, long), float, double), char, and boolean)

Reference Type: class, interface, array, String)

Note: Double quotation marks ("A") are used to indicate the literal quantity of characters. To declare A String, use String name; and

Use "+" in the string to connect the literal

Table-Basic Java Data Types

Data Type Close key Big and small
Node Type Byte 1 byte (8 bits)
Short integer Short 2 bytes (16 bits)
Long Integer Long 8 bytes (64-bit)
Single precision type Float 4 bytes (32 bits)
Dual-precision type Double 8 bytes (64-bit)
Integer Int 4 bytes (32 bits)
Character Type Char 2 bytes (16 bits)
Boolean Boolean Uncertain

Note: boolean values are true and false.

5. Constants

Final data type constant name = constant value;

Example: final double PI = 3.14159;

6. Forced conversion

The forced conversion operator consists of the data types to be forcibly converted in parentheses. ();

When a numeric data expression is used for computing, automatic type conversion is performed from low-precision to high-precision, that is, byte <short <int <long <float <double.

Example: int x;

Double d = 3.5;

X = d; // cannot be compiled

X = (int) d; // compiled

7. Java escape characters

\ B: Return

\ T: Tab

\ N: line feed

\ R: Enter

\ ": Double quotation marks

\ ': Single quotes

\: Backslash

8. Operators

Operators and priorities in Java

Operator class Operator
Pre-or post-increment/Decrement ++ ,--
Unary operator + ,-,~ ,! , (Forced conversion)
Multiplication/Division/modulo *,/, %
Add/subtract/string connection +,-, +
Shift Operator <,>,>
Comparison Operators <, <=,>,> =, Instanceof
Equal Operators = ,! =
Bitwise operators &, |, ^
Conditions AND, OR &, |
Three-object Operator ? :
Value assignment operator =
Extended value assignment operator * =,/=, % =, + =,-=, <=, >=, >>>=, & =, ^ =, | =

A. increment and Decrement Operators

A. Pre-Increment

Example: int x = 5;

Int z = ++ x;

Output: x = 6 z = 6;

B. Post Increment

Example: int x = 5;

Int y = x ++;

Output: x = 6 y = 5;

B. Three-object Operator

Syntax format: (Boolean expression )? X: y;

Example: (x = 5 )? "Yes": "no"; if x is equal to 5, "yes" is displayed; otherwise, "no" is displayed ".

Use the if/else statement: if (x = 5 ){

System. out. println ("yes ");

} Else {

System. out. println ("no ");

}

9. Java annotations

Single line comment ://

Multi-line comment :/*......*/

Text/file note:/**... */(mainly written on the class or method)

 

 

 

 

 

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.