Java Basic syntax

Source: Internet
Author: User

Identifiers: Identifiers are words that we use in Java code.

In Java, we need to identify many elements in the code, including class names, methods, fields, variables, package names, and so on. The name we choose is called an identifier and must follow the following rules:

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

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

3. The first letter of the identifier must be a letter, an underscore (-), or a dollar sign ($).

4. Identifiers are case-sensitive, but do not limit the length.

II. data types, variables, and constants

Java data types fall into two categories:

1. Basic types

Integer: Byte, short, int, long

Float type: float, double

Character type: Char

Boolean Type: Boolean

2. Reference types

Classes: Class

Interface: interface

Array

Declaration of variables: used to hold data of the specified type.

Syntax for variable declarations: data type + variable name; (variables can be assigned using the = symbol while declaring)

Considerations for variables:

1. Length: Different data types, different lengths in memory, error if data type exceeds range.

2. Initialize: The variable must be initialized when it is used and operation, otherwise it will error.

3. Type immutable: The variable defines the type, it cannot hold other types of data, otherwise it will error.

Variables of type 4.int do not use a float, double to define the type of the variable, although it does not error but not high efficiency.

Declaration of a constant: the final type variable = value;

Type conversions are divided into two types:

1. Implicit conversion: Low-level to advanced conversion, automatic conversion.

2. Cast: advanced to low-level conversion.

When performing an expression operation, the rule is automatically lifted:

1. All byte, short, and char types will be promoted to the int type.

2. If one of the operands is a long type, then the computer result is a long type.

3. If one of the operands is of type float, the result is a float type.

4. If one of the operands is of type double, then the computer result is a double type.

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.