Basic syntax for Java 1

Source: Internet
Author: User
Tags naming convention

First, the Java keyword

The Java keyword is a word that is given a special meaning in the Java language.

A) keywords to define the data type

class interface byte short int longfloat double char boolean void    

b) keywords to define data type values

Nullturefalse

c) keywords to define Process Control

Ifelseswitchcasedefaultwhiledoforbreakcontinuereturn

d) Keywords used to define access rights

Publicprotectedprivete

e) Modifier keywords that define classes, functions, and variables

Abstractfinalstaticsynchronized

f) Keywords for the relationship between classes and classes

Extendsimplements

g) To establish an instance to determine the instance keyword

Newthis superinstaceof

h) for handling exception keywords

Trycatchfinallythrowthrows

i) keywords for the package

Packageimport

j) Other Keywords

Nativestrictfptransientvolatieassert

Note: The Java keyword Military lowercase, some upper caps are due to WPS. Java also has two reserved words: Goto and const

Second, Java identifiers

All components of Java require a name. Class names, variable names, and method names are called identifiers.

1. With regard to Java identifiers, the following points need to be noted:

    1. All identifiers should start with a letter (A-Z or a-Z), a dollar symbol ($), or an underscore (_).
    2. Can be a combination of any character after the first character
    3. Keyword cannot be used as an identifier
    4. Identifiers are case-sensitive
    5. You can use Chinese characters
    6. Cannot start with a number

Example:

Examples of legal identifiers: Age, $salary, _value, __1_value

Examples of illegal identifiers: 123abc,-salary

2. Naming conventions for identifiers

    1. Identifiers to see the meaning of the name
    2. Adopt a canonical naming convention. such as: Hump Name method

Third, Java annotations

Comments are text that is used for annotation descriptions and for interpreting programs. It helps to improve the reading of the code. There are three types of comments in Java, as follows:

A) Single-line comment://.....

The single-line comment only notes one line, ending at the enter of the line.

Please enter your name

System.out.println ("Please enter your. Name here:"););

b) Multi-line Comment:/* ... */

Multiline comments start with/* and end with a multiline annotation with the contents of */* and/*.

                                                         /* SYSTEM.OUT.PRINTLN ("Please enter your:");   int age = In.nextint ();                                  System.out.println ("Please enter your gender here:"); String gender = In.next ();                               */

c) Documentation notes:/** ... */

The main purpose of the document annotation is to describe the source program that we write, which can be extracted from a tool in Java and generated by a document. (Tool for JavaDoc.exe)

The Javadoc.exe tool extracts all the document comments from the Java source code and then generates a Web page file that includes the source code and documentation comments. That is to generate a program specification, this is to facilitate the development and maintenance of two times, this is for programmers to see.

/**                                           * Calculate the current interest rate                              * @param                                Year * The            number of years * @param money *            deposited in the principal                       * @return                                    * * *   

d) The role of annotations:

    1. Annotations can be used to debug code, to locate and narrow the range of errors
    2. Annotated source code to improve the readability of the program, improve the maintenance of the program

Attention:

The comments section is in a file that is not written to the bytecode.

Expand Knowledge Points:

1. Hump Naming method:

A) Variable and method name: The first word is all lowercase, the first letter of the following word is capitalized

b) class name and interface name: Capitalize the first letter of each word

c) Constants: Constants all letters of each word are capitalized, and multiple words are separated by _

2. Markup for document annotations

@author  author @param  The name of the input parameter description  @return output parameter Description @since JDK version @version version number @see link Destination @throws exception @deprecated explanation @link Link Address

Blog: http://www.cnblogs.com/cenzhongman/p/6137351.html

Basic syntax for Java 1

Related Article

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.