Return of the method of use
private static int test () {
int count = 0;
for (int i = 0; i < i++) {
for (int j = 0; J <; J + +) {
count++;
System.out.println ("i=" + i + ", j=" + j);
if (j = = 5) {
return count;
}
}
}
return 0;
}
###### (6), switch statement can function on a byte, can function on a long, can function on a string?
The switch statement can act on a byte, short, char, int, String, enum, wrapper class object.
Other basic data types and reference data types are not eligible for case.
###### (7), short S1 = 1; S1 = s1 + 1; what's wrong? Short S1 = 1; S1 + = 1; what's wrong?
for short S1 = 1; S1 = s1 + 1; Because the type of the expression is automatically promoted by the s1+1 operation, the result is of type int, and when assigned to the short type S1, the compiler reports an error that requires a cast type.
for short S1 = 1; S1 + = 1; since + = is a Java-language-defined operator, the Java compiler will treat it specially, so it compiles correctly.
###### (8), char type variable can not be stored in a Chinese character? Why?
A char can be stored as a Chinese character, because Char is used to store Unicode encoded characters, and the Unicode encoding character set contains Chinese characters.
Supplemental Note: Unicode encoding consumes two bytes, so variables of type char are also two bytes.
###### (9), using the most efficient method to calculate 2 times 8 and so on?
2 << 3 Since a number is shifted to the left n bit, it is equivalent to multiplying by 2 of the N-square, then a number multiplied by 8 to move it to the left 3 bits, and the bit operation CPU directly supported, the most efficient, so, 2 times 8 and several of the most efficient method is 2 << 3.
###### (10), when a variable is decorated with the final keyword, is the reference variable immutable or does the referenced object not change?
The reference variable cannot be changed, the contents of the object to which the reference variable is pointing can be changed, but the new object cannot be used again.
例1:如下面代码,编译就会出错 final StringBuffer a=new StringBuffer("immutable"); a=new StringBuffer("");例2:如下面代码,编译正确 final StringBuffer a=new StringBuffer("immutable"); a.append(“123”);
What is the difference between ###### (11), "= =" and the Equals method?
Their difference is primarily in the reference data type:
1.== is compared with memory addresses to compare objects on both sides of the same object;
2.equals is a method, the default is the memory address comparison, after overriding, is mainly used to compare the two sides of the value of the object is the same, and the implementation of the Equals method is related;
Note: = = can be null on both sides, but the reference to the left of equals cannot be empty, otherwise a nullpointerexception exception will occur.
What is the difference between ###### (12), static variables, and instance variables?
1. The difference in syntax definitions: Static variables are added before the variable, and the instance variables are not added.
2. Differences in program operation:
An instance variable is a property of an object, and an instance object must be created where the instance variable is allocated space before the instance variable can be used.
Static variables are not part of an instance object, but belong to a class, so also known as class variables, as long as the program loads the class's bytecode, without creating any instance objects, static variables will be allocated space, static variables can be used.
In summary, an instance variable must be created before it can be used by the object, and a static variable can be referenced directly using the class name.
###### (13), is it possible to make a call to a non-static method from within a static method?
No.
Because a non-static method (instance method) is to be associated with an object, you must create an object before you can make a method call on the object, and the static method call does not need to create the object, which can be called directly.
That is, when a static method is called, there may not be any instance objects created, and if a call to a non-static method is emitted from a static method, which object does that non-static method relate to? This logic cannot be set up, so a static method is issued inside a call to a non-static method.
What is the difference between ###### (14), Integer and int?
1.int is one of the 8 raw data types provided by Java, meaning integer, which takes up 4 bytes.
2.Integer is the wrapper class provided by Java for Int and is the reference data type.
The default value for 3.int is 0, and the default value for integer is null, that is, the integer can distinguish between unassigned and a value of 0, and int cannot express an unassigned condition. For example, if you want to express the difference between not taking an exam and 0 of your exam results, you can use only integer.
4. In JSP development, the default for integer is null, so when displayed in a text box with an El expression, the value is a blank string, and the default value of int is 0, so when displayed in a text box with an El expression, the result is 0, so int does not work as a type of form data for the Web tier.
5. In hibernate, if the OID is defined as an integer type, hibernate can determine whether an object is temporary based on whether its value is null or not, and if the OID is defined for the int type, It is also necessary to set its Unsaved-value property to 0 in the HBM mapping file.
6. In addition, the integer provides multiple integer-related operations, such as converting a string to an integer, and a constant that represents the maximum and minimum values for an integer is also defined in the integer.
###### (15), Math.Round (11.5) equals how much? How much does Math.Round (-11.5) equal?
The result of Math.Round (11.5) is 12,math.round (-11.5) as a result of-11.
Parsing: The Math class provides three methods related to rounding: Ceil, floor, and round, which correspond to the meanings of their English names.
For example: The English meaning of the ceil is the ceiling, the method represents the upward rounding, the result of Math.ceil (11.3) is the result of 12,math.ceil (-11.3) is the -11;floor of the English meaning is the floor, the method is to be rounded down, math.ceil ( 11.6) The result of 11,math.ceil (-11.6) is-12.
###### (16), what's wrong with the code below?