Frontier Dream Workshop 2017-04-18 18:14
Most of the Java interview is divided into written and interview, the following issues are cutting-edge education small series according to the major IT enterprises interview asked the questions sorted out, such as the need for relevant learning materials can leave a mailbox, I hope to help you.
Example 1:
What are the aspects of object-oriented features.
Packaging
The most common is to encapsulate attributes in a class that can only be accessed by means of
Inherited
Subclasses inherit the parent class, inheriting the methods and properties of the parent class
Abstract
A Hero class, for example, abstracts out the attributes of name,hp, making it easier to understand in the development process
Polymorphic
Polymorphism of polymorphic operators and polymorphism of classes. The polymorphism of the class refers to the parent class reference to the subclass object, with inheritance and overrides.
Example 2:
String is the most basic type of data.
String is a class type, not a base type.
There are eight basic types of
The eight basic types are:
Integral type (4 kinds)
Character type (1 kinds)
Floating point type (2 kinds)
Boolean type (1 species)
Example 3:
What is the difference between int and Integer.
int is an integer of basic type 32-bit length
Integer is the class type and is the encapsulated class of int
the int and the integer can be converted to each other by automatic box unboxing,
Example 4:
The difference between String and StringBuffer.
A string is immutable, and once the content is created, it cannot be changed.
StringBuffer can grow longer and content can change.
The principle of change is that the StringBuffer uses a character array to hold the data, create a new array, and copy the original data to the new array when it is necessary to increase the length.
More details can be used to refer to how the Mystringbuffer class that imitates StringBuffer is implemented.
Example 5:
What is the difference between a Run-time exception and a general exception?
Runtime exceptions are also known as non-verifiable exceptions, and in the process of compilation, it is not required to have a display capture
The general exception is also known as the abnormal, in the compilation process, must be processed, or capture, or through the throws thrown away.
Example 6:
Say Arraylist,vector, LinkedList storage performance and features.
First, ArrayList and vector.
both inherit the abstract class abstractlist, but vectors are thread-safe and ArrayList are not thread-safe
Besides, the difference between ArrayList and LinkedList
ArrayList is an array structure, so it's fast, but it's slow to insert and delete.
LinkedList is a two-way linked list structure, so inserts and deletes quickly, but the location is slow
Example 7:
The difference between Collection and collections.
First of all, don't say one is singular, one is plural ...
collection is the interface, which is the parent interface of the list and set
Collections is a tool class that offers a number of practical ways to sort, confuse, etc.
Example 8:
The difference between & and &&
& has two functions, namely, the bit -and-Logic and
&& is the logical and
as logic and, & and && respectively express long and short circuits and
Long road and both sides, will be calculated, short circuit and if the first is false, the second is not operation
Example 9:
The difference between HashMap and Hashtable
Both HashMap and Hashtable implement the map interface, which is the way the key values are stored.
Difference 1:
HashMap can store null
Hashtable cannot store null
Difference 2:
HashMap is not a thread-safe class
Hashtable is a thread-safe class
Example 10:
Final, finally, finalize the difference
Final
Final modifier class, method, basic type variable, when quoted, each has a different meaning
The cosmetic class indicates that the class cannot be inherited
A cosmetic method indicates that the method cannot be overridden
Modifying a base type variable means that the variable can only be assigned once
A cosmetic reference represents an opportunity for the reference to point to an object only once
Finally
Finally is the scene for exception handling, which executes regardless of whether an exception is thrown.
Finalize
Finalize is the method of object, and all classes inherit the method. When an object satisfies the criteria for garbage collection and is reclaimed, its finalize () method is called
Example 11:
The difference between overload and override, that is, the difference between overloading and rewriting. Can the overloaded method change the type of the return value?
Overload is the meaning of method overloading, meaning that the method name is the same in the same class, but the parameters are different.
Override is the meaning of a method rewrite, which means that a subclass inherits a method of the parent class and then writes it again.
can the overloaded method change the type of the return value?
Yes, overloading is essentially a completely different method, but it just happens to take the same name.
Example 12:
What is the difference between error and exception?
both error and exception implement the Throwable interface
error is only JVM-level errors, such as low memory OutOfMemoryError
Exception is only the exception to the code logic, such as subscript out of bounds outofindexexception
Example 13:
What is the difference between abstract class and interface?
The difference between an abstract class abstraction and a interface interface
How to use:
abstract classes can be used only through inheritance
interface must be used through implementation
Implementation method:
Abstract classes can not only provide abstract methods, but also provide implementation methods
interfaces can only provide abstract method hair and cannot provide implementation methods.
However, at the beginning of the JAVA8 version, the interface can provide an implementation method, provided that you add a default modifier before the method
Example 14:
What's the difference between heap and stack?
Heap: Heap
Stack: Stacks (in some books, will be translated into the stack, actually refers to the simple stack)
The contents of the store are not the same:
Heap: The object is stored
Stack: Is the base type (int, float, Boolean, and so on), reference (object address), method call
The way to save is different:
heap: is automatically increased size, so you do not need to specify the size, but access is relatively slow
stack: is a fixed size, and is the order of Filo first, and the access speed is relatively fast
Example 15:
What is a GC? Why should there be a GC?
GC is the abbreviation for garbage collection, that is, garbage collection
The so-called rubbish here refers to those objects that are no longer being used, The JVM's garbage collection mechanism frees developers from the tedious, error-prone manual release of memory resources.
Developers can focus more on the development of business functions, while resource recycling is done automatically by a more professional garbage collection mechanism.
Example 16:
Short S1 = 1; S1 = s1 + 1; what's wrong?
Short S1 = 1; This sentence is correct, and the compiler automatically handles the 1 integer as short.
S1 = s1 + 1; A cast error occurs when the expression on the right returns an integer of type int and assigns the integer of this int type to the short type of S1.
Example 17:
Math.Round (11.5) How much is it? How much is math.round (-11.5)?
Math.Round means +0.5 to take an integer.
So Math.Round (11.5) is 11.5+0.5 = 12
Math.Round (-11.5) is -11.5+0.5 =-11
Example 18:
Create a few string Object?
string s = new string ("XYZ");
First constructs the method new String ("XYZ"); The "XYZ" in itself is a string object
Then the new keyword will definitely create an object
So a total of two string objects were created
Example 19:
Does Java have goto?
Yes, goto is a keyword, but it's a reserved word, not functional.
Example 20:
Does an interface inherit an interface?
you can, like list, inherit the interface collection
does an abstract class implement (implements) interfaces?
yes, like the Mouseadapter Mouse listener adapter is an abstract class and implements the MouseListener interface
whether an abstract class can inherit entity classes (concrete Class).
OK, all abstract classes inherit object
Example 21:
List, Set, does map inherit from collection interface?
the List and Set inherit the collection interface
However, there is no inheritance relationship between the map and the collection, because one is a key-value pair container, one is a single value container, and cannot be compatible
Example 22:
Whether the method of abstract can be static at the same time, or whether it can be synchronized.
No, you can't.
Example 23:
Does the array have the length () method? String has no length () this method.
The method for getting the length of an array is. Length Property
String gets the length of the method that is the length ()
The way the collection gets the length is the size () method
The length () method of the file acquisition is
Example 24:
The elements in set cannot be duplicated, so what is the way to distinguish between duplicates or not?
Taking HashSet as an example, the logic of judging repetition is:
1. First look at whether the hashcode is the same, if different, is not repeated
2. If hashcode the same, and then compare equals, if different, is not repeated, otherwise it is repeated.
More about the principle of hashcode, refer to the Java hashcode principle detailed
Example 25:
Can the constructor constructor be override? Do you inherit the string class?
subclasses cannot inherit the constructor method of the parent class, so there is no constructor that overrides the parent class.
String is final decorated so it cannot be inherited