It's time to investigate java skills~ You can take a look

1. String is not the most basic data type, the basic data types in java are byte, short, int,

long, float, double, char, Boolean, and others are all reference types.

 

2. String cannot be inherited because it is a class modified with final.

 

3. The difference between String and StringBuilder, StringBuffer: String is a read-only string, use String

The content of the quoted string cannot be changed, and a is a mutable string, StringBuffer and StringBuilder

The usage is the same, the difference is that StringBuffer is modified with synchronize, which is more efficient than StringBuilder

Low.

 

Ps (mutable and immutable means: whether the state of the object can be changed after creation, including the members in the object

the state of the variable. What's the meaning? Such as: String a=”2333”, a=”886”, when opening “2333”, it is placed in

The constant pool, and a is placed in the stack to store the address of 2333 in the constant pool, and the latter 886 is actually in the constant

Re-created objects in the pool, that is, any changes to the string will result in a new String object. and

StringBuilder and StringBuffer are mutable classes, their string objects can be changed, for mutable strings

The operation does not generate a new object, that is, the operation on the same string object. )

 

4. The difference between access modifiers public, private and protected:

 

    private: available in the current class, not available elsewhere in this class

    public: available everywhere that this class is accessible

 

    protected: generally used in subclasses and parent classes, when a protected variable is written in the parent class  

      After that, the variable can also be accessed in its subclasses, and other classes in the same package can also access it    

      ask. (Note: The subclass and the parent class may not be in the same package)

 

     When no specific access permission is specified, the default permission is default, and its permission scope can be .

5.        float f=1.1 is wrong , the default in java is double-precision double type, that is to say, double-precision

1.1 Assignment to floating-point type will cause loss of precision, because this is a downcast, if you have to write it like this, you should enter

Line cast, float f=1.1F or float f=(float)1.1.

As shown in the figure: error

                          

 

6. What is the difference between short a=1, a=a+1 and a+=1? 1 The default is int type. The former calculation result is that int needs to be casted before it can be assigned, while the latter is actually equivalent to a=(short)(a+1), and a cast has been done.

As shown in the figure: error

 

 

7. What do you think the output of this picture will be?


 

The first outputs true, the second outputs false, we all know that when comparing objects with "==", the comparison is not

It is the content but the reference, because the numbers between -128 and 127 are already encapsulated in java, so when the number is between

Between them, there will be no new objects, but Integer objects in the constant pool are referenced between them.

 

8. How to escape multiple nested loops in Java? You can use the label tag, as shown in the figure:


9. Can a constructor be overridden?

      Hahahaha, of course not, because it can't be rewritten by inheritance? But it can still be reloaded~

 

10. Int a=5, int b=4, how to realize the exchange without defining the third variable?

Here we need to turn a corner, first a=a+b, then a is 9, then b=ab, b is 4, a=ab, a

为5,哈哈哈哈,交换了,这是一道面试的题目,感觉挺有趣的,就放上来了。



后续更新~~~


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325901804&siteId=291194637