Introduction to Java first quarter chapter II variables and constants

Source: Internet
Author: User

This is my lesson Web Java course notes, the original video link is: http://www.imooc.com/learn/85

2-1 keywords in Java

Ps:Java keyword case sensitive

2-2 Understanding Java 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:The ① identifier can be letters, numbers, underscores (_), dollar characters ($)But cannot contain other special characters, such as @,%, space, cannot start with a number。 ② identifier can't beJava Key WordsAnd Reserved Words(Java reserved keywords, which are likely to be keywords in later versions of the upgrade). However, you can include keywords and reserved words. For example: Void is not available, but myvoid can. The ③ identifier is strictly case-sensitiveOf The name of the ④ identifier is best reflected in the function, to See the name and know it.
What are the 2-3 variables?
In Java, we describe variables by three elements: Variable TypeVariable nameAnd Variable Value





2-4 How to name Java variables


A good engineer's habit: ① variable names are made up of multiple words, first letter in lowercase, followed by the first letter of a word, commonly known as camel-named method (also called Hump name method), such as the Myage② variable name, as short as possible and can clear the role of the expression variable, to do See the name of the idea。 For example: Define variable name stuname save "student name" Information Ps:java variable name No limit on length, but the Java language is Case DifferenceOf
2-5 data types in Java
The Java language is a strongly typed languages。 The popular point is that the data stored in Java is typed and must be determined at compile time.
Ps: byte byte typeis the smallest data type in Java, which occupies 8 bits in memory and ranges from -128~127.  Char Character type2 bytes in memory, representing a character, or you can assign a value to a variable of type char using a value in the range of ASCII code. Since the character does not have a negative range in memory, the value range is from 0~65535.
In the realm of Java, basic data type variablesSaved is The data itself, while Reference type variableSave is saved. the spatial address of the data
the common basic data types are:



Stringis a common Reference Data Type, which is used to represent a string. In program development, many operations are done using strings, such as user names, passwords, e-mail addresses, etc. in the system.
2-6 rules for using variables in Java
Variables in the ①java need to be declared after the use of the ② variable, you can declare the variable is initialized at the same time, you can also declare the assignment ③ variable only one value at a time, but you can modify multiple ④main method defined in the variable must first assign a value before you output
⑤ Although there is no error in the syntax, but in the actual development, the variable name is not recommended to use Chinese, easy to create security risks, such as the late cross-platform operation garbled and so on
2-7 Automatic type conversion in Java
In Java programs, it is often necessary to convert data between different basic data types. For example:
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 conversion is required meet a specific conditionOf: ① target type compatible with source type, such as type double compatible int, but char type is not compatible with int type

The ② target type is greater than the source type, such as a double type of 8 bytes and an int type of 4 bytes, so a variable of type double can directly hold data of type int, but not in turn.

2-8 forced type conversions in Java
Syntax: (data type) values
Operation Result:
The conversion is not rounded, but the decimal bit is truncated directly
2-9 Application of Java constants
The so-called constant, 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 code's maintainability。 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. constant names generally use uppercase characters
2-10 How to use annotations in Java
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, annotations are an important part of the program's source code.
There are three types of annotations in Java: single-line comment, multiline comment, document comment

We can pass Javadoc The command extracts the content from the document comments and generates the program's API help documentation.

Open the home page to view the generated API documentation

PS: When working with document annotations, you can also use Javadoc MarkTo generate more detailed documentation information. @author Identify the author of this module @version the version of the module @see Reference steering, that is, related topics @param description of a parameter in the method @return description of the method return value @exception Description of the possible exceptions to the method

Introduction to Java first quarter chapter II variables and constants

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.