The literal in Java

Source: Internet
Author: User

Literal quantity

In computer science, the literal (literal) is a representation of a fixed value (natation) used to express a source code. Almost all computer programming languages have literal representations of basic values, such as integers, floating-point numbers, and strings, while many also support literal representations of Boolean and character-type values, as well as literal notation for elements of enumerated types and for conforming types such as arrays, records, and objects.

Integer Digital surface Amount

integers may be the most commonly used type in a typical program. The value of any one number is an integer literal. For example the 42. These are decimal values, which means that their descriptions are based on the number 10. There are also 2 other kinds of binary that are used by integer literals, octal (octal, cardinality is 8) and hexadecimal (hexadecimal, cardinality is 16). The value of octal in Java is represented by a leading zeros in front of it. The normal decimal number does not have a leading zero. Thus, a value of 09 that looks valid will produce an error from the compiler because 9 is outside the octal range 0~7. Programmers are more commonly used for numbers in hexadecimal, which clearly matches the size of 8, such as 8,16,32, and 64 bits. a hexadecimal literal is represented by a leading 0x or 0X. The hexadecimal number range is 0~15, which replaces 10~15 with a~ F (or a~f).

The integer number of polygons produces an int value, which in Java is a 32-bit integer value. Since Java is strict with types, you might wonder how it is possible to assign an integer literal to another integer type of Java such as a byte or a long without producing a type mismatch error. Fortunately, this problem is well settled. When a literal value is assigned to a variable of byte or short, no error occurs if the literal value does not exceed the range of the corresponding type.

string literal

string literals in Java are the same as most other languages-enclose a series of characters in double quotation marks. Examples of strings such as:

"Hello World"
"Two\nlines"
"\" This was in Quotes\ ""

The character escape sequence defined for a string is the same as the octal/16 notation within a string. One important thing to note about Java strings is that they must start and end on the same line. Unlike other languages, there is a newline connection escape sequence.

Note: You may be aware that in most other languages, including C + +, strings are implemented as arrays of characters. However, this is not the case in Java. In Java, strings are actually object types. Because Java implements the string as an object, it has a wide range of string processing capabilities and is powerful and useful.


The literal in Java

Related Article

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.