[Java Getting Started note] Java Language Basics (i): Annotations, identifiers, and keywords

Source: Internet
Author: User

Comment What is a comment?

A note is a piece of code, a method, or a class that is written in the code so that you can read the code easily. The annotated content will not be compiled or executed .

Java annotations are divided into three types: single-line comments, multiline comments, and document annotations.

Single-line comments and multiline comments

Single-line comments comment a line of text or code in the program, and in Java, use "//" for a single line comment. Multi-line annotations can comment multiple lines of code at once, using "/*" in Java to start with a multiline comment, "*/" for the end of multiple lines of comments

Cases:

 Public class commenttest{    publicstaticvoid  main (string[] args) {        //  This is a single-line comment        / *         Multiline Comment The first row        second line         *        //  System.out.println ("commented code will not compile and run");        SYSTEM.OUT.PRINTLN ("Code not commented");}    }

Eclipse Comment Accelerator: ctrl+/single-line comment and uncomment; ctrl+shift+/Add/* */comment; ctrl+shift+\/* */Comment

Document comments

Annotations added with document comments can be generated using the document generation tool Javadoc to generate API documentation, and the Javadoc tool only handles annotations in the document source text in front of public and protected-decorated classes, interfaces, methods, Field, constructors, and inner classes.

The document comment begins with "/**" and ends with "*/". The middle part is the document comment, which is generated into the API documentation.

Cases:

/*** This is a test class for document annotations *@authorPing **/ Public classTest {/**This is a filed*/     Public inti; /*** This is the main method of the program *@paramargs*/     Public Static voidMain (string[] args) {}}

You can refer to the following two articles about generating JAVAAPI documents:

To generate an API help document with the Javadoc command

How eclipse generates Javadoc

Identifiers and keyword separators

The delimiters in Java include semicolons (;), curly braces ({}), brackets ([]), parentheses (()), spaces, dots (.), all symbols in English, which are especially important when writing code.

Semicolon: In Java, line breaks do not represent the end of a statement, only semicolons represent the end of a statement, so it is theoretically possible to write multiple statements in a row, but this is not recommended, which can affect the readability of the code and make the code look cluttered.

Curly braces: A pair of curly braces represents a block of statements that need to appear in pairs.

Square brackets: Used for arrays, defining arrays, and accessing array elements, and also need to be used in pairs.

Parentheses: When you define a method to contain formal parameters, call methods and construct methods, you need to have parentheses.

Spaces: Used to split multiple parts of a statement.

Dot: Used as a member of a class using objects and classes.

Identifier

Identifiers are symbols that are used to name classes, methods, and variables in a program. Java identifiers have the following characteristics:

    • is case sensitive.
    • You must start with a character, underscore, dollar sign, followed by characters, underscores, dollar signs, and four elements of a number. Character is not limited to English characters, can be Chinese characters and other countries of the text.
    • You cannot include special symbols other than underscores, spaces, and so on.
    • Cannot be a keyword in java.
Key words

A total of 48 keywords and two reserved words (Goto/const) are included in Java.

Refer to the following article for more information:

The Java keyword and its role

[Java Getting Started note] Java Language Basics (i): Annotations, identifiers, and keywords

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.