[] -Java face questions most basic interview questions summary

table of Contents

 

1. The three characteristics of object-oriented

2. What is polymorphic

3. The benefits of polymorphism

4. How does the virtual machine is a multi-state

5.final keywords added to the classes, methods, variables, respectively, what role

The role of 6.static keyword

7. The difference between the abstract class and interfaces

8. The method of static parent class subclasses can override

9. What is immutable

10. The difference between the static variables and instance variables

11.java create objects in several ways

What 12.String s1 = "ab", String s2 = "a" + "b", String s3 = "a", String s4 = "b", s5 = s3 + s4 s5 == s2 Will return

intern 13.String object ()

Public method which has 14.Object

15.java among four kinds of references

16.java difference in == and equals () of

17.equals () and `hashcode links

18.a = a + b and a = b + any difference

19. The internal documents may have a java class (non-inner classes)

20. The role of internal class

21.java in int char, how many bytes long each accounted for

Among the JVM 22.64, int length is the number of

Integer and the difference 23.int

24.String, StringBuffer and StringBuilder difference

25.java them what type represents a relatively good price

26. can be converted to a byte int strong it will have any problems

27. The garbage collection algorithm

28. You do understand Fail-Fast mechanism

Difference 29.Fail-Fast and Fail-safe of

30.SimpleDateFormat is thread safe?

Exception and the difference 31.Error

And throws the difference 32.throw

The difference 33.Serializable and Externalizable

34. Briefly explain the class loader

35. A custom class loader two ways

36. Description of the difference between stack and heap

37.JDK 1.7 Characteristics

38.JDK 1.8 Characteristics


1. The three characteristics of object-oriented

Inheritance, encapsulation, polymorphism.

2. What is polymorphic

In object-oriented languages, various implementations of the interface is the polymorphic, it is characteristic of the specific performance of the parent class at compile time, but the characteristics embodied in subclass run time.

3. The benefits of polymorphism

Reduce coupling, each module is only responsible for the preparation of their respective functions realized; facilitate the calling interface, the caller only need to write code for a call, do not realize they are written for each way to call.

By inheritance polymorphism may also be implemented to some common parent class into a method to achieve, some personal approach into subclasses to achieve, so as to reduce the code amount.

4. How does the virtual machine is a multi-state

Dynamic binding techniques (dynamic binding), is determined during the execution of the actual type of the referenced object, corresponding to the actual type of method invocation.

5.final keywords added to the classes, methods, variables, respectively, what role

final keyword added to the class, which can not be inherited.

keywords added to the final method, that the method can not be overwritten / rewritten.

Keywords added to the final variable, the variable must show that the initial assignment, and can only be assigned once.

The role of 6.static keyword

keyword static member variables can be modified, can also be modified member method, add the static keyword modified variable or method will give priority to the objects are loaded into memory when jvm class loader, so static methods can be called directly without the need to create new instance of the object. is part of the static keyword modified variable class does not belong to any instance, no matter how many instances of objects class is created, the variables are loaded into memory only once, in memory there is only one copy of the variable.

7. The difference between the abstract class and interfaces

Interface is more than can be achieved, but the abstract class can only be inherited once.

Abstract class packing logic may need to implement a number of sub-classes, and the interface can not be written in the specific implementation.

Abstract class constructor can have, but the interface can not have a constructor.

8. The method of static parent class subclasses can override

Can not rewrite only instance methods, static methods can not be rewritten, if the parent class static methods and the same signature subclass, we call hidden.

9. What is immutable

Once an object is immutable objects are created, a state can not be changed, any changes will have a new object, such as String, Integer, and other packaging.

10. The difference between the static variables and instance variables

Static variables belong to the class, in the method area, instance variables exist in the heap, its reference exists in the current thread stack when garbage collection, static variables will not be recovered, instance variables can be recycled.

11.java create objects in several ways

new

reflection

clone

By serialization mechanism

What 12.String s1 = "ab", String s2 = "a" + "b", String s3 = "a", String s4 = "b", s5 = s3 + s4 s5 == s2 Will return

Returns false, during compilation, the compiler will s2 directly optimized for "ab", which will be placed in the constant pool which, s5 is created in the heap area, corresponding to s5 = new String ( "ab");

intern 13.String object ()

Calling String object of the intern () method, will give priority to the constant pool to find whether there is the constant value, if there is a direct return to the constant value, if not a constant value that is added to the constant pool and back.

Public method which has 14.Object

equals,toString,wait,notify,notifyAll,getClass,clone

15.java among four kinds of references

Four kinds of java references which mainly reflected the recovery in GC

Strong references will not be recovered in any case GC, even in the case where the memory is not enough, jvm will throw outOFMemoryException, nor will a strong reference to the object for garbage collection, if you want to interrupt strong references between an object and links can be displayed references assigned to Null, so that the strong reference to the object will be garbage.

Soft references are often used for caching, which means that in the case of soft enough memory reference is generally not recycled garbage, only when there is insufficient memory, soft references will be garbage.

Weak references Weak references objects owned life cycle is generally relatively short, regardless of whether sufficient memory in the garbage collection, weak references will be recovered immediately.

Virtual reference that is referenced does not exist, exist in name only, it will be garbage in any case.

16.java == and the equals()difference

Is the == operator == basic data types, the equals method of Object class, an object for comparison.

== call is in fact relatively memory address, calling equals compares the contents.

17. equals()and `hashcode links

If equals two objects are equal, then their hashcode are equal, in the presence of a hash collision, two objects are not equal equals, hashcode may be equal.

18.a = a + b and a = b + any difference

a + = b contains implicit type conversion, and a = a + b is not automatically conversion type.

For example int byte a = 127, byte b = 127, a + = b is not given, will automatically result of a + b is upgraded Int type, and a = a + b being given.

19. The internal documents may have a java class (non-inner classes)

A Java file can have only one public-modified class, but you can have multiple default modified class.

20. The role of internal class

Internal class provides better encapsulation, in addition to the inner peripheral class may access class, other classes can access the internal class.

21.java in int char, how many bytes long each accounted for

short / char 2 bytes 16

int / float 4 byte 32

long / double 8-byte 64-bit

Among the JVM 22.64, int length is the number of

int length of the platform-independent, are 32-bit.

Integer and the difference 23.int

int is the basic data types, Integer object type.

The default value is 0 int, Integer default value is Null.

It can be switched between by boxing and unboxing and int Integer.

24.String, StringBuffer and StringBuilder difference

String is a string constant, with final modifications .StringBuffer string variables, modified by synchronized, thread-safe, StringBuilder thread-safe.

From a performance point of view StringBuilder> StringBuffer> String.

25.java them what type represents a relatively good price

If you do not consider the performance and memory overhead, use BigDecimal type better, or the use of fixed-precision Double.

26. can be converted to a byte int strong it will have any problems

It can be, but strong move lead to lost bits.

27. The garbage collection algorithm

Mark - sweep algorithm

Clear labeling algorithm is also a kind it is called: white gray three-color algorithm, marked the first pass, the live objects are marked as white, the referenced objects are marked as gray, no object references marked in black, carried out a second time Clear, garbage collection will mark the node is black, does not actually exist three colors, just to help understand.

Mark - replication algorithm

In surivor region (abbreviated S region) Young region is divided into two equally large area region s0 and s1, s0 and s1 region is always an empty area, marked in the first stage, the useful markers objects are transferred into an empty area, then the mark to remove unwanted objects, and so on ad infinitum ...

Mark - Collation Algorithm

When a large number of live objects, mark replication algorithm will be many times copied, so there is a marked consolidation algorithm to solve this problem, the mark phase tags to organize algorithm with the same mark sweep algorithm, except that after the marking is completed, all live objects will move to another section, then clean out the elements other than the border.

Generational collection algorithm

This piece of garbage I do not know can go look at jvm classification, there have explained in detail. Https://blog.csdn.net/lovexiaotaozi/article/details/82883365

28. You do understand Fail-Fast mechanism

Fail-Fast means fail-fast, error detection mechanism is a set of classes java, when multiple threads at the same time a set of structural changes, it is possible to produce fial-fast mechanism, throw ConCurrentModificationException.

Difference 29.Fail-Fast and Fail-safe of

Collections under java.util package iterators are Fail-Fast, and when a plurality of threads simultaneously on a set of structural changes may be thrown a ConcurrentModificationException; iterator class set in java.util.concurrent packages Fail-safe is of, Fail-safe never throw a ConcurrentModificationException.

30.SimpleDateFormat is thread safe?

Not, DateFormat all implementations are thread safe, if we must use the date format recommended in multiple threads Joda-Time library, not only thread-safe, in the use is also very easy to use.

Exception and the difference 31.Error

Error is generally more serious and the system can not handle exceptions and capture, such as outOfMemoryError, but Exception is generally less serious errors, the system usually can be captured and processed, such exceptions generally do not affect the normal operation of the program, a common For example RuntimeException.

And throws the difference 32.throw

throw for active throws an exception, for example, we often throw a custom abnormalities in the process of writing business in the other throw for throw an exception within the method.

When the throws can not handle or do not want to handle the exception in the current method, the exception may be thrown up by it to deal with the level, if it can not handle the higher, the higher can continue to throw up, until one can handle the far superior.

The difference 33.Serializable and Externalizable

Java Serializable is to provide a serialization interface for transmission over the network and to a variety of content on the disk, the default is jvm serialization, the advantage of automation, to achieve this without code logic disadvantage is low performance, fragile, insecure, Externalizable is serializable subclass, it can control the serialization process, serializable less than the cost in terms of resources, the disadvantage is the need to rewrite their own readExternal and writeExternal method.

34. Briefly explain the class loader

In java class can be divided into five steps of loading

Load -> Connections -> Initialization -> Use -> Uninstall

Wherein the connection can be subdivided into three steps:

Check -> Prepare -> parse

The complete process is shown:

ç ± »to è½½çå½å¨æå¾

java class loading mechanism to delegate adopted parents, the class loader will give priority to call its parent class loader to load, if the parent class loader to load can not be completed, it will call the parent class loader's parent class loader until the request is ... bootstrapClassLoader passed to the top, the top-level class if the loader can not finish loading, will call its own class loader, so you can avoid repeating the class load, but also allows to load the class more secure.

35. A custom class loader two ways

Parents comply with the delegation model: inheritance ClassLoader class, override findClass () method

Parents damage delegation model: inheritance ClassLoader class, override the loadClass () method

36. Description of the difference between stack and heap

Heap: used to store the object, jvm garbage collection occurs mainly in the heap, it can be shared by multiple threads.

Stack: The method used to store a local variable frames and can not be shared by multiple threads.

37.JDK 1.7 Characteristics

Added try-with-resource, the resource can be automatically shut down in the try () {} catch () {} in.

Added support for String types in a switch statement.

38.JDK 1.8 Characteristics

Added lambda expressions, chain programming.

Added LocalDate class, the class is immutable and thread-safe.

Difference 39.BIO, NIO, AIO's

BIO: synchronous blocking IO, each connected to a separate thread to online a classic example of boiling water, to help understand: Suppose there is a row of water bottles in boiling water, the mode of BIO is to make a thread stuck in a kettle until the kettle to boil the water, go to the next processing a kettle, in fact, a thread waiting for the kettle to boil the water this time, had nothing to do, waste of resources, BIO slower.

NIO: Supports synchronous blocking / non-blocking IO, each request occupying a thread has to boil water, for example, NIO is to allow a thread to poll each kettle of state to see if the state has changed kettle. whereby the next step.

AIO: the IO asynchronous nonblocking, each occupying a valid request thread continues to boil water, for example, corresponds to the AIO each bottle tops in a presentation device, when the water boil automatically notify thread to process.

Partial and temporary basis face questions to sort out here, special thanks to information provided by the author: https://blog.csdn.net/dd864140130/article/details/55833087

 

 

 

Published 89 original articles · won praise 70 · views 40000 +

Guess you like

Origin blog.csdn.net/lovexiaotaozi/article/details/89448429