Advanced java interview questions with full answers based on a compilation of Ali Baba 2020 (complete and detailed version)

The interviewer wanted in just a few tens of minutes recognition of your ability? Java technology stack would like to harvest the core of knowledge in the shortest possible time? Want a more comprehensive and in-depth understanding of Java technology? This Java common interview questions article to all the answers you want.

2019 latest Java common interview questions (with answers) .jpg

 1. What is the role of the collection?

Transmitted by the data, delete, change, check, constainsAll, can store different types of objects.

  2, common set of methods are those? What common method? (Operation)

List of collection traversal methods are:

Iterator:

Enumeration

For

Get

set

Collection of common methods are:

Iterator()

Add()

Clear();

remove()

More point I Java common interview questions

  3, tell the difference ArrayList, Vector, LinkedList storage properties and characteristics of HashMap and Hashtable

ArrayListVector: storing in an array manner, add, delete slow search, change fast

ArrayList: thread-safe, fast

ArrayList: thread-safe, slow (synchoronized)

LikedList: single linked list to store, add, delete fast search, change slowly

HashMap and Hashtable implement the Map interface, HashTable thread-safe, HashMap thread-safe.

  4, Collection and Collections of the difference.

Collection root interface is set, under which a list set and

Collections is a collection of algorithms.

 5, Set, the elements are not repeated, then the method used to distinguish whether or not repeat it? It is ()? How do they use == or equals the difference? Is there used to distinguish contains duplicate objects, or not at all.

When comparing the first call to hashCode method, if not identical, to prove unequal.

If so, then call the equals method, the same as if the equals method to prove equal, are not identical, proved unequal.

==: mainly used in basic data types and references

Equals: The main object of comparison or object references.

If a certain set contains an element used to judge.

  6, List, Set, Map whether inherited from the Collection interface?

List, set inherited from the Collection

Map is not inherited from Collection, which is relatively independent.

Collection objects belonging to type, one set may be configured to further set by a constructor.

  7, object-oriented features have what?

1. Abstract:

Find common, the common property, into the parent class method

2. Inheritance:

Subclass inherits from the parent class, all properties and methods of the parent class has, can be reused, may be covered.

3. Package:

Comprising a plurality of class attributes and methods.

4. polymorphism:

dynamic:

Static:

  8, String is the most basic data type?

The basic data types include byte, int, char, long, float, double, boolean and short.

java.lang.String class is final, and therefore can not inherit this class, the class can not be modified. To improve

Space-saving efficiency, we should use StringBuffer class

  9, int and Integer What is the difference?

Int is the basic data type, not objects, representing a memory space, there is no method. Their fellows have long, char, doble

Integer is a wrapper class with methods and properties. Their fellows have Long, Double.Float

 10. What are the similarities and differences with the general exception runtime exception?

Runtime exceptions: javaJVM thrown exception, not the code processing.

General Exception: user exception thrown if the throws declared, calling code this method must deal with them.

  11, & and && difference?

&: And: if it is left to the right also perform false.

&&: short circuit and, if left to the right does not perform false.

  12, final, finally, finalize the difference?

final declaration for properties, methods, and classes, attributes can not be changed, respectively, the method can not be overwritten, the class can not be inherited.

finally exception handling part of sentence structure, means always executed.

finalize is a method of the Object class, at the time of execution of the garbage collector calls this approach is subject to collection,

You can override this method to provide additional resources when recycling garbage collection, such as closing files.

Operator can be used to determine whether an object's class implements the interface.

  13, heap and stack What is the difference?

Stack is a linear collection, add and delete elements should be completed in the same period. Stack for the embodiment according to LIFO

Management.

Heap is an integral element of the stack

  14, StaticNestedClass and InnerClass different?

StaticNestedClass is declared static (static) inner class, it can not rely on an external class instance is a solid

Instantiation. The usual inner class needs to be instantiated in the outer class is instantiated.

  15, when to use assert?

assertion (assertion) is a common debug mode in software development languages ​​support this mechanism for many developers. in

Implementation, assertion is a statement in the program, it checks a boolean expression, a right

The program must ensure that the boolean expression evaluates to true; if the value is false, the program is no longer in the correct description

Under the state, the system will give a warning or quit. Generally speaking, assertion assurance procedures for basic and essential right

Sex. assertion checking is usually open during development and testing. To improve performance, after the software release, assertion check

Charles is usually closed.

  16, GC is the What? Why should there be GC?

GC is a garbage collection means (GabageCollection), memory handling is where programmers prone to problems, forget

Mind or memory error recovery procedures can result in system instability or even collapse, GC function of Java provides automatic monitoring

Whether the target object exceeds the scope so as to achieve the purpose of automatic recovery of memory, Java language does not provide free allocated memory

Method display operation.

  17, shorts1 = 1; s1 = s1 + 1; there is nothing wrong with shorts1 = 1;? S1 + = 1; there anything wrong?

shorts1 = 1; s1 = s1 + 1; (s1 + 1 operation result is an int, need cast type) shorts1 = 1;

s1 + = 1; (compile correctly)

  18, Math.round (11.5) is equal to how much? Math.round (-11.5) equals how much?

Math.round (11.5) == 12Math.round (-11.5) == - 11round method returns the nearest long integer parameter,

Parameter seeking the floor after adding 1/2.

  19, Java has no goto?

java reserved word, there is no use in java.

  20, give me one of your most commonly seen runtimeexception

ArithmeticException,ArrayStoreException,BufferOverflowException,

BufferUnderflowException,CannotRedoException,CannotUndoException,

ClassCastException,CMMException,ConcurrentModificationException,DOMException,

EmptyStackException,IllegalArgumentException,IllegalMonitorStateException,

IllegalPathStateException,IllegalStateException,ImagingOpException,

IndexOutOfBoundsException,MissingResourceException,NegativeArraySizeException,

NoSuchElementException,NullPointerException,ProfileDataException,

ProviderException,RasterFormatException,SecurityException,SystemException,

UndeclaredThrowableException,UnmodifiableSetException,

UnsupportedOperationException

General exceptions:

IOException

FileNotFoundException

SqlException

More point I Java common interview questions

21, the interface is inheritable interfaces? Are abstract class can implement (implements) the interface? Abstract class is inheritable entity class (concreteclass)?

Interface can be inherited interfaces. Abstract class can implement (implements) interface abstract class is inheritable entity class.

 22, abstract whether the method is also static, it also is a native, it is also synchronized?

both are not

23, the array has no length () this method? String has no length () this method?

Arrays are not length () This method has length attribute this

String has a length () this method.

24, whether Constructor constructor can be override?

Constructor constructor can not be inherited, and therefore can not rewrite Overriding, but can be overridden Overloading.

25, can inherit String class?

String class is final class can not inherit it.

26, swtich on whether the role of the byte, whether acting on the long, whether acting on String?

The switch (expr1), expr1 is an integer expression. Therefore, the parameters passed to the switch and case statements should

This is int, short, char or byte. long, string can not act on the swtich.

27, try {} there is a return statement, then followed by the code will finally be executed after the try {} in what

  When executed, before or after the return?

It will be executed, executed before return.

  28, two objects the same value (x.equals (y) == true), but it may have different hashCode, this sentence right?

Yes, the same hashcode.

 29, when an object is passed as a parameter to a method, this method can change the properties of this object, and returns the result of changes in, then in the end is passed by reference or value transfer here?

It is passed by reference

Basic data types: Value

Object: references

  30, the programming problem: to write out a Singleton.

Singleton pattern major role is to ensure that a Java application, a Class of only one instance of existence.

General Singleton pattern usually has several in various forms:

The first form: define a class, its constructor is private, it has a static private class of

Variable, then examples, reference to it by obtaining a public getInstance method in the case of initialization, which in turn calls the method.

publicclassSingleton {

privateSingleton(){}

// define themselves in their own internal one instance, is not it strange?

// Note that this is private for internal calls

privatestaticSingletoninstance = newSingleton ();

// here provides a static method for external access to this class, you can directly access

publicstaticSingletongetInstance(){

returninstance;

}

}

The second form:

publicclassSingleton {

privatestaticSingletoninstance=null;

publicstaticsynchronizedSingletongetInstance(){

// This method is an improvement over the above, do not generate each subject, but for the first time

// create an instance when used to improve the efficiency!

if(instance==null)

instance=newSingleton();

returninstance;}

}

Other forms:

Define a class, its constructor is private, all of the static method.

The first form is generally believed to be more safer

30, simple principle and application of exception handling mechanisms in Java.

principle:

Wrong to go directly to exception handling part or throw up.

application:

Java's exception is wrong, there are two one is running, coding can not capture. One is the general exception if the throws declared, must be treated.

31, advantages and principles of garbage collection. And consider two kinds of recovery mechanisms.

advantage:

Programmers do not control memory, jvm auto-complete, easy development. Running very low priority, the program can not know when the instance is destroyed.

32, describe the principle mechanism JVM class document loading?

The JVM is loaded by a class and its subclasses ClassLoader achieved, JavaClassLoader is an important component of the Java runtime system. It is responsible for finding and class loading class files at run time.

34, char type variable can store a Chinese characters? Why?

Can be defined as a Chinese, because the java coding to unicode, a char accounting for 16 bytes, so put a Chinese is no problem

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

Guess you like

Origin blog.csdn.net/aa541505/article/details/104072680