Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of java virtual machine

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the knowledge points of java virtual machine". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the knowledge points of java virtual machine".

1. Java virtual machine structure

two。 Representation of integers in java virtual machine

Integers are saved as complements in the java virtual machine

Original code: the so-called original code is the binary representation of a symbol bit plus a number. In int, for example, the first bit represents the symbol bit (positive or negative), and the remaining 31 bits represent the binary value of the number.

Inverse code: the so-called inverse code means that the symbol bits remain unchanged and the rest of the bits are inverted.

Complement: the complement of a negative number is the inverse code plus 1, and the complement of a positive number is the original code itself.

In java, you can use a bit operation to see the actual value of each bit in an integer, as follows:

/ / print the actual representation of-10 in the virtual machine public static void main (String [] args) {int a =-10; for (int I = 0; I)

< 32; i++) { int t = (a & 0x8000_0000 >

> > I) > (31-I); System.out.print (t);}}

The basic idea of this program is to cycle 32 times and take out one of the int values each time. The 0x8000_0000 in the third line is an integer with the first bit 1 and the rest 0. By moving the I bit to the right, the I bit is located to the I bit to be obtained, and the other bits except this bit are uniformly set to 0, while the bit remains unchanged. Recently, the bit is moved to the right and output.

Benefits of using complement

You can unify the representation of the number 0. 0 is both a non-positive number and a non-negative number, so it is difficult to determine the symbol bit when it is represented by the original code, and the original code obtained by classifying 0 into a positive number or a negative number is different. However, when using the complement representation, whether you classify 0 as a positive or negative number, you will get the same result.

The addition and subtraction calculation of integers can be simplified by using complement codes, and the subtraction calculation can be regarded as addition calculation, which can realize the complete unity of subtraction and addition, and the unity of positive and negative addition.

3. Representation of floating point numbers in java virtual machine

In java virtual machines, there are two types of floating-point numbers, float and double, which are 32-bit and 64-bit floating-point numbers, respectively. The representation of floating-point numbers in java virtual machines is slightly more complex than integers. By far the most widely used is the floating-point format defined by IEEE 754.

In the definition of IEEE 754, a floating point number consists of three parts: symbolic bit, exponential bit and Mantissa bit. Take the 32-bit float type as an example, the symbol bit occupies 1 bit, which represents the positive and negative number, the exponential bit occupies 8 bits, and the Mantissa is the remaining 23 bits of the point.

31 bits are symbolic bits: 0 indicates positive number, 1 represents negative number

31 bits 23 bits: a total of 8 bits represent exponential bits, and memory data are stored from 0 to 2 ^ 8-1 bits 255. Since the exponents can be positive or negative, the exponential bits can be represented by shift storage, and the 8-bit signed bits can represent data from-128 to 127 bits. So the actual index represented by the exponential bits should be the number of unsigned bits minus 127. for example, 0000 0000 is represented by 0-127 bits, 127bits, 1111, 1111, 255-127 bits, 12851, 0001 0001, 129-127 bits.

2280 bits: a total of 23 bits represent the Mantissa digits, and the data stored in memory ranges from 0 ~ 2 ^ 23-1 to 8388607.

In java, you can get an IEEE 754 representation of a single-precision floating-point number using the Float.floatToRawIntBits () function, as follows:

Public static void main (String [] args) {float a =-5; System.out.println (Integer.toBinaryString (Float.floatToIntBits (a);} Thank you for reading. The above is the content of "what are the knowledge points of java virtual machine". After the study of this article, I believe you have a deeper understanding of what the knowledge points of java virtual machine are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report