Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of keywords in Java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the knowledge points of keywords in Java", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the knowledge points of keywords in Java" can help you solve your doubts.

Basic syntax of java

I. keywords

Definition: a string that is given a special meaning by the Java language and used for special purposes

Features: all letters in keywords are lowercase

II. Identifier

Definition: the sequence of characters used by java to name elements such as variables, methods, and classes is called identifiers (identifiers wherever you can name them).

Legal rules:

1. Consists of 26 English letters in uppercase and lowercase, 0-9 _ or $

two。 A number cannot begin.

3. Keywords or reserved words cannot be used, but can contain keywords and reserved words

In 4.Java, there is strict case sensitivity and unlimited length.

5. Identifiers cannot contain spaces

Naming convention:

1. Package name: when multiple words are formed, all letters are lowercase: xxxyyyzzz

two。 Class name, interface name: when multiple words are composed, the first letter of all words is capitalized: XxxYyyZzz

3. Variable name, method name: when multiple words are formed, the first letter of the first word is lowercase, and the second word begins with an uppercase letter of each word: xxxYyyZzz

4. Constant name: all letters should be capitalized. When multiple words are made up, each word is connected by a new line: XXX_YYY_ZZZ.

III. Variables

Concept:

1. Is a storage area in memory

two。 The area has its own name (variable name) and type (data type)

Each variable in 3.java must be declared (defined) before using the

4. The data in this area can change continuously within the same type range (for example, declare int I = 1 first; then declare I = 2; then the value of I changes from 1 to 2)

5. The variable accesses this area through the variable name

Define variable format: data type variable name = initialization value

Note:

1. Scope of variable: valid between pair {}

two。 Must have an initialization value (assign a value to the variable for the first time): for example, int I = 0; if only int m; it is wrong because the variable is not initialized

3. The = in the process of declaring a variable, unlike the mathematical =, represents an assignment in java.

Classification of variables-by data type (all but 8 basic data types are reference data types)

8 basic data types

1. Integer types: byte, short, int, long

Note:

Each integer type of 1.java has a fixed table range and byte length, which is not affected by specific OS, so as to ensure the portability of java programs. For example, byte b = 129exceeds the table range of byte and is illegal.

The integer constant of 2.java defaults to type int

3. Declare a long constant followed by'l' or'L' (long integer) for example: long l = 6L (preferably uppercase L, because lowercase l is similar to 1)

two。 Floating point type: float, double

Note:

1.Java floating-point types also have fixed table ranges and field lengths, which are not affected by OS

The floating-point type constant of 2.Java defaults to double type

3. Declare a constant of type float, followed by'f'or'F'

4. Floating-point constants have two representations: decimal numbers (such as 5.12512.0f. 512) must have a decimal point

The "E + number" at the end of the scientific counting form (such as 512 512E2 100E-2) indicates how many powers the number before E should be multiplied by 10. For example, 3140 is 3.14 x 10-3 = 3140. 3.14 E + 3 is 3.14 x 10-3 = 0.00314.

3. Character type: char

Note:

1.char data is used to represent "characters" in the usual sense (2 bytes).

two。 The expression of character constant: a character constant is a single character enclosed in English single quotation marks, covering all written language characters in the world. For example: char C1 = 'asides'; char c2 = '6percent; char c3 =' medium'

The escape character'\'is also allowed in Java to convert subsequent characters into special character-type constants. For example: char c3 ='\ n'; / /'\ n 'indicates a newline character

The 3.char type is operable because it all corresponds to a Unicode code.

Boolean type: boolean

Note: the 1.boolean type is suitable for logic operations and is generally used for program flow control: if conditional control statements; while loop control statements; do-while loop control statements; for loop control statements.

Only values true and false are allowed for 2.boolean type data. No null (true and false cannot be replaced with 0 or non-0 integers) for example: boolean b1 = true; or boolean b1 = false

Beyond the basic type is the reference type: for example, the String class

Characteristics of reference types:

1. In Java, a variable of a reference type is very similar to a pointer to Cstroke +. The reference type points to an object, and the variable pointing to the object is the reference variable. These variables are specified as a specific type when declared, such as Employee, Puppy, and so on. Once a variable is declared, the type cannot be changed.

two。 Objects and arrays are reference data types.

3. The default value for all reference types is null.

4. A reference variable can be used to reference any type that is compatible with it.

String class:

1. The value null can be assigned to a variable of any reference type to show that the address stored in the reference variable is empty. The String class belongs to the reference type and can be assigned by null.

The 2.String class is a typical immutable class, and the String object cannot be changed when it is created. The created string will be stored in the data area, ensuring that there is only one constant for each string and will not produce multiple copies such as: int i0 = 1; int i1 = 1; in this case, two 1 values are stored in memory, while String S0 = "hello"; String S1 = "hello" In this case, there will only be a "hello" in memory, assuming that the memory address of "hello" is xxxxxx. When declaring the S0 variable, assigning the value "hello" to S0 actually causes the S0 variable to refer to the memory address xxxxxx of "hello". When we declare that the variable S1 is also assigned to "hello", we actually directly refer the memory address of the existing "hello" to S1.

3.String classes can be concatenated with a plus sign, for example: String S3 = "he" + "ll" + "o"; output as "hello"

Basic data type conversion

1. Automatic type conversion: data types with small capacity are automatically converted to data types with large capacity, and the data types are sorted by capacity as follows:

two。 When there are multiple types of data mixed operation, the system first automatically converts all the data into the data type with the largest capacity, and then calculates it.

3. There is no conversion between byte.Byte and int, and the three of them are first converted to Bytec when calculating.

4. When concatenating a value of any basic type with a string (+), the value of the basic type is automatically converted to the string type

Note: 1. You cannot cast a boolean type.

two。 You cannot convert an object type to an object of an unrelated class.

3. Cast must be used when converting a type with large capacity to a type with small capacity.

4. The conversion process may result in overflow or loss of precision, for example:

Int I = 128,

Byte b = (byte) I

Because the byte type is 8 bits and the maximum value is 127, when int is cast to byte type, the value 128 will cause an overflow.

5. Floating-point to integer conversion is achieved by discarding decimals rather than rounding, for example:

(int) 23.7 =

(int)-45.89f =-45

6. When there is a series of + operations, if a part contains a string, then the string will be viewed according to string concatenation, for example:

String str = 1 + 2 + 3 + "a" + 4 + 5; the print result is 6a45

Forced type conversion

1. The condition is that the converted data type must be compatible.

two。 Format: (type) value type is the data type after type conversion

Int k = 7

Byte b = (byte) k; / / the converted data type should be enclosed in parentheses

3. In general, strings cannot be converted directly to base types, but strings can be converted to base types through the wrapper class corresponding to the base type.

After reading this, the article "what are the knowledge points of keywords in Java" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report