Comparison in Java

Source: Internet
Author: User
Tags set set

Sleep is a thread-class method that causes this thread to pause execution for a specified time and will execute the opportunity to other threads, but the monitoring state remains and is automatically restored when it is finished. Calling sleep does not release the object lock. Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify method (or Notifyall) is issued for this object the thread enters the object lock pool ready to get the object lock into the running state.

Sleep is the thread that is executing the active cpu,cpu to execute other threads, after the time specified by sleep (in milliseconds), the CPU will go back to the thread to continue execution, if the current thread entered a synchronization lock, the Sleep method does not release the lock, Even if the current thread uses the Sleep method to give out the CPU, other threads that are blocked by the sync lock cannot be executed. Wait refers to a thread that has entered a sync lock, allowing itself to temporarily let out a sync lock so that other threads waiting for the lock can get a synchronous lock and run, and only other threads call the Notify Method (notify does not release the lock, Just tell the thread that called the wait method to be able to participate in the competition to get the lock, but not immediately get the lock, because the lock is still in the hands of others, others have not been released. If the code behind the Notify method is a lot more, it needs to be done before releasing the lock, you can add a wait and some code after the Notfiy method, see the effect, and the thread that calls the wait method will dismiss the wait state. The program can get the lock again and continue to run down.

What are the similarities and differences between synchronous and asynchronous, and under what circumstances are they used separately? An example is described.

if the data will be shared between threads. For example, the data being written may be read by another thread later, or the data being read may have been written by another thread, then the data is shared and must be accessed synchronously.

When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the method to be returned, it should use asynchronous programming, which is often more efficient in many cases with asynchronous approaches.

List, Set, map three interfaces, when accessing elements, what are the characteristics of each

First, the list and set have similarities, both of which are a collection of single-column elements, inheriting the common parent interface, Collection.

The List indicates a sequential collection, noting that it is not sort by age, by size, by price, and so on. When we call the Add (OBJ-E) method multiple times, each time the object is added is like a train station to buy tickets in the same order as the queue, sorted by first served. Sometimes, you can also jump in the queue, that is, by calling the Add (int index,obj e) method, you can specify where the current object is stored in the collection. An object can be repeatedly stored in the list, each call to the Add method, the object is inserted into the collection once, in fact, not the object itself is stored in the collection, but in the collection with an index variable point to the object, when the object is add multiple times, That is, there are multiple indexes in the collection pointing to this object, as shown in X. List In addition to the iterator interface can get all the elements, and then iterate through each element, you can also call get (index i) to clarify the number of the first.

The set does not allow repeating elements, so-called repetition, that is, there cannot be two equal (note, not just the same) object, that is, assuming that the set set has an A object, now I want to put a set set of a B object, but the B object is equal to equals of the A object, The B object is not stored, so the Add method of the Set collection has a Boolean return value, when there is no element in the collection, when the Add method can successfully join the element, it returns True when the collection contains an element equal to the equals of an element. The Add method cannot join the element at this point, and the return result is false. When set takes an element, it is impossible to say the first number of elements, only the iterator interface to get all the element, and then iterate through each element.

Unlike list and set, Map is a collection of two columns, with the Put method defined as follows: Put (obj key,obj value), each time you store a pair of key/value, you cannot store duplicate keys, This repeating rule is also equal to equals. You can obtain the corresponding value according to key, which is the value that the get (Object key) returns to key. In addition, you can get all the key combinations, you can also get all the value of the union, you can also get a combination of key and value of the Map.entry object collection.

A List of single-column data sets that hold elements in a particular order (in order) and can have repeating elements. Set single-column data collection, internally ordered, with no duplicate elements. Map Double column data collection, save Key-value value, no order, key cannot be duplicated, value can be duplicated.

HashSet is stored according to the hashcode value, rather than directly by the size of the hashcode value. For example, "ABC"--->, "def"--->, "xyz"---> 65 the Order of storage in HashSet is not 62,65,78. HashSet are stored in the order in which they are inserted, what does the Hashcode method of the stored object do? Think of the!hashset collection to compare two objects for equality, first to see if the Hashcode method is equal, and then to see if the Equals method is equal. New two student are inserted into the hashset, look at the size of the hashset, implement the Hashcode and Equals methods, and then look at size.

The same object can be added multiple times in the vector. Add elements to the collection, which is equivalent to a string connected to the target object. To HashSet but not to add many times.

The difference between UE and UI

UE (user Experience) is the experience of users
UI (User Interface) is an interface prototype (equivalent to the model used to buy a house)
UI design refers to the whole design of human-computer interaction, Operation logic and beautiful interface of software. Good UI design is not only to make the software has a personality and taste, but also to make the operation of the software comfortable, simple, free, fully reflect the positioning and characteristics of the software. In the interactive process between man and machine (Human machines Interaction), there is a dimension, that is, the interface (Interface) we call. From the psychological point of view, the interface can be divided into sensory (visual, tactile, auditory, etc.) and two levels of emotion. User interface design is an important part of screen products. Interface design is a complex project involving different disciplines, and cognitive psychology, design and linguistics play an important role in this field. The three main principles of user interface design are: Placing the interface under the control of the user, reducing the user's memory burden and maintaining the consistency of the interface. So if we want to build the site in the future, we must grasp the human-computer interaction, in the first time to win customers.
The role of the design UI:
1, to help programmers work (the interface has been completed by the art design)
2, in advance to let users have a macro understanding of the project, know what the effect looks like.

Comparison in Java

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.