Java Simple syntax

Source: Internet
Author: User

First, identifiers

Definition: The naming mark used when naming individual elements in a program is called a marker.

Basic composition: Consists of numbers, letters, underscores, dollar signs ($). It is not possible to start with a number. For example: Identifier,username,user_name, $sys and so on.

Rule: 1) the same marker, which is unique within the same area, can be used multiple times in different regions.

2) You cannot use spaces to delimit markers.

3) class name: Capitalize the first letter of each word. such as dog, Newdog and so on.

In the method: the first letter is lowercase, the remaining initials are capitalized, and as few underscores as possible.

Variable: The constant name of the base data type uses all uppercase letters, and the words are separated by underscores. Object constants can be mixed in size.

Constants: Can be mixed in case, first letter lowercase, inter-word separator with the first letter of the word uppercase. Don't underline, use the dollar sign less.

Package name: all letters lowercase.

Ii. expressions

Definition: A sequence of expressions composed of identifiers and operators.

Classification:

Comma expression (delimited expression): int a,double b;
Question-Mark expression: Expression1? Expression2:expression3

Expression1 is a Boolean expression. If the value of the expression1 expression is true, the value of expression2 is taken, and if the expression1 value is false, the value of Expression3 is taken.
Logical expression: a meaningful expression that uses a logical operator to concatenate a relationship expression or a logical amount is called a logical representation. The value of a logical expression is a logical value, which is "true" or "false".

Third, modifier

Java provides a public,private,protected of three access modifiers, providing four control systems:

Public: Publicly available and can be accessed arbitrarily.

Protected: Protected Permissions. Modifies properties, methods. can be accessed in the same package, with different package access, which must be a subclass of the class to be accessible.

Private: can only be accessed within this.

Default: The same package permission can only be accessed by the same package class.

Four, the package

Definition: A package is a collection of logically related classes that can be understood as a folder where multiple files are loaded, where the file is a class, and the content is the class body, and the object is decorated.

Function: The package has two functions. Control access and avoid class names.

Naming conventions: The type of the project + the name of the company to which the project is developed or run + the name of the project + the name of the module.

The type of the project, such as com,org,gov, generally we take com.
The name of the company to be developed or run by the project, such as: Chinasofti,icss,huawei, etc.
The name of the project, such as: JISUAN,BCMS,OA,ERP, etc.
The name of the project module, such as: Bean,action,exception,chapter01, remember that the package name is lowercase.

Here, for example, we are going to create a package that can compute the addition, so name it: Com.zhongruan.calculation.jiafa

Java Simple 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.