Java partial face question

Source: Internet
Author: User

One, the difference between vector and ArrayList
1,vector is thread-synchronized, so it is thread-safe, and ArrayList is thread-asynchronous and unsafe. If the thread security factors are not taken into account, the ArrayList efficiency is generally higher.
2, if the number of elements in the collection is greater than the length of the current collection array, the vector growth rate is 100% of the current array length, while the ArrayList growth rate is 50% of the current array length. Vector has the advantage of using a larger amount of data in the collection.
3, if you look for data at a given location, the vectors and ArrayList use the same time, and if you frequently access the data, you can use both vectors and ArrayList. If moving a specified position causes subsequent elements to move, this should take into account the use of linklist, since it moves the data at a specified position without moving the other elements.
ArrayList and vectors are stored in an array of data, which is larger than the actual stored data in order to add and insert elements, both allow the direct ordinal index element, but the insertion of data to involve the array element movement and other memory operations, so index data fast, insert data slow, Vector because of the use of the Synchronized method (thread safety) so the performance is worse than the ArrayList, LinkedList using the two-way linked list to implement storage, indexed by ordinal data needs to be traversed forward or backward, but when inserting data only need to record the item's front and rear items, So the insertion is faster.

Ii. the difference between ArrayList and LinkedList
1.ArrayList is the realization of the data structure based on dynamic array, LinkedList data structure based on linked list.
2. For random access get and set,arraylist feel better than LinkedList, because linkedlist to move the pointer.
3. Add and Remove,linedlist are the dominant for new and deleted operations because ArrayList is moving the data. This point depends on the actual situation. If you insert or delete only a single piece of data, the ArrayList speed is better than LinkedList. But if bulk random insert deletes data, LinkedList speed is much better than ArrayList. Because ArrayList each insertion of data, you move the insertion point and all subsequent data.

Three, the difference between HashMap and TreeMap
1, HashMap through the hashcode of its content to quickly find, and treemap all the elements are kept in a fixed order, if you need to get an ordered result you should use TREEMAP (the order of the elements in HashMap is not fixed).
2, inserting, deleting and locating elements in map, HashMap is the best choice. But if you want to traverse the key in natural order or in a custom order, TreeMap is better. The implementation of Hashcode () and Equals () is clearly defined by the key class that is required to be added using HashMap.
The elements in the two map are the same, but the order is different, causing hashcode () to be different.
Do the same test:
In HashMap, the same value of the map, the order is different, equals, false;
And in TreeMap, the same value of the map, the order is different, equals, true, the treemap in Equals () is sorted out in order.

Iv. the difference between Hashtable and HashMap
1, synchronization: Hashtable is thread-safe, that is, synchronous, and HashMap is a line program is not secure, not synchronous.
2. HashMap allows the existence of a null key with multiple null value.
3, the Hashtable key and value are not allowed to be null.

V. Short S1 = 1; S1 = s1 + 1; Is it wrong? short S1 = 1; S1 + = 1; Is it wrong?

Short S1 = 1; S1 = s1 + 1; not compiled correctly, 1 int integer, s1=s1+1 automatically transformed to int type and then assigned to S1, the result is int type; short S1 = 1; S1 + = 1; can be compiled correctly because s1+= 1; equivalent to S1 = (short) (S1 + 1) with implicit coercion type conversions

Six, the common design pattern of the Java EE? Description Factory mode

23 Design Patterns in Java: Factory (Factory mode), builder (build mode), Factory method (Factory mode), Prototype (original model mode), Singleton (singleton mode), facade (façade mode) , Adapter (adapter mode), Bridge (bridge mode), Composite (compositing mode), Decorator (decoration mode), Flyweight (enjoy meta mode), proxy (proxy mode), command (order mode), Interpreter (interpreter mode), Visitor (visitor mode), Iterator (iterative sub-mode), Mediator (mediator mode), Memento (Memo mode), Observer (viewer mode), State (status mode), Strategy (policy mode), template method (pattern mode), Chain of responsibleity (responsibility chain mode)

Factory mode: Factory mode is a frequently used pattern, and classes implemented according to the factory pattern can generate an instance of a class in a set of classes based on the data provided, usually this group of classes have a common abstract parent class and implement the same method, but these methods have different operations for different data. First, you need to define a base class in which subclasses implement methods in the base class in different ways. Then you need to define a factory class where the factory class can generate different subclass instances based on the criteria. When an instance of a subclass is obtained, the developer can call a method in the base class without having to consider which instance of the subclass is returned.

Java partial face question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.