Java data type

zhaozj2021-02-08  337

§ 2.1 Durable

The data type refers to a variable or a formula state and a line. Number of java

According to the type of type:

Java does not support C, C pointer type, junction structure type and common body type.

This chapter we owners should introduce a simple type.

§ 2.2 constant and variables

First, constant

The constant value in Java is indicated by a text string, which is divided into different types.

, Such as intensive constant 123, real constant type 1.23, character constant 'a', Bull constant TRUE,

False and string string constant "this is a constant string.".

Divided with C, C , can not pass the #define command to set a label in Java

Righteous constant, but use the keyword finAl to realize, such as Final Double Pi = 3.14159 (with

See [6.2.3]).

Second, variables

Variable is the basic storage unit in the Java program, and its definition includes variable name

, Variable type and several parts of the field.

1 The variable name is a synergist of a combination, it is a letter, a number, and a next plan.

The sequence of the line or US 元 符 "$", Java points to variable names, variable names

Head with a number, and cannot leave the word. Method of variable names such as: MyName,

Value-1, Dollar $, etc. Non-magical variable names such as: 2mail, room #, Class (Leave

Words), etc., variable names should have a constant meaning to increase the readability of the program.

2 variable types can be used for any of the above-mentioned data types.

3 The action domain of the variable indicates that the variable can be accessed. Speak

The variable is also specified in the same time. Press the work domain, variable

There are several ways to have fewer parts: local variables, class variables, method of method, and exception

Number. Partial variables in a code of the method or the method of the method, its role domain

For the code blocks it is in the code block (a piece of code in the entire method or method).

Class variables are spoiled in the class, rather than in a part of the class, it

The work domain is the entire class.

The method of passing the method is delivered to the method, and its work is this method.

Exquisite processing parameters pass to the exceptional processing code, its work domain is an example

Foreign part of the department.

In a certain domain, the variable name should be only one. Tongmong, one domain

Decide by bulk {}.

There is a customary variable, the parameter transmission and exception processing will be in [6.7.1],

[6.2 .4] and Chapter 8.

4 Vocal format of variables:

Type Identifier [= Value] [, Identifier [= Value] ...];

For example, int a, b, c;

Double D1, D2 = 0.0;

Among them, a plurality of variables are separated from a comma, and D2 = 0.0 is assigned to real-type variable D2.

0.0, only partial variables and class variables can be assigned to initiate, while

The variable value of the exquisite part is given by the call. § 2.3 Integer data

First, intensive constant:

Similar to C, C , the number of Java has three forms:

1 Ten into the integer, such as 123, -456, 0

2 Eight-entered integer, start with 0, such as 0123, show the number of decimers 83, -011

Entering -9.

3 Ten six-to-integer, start with 0x or 0x, such as 0x123

291, -0x12 Meter Tenjin -18.

The whole constant constant accounts for 32 bits in the machine, with an int type value, for the long value, then

To add L or L after the number, such as 123L, a long integer, which accounts for 64 digits in the machine.

Second, integer variables:

The type of integer variable has four types of Byte, Short, Int, long. The following list is listed.

The digits of the various types of memory and their representation are shown.

(Untonged to stay)

The INT type is an integer type of integral use. The data it has indicated is large enough, and it is suitable for 32-bit, 64-bit handlers. However, for large-scale calculations, it will often encounter a large integer, exceeded the range indicated by the int type, which is used to use the long type. Since different machines have different storage modes of multi-byte data, it may be stored from low bytes to high byte, or may be stored from high bytes to low byte, so that when analyzing network protocols or file formats, In order to solve the problem of byte storage on different machines, use the Byte type to indicate that the data is appropriate. In the case of normal circumstances, the number of the representation is very small, which is easy to cause overflow, and should be avoided. The Short type is rarely used, and it limits the deposit of the deposit as a first high byte, the low-low byte, which will be wrong in some machines. Third, the definition of integer variables, such as: byte b; // Specify variable B is BYTE type short s; / / Specify variable S is Short type INT I; // Specify variable I is INT LONG L; // Specify variable L is a long type § 2.4 floating-point (real) data 1. The real constant is the same as C, C , and the normal number of Java has two representations: 1 decimal form, consisting of numbers and decimal points, and must have a decimal point , Such as 0.123, .123, 123., 123.02 scientific counting form. Such as: 123E3 or 123E3, there must be a number before E or E, and the index of E or E will be an integer. The constant is 64 in the machine, with a Double type value. For the Float type, you have to add f or f, such as 12.3f, which accounts for 32 bits in the machine, and the expression is low. Second, the type of real variable real-type variable has two kinds of float and double, which lists the numbers of memory in these two types and their representation ranges. Data Types The range of the number of parts of the number of Float 32 3.4e-038 ~ 3.4e 038double 64 1.7e-308 ~ 1.7e 308 Double precision Type Double Double Compare the single precision type FLOAT has higher precision and greater scope It is often used. Third, the real variable definition, such as float f; // Specify variable f to FLOAT Double D; // Specify variable D is Double type [Note] Unlike C, C , there is no symbolic integer in Java, and clearly regulate The number of memory bytes accounted for integer and floating-point data, which guarantees security, robustness and platform-independence. § 2.5 Character data 1. The character constant character constant constant is a character that is enclosed in a single quotes, such as 'A', 'A'. In addition, with C, C , Java also provides escape characters, opening the head in a counter slash (/), turning it into an additional meaning, the following table lists the transmissions characters in Java. Similar to C, C , the character data in Java is 16-bit unsigned data, which shows the Unicode set, not just ASCII sets, such as / u0061 indicates 'a' of the ISO pull-Ding code.

Essential character description / DDD 1 to 3 bits 8 binding data represented by characters (DDD) / UXXXX 1 to 4-bit 16-based number of characters (XXXX) / 'single quotes characters // backslash characters / R Enter / N Ranking / F Paper Change Page / T Transverse Jumping Grid / B Randide 2, the type of character variable character variable is char, which accounts for 16 bits in the machine, and its range is 0 ~ 65 535. The definition of the character type variable is as follows: CHAR C = 'a'; / / Specifies the variable C to a CHAR type, and the first value is 'A' and C, C , and the character data in Java cannot be used as an integer, because Java No symbolic integer types are not available. But the same can be operated as an integer data. For example: int three = 3; char one = '1'; char fund = (char) (three one); // four = '4' above, when calculating the addition, the character type variable one is converted to an integer , Perform addition, finally convert the results into characters. Third, the string constant is the same, and the string of the string of Java is a string of characters enclosed in double quotes (""), such as "this is a string./n". However, it is not true that the string constant in Java is handled by a pair of String class, not an data. There are customary String, we will tell them in Chapter VII. § 2.6 Bur-type data Bull data has only two values, true and false, and they do not correctly apply any integer values. It is often used in stream control. The definition of the Boolean variable is as follows: Boolean B = true; // Definition B is the Boolean variable, and the initial value is True§ 2.7 Example 2.1, in the following example, the data type mentioned earlier is used, and the screen is displayed value.

转载请注明原文地址:https://www.9cbs.com/read-868.html

New Post(0)