Variable definitions in Java

Source: Internet
Author: User

You can also assign a value after declaring it first

Automatic type conversion

1. The target type can be compatible with the source type, such as type double compatible int, but char type cannot be compatible with int

2. The target type is greater than the source type, such as the double type is 8 bytes long, the int type is 4 bytes, so the double type of the variable can directly hold the int type of data, but the reverse is not possible

Forcing type conversions

For example, how do you do this when you need to assign the value of a double variable to a variable of type int?

Obviously, this conversion is not automatic! Because the int type has a smaller storage range than a double type. This is done by forcing type conversions.

Syntax: (data type) values

Constant

The so-called constant, which we can understand as a special variable, whose value is set, is not allowed to change during program operation.

Syntax: final constant name = value;

Comments

In general, for a specification of the program source code, the note should be accounted for more than 1/3 of the source code. Therefore, note is an important part of the program source code, we must pay attention to Oh!

There are three types of annotations in Java: single-line comments, multiline comments, document annotations

Run Result: Hello imooc!

We can use the Javadoc command to extract the content from the documentation comments and generate the program's API help documentation.

PS: You can also use the Javadoc tag when using document annotations to generate more detailed document information:

@author identify the author of the development of such modules

@version indicate the version of the module

@see reference steering, i.e. related topics

@param a description of a parameter in the method

@return Description of the return value of the method

@exception description of the exceptions that the method might throw

Variable definitions in Java

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.