1. Access modifier public,private,protected And the difference when not writing ?
Java Learn from junyang :479121291
When members of a class do not write access modifiers , By default default.

2.Stirng Is it the most basic data type ?

  answer : no . 

 java There are eight basic data types in : byte, short, int, long, float, double, char,  

 boolean. The rest are reference types (reference type).

3.float f = 1.1; Is that right ?

answer : incorrect . 1.1 It's double precision , Assign double to floating point , It belongs to downward transformation , Loss of accuracy . If you want to force

Type conversion , It can be written like this float f = (float)1.1; perhaps float f=1.1F;

4.short a = 1; a = a + 1 and short a = 1 ; a += 1 What's the difference? ?

answer : about a = a + 1 because 1 yes int Value type , So the result is int, To assign to short, Mandatory type installation required

To assign to short.

about a += 1; It is equivalent to a = (short)(a+1) ; Mandatory type replacement has been done .

5. The following code prints the result ?

Integer a = 100, b = 100, c = 130, d = 130 ; 

System.out.println(a ==> b); 

System.out.println(c == d);

The first is true, The second is false. 

because a,b,c,d All four variables are integer References to objects , therefore == The comparison is not a value , It's a reference . If integer literal

The value of the quantity is -128 reach 127 between , Then not new new Integer object , It refers directly to the Integer object .

6.Java How to jump out of multiple nested loops in ?

answer : Mark the outermost cycle A, utilize break A; Can jump out of the loop

7.String Can classes be inherited ?

answer : may not . because String Class is final class .

8.String and StringBuilder,StringBuffer The difference between ?

answer :String Is a read-only string ,String The content of the referenced string cannot be changed . and StringBuffer and

StringBuilder Is a variable string .StringBuilder and StringBuffer Same usage for ,
The difference is StringBuffer cover synchronized modification , Efficiency ratio StringBuilder low .

9. Can the constructor be overridden ?

answer : Constructor cannot be inherited , So it can't be rewritten , But it can be overloaded . a = 1; int b = 2; How to make a,b Value exchange ?

answer : 

a = a ^ b;    

b = a ^ b;    

a = a ^ b;


1. Similarities and differences between abstract classes and interfaces .

answer : 1. Neither abstract classes nor interfaces can instantiate objects , But you can define references to abstract classes and interface types . 

    2. To inherit abstract classes and implement interfaces, all abstract methods must be implemented

    3. Interface is more abstract than abstract class , Constructors can be defined in abstract classes , There can be abstract methods and concrete methods .

    4. All methods in the interface are abstract methods .

    5. Members in an abstract class can be private,protected,public, Interfaces are all public

    6. Member variables can be defined in abstract classes , The member variables defined in the interface are actually constants .

    7. Classes with abstract methods must be declared as abstract classes , Abstract classes do not need abstract methods . Is there a memory leak in ?

answer : theoretically java No memory leaks , There should be a garbage collection mechanism (GC). However, in actual development , May exist

Useless but reachable objects , These objects cannot be GC recovery , This can cause memory leaks . for example hibernated Of Session in

Object of belongs to persistent state , The garbage collector does not recycle these objects , There may be useless garbage objects in these objects . If off

Not in time , First level cache may cause memory leak .

3.try{ } inside return, finally Will the code in execute , When is it implemented ?

answer : Will execute . Execute before the method returns to the caller . Because if it exists finally Code block , try In return Statement will not

Return to the caller immediately , Instead, record the return value to be finally Return after code block execution .

4.List,Map,Set When three interface access elements , What are their characteristics ?

answer :List Access elements with a specific index , Can have repeating elements

Set Cannot store duplicate elements .

Map Save mapping of key value pairs , The mapping relationship can be one to one or many to one .

Set and Map Containers have two implementation versions based on Hash storage and sorting tree , The access time complexity based on Hash storage theory is O(1).

5.Thread In class sleep() And wait() What's the difference? ?

answer :sleep() Method is a static method of thread class , Calling this method causes the current thread to pause execution for a specified time . take CPU Time slice

To other threads , But the lock of the object remains , The end of sleep time will automatically return to ready state .

wait() yes Object Method of class , Calling object's wait() Method causes the current thread to abandon the lock on the object , Thread pause ,

Enter object's waiting pool , Only the notify() Method or notifyAll() Method time , To wake up the

Thread enters equal lock pool , If the thread reacquires the lock of the object, it can enter the ready state

6. When a thread enters an object's synchronized method A after , Whether other threads can enter the synchronized method B?

answer : No . Other threads can only access the object's asynchronous methods , Synchronization method cannot enter .

Because the synchronized The modifier requires the lock of the object to be obtained when the method is executed , If you have already entered A Methodology

The object lock has been removed , Then try to enter B The thread of the method can only wait for the lock pool ( Notice it's not a waiting pool ) Lock of waiting object in

7. say something synchronized Usage of keywords ?

answer :synchronized Keyword can mark an object or method as synchronized , To achieve exclusive access to objects and methods , It can be used

synchronized( object ) { … } Define synchronization code block , Or when declaring a method synchronized Modifier as method

8.Java How to realize serialization , What's the point ?

answer : Serialization is a mechanism for processing object streams , The so-called object flow is to flow the content of the object . Can be convective

Read and write operation of the object after , You can also transfer the streamed objects between networks .

Serialization is to solve the problems that may be caused by the read and write operations of the object stream ( If not serialized, the data may be out of order )

To implement serialization , Let class implement Serializable Interface . The interface is an identifying interface , Note that this kind of object can be sequenced

Chemical , Then an output stream is used to construct an object output stream and pass the writeObject(Object) Method to write out the implementation object

If you need to deserialize, you can use an input stream to build an object input stream , And then through readObject Method to read a pair from the stream

as . Serialization can achieve object persistence , Can also be used for deep cloning of objects

9. Threaded sleep() Methods and yield() What's the difference between methods ?

answer :sleep() Method gives other threads a chance to run regardless of thread priority , So it gives low priority threads a chance to run ;

yield() Method gives only threads of the same or higher priority the chance to run ; 

Thread execution sleep() Method to block (blocked) state , And execution yield() Transfer in ready after method (ready) state ; 

sleep() Method declaration throw InterruptedException, and yield() Method does not declare any exceptions ;

sleep() Method ratio yield() method ( Follow the operating system CPU Scheduling related ) Better portability .

10. Talk about your understanding of synchronization and asynchrony .

answer : If there are critical resources in the system ( Resources with fewer resources than threads competing for resources ), For example, the data being written may be read by another thread later , Or the data being read may have been written by another thread , Then these data must be accessed synchronously ( Exclusive lock in database operation is the best example )

When an application calls a method on an object that takes a long time to execute , And don't want the program to wait for the return of the method , You should use asynchronous programming , Asynchronous approaches are often more efficient in many cases . in fact , Synchronization means blocking operation , Asynchronous is nonblocking .


1. forward (forward) And redirection (redirect) The difference between ?

answer :forward Is the shift of control in the container , Is a server request resource , The server directly accesses the URL, Put that URL
Read the response content of , And then send it back to the browser , The browser has no idea where the content sent by the server comes from , So its address bar is still the original address redirect It's the server side according to the logic , Send a status code , Tell the browser to request that address again , So you can see the link address after jump from the address bar of browser , Obviously redirect Unable to access server protected resource , But from a website redirect To other websites .

2. Say it spring Middle dependency injection and AOP Implementation mechanism of .

answer : Ways to implement dependency injection include : Constructor Injection , Set point injection and interface ( Callback ) injection .Spring Can be injected by setting value in (setter Method injection ) And constructor injection implementation IoC, The recommended method is set value injection .

realization AOP Methods include : Compile time AOP( Special compiler required ), Runtime AOP( proxy pattern ), On load AOP( Special classloader required ).Spring The runtime AOP, Mainly through the way of agent to enhance the implementation of the original code . For classes that implement interfaces ,Spring adopt Java Dynamic agent for ( Please refer to Proxy Class and InvocationHandler

Interface ) To enhance ; For classes that do not implement interfaces ,Spring Using third-party bytecode generation tools CGLIB, Enhance the original code by inheritance

3. What is? ORM?

answer : Object relation mapping (Object-Relational
Mapping, abbreviation ORM) It is a technology to solve the problem of mismatch between the object-oriented model of program and the relational model of database ; In a nutshell ,ORM By using metadata that describes the mapping between objects and databases ( stay Java Can be used in XML Or comments ), Automatically persist objects in a program into a relational database or convert rows in a relational database table into Java object , In essence, it is to transform data from one form to another . 

Here I recommend my own Java Learning group :479121291, Welcome to junior and advanced Java Small partners enter learning exchange .

4. A brief introduction to " Six principles and one principle "

answer :
Principle of single responsibility : A class only does what it should do . What the single responsibility principle wants to express is " High cohesion " Principle of opening and closing : Software entities should be open to expansion , Close for changes . There are two key points to open and close : Abstraction is the key , If there is no abstract class or interface in a system, there is no extension point ; Package variability , Encapsulate various variables in the system into an inheritance structure , Dependence Inversion Principle :
Interface oriented programming , Is the parameter type of the declared method , Return type of method , When the reference type of a variable is , Use abstract types instead of concrete types as much as possible , Because an abstract type can be replaced by any of its subtypes : You can replace the parent type interface isolation principle with a child type at any time : The interface should be small and specialized , Never be big and complete . Interfaces should also be highly cohesive .Java Interface representation capabilities in , Representation agreement , Representative role , Whether the interface can be used correctly or not must be an important mark of programming level : Use aggregate or composite relationship reuse code first

©2019-2020 Toolsou All rights reserved,
JS How to operate java Realize the function of grabbing red packets C Language programming to find a student's grade The United Nations 《 Glory of Kings 》 Please go to the studio : To save the earth Dialogue between apple and Nissan suspended ,Apple Car How's it going ?CSS architecture design China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour First knowledge MySQL Comprehensive review ( dried food )2021 year 1 Monthly programmer salary statistics , average 14915 element How to use it quickly html and css Write static page