A string cannot cross lines (wrap to the next line) in the source code! To fix lines that have to wrap around to the next line break the string into separate substrings and use the concatenate operator, +.
An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit.
The $ by convention, is used only in mechanically generated source code
An identifier cannot be a reserved word.
And identifier cannot be true, false, or null.
An identifier can be of any length.
Java is case sensitive!
Data Type: the kind of data stored in a variable
Primitive Data Types: integers, floating-point (numbers with decimal point), characters, and Boolean
Variables: represents a value stored in the computer’s memory
The value can be changed in the program
Represent data of a certain type
The variable must be declared before it can be assigned a value
When possible, declare and assign its initial value in one statement
Declaring variables: telling the computer (compiler) what the variable is & allocates memory space for the variable based on its data type
You can use a variable in an expression: x = x + 1;
System.out.println(x = 1); is equivalent to x = 1;
i =j = k = 1; is equivalent to k = 1;
j = k;
i = j;
Initialize Variables / Assignment Operator: = assigning a value to a variable
variable = expression;
Example: int y = 1;
Assignment Statements: designates a value for a variable
Integer division results in integer number – not a decimal number (the fractional part is truncated)
To force 2 integers to perform floating-number division, make one be a floating-point number (cast)
Writing code to create multiple input objects for each input – creating a Scanner for each reading for each object to be read
Not prompting a user to enter the input
Character Data Type
A character data type represents a single character
A character literal is enclosed in signal quotations:
char letter = ‘A’; // assigns A to the variable letter
char numChar = ‘4’; // assigns digit character 4 to the variable numChar
A string literal must be enclosed in double quotation marks (“”).
A character literal must be enclosed in a single quotation mark (‘’).
The increment and decrement operators can also be used on char variables to get the next or preceding Unicode character. For example, the following statements display character b.
char ch = 'a';
The String Type
a string is a sequence of characters
String is actually a predefined class in the Java library just like the System class and JOptionPane class.
The String type is not a primitive type. It is known as a reference type. Any Java class can be used as a reference type for a variable.
Reference data types will be thoroughly discussed in Chapter 7, “Objects and Classes.” For the time being, you just need to know how to declare a String variable, how to assign a string to the variable, and how to concatenate strings.
// Three strings are concatenated
String message = "Welcome " + "to " + "Java";
// String Chapter is concatenated with number 2
String s = "Chapter" + 2; // s becomes Chapter2
// String Supplement is concatenated with character B