Band of Brothers Grammar Java Java syntax based on the classic face questions

1. Java language has several basic types? What are they? Please elaborate on the scope of each type and size of the space occupied?

Java language has 8 basic types, which are representative of shaping byte, short, int, and long, on behalf of the floating-point type float and double, char representing characters has represented Boolean boolean.

byte: 8-bit binary, -27 ~ 27-1.

short: 16-bit binary, -215 ~ 215-1.

int: 32-bit binary, -231 ~ 231-1.

long: 64-bit binary, -263 ~ 263-1.

float: 32-bit binary, -3.4 ~ 3.4 * 1038 * 1038.

double: 64-bit binary, -1.7 to 1.7 * 10308 * 10308.

char: 16-bit binary, 0 to 65535.

boolean: boolean type is special in that only said true and false, so in theory only one byte can be expressed using 0 and 1.

 

2. What is a variable?

When a single content data to be recorded in the program, can be used to record a variable, the variable nature of the application is a memory area in the memory, and the data contents of the area may change, hence the name variable. Since different data contents stored in the desired memory results in different sizes, to be described address information is recorded using the concept of data types in the Java language, and the concept of the designated region of a variable name.

 

3. Identifier (variable name) naming convention?

Java identifier made up of letters, numbers, underscores and dollar sign, where the numbers do not begin with, because Java can be used in digital literal, if the compiler starts with a number mistakenly think that this is literal rather than a numeric identifier.

Java identifier can not be the same as Java keywords, JavaSE 8 contains 50 keywords, the Java language is used to represent the special meaning of the word.

Java identifiers strictly case-sensitive.

Java identifier length is not limited, but does not recommend the use of long identifiers.

Java identifier support Chinese, but strongly recommended the use of Chinese.

 

4. Decimal integer in the range of a single byte (8 bits binary) represented by?

In the computer occupies a single byte 8 bits, the maximum represented by symbols indicate positive and negative numbers.

A single-byte binary integer range representation is: 0000 0000 ~ 01111111.

Using the weighted method, so that each of the binary number is multiplied by the weight of the current bit, then all summed together to give the opportunity to decimal number.

0000 0000 => 0

0111 1111 => 0*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20

=> 64 + 32 + 16 + 8 + 4 + 2 + 1

=> 127

Single byte binary negative integer range representation is: 1000 0000 1111 1111 ~.

Binary Decimal negative first binary number minus 1 bits then inverted, and then combined using weighting as a decimal integer, a negative sign is added last.

10000000 => Save 1: 01,111,111

=> Bitwise: 1000 0000

=> Decimal Conversion: 128

=> Add negative sign: -128

11111111 => Save 1: 11,111,110

=> Bitwise: 0000 0001

=> Decimal Conversion: 1

=> Minus sign: -1

Therefore, a single byte decimal integer in the range: -128 to 127.

 

5. In the Java language, how to represent a character? In the Java language, how to represent a Chinese character?

In the Java language, using the char type represents a character, Java language specification, the char is two bytes 16 bits. In fact, char is an unsigned integer type, range is 0 to 65535, but the underlying Java uses the Unicode character set supports all the characters in the world, so in Java char type is designed to represent Unicode character encoding is not an integer. Unicode contains Chinese characters, so you can use char represent a Chinese character in Java.

 

6. What is a data type conversion? Data type conversion There are several ways?

Data type conversion is a type of data into another type of data. Java conversion between data types fall into two categories:

Automatic type conversions: Automatic data type conversion means to convert small range between a wide range, does not require human intervention to complete the conversion automatically.

Cast: cast refers to the conversion of data between a small range, it is necessary to use a wide range from the variable name "(data type)" cast manner. Casts may result in loss of data.

7. Former ++ / - and after ++ / - What is the difference?

+ Represents addition operator, ++ means increment operator, ++ will add a value of the variable itself and then assigned to the variable. ++ i / i ++ is equivalent to i = i + 1.

- represents a subtraction operator, - indicates decrement operator, - let the variable value minus 1 itself then assigned to the variable. --i / i-- equal to i = i-1.

Before ++ / - or after ++ / - if present in the expression, then / front ++ - first variable value is incremented by 1 / minus 1 and then use this variable, the + / - is to use the variable, then the variable value plus 1 / minus 1. If used alone before ++ / - or after ++ / -, they make no difference.

 And & && logical operators are represented by logic and meaning equivalent of "and", only the sides of the operator results are true, the final result to be true, if there was a result of the expression is false, then the entire expression is false. Use & will evaluate the expression of both sides, and the use &&, if the value of the left side of the expression can already determine the value of the whole expression when (the result of the left expression is false, then the entire expression on some false), it does not calculate the value of the second expression.

Guess you like

Origin www.cnblogs.com/itxdl/p/11261968.html