Visual Basics Chapter 2: Intro to Java
Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night"); This statement will output ______ lines of text.
2
public class Questions 1_4 { public static void main(String[] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } How many Lines of output are provided by this program?
2
A color image is broken down into individual pixels (points), each of which is represented by _______
3 values denoting the intensity of red, green, and blue (RGB) in the image
Following Java naming convention, which of the following would be the best name for a class about store customers? a) StoreCustomer b) Store Customer c) storeCustomer d) STORE_CUSTOMER e) Store-Customer
A
If a, b, and c are int variable with a=5, b=7, and c=12, then the statement int z=(a*b-c)/a will result in z equal to a) 4 b) -5 c) 0 d) 23 e) 5
A
In order to create a constant, you would use which of the following Java reserved words? a) final b) private c) class d) static e) int
A
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? a) 15 b) x+y c) 10 5 d) 105 e) An error since neither x nor y is a String
A
import java.util.Scanner; public class Questions33_34 { public static void main(String[] args) { int x, y, z; double average; Scanner scan = Scanner.create(System.in); System.out.println("Enter an integer value"); x=scan.nextInt(); System.out.println("Enter another integer value"); y=scan.nextInt(); System.out.println("Enter a third integer value"); z=scan.nextInt(); average=(x+y+z)/3; System.out.println("The result of my calculation is" + average); } } Questions33_44 computes a) The average of x, y,and z as a double, but the result may not be accurate b) The correct average of x, y, and z as a double c) The sum of x, y, and z d) The remainder of the sum of x, y, and z divided by 3 e) The correct average of x, y, and z as an int
A
Given the following assignment statement, which of the following answers is true regarding the order the operators will be applied based on operator precedence? a=(b+c)*d/e-f; a) *, +, /, - b) +, *, /, - c) +, -, *, / d) +, /, *, - e) *, /, +, -
B
If x is an int and y is a float, all of the following are legal except which assignment statement? a) y=x; b) x=y; c) y=(float)x; d) x=(int)y; e) all of the above are legal
B
If you want to output the text "hi there," including the quote marks, which of the following could do that? a) System.out.println("\"hi there"); b) System.out.println("\"hi there\""); c) System.out.println(""hi there""); d)System.out.println("hi there"); e) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output
B
What will be the result of the following assignment statement? Assume b=5 and c=10 int a=b*(-c+2)/2; a) 20 b) -20 c) -30 d) 30 e) -6
B
Which of the following is a legal Java identifier? a) class b) i c) ilikeclass! d) idon'tlikeclass e) i-like-class
B
import java.util.Scanner; public class Questions33_34 { public static void main(String[] args) { int x, y, z; double average; Scanner scan = Scanner.create(System.in); System.out.println("Enter an integer value"); x=scan.nextInt(); System.out.println("Enter another integer value"); y=scan.nextInt(); System.out.println("Enter a third integer value"); z=scan.nextInt(); average=(x+y+z)/3; System.out.println("The result of my calculation is" + average); } } What is the output if x=0, y=1, and z=1? a) 0.67 b) 0.0 c) 0.6666666666667 d) 0 E) 0.666666666666
B
public class Questions 1_4 { public static void main(String[] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } The program will print the word "Here" and then print a) "There" on the line after "Here" and "Everywhere" on the line after "There" b) "There Everywhere" on the same line as "Here" c) "There Everywhere" on the line after "Here" d) "ThereEverywhere" on the same line as "Here" e) "ThereEverywhere" on the line after "Here"
B
A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java's ______.
Bytecodes
Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x/y/x? a) 12 b) 16 c) 0 d) a syntax error as this is syntactically invalid e) a run-time error because this a division by 0
C
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following set of commands might you use? a) page.setColor(Color.red); page.fillOval(50, 50, 100, 100); page.setColor(Color.green); page.fillRect(60, 60, 80, 80); b)page.setColor(Color.red); page.fillOval(60, 60, 80, 80); page.setColor(Color.green); page.fillRect(50, 50, 100, 100); c) page.setColor(Color.green); page.fillRect(50,50,100,100); page.setColor(Color.red); page.fillOval(60, 60, 80, 80); d)page.setColor(Color.green); page.fillRect(60, 60, 80, 80); page.setColor(Color.red); page.fillOval(50, 50, 100, 100); e)any of the above would accomplish this
C
Java is a strongly types language. What is meant by "strongly typed"? a) Every variable must have an associated type before you can use it b) Variables are allowed to change types during their existence in the program but only if the change is to a narrower type c) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type d) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be e) Variables can be used without declaring their type
C
Java is similar in syntax to what other high level language? a) Ada b) BASIC c) C++ d)PORTRAN e) Pascal
C
Of the following types, which one cannot store a numeric value? a) byte b) int c) char d) float e) all of these can store numeric values
C
What is the output with the statement System.out.println(''"+x+y); if x an y are int values where x=10 and y=5? a) 15 b) x+y c) 105 d) 10 5 e) An error since neither x nor y is a String
C
What value will z have if we execute the following assignment statement? float z = 5/10; a) z will equal 0.05 b) z will equal 5.0 c) z will equal 0.0 d) z will equal 0.5 e) none of the above, a run-time error arises because z is a float and 5/10 is an int
C
public class Questions 1_4 { public static void main(String[] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } A reasonable documentation comment for this program might be _______. a) //a program that outputs a message about Texas b) //a program that demonstrates nothing at all c) //a program that demonstrates the differences between print, println and how + works d) //a program that outputs the message "Here There Everywhere But not in Texas" e) //a program that contains three output statements
C
public class Questions 1_4 { public static void main(String[] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } The final println command will output a) "But not+in Texas" b) "But not in Texas" c) "But notin Texas" d) "But not" on one line and "in Texas" on the next line e) "But not + in Texas"
C
A cast is required in which of the following situations? a) using charAt to take an element of a String and store it in a char b) store an int in a float c) storing a float in a double d) storing a float in an int e) all of the above require casts
D
What value will z have if we execute the following statement? int z=50/10.00; a) 10 b) 5 c) 50 d) 5.0 e) none of the above, a run-time error arises because z is an int and 50/10.00 is not
E
Which of the following is true regarding the mod operator, %? a) It can only be performed on int values and its result is an int b) It can only be performed on int values and its result is a double c) It can only be performed on float or double values and its result is an int d) It can only be performed on float or double values and its result is a double e) It can be performed on any numeric values, and the result is always numeric
E
Java is an example of a(n) a) assembly language b) machine language c) high-level language d) fourth-generation language e) both C and D
E, both C and D
True or False? A variable of type boolean will store with a 0 or a 1
False
A Java variable is the name of a a) data value stored in memory that can change both its value and its type during the program's execution b) data value or a class stored in memory that can change both its value and its type during the program's execution c) numeric value stored in memory d) data value stored in memory that can not change during the program's execution e) data value stored in memory that can change its value but cannot change its type during the program's execution
e
public void paint(Graphics page) { page.setColor(Color.blue); page.fillRect(50, 50, 100, 100); page.setColor(Color.white); page.drawLine(50, 50, 150, 150); page.drawLine(50, 150, 150, 50); page.setColor(Color.black); page.drawString("A nice box", 50, 170); } The figure drawn in this applet is a) a blue square b) a white square with two blue lines drawn vertically through it c)a blue square with two white lines drawn vertically through it d) a blue square with two white lines drawn horizontally through it e) a blue square with two white lines drawn diagonally through it
e
Mistyping "println" as "printn" will result in a ________ error.
Syntax
In Java, 'a' and 'A' are considered to be different values
True
True or False? A double is wider than a float and a float is wider than an int.
True
Which of the following is not syntactically legal in Java? a) s t a t i c main(String[] args) b) System.out.println("Hi"); c) {} d) public class Foo E) Only B is legally valid, all of the rest are illegal
a
Comments should a) rephrase the code it explains in English b) be insightful and explain what the instruction's intention is c) only be included in code that is difficult to understand d) be used to define variables whose names are not easy to understand e) all of the above
b
In the following list, which statement is not true regarding Java as a programming language? a) It is a relatively recent language, having been introduced in 1995 b) It is a language whose programs do not require translating into machine language before they are executed c) It is a language that embraces the idea of writing programs to be executed using the World Wide Web d) It is an object-oriented program e) all of the above are true
b
Which character below is not allowed in an identifier? a) _ b) ^ c) q d) $ e) 0 (zero)
b
Which of the following is a legal Java identifier? a) 1ForAll b) oneForAll c) one/4/all d) 1_4_all e) 1forall
b
You specify the shape of an oval in a Java applet by defining the oval's ______.
bounding box
The instruction: System.out.println("Hello World"); might best be commented as a) //prints "Hello World" to the screen b) //prints a message c) //used to demonstrate an output message d) // e) //meaningless instruction
c
The main method for a Java program is defined by a) public static main () b) public static main(String[] args); c) public static main(String[] args) d) private static main(String[]args) e) the main method could be defined as in A, C, or D but not B
c
Which of the following characters does not need to have an associating "closing" character in a Java program? a) [ b) ( c) < d) { e) all of these require closing characters
c
Which of the following is true regarding Java syntax and semantics? a) a Java compiler can determine if you have followed proper semantics but not proper syntax b) a Java compiler cannot determine if you have followed either proper syntax or semantics c) a Java compiler can determine if you have followed proper syntax but not proper semantics d) a Java compiler can determine if you have followed both proper syntax and semantics e) a Java compiler can determine if you have followed proper syntax and can determine if you have followed proper semantics if you follow the Java naming convention rules
c
Which of the following would be a good variable name for the current value of stock? a) curstoval b) theCurrentValueOfThisStockIs c) currentStockVal d) csv e) current
c
The line of Java code "// System.out.println("Hello");" will a) cause a syntax error b) cause "(Hello)" to be output c) cause "Hello" to be output d) do nothing e) there is no way to know without executing this line of code
d
An error in a program that results in the program outputting $100 instead of the correct answer, $250 is a _______ error.
logical or semantics
The word println is a(n) ______.
method
