Java third Day-porting of programs

Source: Internet
Author: User
Tags java keywords

One, right button->import->general->existing Projects into workspace->browse-> Select File
Ii. Methods of Learning

Third, the Java keyword
Some words in the Java language that have special uses are called keywords. The keyword on the Java compiler has a special meaning, in the application of the program must be cautious Oh!!
Common keywords in Java:

Java keywords are case-sensitive Oh! So void is the keyword, but void is not the ~ ~

Iv. identifiers
Identifiers are symbols that are used to name variables, classes, methods, and so on in a Java program.

There are several rules to follow when using identifiers:

1. Identifiers can consist of letters, numbers, underscores (_), dollar symbols ($) , but cannot contain other special characters, such as @,%, space, etc. , and cannot begin with a number . For example: 123name is not legal drop

2. Identifiers cannot be Java keywords and reserved words (Java reserved keywords, which may be used as keywords in later versions of the upgrade), but can contain keywords and reserved words. For example, void may not be used as an identifier, but myvoid can

3. Identifiers are strictly case-sensitive . So nirvana, be sure to distinguish between Chu Imooc and Imooc is two different identifiers Oh!

4. The name of the identifier should best reflect its role, to be known .

V. variables

In Java, we describe variables by three elements: variable type, variable name , and variable value .

1, the variable name consists of multiple words, the first letter lowercase , followed by the first letter of the word capitalization , commonly known as camel-named method (also known as hump name), such as MyAge

2, when the variable name, as short as possible and can clearly express the role of variables, do see the name of understanding . Such as: Define variable name stuname save "student name" information

The length of the Ps:java variable name is not limited , but the Java language is case-sensitive , so price and price are two completely different variables Oh!


Vi.data types in Java
The Java language is a strongly typed language. The popular point is that the data stored in Java is typed and must be determined at compile time. There are two kinds of data types in Java:

In the Java domain , the basic data type variable is stored in the data itself , whereas the reference type variable holds the spatial address of the saved data. Frankly, the basic data type variables are stored directly in the drawer, and the reference data type variable is stored in the drawer key, key and drawer one by one corresponding.

The common basic data types are:

string is a common reference data type that is used to represent a string. In the development of programs, many operations are done using strings, such as user names, passwords, e-mail addresses, etc. in the system.
Vii.Automatic type conversion in Java

The int variable score1 in the code can perform the assignment directly for the double type variable score2, and the result is: 82.0

This conversion is called automatic type conversion .

Of course automatic type conversions are required to meet specific conditions :

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


Viii.Forced-type conversions in Java

How do you do this when you need to assign the value of a double variable to an int variable?

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 .

Ix.Application of Java constants

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;

Using Constants in your program can improve the maintainability of your code. For example, in project development, we need to specify the user's gender, at this time can be defined as a constant sex, assigned to "male", in the need to specify a user-specific place to call this constant directly, to avoid the user's non-standard assignment caused the program error situation.

Guys, watch out.: Constant names generally use uppercase characters

X. How to use annotations in Java

When you write a program, you often need to add some comments to describe the role of a piece of code.

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

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

Open the home page to view the generated API 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

Java third Day-porting of programs

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.