Some records of wrong questions on Niuke.com

1. Java runtime memory is divided into two parts: thread sharing and thread private

Thread sharing: method area and heap

Thread private: Java virtual machine stack, program counter, local method stack

2.new java.util.SortedMap().put("key","value"); This instance method is wrong because SortedMap is an interface

3. The order of execution of the for loop

 

for(initialization statement; Boolean expression; update statement) {

Body process;

}

The initial statement is executed only once before the start of the loop

Boolean expressions are used to determine whether to continue executing the text process, and an exception in the expression will end the loop

The body process, if there is a break, return or exception in the process, the loop will end (the update statement will not be executed) if it encounters continue, the update statement will be executed and the next loop will enter

Update the statement, note that the update statement does not make a logical judgment of true and false, and the cycle ends here

Boolean expression, enter a new cycle

.........

4. byte b = (byte)129;

Positive overflow: minimum value + remainder -1

Negative overflow: maximum value-remainder +1

byte storage range [-128,127]

129 is positive overflow, the result is -128+(129%127)-1 = -127

If it is -129 negative overflow, the result is 127-(129/128)+1 = 127

 

5. String s = "test";//This method defines that the class loader will determine from the constant pool whether this string exists, if it exists, it is pointed to by s, and if it does not exist, it will be created

String s1 = new String("test");//new an object directly in the heap

s==s1 is false, because s points to a string variable in the constant pool

And s1 points to the string duix in the heap

 

6. The value of -12%-5 is -2

Modulo operation, the value of the quotient is the same as the sign of the dividend

 

7. Java is divided into two categories

Shared thread area: method area and heap

Private thread area: program counter, virtual machine stack and local method stack

 

 Program counter:

The heap is the largest piece of memory space managed by jvm, which mainly stores instance objects of various classes

The heap is divided into two different areas in Java: the new generation and the old generation

The Cenozoic is divided into three regions:

The division of Eden, From Survivor, To Survivor is to enable jvm to better manage objects in the heap memory. The heap memory model is roughly

 

 8. Several ways that the subclass will not be initialized:

1). The static method or field of the parent class is called

2). The final method or field of the parent class is called

3). Reference by array

SuperCLass [] sca = new SuperClass[10];

When initializing a class, if it is found that its parent class is not initialized, its parent class will be initialized first

 

9. Four reference types

1). Strong reference: Assigning an object to a reference is a strong reference, such as new an object, an object is assigned an object

2). Soft reference: It is implemented by softreference class, generally it will not be easily recovered, only when there is not enough memory will it be recovered

3). Weak reference: implemented by weakReference class, once garbage collection is started, it will be recycled

4). Virtual reference: cannot exist alone, must be used in conjunction with the reference queue, the main function is to track the state of the object being recycled

 

10. Final modified variables are equivalent to constants.

The parameters in the final modification method are final parameters.

Final modification of the class, the class cannot be inherited.

Final modification method, the method cannot be overridden.

final cannot modify abstract classes

If final modifies the reference variable, the value pointed to by the reference variable can be changed, but the reference can only point to this address, that is, the value of the reference itself cannot be changed.

Guess you like

Origin blog.csdn.net/pengyiccb/article/details/106326384