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 java constants

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

Share

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

In this issue, the editor will bring you what are the java constants. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

JAVA constants are values that are fixed in the program and are data that cannot be changed. For example, the number 1, the character "a", the floating point number 3.2, and so on. So what are the constants of java? In Java, constants include integer constants, floating point constants, Boolean constants, character constants, and so on.

Let's take a look at these constants in java.

1. Integer constant

Integer constants are integer data, which are represented in four forms: binary, octal, decimal and hexadecimal.

Binary: a sequence of numbers consisting of the numbers 0 and 1. In JDK7.0, literal values are allowed to represent binary numbers, starting with 0b or 0B in order to distinguish them from decimal systems, such as 0b01101100 and 0B10110101.

Octal: a sequence of numbers, such as 0342, that begins with 0 and is followed by integers in the range 0 to 7 (inclusive).

Decimal: a sequence of numbers consisting of integers in the range of 0 to 9 (including 0 and 9). Such as 198.

Hexadecimal: a sequence of numbers, such as 0x25AF, that begins with 0x or 0X and is followed by 0x 9, A F (including 0 and 9, An and F).

It should be noted that in the program, in order to identify different decimal systems, the data has a specific identification, octal must start with 0, such as 0711 0123; hexadecimal must start with 0x or 0X, such as 0xaf3, 0Xff. when integers are represented in decimal, the first place cannot be 0B0 itself. For example, decimal 127 is represented as 011111 octal in binary, 017 in octal and 0x7F or 0X7F in hexadecimal.

two。 Floating point constant

Floating point constant is the decimal used in mathematics, which can be divided into two types: foat single precision floating point number and double double precision floating point number. Where single-precision floating-point numbers end with F or f, while double-precision floating-point numbers end with D or d. Of course, you can also use floating-point numbers without any suffix at the end, and the virtual machine defaults to double double-precision floating-point numbers. Floating point constants can also be expressed in exponential form. Specific examples are as follows:

2e3f 3.6d 0f 3.84d 5.022e+23f

3. Character constant

Character constants are used to represent a character. A character constant is quoted by a pair of single quotes in English half-width format. It can be English letters, numbers, punctuation marks and special characters represented by escape sequences. Specific examples are as follows:

'a'1' &'\ r'\ u0000'

In the above example,'\ u00' represents a white space character, that is, there are no characters between single quotation marks. The reason for this is that Java uses the Unicode character set, the Unicode character begins with\ u, and the value of the white space character in the Unicode code table is'\ u0000'.

4. String constant

String constants are used to represent a series of consecutive characters, and a string constant is enclosed by a pair of double quotes in English half-width format, as shown in the following example:

"HelloWorld"123"We come\ nXXX"

A string can contain one or more characters, or it can not include any characters, that is, zero in length.

5. Boolean constant

Boolean constants are Boolean values true and false, which are used to distinguish the true from the false of a thing.

6. Null constant

The null constant has only one value, null, indicating that the reference to the object is empty.

These are the java constants shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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