The use of long data type in Java programming
In Java programming, we often encounter some problems with the use of integer types. Let's look at the use of long shaping data. Today, when writing a java thread, I want the thread to sleep for 720 hours and continue to execute. The code is as follows:
When starting the thread test, it was found that the thread did not execute after 720 hours as expected, but kept executing. Finally, the tracking code found that the value of runsperiod was negative. After careful study, it is found that when Java multiplies several numbers, if several numbers are of type int, the calculated value is of type int. the computer result above is of type int, but it is beyond the scope of type int in Java, so the result is negative. The solution is very simple. Just add L after the multiplied number (as long as a number is added after it). Identify that the number type is a long integer, and the calculated result is a long type.
Under normal circumstances, if an integer number, such as 35, appears in Java, the number is of type int. if we want it to be of type byte, we can add uppercase B: 35b after the data to indicate that it is of type byte. Similarly, 35S means short, 35L means long, and means Int. we don't need to add anything, but if we want to indicate long, You must add "L" after the data.
summary
The above is all about the use of Java programming data type long in this article. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you for your support.