Fast Starts + Review Questions
What is the output? System.out.println(w2.compareTo(w3)); error 5 -1 -5 0
-5
What will be printed by the following code? String s = "Animal";System.out.println(s.indexOf("al")); 3 2 1 4 Nothing is printed, an error occurs
4
Consider the following code: int a = 43; int b = 17; System.out.println(a % b); What is the output? 34 9 2 0 43 % 17
9
Which one of the following sentences is true? A double is a primitive data type so a double variable directly stores the data for the double. A double is a primitive data type so a double variable holds a reference to a location in memory. A double is a class data type so a double variable directly stores the data for the double. A double is a class data type so a double variable holds a reference to a location in memory.
A double is a primitive data type so a double variable directly stores the data for the double.
Suppose s1 and s2 are Strings and the following code is run: s1 = s1.toLowerCase();s2 = s1.toUpperCase();System.out.println(s1.compareTo(s2)); What should be the expected output? A positive value is printed 0 is printed A negative value is printed
A positive value is printed
Consider the following code: int x = 27; int y = 13; System.out.print("Answer: " + x + y); This code outputs: Answer: 2713
False IT WILL ADD 27 and 13 to get 40!
Which of the following best describes the relationship between a class and an object? A class is a piece of data which is contained in an object. An object is used to create classes, which are primitive data types. A class is a specific variable in a program, which has behaviors defined by objects. Objects are created using classes, which are similar to blueprints.
Objects are created using classes, which are similar to blueprints.
Select all the classes from the list int void "Java" 14 Scanner double String 7.5
Scanner String
Which code shows us creating an object of data type Scanner class and storing it with a variable named stat ? Scanner stat = Scanner(System.in); stat = new Scanner(System.in); new Scanner stat = new Scanner(System.in); stat Scanner = new Scanner(System.in); Scanner stat = new Scanner(System.in);
Scanner stat = new Scanner(System.in);
Which of the following would set the String variable hobby to be completely empty (i.e. not even storing a memory address)? String hobby = ""; String hobby = null; String hobby = "null"; String hobby = 0; String hobby = " ";
String hobby = null;
Which of the following code segments correctly declares a String s and gives it a value of "fundamentals"? Select all that apply. String s = "fundamentals"; s = new String(); String s = new "fundamentals"; String s; s = "fundamentals"; String s = ("fundamentals"); String s = new "fundamentals"; s = new String(); s = "fundamentals";
String s = "fundamentals"; String s; s = "fundamentals"; String s = ("fundamentals");
Which of the following symbols need an escape character to be output in a System.out.print statement? \ @ # $ !
\
To output: Nums: [31, 43, 28, 17 ] You would need to use what escape sequence in the blank: System.out.print("Nums: [31, 43, 28, 17____]"); \s \n \t None of the above \\
\n
Which of the following are true about class data types? Click all that apply. can hold multiple pieces of data of different types can be customized cannot be created can be created
can hold multiple pieces of data of different types can be customized can be created
_____ data types can hold many pieces of information at a time. null alphanumeric class primitive
class
Which of the following correctly declares a new variable which can be used to point to an object of the double class type? double d; d = new double(); d double; new double; d = double;
double d;
What is stored in w1 by the following? w1 = w3.substring(1, 3); nts li nt n lie
li
To define an empty variable, ____ keyword can be used. primitive null class alphanumeric
null
Java allocates a space in memory called a(n) _____. location reference alphanumeric datatype
reference
Consider the following code: String a = "first"; String b = a; a = "second"; System.out.println(a + " " + b); What is printed when the code is run? Hint: Remember Strings are immutable. second first second second first second first first
second first Correct. Strings are immutable, where a is first set to "first", b is also set to "first" as a result, where a's value is then changed to "second" resulting in "second first" being the output.
Use the following code for questions 2-7: String w1; String w2 = "ants"; String w3 = "flies"; What is stored in w1 by the following? w1 = "type: " + w2; type: fly type: ants type:fly Nothing, + does not work on Strings type:ants
type: ants