In the cattle (a lot of written interview platform, feel every day a set can Meng ☆_☆) see a big God, is an offer harvester tat, its face through a lot of things are the foundation, feel that they need to summarize and learn I do not understand the module, while I still have time, refueling!!
PS: Most of the content is online search, there is infringement, the deletion (m (_ _) m)
------------------------------
1, Volley is Google launched the Android Asynchronous network request framework and picture loading framework. Volley features: Especially suitable for small data volume, frequent communication network operation, prevent Oom, ListView, each line is taken from the network of a picture and a few lines of text, using volley
Stringrequest, Jsonrequest, imagerequest
In order to send a request, you can use the construct method new to come out a request, and then call Add () to put the requests into the Requestqueue, when the Add method is called, Volley will run a cache processing thread and a network dispatch pool. If the request is cached by the cache thread, the request will not be placed in the request queue, that is, the HTTP request is not made. The request is directly reused and the data is returned to the main thread. If the cache thread is not cached to the request, the request will be placed in the request queue, and after the network request succeeds, the request will be cached into the cache, and the network dispatch thread will process the request and parse the data.
http://blog.csdn.net/guolin_blog/article/details/17482095 other, not seen
2, the size of the nine basic data types, and their encapsulation class.
3. Can switch use string to do parameters? (An integer expression can be an int primitive type or an integer wrapper type, because Byte,short,char can be implicitly converted to int so it can, and long, float, double types do not conform to the syntax of switch, and cannot be implicitly converted to an int type, so they cannot be used in Swtich statements. Note: The string type is supported by Java7. )
4. The difference between equals and = =
= = can be used to compare basic types and reference types, to determine content and memory addresses;
equals can only be used to compare reference types, it only determines the content.
5. What are the common methods of object?
Method equals tests whether two objects are equal,
Method clone for object copy,
The GetClass method returns the class object associated with the current object,
The Notify,notifyall,wait method is used for thread synchronization of a given object.
6, the Java four kinds of references, weak strength soft virtual, uses the scene.
Strong references are the way we normally use objects, and they are not recycled by the garbage collector. Even if there is not enough memory space, the JVM does not reclaim it, but instead throws a outofmemoryerror error that causes the program to terminate unexpectedly. When the method finishes running, the variables do not exist, so the objects they point to will be reclaimed by the JVM.
However, if you want to break the association between a strong reference and an object, you can explicitly assign a reference to NULL, so that the JVM will reclaim the object at the appropriate time.
Soft references are created through softreference, and when soft references are used, soft references can continue to be used without being reclaimed by the garbage collector, if there is sufficient memory space, and the soft reference is reclaimed by the garbage collector only when there is insufficient memory. This feature of soft references makes it ideal for solving OOM problems, implementing caching mechanisms such as image caching, Web caching, and so on ... A soft reference can be used in conjunction with a reference queue (Referencequeue), and if the object referenced by the soft reference is reclaimed by the JVM, the soft reference is added to the reference queue associated with it.
Weakly referenced objects have a more ephemeral life cycle. Because when the JVM is garbage collected, weak references are recycled whenever a weak reference object is found, regardless of whether the current memory space is sufficient. However, because the garbage collector is a low-priority thread, it is not always possible to quickly discover weak reference objects.
A weak reference can be used in conjunction with a reference queue (Referencequeue), and if the object referenced by the weak reference is reclaimed by the JVM, the weak reference is added to the reference queue associated with it.
A virtual reference does not affect the life cycle of an object. If an object holds only virtual references, it is equivalent to no references and can be reclaimed by the garbage collector at any time. A virtual reference must be used in association with a reference queue, and when the garbage collector prepares to reclaim an object, if it finds that it has a virtual reference, it adds the virtual reference to the reference queue associated with it. The program can see if the referenced object is going to be garbage collected by judging whether the reference queue has been added to the virtual reference. If the program discovers that a virtual reference has been added to the reference queue, it can take the necessary action before the memory of the referenced object is reclaimed.
Assuming you now have a virtual reference PR with a string--"Hello", then when the garbage collector recycles Hello, it puts a virtual reference into the queue of reference queues and then completes the collection. Simply put, you know that the object is being recycled.
7, the role of Hashcode.
Java uses the principle of a hash table. A hashing algorithm, also known as a hashing algorithm, is a direct assignment of data to an address based on a particular algorithm. This way, when the collection is to add a new element, the Hashcode method of the element is called first, and then it can be positioned at the physical location where it should be placed. If there is no element in this position, it can be stored directly in this position without any further comparison, if there is already an element in this position, the Equals method of calling it is compared with the new element, the same is not saved; Then in this hash key where a linked list, all the objects that produce the same hashcode to the single-linked list up, strung together. So there is a problem of conflict resolution (rarely appearing). In this way, the number of actual calls to the Equals method is greatly reduced, almost only one or two times.
So, Java for the Eqauls method and the Hashcode method are defined as:
1, if two objects are equal, then their hashcode values must be equal;
2, if the hashcode of two objects are equal, they are not necessarily equal.
8, ArrayList, LinkedList, vector difference.
ArrayList is implemented internally through arrays. The disadvantage of an array is that there can be no interval between each element, and when the array size does not meet the need to increase storage capacity, it is necessary to copy the data of the array into the new storage space. When inserting or deleting elements from the middle of a ArrayList, it is necessary to copy, move, and cost the array. Therefore, it is suitable for random lookups and traversal, and is not suitable for insertions and deletions.
Vector array implemented, thread-safe level. It supports thread synchronization, which means that only one thread at a time can write vectors and avoid inconsistencies caused by simultaneous writing of multiple threads, but achieving synchronization requires a high cost, so accessing it is slower than accessing ArrayList. At the same time the vector query data has iterators, there are enumerations, there are get (int index), there are indexof (int index) Four ways, and ArrayList is not enumerated.
LinkedList is used to store data in a linked list structure, which is very suitable for the dynamic insertion and deletion of data, and the random access and traversal speed is relatively slow. In addition, he provides methods that are not defined in the list interface, specifically for manipulating the header and footer elements, and can be used as stacks, queues, and bidirectional queues.
9, the difference between String, StringBuffer and StringBuilder. http://hualang.iteye.com/blog/1181469
StringBuffer (cache) thread-safe variable character sequence. A string-like buffer, but cannot be modified, but some method calls can change the length and content of the sequence.
String buffers can be safely used with multiple threads. These methods can be synchronized if necessary, so all operations on any particular instance appear to occur in a serial order that is consistent with the sequence of method calls made by each thread involved.
The main operations on StringBuffer are the Append and insert methods, which can be overloaded to accept arbitrary types of data. Each method effectively converts the given data into a string, and then appends or inserts the character of the string into the string buffer. The Append method always adds these characters to the end of the buffer, while the Insert method adds characters at the specified point.
StringBuilder is generally used inside the method to complete a similar "+" function, because the thread is unsafe, so after use can be discarded. StringBuffer to be used in global variables
1. If you want to manipulate a small amount of data with = string, the character + into a sentence, with a string fast
2. Handling large amounts of data under single-threaded operation string buffers = StringBuilder (unsafe)
3. Multi-threaded operation string buffer operation large amount of data = stringbuffer (thread safe)
10. The characteristics and usage of MAP, Set, List, Queue, stack. (Usage: http://www.cnblogs.com/LittleHann/p/3690187.html)
1) Collection: Only one element (object) can be saved per location
1.1) List must maintain element-specific order, ordered repeatable, sequential index
1.2) Set cannot have duplicate elements, judging by equals
1.3) queue maintains the order of the Queues (FIFO)
2) Map: A pair of "key-value pairs" objects, like a small database. We can find the "value" of the key by "key"
To hold data with a "mapping", so there are two sets of values stored in the map collection, one set of values to hold the key in the map, and the other set of values to hold the value in the map. Both key and value can be data of any reference type. Map's key forbid
Duplicate, that is, any two key of the same map object is always returned false by the Equals method to compare the result.
As for map, we need to understand from the point of code reuse that Java implements the map first and then implements the set set by wrapping a map of all value NULL.
11. The difference between HashMap and Hashtable and Concurrenthashmap
HashMap is non-synchronous and can accept null (HashMap can accept null key values (key) and values (value), and Hashtable does not); There is no guarantee that the order of elements in the map will be constant over time.
While Hashtable is synchronous, which means that Hashtable is thread-safe, multiple threads can share a hashtable, that is, only one thread can write hashtable at any one time, and therefore Hashtable is slower to write. ; it is slower than HashMap in a single-threaded environment. Similar to HashMap, it inherits from the dictionary class, which is different: it does not allow the record key or the value to be empty Java 5 provides the Concurrenthashmap, which is a hashtable alternative, better than Hashtable extensibility.
Concurrenthashmap is the use of lock segmentation technology to ensure thread safety.
Lock Segmentation Technology: The data is divided into a period of storage, and then to each piece of data with a lock, when a thread occupies a lock to access one of the data, the other segments of the data can also be accessed by other threads.
12, TreeMap, HashMap, Lindedhashmap difference
Map is primarily used to store health-value pairs, which are given a value based on the key, so the key is not allowed to repeat, but the allowed value repeats.
Hashmap is the most commonly used map, it stores data according to the hashcode value of the key, can get its value directly according to the key, has the fast access speed, when traversing, obtains the data the order is completely random. HashMap allows a maximum of one record's key to be null, does not support thread synchronization, which means that multiple threads can write HashMap at any one time, and may result in inconsistent data. If synchronization is required, you can use the collections Synchronizedmap method to make the HashMap capable of synchronizing or using Concurrenthashmap.
Linkedhashmap preserves the order in which records are inserted, and when traversing linkedhashmap with iterator, the first record must be inserted first. You can also use the parameters in the construction to sort by the number of applications. The traversal will be slower than HashMap, but there is an exception, when the HashMap capacity is large, the actual data is small, the traversal may be slower than Linkedhashmap, because the Linkedhashmap traverse speed is only related to the actual data, and capacity-independent, And HashMap's traverse speed is related to his capacity.
TreeMap implements the Sortmap interface, it can save the record according to the key sort, the default is the key value of ascending order, you can also specify a sort of comparator, when using iterator traversal treemap, the resulting records are ordered.
In general, we use the most is the hashmap,hashmap inside the key value of the pair when it is taken out is random, it according to the hashcode value of the key to store data, according to the key can directly get its value, with fast access speed. HashMap is the best choice for inserting, deleting, and locating elements in a map.
The treemap takes out the sorted key-value pairs. But if you want to traverse the key in natural order or in a custom order, TreeMap is better.
Linkedhashmap is a subclass of HashMap, and if the order of output needs to be the same as the input, then it can be implemented by LINKEDHASHMAP, and it can be arranged in the order of reading.
13, collection package structure, and the difference between collections
Collection is the ancestor interface of the collection class, and the sub-interfaces are mainly set and list, Map.
Collections is a helper class for collection classes, a variety of static polymorphic methods for collection operations, providing a tool approach to the set of operations: A series of static methods for searching, sorting, and threading the various collections.
14, try Catch Finally,try have return,finally also execute? Implementation
The statement of a finally block is returned before the return statement in a try or catch is executed and the modified statement in the finally may or may not affect the return value that has been determined in the try or catch. If there is a return statement in Finally, the return statement in the try or catch is overwritten directly. Unless you call System.exit () to let the program quit or power off and other factors cause the program to abort, otherwise, regardless of any factor, finally block will certainly execute!!
15, Excption and error packet structure. Oom What situation you have encountered, SOF what you have encountered.
Java divides the throwable structure into three types: checked exceptions (Checked Exception), run-time exceptions (runtimeexception), and Errors (error).
Http://www.cnblogs.com/yumo/p/4909617.html
Out of Memory (OOM): There are 2 main causes of oom, namely memory leaks and memory overflows (that is, heap overflow and stack overflow).
Stack over Flow (SOF): (heap) stack overflow occurs primarily in recursive calls.
Oom and SOF: Recursive calls can cause stacks to overflow, and constantly creating objects can cause heap overflow.
16, Java object-oriented three features and meanings.
Encapsulation: It is to hide some of the class's sensitive information in the class part of the class, not to be directly accessible to the outside world, but can be accessed indirectly through Getter () and setter ().
Inheritance: Subclasses accept all public, protected member variables and member methods of the parent class in a way.
Polymorphism: In the course of operation, the same type behaves differently under different conditions, and the form of this indeterminate state is called polymorphism.
17. The meaning and difference of override and overload
The difference: Override is a representation of the polymorphism between the parent class and the subclass, whereas overloading (overload) is a representation of polymorphism in a class. If a method is defined in a subclass with its
Override: The parent class has the same name and parameters, and we say that the method is overridden (override). When an object of a subclass uses this method, the definition in the subclass is called, and the definition in the parent class is masked.
Overloading (overload): If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types or have different parameter orders, which is called a method overload (overload).
The difference between interface and the abstract class.
The difference between the static class and the Non static class [23].
Parsing: You can have static instance variables, static methods, static blocks, and of course, static classes in Java, but you can't decorate top-level classes with static, only the inner classes.
What is the difference between a static inner class and a non-static inner class?
Internal static classes do not need to have references to external classes, because static inner classes declared with static become external classes, but non-static inner classes need to hold references to the external class;
Non-static inner classes can access static and non-static members of external classes (data members and member functions), but static inner classes can access only static members of external classes (data members and member functions);
Non-static inner classes cannot be created from external class entities, but non-static inner classes can access data and functions of external classes because they are inside external classes;
If the inner class defined in the method wants to access the parameters in the method, then the final keyword must precede the argument.
Implementation principle of Java polymorphism [24].
Analytical:
A reference variable that is defined by a parent class or interface can point to a subclass or an instance object of a specific implementation class, and the method called by the program is dynamically bound at run time, that is, the method that refers to the specific instance object that the variable points to, that is, the method of the object that is running in memory, rather than the method defined in the
- Two ways to implement Multithreading: Thread and runable.
Analytical:
Thread class: It is defined in the Java.lang package, and a class is called a multithreaded implementation class as long as it inherits the thread class. In the thread subclass, run () in the thread class must be explicitly covered because this method is the principal of the thread.
Runable interface: In Java it is also possible to implement multi-threading in a way that implements the Runnable interface, with only one abstract method defined in the Runnable interface: public void Run ().
Difference: Through the public class Thread extends Object implements Runnable found that the Thread class is also a subclass of the Runnable interface, However, in the thread class, the run () in the Runnable interface is not fully implemented, but the run () in the Runnable interface is called. Therefore, if you implement multi-threading by inheriting the thread class, you must overwrite run (). In fact, the runnable interface is more appropriate than the thread class for multiple threads of the same program code to handle the same resource situation.
22. Thread synchronization methods: Sychronized, Lock, Reentrantlock, Atomic, etc. [25][26].
Parsing: Synchronized is the key word for the JVM virtual machine, there is a lock interface in the Java.util.concurrent.locks namespace, and the implementation class Reentrantlock (Reentrant Lock) of the lock interface.
If the resource competition is not very intense, occasionally there will be synchronization situation, then synchronized is a very suitable choice;
Reentrantlock provides a variety of synchronization, such as the synchronization can be interrupt (synchronized synchronization is not interrupt) and so on. If the resource competition is not very intense, then its performance is slightly more than synchronized. However, when the resource competition is very intense, synchronized is a very suitable choice;
Similar to Reentrantlock's case, if the resource competition is not very fierce, then its performance is slightly more than the synchronized almost. However, when the resource competition is very intense, the performance of atomic will be better than reentrantlock one times. However, it also has a drawback, which is that only one value can be synchronized.
23. Level of Lock: Object Lock (Method Lock), class lock and other relevant knowledge points [27].
Resolution: Simply put, the size of the two locks is different. The granularity of an object lock is an object, whereas a class lock object is a class.
Object lock is the Synchronized keyword (the method of the object) in front of a method of a class.
Class locks are synchronized the Static keyword (the method of a class) before a method of a class.
Interview Ready for Android (i)