Updates
What makes a valid Java Identifier? ANS The first character must be picked from: alpha, underscore, or
dollar sign. The first character can not be a digit.
The rest of the characters (besides the first) can be from: alpha, digit, underscore, or dollar sign. Cannot use
reserved words.
! false && true ANS True
What indicates a string in? ANS anything inside " "
Name the 8 java primitive types. ANS boolean, float, char, int, double, byte, short, long
When the following expression is evaluated, the result will be what Java data type?
-80.16 - -10.11 ANS double
When the following expression is evaluated, the result will be what Java data type?
3 + 5.0 ANS double
Which of the following would be the best data type for a variable to store a phone number, like (602) 555-
1212? ANS String
Write a line of Java code that will declare a boolean variable named version that is initialized to the value true.
ANS Answer: boolean version = true;
What will this small program output?
class Main {
public static void foo() {
System.out.println(x);
}
public static int x = 6;
, public static void main(String[] args) {
int x = 33;
foo();
}
} ANS 6
class Main {
public static void foo() {
x = 19;
}
public static int x = 1;
public static void main(String[] args) {
foo();
System.out.println(x);
}
} ANS 19
Instantiate an array of 5 integers in java. ANS new int[5]
declare and instantiate an array of 5 integers in java. ANS int[] my_array = new int[5];
Java arrays have an attribute named _____ that can be accessed to get the size (number of elements) of the
array. ANS length
Given the following declaration:
int[][] values = { {7, 71, 29, 58},
{23, 91, 45, 52},
{78, 33, 82, 97}
};
Evaluate the following expression: