Small ape learning Java circle share face questions 2019Java

Although gold and three silver four door is over but I'll have to come to the graduation season, many students every day Whisper small circle ape teacher, would like to ask interview skills, the teacher can only say that the most important thing is the ability to interview, so small ape circle gave you compiled some relatively high frequency of occurrence of interview questions, hope can help to you.

1, a ".java" source files may include a plurality of whether the class (not an internal class)? What are the limits? There can be multiple classes, but only one public class, and the public class name must be consistent with the file name.

2, Java has no goto? Java reserved words in, there is no use in java.

3, talk about the difference and & & &. & && and can be used as the logical AND operator, and represents a logical (and), when the result of the expression operators on both sides are true, the result was the entire operation is true, otherwise, as long as one of them is false, then the result is false. && also has a function of short circuit, i.e. if the first expression is false, the second expression no longer, e.g., for if (str! = Null &&! Str.equals (s)) expression, when str is when null, the latter expression does not occur, so no NullPointerException if && change & will throw a NullPointerException. If (x == 33 & ++ y> 0) y grow, If (x == 33 && ++ y> 0) will not grow & bitwise operators may also be used, when both sides of the expression & operator when the type is not a boolean, & represents a bitwise aND operation, we typically use computing and & 0x0f to an integer, to obtain the lowest 4 bits of the bit integer, for example, as a result of 0x31 & 0x0f 0x01.

4, how to jump out of the current multiple nested loops in JAVA? In Java, to multi-loop out, a label can be defined before the outer loop, with the break statement label and then use the code in the loop body layer, to the outer loop out. For example: for (int i = 0; i <10; i ++) {for (intj = 0; j <10; j ++) {System.out.println ( "i =" + i + ", j =" + j) ; if (j == 5) break ok;}} in addition, reference numeral I personally usually do not use this manner, but the results of the cycle so that the conditional expression may be controlled in the outer layer of the loop body code, for example, to find the number in a two-dimensional array. int arr [] [] = {{1,2,3}, {4,5,6,7}, {9}}; boolean found = false; for (int i = 0;! i <arr.length && found ; i ++) {for (intj = 0; j <arr [i] .length; j ++) {System.out.println ( "i =" + i + ", j =" + j); if (arr [i] [j] == 5) {found = true; break;}}}

5, switch statement can act on byte, whether acting on the long, whether acting on String? In switch (e), e can only be an integer expression or enumeration constant (larger font), integer expression can be a primitive type int or integer type of packaging, because the byte, short, char can be implicitly converted to int, so these types, and these types of packaging types are also possible. Obviously, long and String types are not in line with the provisions of the syntax of the switch, and can not be implicitly converted to int type, so they can not act on the swtich statement. The switch statement can act on String wrong, after Java1.7 has supported such an approach it!

6, short s1 = 1; s1 = (s1 + 1 is int type, and type an equal sign left is short, so you need strong turn) 1 + 1; there is nothing wrong with short s1 = 1;? S1 + = 1; there ? What wrong (nothing wrong) for short s1 = 1; s1 = s1 + 1; s1 + automatically upgrade because the expression of type 1 operation, the result is an int, then assigned to the short time type s1, compiler reports need to cast the type of error. For short s1 = 1; s1 + = 1; a = + Since a predetermined java language operators, it will java compiler special treatment, it is possible to correct translation.

7, char type variable can store a Chinese characters? Why? Char variable is used to store Unicode character encoding, unicode character set encoding contains Chinese characters, so, char variables can be stored in Chinese characters of course friends. However, if a special unicode characters not included in the coded character set, then the char type variable can not store the special characters. Supplement: unicode encoding occupies two bytes, therefore, char type variable is occupies two bytes.

8, is calculated by multiplying 8 2 equal to a few? 2 << 3 most efficient method, (left three) as an n-bit number to the left, multiplied by the equivalent of the n-th power of 2, then, a number times as long as it can be left by 3 bits, and the bit computing cpu directly supported, the most efficient 8, therefore, is equal to 2 multiplied by 8 the most efficient method is several 2 << 3.

9, when modifying a variable with the final keyword, a reference can not be changed, an object or a reference can not be changed? When modifying a variable with the final keyword, refer to reference variables can not be changed, the content object reference variable points in the still can be changed. For example, the following statement: finalStringBuffer a = new StringBuffer ( "immutable"); execute statement reports compile-time error: a = new StringBuffer ( ""); however, the following statement may be performed by the compiler: a.append ( " broken "); parameter definition method someone might want to use the following method modified form to prevent the interior passed in the parameter object:! public void method (final StringBuffer param) {} in fact, it is impossible, in the interior of the method can still add the following code to modify the parameter object: param.append ( "a");

10, the difference between static variables and instance variables? Differences in syntax definition: former static variable to add the static keyword, but not before adding instance variables. Differences in program runtime: instance variables belonging to the properties of an object, you must create an instance of an object, in which instance variables are allocated space in order to use this instance variable. Static variables do not belong to an instance of an object, but belong to the class, it is also known as class variables, as long as the program is loaded bytecode class, do not create any instance of an object, static variables will be assigned space, static variables can be used. In short, after the instance variables must create an object can be used by this object, you can use static variables directly reference the class name. For example, for the following program, no matter how many instances of an object is created, only assigned a staticVar always variable, and each creates an instance of an object, this will add staticVar 1; however, create an instance of each object will be assigned a instanceVar , i.e., may be assigned a plurality instanceVar, and only from the value of each instanceVar plus 1 times. public class VariantTest {publicstatic int staticVar = 0; publicint instanceVar = 0; publicVariantTest () {staticVar ++; instanceVar ++; System.out.println (staticVar + instanceVar);}} today to share a small circle ape Java interview on here, and we Do not just go to practice Oh, remember to knock the code several times, then what is the problem you can go to the official website to learn small circle ape Oh, remember to focus on small ape circle, will give share some dry goods every day, bye.

Reproduced in: https: //juejin.im/post/5cf080fce51d455cd73ba02c

Guess you like

Origin blog.csdn.net/weixin_33736048/article/details/91454903