JAVAOO Chapter II Knowledge Summary

Source: Internet
Author: User
Tags java keywords

First, the data type

(i), integer type

1 data types are easy-to-read tags that represent specific uses of computer memory.

2 when used in a program, the data type specifies the size of the memory used and the valid values that can be stored in that memory.

3 Java is a strongly typed programming language, which means that all variables used in Java programs must have well-defined data types.

4 AVA defines 4 classes of 8 basic data types

5 Java divides the memory into heap, stack, data area, constant area, code block, and the basic data type is usually placed on the stack.

Logical Type Boolean (Boolean)

Character Char

Integer byte, short, int, long

Floating-point type float,double

Reference data type string string

5 java Each integer type has a fixed number of table range and field length, which is not affected by the specific operating system, to ensure the portability of Java programs.

6 Three representations of the Java-language integer constants: decimal integers, octal integers, hexadecimal numbers.

7 The integer constants of the Java language default to int.

(b), floating-point type

1 similar to integer types, Java floating-point types have a fixed number of table ranges and field lengths that are not affected by the platform.

2 Java floating-point type constants are represented in two forms: decimal number form, exponential form.

(c), character type

1 char data is used to denote "characters" in the usual sense.

A 2-character constant is a single character enclosed in single quotation marks.

3 Java characters are Unicode encoded, and each character occupies two bytes. The code for ' A ' is: 65 and so on, the code of ' A ' is: 97 and so on

4 The Java language also allows the use of the escape character ' \ ' to convert subsequent characters to other meanings. For example ' \ n ', ' \ t '.

(d), logical (Boolean)

1 Boolean types are suitable for logical operations and are generally used for program flow control.

2 Boolean type data only allows values of true or false to be substituted for false and true for integers of 0 or not 0, which differs from C language.

Ii. declaring variables and creating variables

Java variables are the most basic storage units in a program, and their features include data types, variable names, and variable values.

Each variable in a Java program belongs to a specific data type, which must be declared before use, in the form of a data type variable name, variable value;

A variable is actually a small area of memory, using the variable name to access the area;

After declaring a variable, you should initialize the variable (habit)

Initialization syntax: data type variable name = initial value;

Third, Java constants

The constant area of Java is divided into different data types.

Note: Differentiate between character constants and string constants.

The Java floating-point constant defaults to double, and if you want to declare a constant of type float, you need to add F or F after the number.

We can also give a constant an identifier name syntax: Final data type variable name = constant value;

Must be assigned when a symbolic constant is declared

cannot be changed throughout the program cannot be re-assigned value

The advantages of using symbolic constants are:

The meaning is clear. As in the above program, you can tell from price when you look at the program that it represents prices.

When you need to change a constant, you can "change the whole change". For example, in the program to use the price of an item, if the price is expressed in constant, then in the price adjustment, you need to make changes in the program, if the symbol constant price to represent prices, just change a place.

Iv. identifiers

As the name implies, an identifier is a variety of character sequence symbols in a computer language, indicating a particular meaning

User-defined identifiers

System-defined Identifiers

(i), Java identifier naming rules:

The 1 identifier consists of a letter, an underscore "_", a dollar symbol "$", or a number.

2 identifiers should start with a letter, underscore, dollar symbol.

3 Java identifiers are case sensitive and have unlimited length.

4 "See the name and know It"

5 cannot be a keyword

6 adherence to the rule of the Hump nomenclature

(ii), custom identifiers

The name used to identify the variables, symbol constants, methods, and so on in the program.

Any place you can name yourself is a custom identifier.

Naming Special habits:

1 Custom identifiers cannot have duplicate names with keywords.

2 The variable name is all lowercase (if it consists of multiple words, the first letter of the following word is capitalized)

3 constant names are all uppercase

Five, key words

Some of the specific meanings in Java are called keywords (keyword), which are used as specialized strings.

Most editors mark keywords in a special way.

All Java keywords are in lowercase english.

VI. Basic Data type conversions

Automatic data type conversion float F = 2 + 3.3f;

The small size of the type is automatically converted to a large data type;

Force data type conversions int x = 2.3; int x = (int) 2.3;

Add a cast character, but may result in a decrease or overflow of precision, especially when used.

The Boolean type cannot be converted to another data type.

A floating-point constant (for example: 1.2) defaults to double. To declare a constant of type float, you need to add F or F after the number.

An integer constant (for example: 123) defaults to int. Declares that a long constant can be followed by an ' l ' or ' l '.

JAVAOO Chapter II Knowledge Summary

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.