Java Reference
In-Depth Information
Even if this line is a comment line, it will generate a compiler error. The comment will be split into two lines
before compilation, like so:
// char c = '
';
The second line, which contains, '; , causes the compiler error. The multi-line comment syntax would not
generate a compiler error in such a case.
/* char c = '\u000A'; */
would be converted to
/* char c = '
'; */
which is a valid multi-line comment.
A Short Break
I have finished discussing all primitive data types available in Java. In the following section, I will discuss the general
concepts of binary numbers and their use in representing different types of values in Java. If you have a computer
science background, you may skip this section.
The program in Listing 3-1 shows how to declare variables of different data types using literals. It also prints the
values for some constants in the Double class. Java 8 has added the Double.BYTES constant that contains the number
of bytes used by a double variable.
Listing 3-1. Using Primitive Data Types
// NumTest.java
package com.jdojo.datatype;
public class NumTest {
public static void main(String[] args) {
int anInt = 100;
long aLong = 200L;
byte aByte = 65;
short aShort = -902;
char aChar = 'A';
float aFloat = 10.98F;
double aDouble = 899.89;
// Print values of the variables
System.out.println("anInt = " + anInt);
System.out.println("aLong = " + aLong);
System.out.println("aByte = " + aByte);
System.out.println("aShort = " + aShort);
System.out.println("aChar = " + aChar);
System.out.println("aFloat = " + aFloat);
System.out.println("aDouble = " + aDouble);
 
Search WWH ::




Custom Search