Questions and CORRECT Answers
Which of the following are Valid Java Identifiers?
• sum & difference
• SpEcIaL_vAlUe
• 00xTrick
• age1
• a-javapoint
• 1AGE
• Test Variable
• Tax
• a555c - CORRECT ANSWER - • SpEcIaL_vAlUe
• age1
• Tax
• a555c
Valid Java Identifiers will consist only of letters (a-z, A-Z), underscore ( _ ), dollar sign ($), and
digits (0-9)
HOWEVER Identifiers can ONLY START with a letter (a-z, A-Z), underscore ( _ ), or dollar
sign ($)
Identifiers CANNOT begin with a digit(0-9)
Evaluate logical expression:
! false && false
,True of False ? - CORRECT ANSWER - False
! means "not" in Java
&& means "and"
therefore, the logical expression states "not false and false"
this cannot be simultaneously true, so we evaluate this expression to be False
Which of the following Java literals have data type double?
• false
• true
• 123
• 1.23f
• 123.0
• 3f
• "3.0"
• 'a'
• -3
• -1.23
• "true"
• '\n' - CORRECT ANSWER - • 123.0
• -1.23
When the following expression is evaluated, the result will be what Java data type?
49.63 * 81.7f
,1) int
2) float
3) double
4) boolean
5) char
6) String
7) none of these - CORRECT ANSWER - 3) double
49.63 is a double and 81.7f is a float
double takes over a float because it is more precise
Which of the following would be the best data type for a variable to store the average tax rate
payed by corporations in the United States?
• boolean
• float
• int
• char
• none of these
• String - CORRECT ANSWER - • float
tax rate will most times be in a decimal form
Write a line of Java code that will declare a double variable named x, that is initialized to a value
of 90.24. - CORRECT ANSWER - double x = 90.24;
When there are no remaining references to an object in your Java program, the object will be
destroyed.
, True or False - CORRECT ANSWER - True
Which of the following would correctly declare and instantiate an array of 6 ints?
• int[] values = int[4];
• int[] values = new int[5];
• int[] values = int [6];
• int[] values = int [5];
• int[5] values = new int [5];
• int[5] values = new int[];
• int[] values = new int[6];
• int[6] values = new int [];
• int[6] values = new int [6];
• int[4] values = new int;
• int[4] values = new int [4];
• none of these;
• int[] values = new int [4]; - CORRECT ANSWER - • int[] values = new int[6];
1-D array of # ints: int[] variablename = new int[#];
Which of the following would correctly declare and instantiate a 2-D array with a total of 16
ints?
• int[4][4] values = new int;
• int[2] values = new int[8];
• int[2][8] values = new int;
• int[,] values = new int[2,8];