Thread paused method, basic data type wrapper class, decimal single precision floating point number (32 bits) in memory, TreeSet, and TreeMap

Source: Internet
Author: User
Tags comparable thread class

How does the thread suspend execution?

The sleep () method of the 1.Thread class causes the thread to enter a blocking state, sleeping for a specified period of time.

The wait () method of the 2.Object class causes the thread to discard the object lock and enter the lock pool until the object lock is acquired before continuing down execution

The yield () method of the 3.Thread class is usually less used, leaving the thread in a ready state rather than blocking state, that is, the next thread of execution may be the thread, and of course it may be for another thread, and the thread is paused.

4.java5 after the use of the lock interface can also be implemented similar to the object lock function, the advantage is more flexible, you can know the thread to obtain the lock did not wait, the larger disadvantage is the need to manually release the lock, if not released may result in deadlock.

Which of the eight data types in the wrapper class uses the constant pooling mechanism?

Byte,character,short,interger,long. Where the Chang (array) size of the character class is 128, the other four classes have a constant pool size of 256, when using a similar to the integer i = 1, such an assignment statement will use a constant pool, and he and other worthy objects assigned to him, rather than create a new object, The premise is that the range of assignments is -128~127, which means:

Integer N1 = 100,n2 = 100,n3 = 150,n4 = 150;

System.out.print (n1 = = N2); True two variables point to the same address

System.out.print (n3 = = N4); False two variable points to a different address

The scope of P.S. Byte is that -128~127, which is the direct assignment (not new), is bound to use a constant pool.

Floating-point number 6.125 in memory form?

Floating-point number in memory sign bit (1bit), exponential sign bit (1bit), digit digit (7bit) and tail digit (23bit) composition

The first step

The decimal 6.125 is first converted to binary, 6-->0110.

0.125 times 2, 0.25 takes 0.

0.25 times 2, 0.5 takes 0.

0.5 times 2, 1 takes 1.

0.125-->0.001

(PS. How binary decimals are converted to decimal:

The nth number after the decimal point is multiplied by the negative N of 2 to add all:

Take 0.001 for example 0 x 0 x + 1 x 1/8 = 0.125)

Step Two

The highest bit of floating-point number is positive or negative, 1 is positive, 0 is negative

The second high position indicates the positive or negative of the exponent, 1 is positive, and 0 is negative.

110.001 = 1.10001 x 2 x 2

Index is 4-->0000 100 (seven bit binary)

The end result is

1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1

The objects stored by TreeSet and TREEMAP require the implementation of the comparable interface, because both of the stored objects are ordered, and in fact the map is implemented inside the TreeSet.

Collections is a tool class (separate from the Collection Interface collection), sort provides two overloaded sort (list) and sort (list,obj) that require the comparable interface for objects stored in the list, the latter Without this requirement, but obj does not need to implement the Comparor interface, which is equal to the temporary provision of collations.

Thread paused method, basic data type wrapper class, decimal single precision floating point number (32 bits) in memory, TreeSet, and TreeMap

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.