Three variables and data types of Java: Data Types and escape character

Hello everyone, small music again, Previous: Le Java byte data type of the two variables: Java constants and variables,

Today, Java variables and then say three types of data: data types with the escape character

 

A data type

1. Definitions

Java is a strongly typed language, data are provided for each corresponding data type.

Java data types

2, classification

A: Basic Data Type: eight kinds of class 4

B: reference data types: class, interface, array.

3, the basic data types

① integer number of bits occupying byte / bit range

byte (byte) 18 bits [-128, 127]

short (short integer) 2 16 [-32768, 32767]

int (integer) 4 32 [-21 million 2100000000]

long (long integer) 8. 64 very big

Note: The default value of an integer type int, long if you need to define a variable of type int when out of range, the need to increase the value l or when L

② float

float (single-precision) 4

double (double precision) 8

Bit 7 is effectively float, double significant bit is 14

Note: The default type double floating point, if you need to define a variable of type float, the value f or the need to add F

③ character (0 to 65535)

char (character) a character can store 2 a Chinese characters

Requirements: The '' character enclosed

④ Logical (Boolean)

boolean (Boolean) 1

4, note:

The default integer type is int, float Default is double.

To add long integers L or l, single-precision floating-point add to F or f.

 

Second, the data type conversion

1. Definitions

boolean type does not participate in the conversion

2, the default conversion

A: small to large

B:byte,short,char --> int long float double

C: between byte, short, char is the same level, not interchangeable, transferred directly involved in computing an int.

3, cast

A: descending

B: There may be loss of accuracy is generally not recommended for such use.

C: format:

The target variable name = data type (data type target) (converted data);

4 Questions and interview questions:

A: Is there a difference two ways?

float f1 = 12.345f;

float f2 = (float) 12.345; downcasting, the default floating-point type double

B: The following program has a problem, and if so, where is it?

byte b1 = 3;

byte b2 = 4;

byte b3 = b1 + b2;

short s1=3;

short s2=3;

short s3=s1+s2;

char c1=3;

char c2=4;

char c3=c1+c2;

byte, short, char during operation, automatically upcast int type, the returned result is int type, int type received are not, because the type does not match, the error

byte b4 = 3 + 4;

short s=3+4;

Value is calculated constant, when the pre-compiler can determine whether it is out of range

int a=1;

int b=2;

int c=a+b;

long l1=3l;

long l2=3l;

long l3=l1+l2;

float f1=2.3f;

float f2=2.3f;

float f3=f1+f2;

double d1=3.7;

double d2=3.9;

double d3=d1+d2;

Are not being given, java optimized.

C: What is it the result of the following actions?

byte b = (byte)130;

D: characters involved in computing

It is to look inside the ASCII value

'a' 97

'A' 65

'0' 48

Space 32

System.out.println('a');

System.out.println('a' + 1);

E: String involved in computing

In fact, here is the connection string

System.out.println("hello"+'a'+1);

System.out.println('a'+1+"hello");

System.out.println("5+5="+5+5);

System.out.println(5+5+"=5+5");

Operating results: helloa1

98hello

5+5=55

10=5+5

 

Third, the escape character

\ ': Represents a single quote

\\: Represents a backslash character "\"

\ ": Represents a double quote character

\ B: backspace, is to move the cursor to a character before the current character, it does not delete the current character.

Note: eclipse which does not recognize the need to run in a DOS environment

\ N: line feed, the current position to the beginning of the next line

Enter the beginning, the current position to move to the Bank: \ r

Note: \ n, \ r no difference in eclipse, you need to run in a DOS environment

\ T: Horizontal tab position: Tab jumps to the next position

Guess you like

Origin www.cnblogs.com/lotbyte/p/11139878.html