Today to take part in the written test, there are design patterns, and some basic questions!
The deepest impression is: What is not the function of the object , I blindfolded finalize, hey, ignorance!
Also asked, interface and abstract class , there are many ways to implement the multi-threading ! There are basically the following.
Also asked, Observer mode , design mode, I do not, it seems to work!
1. What are the three main features of object-oriented programming, please briefly describe
(1). Inheritance:
Inheritance is a hierarchical model of a junction class and allows and encourages the reuse of classes, which provides a way to articulate commonalities. A new class of objects can be derived from existing classes, a process known as class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class of the new class (The parent Class). Derived classes can inherit methods and instance variables from their base classes, and classes can modify or add new methods to make them more suitable for special needs.
(2). Package:
Encapsulation is the process and data is surrounded, access to data only through the defined interface. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.
(3). Polymorphism:
Polymorphism refers to allowing objects of different classes to respond to the same message. Polymorphism consists of parameterized polymorphism and inclusion polymorphism. Polymorphism language has the advantage of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.
2. The difference between String and StringBuffer
The Java platform provides two classes: string and StringBuffer, which can store and manipulate strings, That is, character data that contains more than one character. This string class provides values that cannot be changed strings and the strings provided by this StringBuffer class are modified when you know that character data is going to change, you can use StringBuffer typically, You can use Stringbuffers to dynamically construct character data
3. say Arraylist,vector, LinkedList storage performance and features
both ArrayList and vectors store data using arrays, which are larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement. So index data fast and insert data slow, vector because of the use of synchronized thinking method (thread safety), usually performance is worse than ArrayList, and LinkedList use a doubly linked list for storage, index data by ordinal need forward or back traversal, But when inserting data, you only need to record items before and after items, so the insertion speed is faster
4. The difference between Collection and collections
Collection is the ancestor interface of the collection class, and the main interface for inheriting it is set and list. Collections is a helper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections.
5. The difference between HashMap and Hashtable
HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), due to non-thread-safe, may be more efficient than the Hashtablejava Chinese station Community portal OC) | G| AX, HashMap allows NULL to be used as a Entryde key or value, and Hashtable does not allow HashMap to remove Hashtable thought methods, Change to Containsvalue and ContainsKey because contains thought method is easy to cause misunderstanding Hashtable inherit from dictionary class, and HashMap is an implementation of Java1.2 introduced map interface.
The biggest difference is that Hashtable way of thinking is synchronize, and HashMap is not, when multiple threads access Hashtable, do not need their own way of thinking to achieve synchronization, and HashMap must provide external synchronization.
The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.
6. Final, finally, finalize the difference
Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable.
Finally is part of the exception-handling statement structure, which indicates that it is always executed.
Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resource recycles, such as closing the file.
7. The difference between overload and override. Can the overloaded method change the type of the return value?
Overload (Overload):
(1) method overloading is a means of allowing classes to handle different types of data in a uniform manner. Multiple functions with the same name exist at the same time, with different number/types of parameters. Overloaded overloading is a representation of polymorphism in a class.
(2) Java's method overloading is the ability to create multiple methods in a class that have the same name but have different parameters and different definitions. The method is called polymorphism by the number of different arguments passed to them and by the type of parameter to determine which method to use.
(3) When overloading, the method name is the same, but the parameter type and number are different, the return value type can be the same or different. The return type cannot be used as a distinguishing criterion for overloaded functions.
Rewrite ( Override ):
(2) If a method in a subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. If you need a method from the parent class, you can use the Super keyword, which references the parent class of the current class.
(3) The access adornment permission of a subclass function cannot be less than the
of the parent class.
rules for overriding methods:
1. The parameter list must be exactly the same as the overridden method, otherwise it cannot be called overridden but overloaded.
2. The returned type must always be the same as the return type of the overridden method, otherwise it cannot be called overridden but is overloaded.
Instead of overloading the rules:
1. Must have a different parameter list;
2. You can have different return types, as long as the parameter list is different;
3. Can have different access modifiers;
4. Different exceptions can be thrown;
The difference between overrides and overloads is that:
Overriding polymorphism works, and calling overloaded methods can greatly reduce the amount of code input, and the same method name can have different functions or return values as long as it passes different parameters inside.
With good rewriting and overloading, you can design a clear and concise class that can be said to be overridden and overloaded in a way that is very unusual in the process of writing code.
The overloaded method is to change the type of the return value.
8. What is the difference between error and exception?
Error indicates a serious problem in situations where recovery is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such situations.
Exception represents a design or implementation issue. That is, it means that if the program runs normally, it never happens.
9. What is the difference between abstract class and interface?
1.abstractclass represents an inheritance relationship in the Java language, and a class can only use one inheritance relationship at a time. However, a class can implement multiple interface.
2. In AbstractClass, you can have your own data members, or you can have non-ABSTARCT member methods, and in interface, you can only have static data members that cannot be modified (that is, it must be static final, but Data members are not generally defined in interface, and all member methods are abstract.
The 3.abstract class and interface reflect a different design concept. In fact, abstract class represents the "is-a" relationship, interface represents the "like-a" relationship.
4. Classes that implement abstract classes and interfaces must implement all of these methods. Abstract classes can have non-abstract methods. There is no implementation method in the interface.
5. The variable defined in the interface is the public static final type by default, and must be given its initial value, so the implementation class cannot be redefined or changed.
6. Variables in abstract classes are friendly by default, whose values can be redefined in subclasses or re-assigned.
7. The methods in the interface are public,abstract type by default.
List,set, whether the Map inherits from the collection interface
List,set is inherited from Collection,map not.
Swtich whether it can function on a byte, can it function on a Long, and can it function on a string?
Swtich can only be used in byte short int char
can a Chinese character be stored in a char variable?
Can be defined as a Chinese, because in Java encoding in Unicode, a char accounted for 16 bytes, so put a Chinese is no problem .
There are several ways to implement multithreading, what is it? What is the best way to do it? How are there several implementations of synchronization ?
There are two ways to implement multithreading, namely, inheriting the thread class and implementing the Runnable interface.
The implementation of the Runnable interface is good because the implementation class can implement multiple interfaces and only inherit one class.
There are two implementations of synchronization, namely Synchronized,wait and notify
There are several types of streams in Java? The JDK provides some abstract classes for inheritance for each type of stream, stating which classes they are
Byte stream, character stream. The byte stream inherits from the Inputstream/outputstream, and the character stream inherits from the Inputstreamreader/outputsteamwriter.
"Java Development Series"--java face question (1)