Java Identifiers, Primitivies, & Reference Types Flashcards
Legal Java identifies can only being with the following characters:
A letter
The $ character
The _ character
Can numbers be used in Java identifiers?
Yes but it can’t be the first character in the variable name.
If a Java identifier is composed only of letters, is it always a legal variable name?
No. Java reserved words can not be used as variable names.
With the exception of the first character, legal Java identifies can only contain the following characters:
Letters
Numbers
The $ character
The _ character
What structures in Java are named using identifiers?
Variables
Methods
Classes
Fields
What is a variable?
A variable is a name for a piece of memory that stores
data.
What are the minimum requirements when declaring a variable in Java?
At a minimum, a variable must have a variable type and an identifier (or name).
Java has two types of data variables, what are they?
Primitive Types
Reference Types
How many primitive types (or primitives) does Java have?
8
What are the Java primitive types?
boolean byte short int long float double char
How much memory is required for a byte? What values can it hold? What is its default value?
8-bits or 1 byte
-128 to 127
0
How much memory is required for a short?What values can it hold?What is its default value?
16-bits or 2 bytes
-32,768 to 32,767
0
How much memory is required for an int? What values can it hold? What is its default value?
32-bits or 4 bytes
-2^31 to (2^31)-1
0
How much memory is required for a long? What values can it hold? What is its default value?
64-bits or 8 bytes
-2^63 and a maximum value of (2^63)-1
0L
How much memory is required for a float?
32-bits or 4 bytes
How much memory is required for a double?
64-bits or 8 bytes
How much memory is required for a char in Java 8? What values can it hold? What is its default value?
16-bits or 2 bytes
A Unicode character
‘\u0000’
What is the default value of a boolean?
false
Does the following line of code compile?
long max = 3123456789;
Why or why not?
No. When using literal values, Java treats numbers like ints. This value is greater than the maximum int value. To fix the problem append ‘L’ to make Java treat this is a long.
long max = 3123456789L;