1. When does a logic error get detected? At compile time At run time, and causes
ID: 3919300 • Letter: 1
Question
1. When does a logic error get detected?
At compile time
At run time, and causes the program to stop and display the error
When the program is run multiple times
At run time, but the program does not stop or display that an error occurred
2. To create a window in an application using JavaFX, you must extend which class?
none of these choices
Applet
EventHandler
Application
JFrame
3. Which ONE or MORE of the following, if any, ARE characteristics of Object-Oriented Programming? (you may select zero, one, or more than one choice)
A class can be thought of as a category from which multiple "instances" or objects can be created.
Object-Oriented Programming often results in "spaghetti code" that is hard to follow
Flow of control is structured so that one function after another can manipulate data, which is available globally to all functions.
Classes can inherit characteristics from other classes.
Data and behaviors are grouped together in objects
4. Which of the following serves as a template for objects to be created?
class
array
field
method
5. What will be displayed as a result of executing the following code?
int counter = 4;
String string = "Think before you code";
System.out.println(string+". Character number "+(counter+1)+" is "+string.charAt(counter));
string = string.toLowerCase();
System.out.println(string+". Character number "+(counter)+" is "+string.charAt(--counter));
System.out.println("string is "+string.length()+" characters long.");
Think before you code. Character number 4 is k
THINK BEFORE YOU CODE. Character number 3 is N
string is 21 characters long.
Think before you code. Character number 5 is k
think before you code. Character number 4 is n
string is 21 characters long.
Think before you code. Character number 4 is n
think before you code. Character number 3 is n
string is 21 characters long.
This code will not compile.
6. Which of the following does NOT indicate a comment in Java?
Starts with two semi-colons, that is, ;;
/**
...
*/
Starts with two slashes, that is, //
/*
...
*/
7. What will be printed out as a result of the following code?
int x = 5, y = 7;
System.out.println(++x);
x += y++;
System.out.println(x + "," + y);
6
6,8
6
13,8
5
13,8
5
12,7
8. Encapsulation is a key principle of structured programming. It states that a class should contain private data and public methods to manipulate that data
True
False
9. One problem with Java is that a Java program has to be recompiled for each type of computer it will run on.
True
False
10. Assume that myVar is correctly declared as an array, and then initialized as myVar = {17,30,2,51};
Will the following will correctly print out the values of the myVar array?
for (int i=0; i<=4; i++) {
System.out.println(myVar[i]);
}
True
False
11. GUI programs, whether using the Swing Java API or the JavaFX API, use events. What does an event do?
none of the above
An event is thrown when an error occurs in the program.
An event is an object that signals that a GUI component has been used (for example, a button has been pushed, a text field has text entered, etc.)
An event is an object that is effectively final, i.e., it is set once and cannot be reset.
e. An event launches the initial GUI, then is deleted.'
12. What does the Scanner object do when instantiated as follows?
Scanner myScanner = new Scanner (System.in);
It reads keystrokes from the keyboard.
Scanner prints output to the console.
It scans a String object character by character to remove any non-printable characters.
The programmer must define the class Scanner and specify what it does.
13. When using JavaFX, the program must call the method "launch", which is predefined and calls the method "start", which is implemented by the programmer.
True
False
14. Given the following declaration:
double deposit;
then the following statement is valid (T/F)
15. Which of the following code snippets will correctly swap the values contained in variables num1 and num2 (assume all variables are declared as int and previously initialized)
myVar1 = temp;
myVar2 = myVar1;
temp = myVar2;
myVar1 = temp;
myVar2 = myVar1;
myVar1 = myVar2;
temp = myVar1;
myVar1 = myVar2;
myVar2 = temp;
myVar1 = myVar 2;
myVar2 = myVar 1;
deposit = $2,100.00;
True
False
a.At compile time
b.At run time, and causes the program to stop and display the error
c.When the program is run multiple times
d.At run time, but the program does not stop or display that an error occurred
Explanation / Answer
1) When does a logic error get detected?
Ans :- d) At run time, but the program does not stop or display that an error occurred
explaination:- Logical errors in Java programming can be extremely difficult to find
because they don’t reflect any sort of coding problem or an error in the use of Java language elements.
The code runs perfectly as written — it just isn’t performing the task that you expected it to perform
2) To create a window in an application using JavaFX, you must extend which class?
Ans: d) Application
3)Which ONE or MORE of the following, if any, ARE characteristics of Object-Oriented Programming?
Ans :
a) A class can be thought of as a category from which multiple "instances" or objects can be created.
c) Flow of control is structured so that one function after another can manipulate data,
which is available globally to all functions
d) Classes can inherit characteristics from other classes.
e)Data and behaviors are grouped together in objects
4) Which of the following serves as a template for objects to be created?
Ans
a) class
5) What will be displayed as a result of executing the following code?
Ans
b) Think before you code. Character number 5 is k
think before you code. Character number 4 is n
string is 21 characters long.
6) Which of the following does NOT indicate a comment in Java?
Ans
a) Starts with two semi-colons, that is, ;;
7) What will be printed out as a result of the following code?
int x = 5, y = 7;
System.out.println(++x); print 6 and x = 6
x += y++; x = 13 and y = 8
System.out.println(x + "," + y);
Ans
b) 6
13,8
8). Encapsulation is a key principle of structured programming.
It states that a class should contain private data and public methods to manipulate that data
Ans TRUE
9)One problem with Java is that a Java program has to be recompiled for each type of computer it will run on.
Ans FALSE
10) Assume that myVar is correctly declared as an array, and then initialized as myVar = {17,30,2,51};
Will the following will correctly print out the values of the myVar array?
for (int i=0; i<=4; i++) {
System.out.println(myVar[i]);
}
Ans : It will genetrate ArrayIndexOutOfBoundException for i = 4 So Answer is FALSE
11) GUI programs, whether using the Swing Java API or the JavaFX API, use events. What does an event do?
Ans : c) An event is an object that signals that a GUI component has been used
(for example, a button has been pushed, a text field has text entered, etc.)
12) What does the Scanner object do when instantiated as follows?
Scanner myScanner = new Scanner (System.in);
Ans : a) It reads keystrokes from the keyboard.
13) When using JavaFX, the program must call the method "launch",
which is predefined and calls the method "start", which is implemented by the programmer.
Ans: FALSE IT it not essential for programer to call launch method.
14) Given the following declaration:
double deposit;
deposit = $2,100.00; Not Valid Value shoult not contain $ and ,
Ans : FALSE
15) Which of the following code snippets will correctly swap the values contained in variables num1 and num2
(assume all variables are declared as int and previously initialized)
ANS : c) temp = myVar1;
myVar1 = myVar2;
myVar2 = temp;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.