In C, a string literal represents an array of characters (the char primitive data type). However, as you will learn soon, Java does not follow suit. The following code provides some examples of the use of a string literal and the \t escape characters:
“This is a test”
“This is V test”
The first line above simple prints out the statement “This is a test.” The second line prints out the same thing, but places a tab where the \t is so, when printed, it will look something like “ This is a \test.”
Showing posts with label Literal. Show all posts
Showing posts with label Literal. Show all posts
Monday, May 26, 2008
Sunday, May 25, 2008
Non-Numerical Literals 2
\b Backspace
\f Form Feed
\n New line
\t Tab
\ Backslash
\’ Single quote
\” Double quote
You worked with string literal, the second major non-numerical literals, to print statements on the screen in the example in the last chapter. String literals are merely collections of character literals. Java stores string literals in a more complex type known as string object.
\f Form Feed
\n New line
\t Tab
\ Backslash
\’ Single quote
\” Double quote
You worked with string literal, the second major non-numerical literals, to print statements on the screen in the example in the last chapter. String literals are merely collections of character literals. Java stores string literals in a more complex type known as string object.
Friday, May 23, 2008
Non-Numerical Literals
Non-Numerical Literals
There are two major non-numerical literals in Java. The first, a character literal, represents a single character surrounded by quotations. Some characters are not so obvious or simply cannot be encased in quotations. That is where character escapes come in. The following post is a list of commonly used escape characters to print the not-so –obvious values:
There are two major non-numerical literals in Java. The first, a character literal, represents a single character surrounded by quotations. Some characters are not so obvious or simply cannot be encased in quotations. That is where character escapes come in. The following post is a list of commonly used escape characters to print the not-so –obvious values:
Tuesday, May 20, 2008
Literals Notes 2
Literals Notes 2
Floating-point types also let you specify scientific notation by using the letter e or (E) to represent the exponential power. For example, the value 2.54 x 10 power 5 represented in Java is 2.54e5 or 2.54e5f housed in the float type.
Unlike C and C ++, Java has Booleans literals, Java Booleans represent either the non-numerical value true or false.
Floating-point types also let you specify scientific notation by using the letter e or (E) to represent the exponential power. For example, the value 2.54 x 10 power 5 represented in Java is 2.54e5 or 2.54e5f housed in the float type.
Unlike C and C ++, Java has Booleans literals, Java Booleans represent either the non-numerical value true or false.
Monday, May 19, 2008
Literals Notes
Appended letters for specifying a particular data type when using literals are not case sensitive. For example, 100001 and 10000L both specify this literal to be a numerical type long. Extremely large values utilize the integer data type long. Floating-point values are automatically assumed to be a type double. However if you wish to use the smaller floating-point type float, then you need to append a letter “f” to represent that data type 2.313f.
Sunday, May 18, 2008
Numerical Literals
In Java programs, numerical literals represent quantitative values, Java supports several different numerical systems, including octal (a numbering system with a base of 8) and hexadecimal (using a base of 16). If needed, you can specify the literal to be long by appending the letter “L”: 24050000L. An int is the default type used for integer literals.
Thursday, May 15, 2008
Literal 2
Literal 2
Data types, discussed later in the chapter are values (a.k.a variables) that represent or hold other values. This is very similar to algebra, where x can be more than just x; x could be 2, square root of -5, or the gross national product. As you will learn later, Java has a specific set of data types for certain values.
Data types, discussed later in the chapter are values (a.k.a variables) that represent or hold other values. This is very similar to algebra, where x can be more than just x; x could be 2, square root of -5, or the gross national product. As you will learn later, Java has a specific set of data types for certain values.
Monday, May 12, 2008
Literal
Literal
A literal is any value expressed as itself. There are several types of literals; numerical literals, including integers, floating-point values, and Booleans; and non-numerical literals, including characters and multiple literals (known as string literals).
A literal is any value expressed as itself. There are several types of literals; numerical literals, including integers, floating-point values, and Booleans; and non-numerical literals, including characters and multiple literals (known as string literals).
Subscribe to:
Posts (Atom)