You are on page 1of 316

Question 1

What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0;
Select one:
a. .03
b. .01
c. .05
d. 0
Question 2
Which of the following statements creates a class that is extended from the JFrame class?
Select one:
a. public class DerivedClass extends JFrame{}
b. JFrame DerivedClass = new JFrame();
c. class JFrame DerivedClass;
d. JFrame(DerivedClass);
Question 3
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. link
b. assume
c. import
d. use
Question 4
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Select one:
a. True
b. False
Question 5
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();

timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Select one:
a. 3
b. 1
c. 4
d. 2
Question 6
In a general sense, a method is
Select one:
a. a comment
b. a statement inside a loop
c. a collection of statements that performs a specific task
d. a plan
Question 7
You cannot assign a value to a wrapper class object.
Select one:
a. True
b. False
Question 8
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
Select one:
a. 80
b. No value, this is a syntax error.
c. 50
d. 30
Question 9
A variable's scope is the part of the program that has access to the variable.
Select one:
a. False
b. True
Question 10
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{

x += 10;
}
Select one:
a. 100
b. 90
c. This is an infinite loop
d. 110
Question 11
Each byte is assigned a unique number known as an address.
Select one:
a. True
b. False
Question 12
This is a variable whose content is read only and cannot be changed during the program's execution.
Select one:
a. literal
b. named constant
c. operator
d. reserved word
Question 13
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Select one:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question 14
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Select one:
a. True
b. False
Question 15
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. This is an error
b. 8.0
c. 18 (as an integer)
d. 18.0

Question 16
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?
PrintWriter diskOut = new PrintWriter("DiskFilE.txt");
Select one:
a. diskOut.println("Calvin");
b. System.out.println(diskOut, "Calvin");
c. PrintWriter.println("Calvin");
d. DiskFilE.println("Calvin");
Question 17
When you are writing a program with String objects that may have unwanted spaces at the beginning or end of
the strings, use this method to delete them.
Select one:
a. replace
b. trim
c. valueOf
d. substring
Question 18
This is a group of related classes.
Select one:
a. archive
b. package
c. collection
d. attachment
Question 19
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.

c. I am enjoying this class.


I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
Internally, the central processing unit (CPU) consists of two parts:
Select one:
a. The arithmetic and login unit (ALU) and main memory
b. The control unit and main memory
c. The input and output devices
d. The control unit and the arithmetic and logic unit (ALU)
Question 21
In all but rare cases, loops must contain within themselves
Select one:
a. a way to terminate
b. if statements
c. nested loops
d. arithmetic statements
Question 22
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Select one:
a. import javA.filE.*;
b. import javA.io.*;
c. import PrintWriter;
d. import javax.swing.*;
Question 23
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question 24
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. conditional import

b. an explicit import
c. a wildcard import
d. unconditional import
Question 25
All Java statements end with semicolons.
Select one:
a. True
b. False
Question 26
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 27
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Select one:
a. 130
b. 210
c. 90
d. 110
Question 28
This type of method performs a task and then terminates.
Select one:
a. void
b. simple
c. value-returning
d. local
Question 29
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. for loop
b. while loop
c. do-while loop

d. if statement
Question 30
Software refers to:
Select one:
a. Peopleware
b. Firmware
c. Programs
d. The physical components that a computer is made of.
Question 31
Class objects normally have __________ that perform useful operations on their data, but primitive variables
do not.
Select one:
a. methods
b. relationships
c. fields
d. instances
Question 32
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is a short and b is a byte
b. displayValues(a,b); // where a is an int and b is a byte
c. displayValues(a,b); // where a is a short and b is a long
d. displayValue(b,a); // where a is a short and b is a long
Question 33
Which of the following is included in a method call?
Select one:
a. return type
b. method modifiers
c. return variable
d. parentheses
Question 34
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 7
b. 12
c. 105
d. 8
Question 35
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';

if (sales > 100000)


if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Select one:
a. 2000
b. 1500
c. 1000
d. 1250
Question 36
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, Panel panel = new Panel(bGroup);
b. use the statement, panel.add(bGroup);
c. use the statement, bGroup.add(panel);
d. add each button to panel one at a time, e.g. panel.add(button1);
Question 37
What is the result of the following expression?
10 + 5 * 3 - 20
Select one:
a. 25
b. -5
c. -50
d. 5
Question 38
The expression tested by an if statement must evaluate to
Select one:
a. 0 or 1
b. t or f
c. +1 or -1
d. true or false
Question 39
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;

System.out.println("The product is " + product);


}
Select one:
a. showProduct(5.5, 4.0);
b. showProduct(33.0, 55.0);
c. showProduct(10.0, 4);
d. showProduct(10, 4.5);
Question 40
An access specifier indicates how the class may be accessed.
Select one:
a. False
b. True
Question 1
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. 10
b. 20
c. 145
d. No value, there is a syntax error
Question 2
A classs responsibilities include
Select one:
a. the things a class is responsible for knowing
b. the things a class is responsible for doing
c. neither A or B
d. both A and B
Question 3
Because Java byte code is the same on all computers, compiled Java programs
Select one:
a. Must be re-compiled for each different machine it is run on
b. Are non-existent
c. Are highly portable
d. Cannot run on Linux systems
Question 4
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:
a. x

b. Nothing, there is an error in the code.


c. x = 54.3
d. x = 108.6
Question 5
Look at the following statement.
import java.util.*;
This is an example of
Select one:
a. a wildcard import
b. an explicit import
c. unconditional import
d. conditional import
Question 6
Which of the following is included in a method call?
Select one:
a. method modifiers
b. return variable
c. parentheses
d. return type
Question 7
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(Character.toUpperCase(str.charAt(m)));
m++;
}
Select one:
a. 456
b. ABC456
c. ABC
d. abc456
Question 8
=What will be the results of executing the following code, if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,"Select color", Color.blue);
panel.setForeground(selectedColor);
Select one:
a. The foreground color will remain unchanged.
b. The foreground color will be set to white.

c. The foreground color will be set to black.


d. The foreground color will be set to blue.
=Question 9
=Which of the following is the correct boolean expression to test for: int x being a value between, but not
including, 500 and 650, or int y not equal to 1000?
Select one:
a. ((x > 500 AND x < 650) OR !(y.equal(1000)))
b. ((x >= 500 && x <= 650) && (y != 1000))
c. ((x > 500 && x < 650) || (y != 1000))
d. ((x < 500 && x > 650) || !(y == 1000))
Question 10
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Select one:
a. There are 5785 hens in the hen housE.
b. There are 5785
hens in the hen housE.
c. There are x5\nhens in the hen housE.
d. There are 583 hens in the hen housE.
Question 11
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is a short and b is a long
b. displayValues(a,b); // where a is an int and b is a byte
c. displayValue(b,a); // where a is a short and b is a long
d. displayValues(a,b); // where a is a short and b is a byte
Question 12
When saving a Java source file, save it with an extension of
Select one:
a. .class
b. .java
c. .src
d. .javac
Question 13
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Select one:
a. radio.Click();

b. Click(radio, true);
c. Click(radio);
d. radio.doClick();
Question 14
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 500
b. Numbers greater than 500
c. Numbers less than 100 or greater than 500
d. Numbers in the range 100 - 499
Question 15
What will happen when the following statement is executed?
x.setEditable(false);
Select one:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question 16
In GUI terminology, a container that can be displayed as a window is known as a _______________.
Select one:
a. frame
b. Swing package
c. buffer
d. message dialog
Question 17
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. assume
b. link
c. use
d. import
Question 18
What will be the value of x after the following code is executed?

int x = 10;
do
{
x *= 20;
} while (x < 5);
Select one:
a. 10
b. 200
c. The loop will not be executed, the initial value of x > 5.
d. This is an infinite loop.
Question 19
The String classs valueOf() method accepts a string representation as an argument and returns its equivalent
integer value.
Select one:
a. True
b. False
Question 20
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
Select one:
a. False
b. True
Question 21
A file must always be opened before using it and closed when the program is finished using it.
Select one:
a. False
b. True
Question 22
Character literals are enclosed in _____; string literals are enclosed in _____.
Select one:
a. single quotes; single quotes
b. single quotes; double quotes
c. double quotes; single quotes
d. double quotes; double quotes
Question 23
You must have a return statement in a value-returning method.
Select one:
a. True
b. False
Question 24
How many times will the following do-while loop be executed?
int x = 11;
do
{

x += 20;
}
while (x <= 100);
Select one:
a. 1
b. 3
c. 5
d. 4
Question 25
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
Select one:
a. control is returned to method A
b. the program terminates
c. control is returned to method B
d. control is returned to method C
Question 26
Overloading means multiple methods in the same class
Select one:
a. have different names, but the same parameter list
b. have the same name, but different parameter lists
c. perform the same function
d. have the same name, but different return types
Question 27
This refers to the combining of data and code into a single object.
Select one:
a. Object
b. Data hiding
c. Encapsulation
d. Abstraction
Question 28
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 8
b. 18 (as an integer)
c. This is an error
d. 18.0

Question 29
The primitive data types only allow a _____ to hold a single value.
Select one:
a. class
b. literal
c. object
d. variable
Question 30
Encapsulation refers t the combining of data and code into a single object.
Select one:
a. False
b. True
Question 31
Which of the following are pre-test loops?
Select one:
a. while, for, do-while
b. while, for
c. while, do-while
d. for, do-while
Question 32
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a local variable
b. a complex method
c. a value-returning method
d. a void method
Question 33
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 22, y = 4
b. x = 22, y = 88
c. 22, y = 26
d. Nothing, this is an error
Question 34
Which of the following expressions will determine whether x is less than or equal to y?
Select one:

a. x >= y
b. x <= y
c. x > y
d. x =< y
Question 35
What would be the value of discountRate after the following statements are executed?
double discountRate;
char custType = 'B';
switch (custType)
{
case 'A':
discountRate = .08;
break;
case 'B':
discountRate = .06;
case 'C':
discountRate = .04;
default:
discountRate = 0.0;
}
Select one:
a. .08
b. 0.0
c. .04
d. .06
Question 36
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string
before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last
token.
Select one:
a. True
b. False
Question 37
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Select one:
a. ans = 45, x = 50, y = 0
b. ans = 45, x = 50, y = 50

c. ans = 60, x =0, y =50


d. ans = 60, x = 50, y =100
Question 38
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
Select one:
a. False
b. True
Question 39
Correct
Mark 1.00 out of 1.00

Flag question
Java source files end with the .class extension.
Select one:
a. False
b. True
Question 40
Which of the following is not a class used in constructing a menu system?
Select one:
a. JMenuItem
b. JCheckBoxMenuItem
c. JButton
d. JRadioButtonMenuItem
Question 1
The term "default constructor" is applied to the first constructor written by the author of a class.
Select one:
a. False
b. True
Question 2
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
Select one:
a. False
b. True
Question 3
What would be the value of discountRate after the following statements are executed?
double discountRate;
char custType = 'B';
switch (custType)
{

case 'A':
discountRate = .08;
break;
case 'B':
discountRate = .06;
case 'C':
discountRate = .04;
default:
discountRate = 0.0;
}
Select one:
a. .08
b. 0.0
c. .04
d. .06
Question 4
StringBuilder objects are immutable.
Select one:
a. True
b. False
Question 5
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 20
b. x = 30
c. x is unknown when the last statement is executed
d. x = 40
Question 6
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 8.0
b. 18.0
c. This is an error

d. 18 (as an integer)
Question 7
Assuming that inputFile references a Scanner object that was used to open a file, which of the following
statements will read an int from the file?
Select one:
a. int number = inputFilE.next();
b. int number = inputFilE.integer();
c. int number = inputFilE.nextInt();
d. int number = inputFilE.readInt();
Question 8
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are
equal?
(1) (str1 == str2)
(2) str1.equals(str2)
(3) (str1.compareTo(str2) == 0)
Select one:
a. 2 and 3
b. 1 and 2
c. 1, 2, and 3 will all work
d. 1 and 3
Question 9
In a switch statement, if two different values for the CaseExpression would result in the same code being
executed, you must have two copies of the code, one after each CaseExpression.
Select one:
a. True
b. False
Question 10
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
Select one:
a. control is returned to method A
b. control is returned to method B
c. the program terminates
d. control is returned to method C
Question 11
The primitive data types only allow a _____ to hold a single value.
Select one:
a. class
b. object
c. literal
d. variable

Question 12
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.
Select one:
a. False
b. True
Question 13
What is wrong with the following method call?
displayValue (double x);
Select one:
a. x should be a String.
b. Do not include the data type in the method call.
c. There is nothing wrong with the statement.
d. displayValue will not accept a parameter.
Question 14
When an objects internal data is hidden from outside code and access to that...
Select one:
a. False
b. True
Question 15
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Question 16
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
Select one:
a. 3
b. 5.25
c. 19
d. 7
Question 17
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");

timeOfDayButtonGroup = new ButtonGroup();


dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Select one:
a. 2
b. 4
c. 1
d. 3
Question 18
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers greater than 500
b. Numbers less than 100 or greater than 500
c. Numbers in the range 100 - 500
d. Numbers in the range 100 - 499
Question 19
One of the design tools used by programmers when creating a model of the program is:
Select one:
a. Pseudocode
b. Compiler
c. ALU
d. Disk drive
Question 20
A flag may have the values:
Select one:
a. of any character
b. 0 or 1
c. true or false
d. 1 or -1
Question 21

Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10, 4.5);
b. showProduct(5.5, 4.0);
c. showProduct(10.0, 4);
d. showProduct(33.0, 55.0);
Question 22
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
Select one:
a. Space
b. Tab
c. Semicolon
d. Newline
Question 23
Instance methods should be declared static.
Select one:
a. True
b. False
Question 24
This type of loop is ideal in situations where you always want the loop to iterate at least once.
Select one:
a. for loop
b. if statement
c. do-while loop
d. while loop
Question 25
Which of the following correctly tests the char variable chr to determine whether it is not equal to the
character B?
Select one:
a. if (chr != 'B')
b. if (chr > 'B')
c. if (chr != "B")
d. if (chr < 'B')
Question 26
To use the ActionListener interface, as well as other event listener interfaces, you must have the following
import statement in your code:
Select one:

a. import java.awt;
b. import java.awt.event.*;
c. import java.swing;
d. import java.awt.*;
Question 27
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 1 and 2
b. 1
c. Neither 1 or 2
d. 2
Question 28
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
Select one:
a. 10
b. The loop will not be executed, the initial value of x > 5.
c. 200
d. This is an infinite loop.
Question 29
Local variables can be initialized with
Select one:
a. parameter values
b. any of the above
c. the results of an arithmetic operation
d. constants
Question 30
Which of the following is valid?
a) float y;
y = 54.9;
b) float y;
double z;
z = 934.21;
y = z;
c) float w;
w = 1.0f;
d) float v;
v = 1.0;
Select one:

a. Answer a)
b. Answer c)
c. Answer d)
d. Answer b)
Question 31
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Select one:
a. 110
b. 90
c. This is an infinite loop
d. 100
Question 32
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
Select one:
a. True
b. False
Question 33
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Select one:
a. False
b. True
Question 34
Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44;
Select one:
a. True
b. False
Question 35
It is common practice in object-oriented programming to make all of a class's
Select one:
a. fields and methods public
b. fields public
c. fields private
d. methods private
Question 36

What would be displayed as a result of the following code?


int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Select one:
a. There are 5785 hens in the hen housE.
b. There are 583 hens in the hen housE.
c. There are x5\nhens in the hen housE.
d. There are 5785
hens in the hen housE.
Question 37
This is a cross between human language and a programming language.
Select one:
a. Java
b. Pseudocode
c. The compiler
d. The Java Virtual Machine
Question 38
What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 8.0
b. 8.25
c. 8
d. 4
Question 39
What will be the value of loc after the following code is executed?
int loc;
String str = "The cow jumped over the moon.";
loc = str.lastIndexOf("ov", 14);
Select one:
a. 15
b. 16
c. 0
d. -1
Question 40
Methods are commonly used to
Select one:
a. break a problem down into small manageable pieces
b. emphasize certain parts of the logic
c. speed up the compilation of a program

d. document the program


Question 1
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 499
b. Numbers less than 100 or greater than 500
c. Numbers in the range 100 - 500
d. Numbers greater than 500
Question 2
A for loop normally performs which of these steps?
Select one:
a. updates the control variable during each iteration
b. initializes a control variable to a starting value
c. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
d. None of the above
e. all of the above
Question 3
An important style rule you should adopt for writing if statements is to write the conditionally executed
statement on the line after the if statement.
Select one:
a. True
b. False
Question 4
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Select one:
a. 11
b. 1
c. 0
d. 10
Question 5
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);

Select one:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question 6
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);
Select one:
a. The loop will not be executed, the initial value of x > 5.
b. This is an infinite loop.
c. 200
d. 10
Question 7
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
Select one:
a. 5.0
b. 5.60
c. 3.0
d. 5.6
Question 8
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 9
Look at the following statement.
import java.util.*;
This is an example of

Select one:
a. unconditional import
b. an explicit import
c. conditional import
d. a wildcard import
Question 10
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
Select one:
a. token
b. delimiter
c. buffer
d. separator
Question 11
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
Select one:
a. 50
b. No value, this is a syntax error.
c. 80
d. 30
Question 12
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
Select one:
a. 3
b. 7
c. 19
d. 5.25
Question 13
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many
characters.
Select one:
a. 0 characters
b. 8 characters
c. 16 characters
d. 32 characters
Question 14

In the following Java statement what value is stored in the variable name?
String name = "John Doe";
Select one:
a. The memory address where name is located
b. name
c. John Doe
d. The memory address where "John Doe" is located
Question 15
When a component is added to a region in the BorderLayout manager,
Select one:
a. the component retains its original size
b. the region is resized to fit the component
c. the component is stretched so it fills up the entire region
d. it results in a compile time error, if it is too large
Question 16
What is wrong with the following method call?
displayValue (double x);
Select one:
a. x should be a String.
b. There is nothing wrong with the statement.
c. Do not include the data type in the method call.
d. displayValue will not accept a parameter.
Question 17
A computer program is:
Select one:
a. A flow chart
b. Pseudocode
c. A set of instructions that enable the computer to solve a problem or perform a task.
d. Main memory
Question 18
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Select one:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question 19
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;

z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
Select one:
a. x = 27, y = 3, z = 18
b. x = 27, y = 2, z = 18
c. x = 27, y = 3.333, z = 18
d. Nothing. There is an error in the code!
Question 20
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
Select one:
a. control is returned to method A
b. the program terminates
c. control is returned to method B
d. control is returned to method C
Question 21
Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44;
Select one:
a. True
b. False
Question 22
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(5.5, 4.0);
b. showProduct(33.0, 55.0);
c. showProduct(10, 4.5);
d. showProduct(10.0, 4);
Question 23
One or more objects may be created from a
Select one:
a. field
b. instance
c. method
d. class
Question 24

To use the ActionListener interface, as well as other event listener interfaces, you must have the following
import statement in your code:
Select one:
a. import java.awt;
b. import java.awt.event.*;
c. import java.awt.*;
d. import java.swing;
Question 25
A file must always be opened before using it and closed when the program is finished using it.
Select one:
a. False
b. True
Question 26
This type of method performs a task and sends a value back to the code that called it.
Select one:
a. complex
b. value-returning
c. void
d. local
Question 27
Application software refers to programs that make the computer useful to the user.
Select one:
a. True
b. False
Question 28
Which of the following is not a rule that must be followed when naming identifiers?
Select one:
a. The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign.
b. Uppercase and lowercase characters are distinct.
c. After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9.
d. Identifiers can contain spaces.
Question 29
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Select one:
a. False
b. True
Question 30
A classs responsibilities include
Select one:
a. the things a class is responsible for doing
b. both A and B

c. the things a class is responsible for knowing


d. neither A or B
Question 31
Overloading means multiple methods in the same class
Select one:
a. have the same name, but different return types
b. perform the same function
c. have different names, but the same parameter list
d. have the same name, but different parameter lists
Question 32
The following package is automatically imported into all Java programs.
Select one:
a. java.lang
b. java.default
c. java.util
d. java.java
Question 33
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18 (as an integer)
b. 8
c. This is an error
d. 18.0
Question 34
A sentinel value _________ and signals that there are no more values to be entered.
Select one:
a. guards the list
b. indicates the start of a list
c. is a special value that cannot be mistaken as a member of the list
d. is a different data type than the values being processed
Question 35
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Select one:
a. "red", "green", "blue"and "orange"
b. "[", "$", "&", "#", and "]"

c. "$", "&", and "#"


d. None of the other three options.
Question 36
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. 20
b. 10
c. 145
d. No value, there is a syntax error
Question 37
Logical errors are mistakes that cause the program to produce erroneous results.
Select one:
a. True
b. False
Question 38
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Select one:
a. 1000
b. 1250
c. 2000
d. 1500
Question 39
The header of a value-returning method must specify this.
Select one:
a. The name of the variable in the calling program that will receive the returned value
b. All of the above
c. The method's local variable names

d. The data type of the return value


Question 40
Enclosing a group of statements inside a set of braces creates a
Select one:
a. loop
b. Nothing, it is just for readability
c. block of statements
d. boolean expression
Question 1
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. neither num or str will be changed
b. str will have a value of 560
c. the last line of code will cause an error
d. num will be set to 560
Question 2
These operators are used to determine whether a specific relationship exists between two values.
Select one:
a. Syntactical
b. Arithmetic
c. Assignment
d. Relational
Question 3
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
}
while (x <= 100);
Select one:
a. 1
b. 4
c. 3
d. 5
Question 4
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");

months = new JRadioButton("Months");


years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Select one:
a. 2
b. 1
c. 3
d. 4
Question 5
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct("5", "40");
b. showProduct(10, 4.5);
c. showProduct(3.3, 55);
d. showProduct(10.0, 4.6);
Question 6
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
Select one:
a. 30
b. 50
c. No value, this is a syntax error.
d. 80
Feedback
Die Antwort ist richtig
Weil die Bedingung = immer folgendermaen geschrieben werden muss:
if ( x==y)
ans = x + 10;

The correct answer is: No value, this is a syntax error.


Question 7
This type of method performs a task and sends a value back to the code that called it.
Select one:
a. complex
b. void
c. local
d. value-returning
Question 8
Which of the following is not involved in finding the classes when developing an object-oriented application?
Select one:
a. Describe the problem domain.
b. Write the code.
c. Identify all the nouns.
d. Refine the list of nouns to include only those that are relevant to the problem.
Question 9
Which of the following will run the compiled program ReadIt?
Select one:
a. go ReadIt
b. run ReadIt
c. java ReadIt.java
d. java ReadIt
Question 10
What does the following code display?
double x = 12.3798146;
System.out.printf("%.2f\n", x);
Select one:
a. 1238
b. %12.38
c. 123798146
d. 12.38
Question 11
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question 12
Two or more methods in a class may have the same name as long as
Select one:

a. they have different parameter lists


b. they have different return types, but the same parameter list
c. you cannot have two methods with the same name
d. they have different return types
Question 13
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 14
What will be displayed as a result of executing the following code?
int x = 8;
String msg = "I am enjoying javA.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " +
ltr);
System.out.println("msg has " + strSize +
" characters.");
Select one:
a. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = y
msg has 19 characters.
b. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 19 characters.
c. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 20 characters.
d. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.

Character at index x = j
msg has 20 characters.
Question 15
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Select one:
a. radio.doClick();
b. Click(radio, true);
c. radio.Click();
d. Click(radio);
Question 16
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL
the world's alphabets.
Select one:
a. False
b. True
Question 17
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
Select one:
a. x = 27, y = 2, z = 18
b. Nothing. There is an error in the code!
c. x = 27, y = 3, z = 18
d. x = 27, y = 3.333, z = 18
Question 18
Logical errors are mistakes that cause the program to produce erroneous results.
Select one:
a. True
b. False
Question 19
One or more objects may be created from a
Select one:
a. class
b. instance
c. field
d. method
Question 20
The data contained in an object is known as:
Select one:

a. Methods
b. Atriums
c. Attributes
d. Classes
Question 21
In all but rare cases, loops must contain within themselves
Select one:
a. arithmetic statements
b. nested loops
c. a way to terminate
d. if statements
Question 22
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
Select one:
a. token
b. delimiter
c. buffer
d. separator
Question 23
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Select one:
a. import javax.swing.*;
b. import javA.filE.*;
c. import javA.io.*;
d. import PrintWriter;
Question 24
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10.0, 4);
b. showProduct(10, 4.5);
c. showProduct(5.5, 4.0);
d. showProduct(33.0, 55.0);
Question 25
If x has been declared an int, which of the following statements is invalid?

Select one:
a. x = 1,000;
b. x = 592;
c. x = 0;
d. x = -58932;
False, because -58932 is an integer. The correct anser would be 1,000 because it's a double.
Question 26
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. Only a
b. a and b
c. (str1.equalsIgnoreCase(str2))
d. (str1.compareToIgnoreCase(str2) == 0)
Question 27
When you are writing a program with String objects that may have unwanted spaces at the beginning or end of
the strings, use this method to delete them.
Select one:
a. replace
b. trim
c. valueOf
d. substring
Question 28
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;
else if (sales < 7500)
bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
Select one:
a. 1000
b. 200
c. 750
d. 1250
e. 500
Question 29
Another term for an object of a class is
Select one:

a. instance
b. access specifier
c. method
d. member
Question 30
Constants, variables, and the values of expressions may be passed as arguments to a methoD.
Select one:
a. False
b. True
Question 31
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. unconditional import
b. a wildcard import
c. conditional import
d. an explicit import
Question 32
A do-while loop is a pre-test loop.
Select one:
a. False
b. True
Question 33
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Select one:
a. panel.attachLayout(GridLayout(2,3));
b. panel.addLayout(new (GridLayout(2,3));
c. panel.setLayout(new (GridLayout(2,3));
d. panel.GridLayout(2,3);
Question 34
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 32, y = 4
b. x = 9, y = 52
c. x = 37, y = 5
d. x = 160, y = 80

Question 35
Which Scanner class method reads a String?
Select one:
a. readString()
b. getString()
c. nextString()
d. nextLine()
Question 36
A variable's scope is the part of the program that has access to the variable.
Select one:
a. False
b. True
Question 37
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Select one:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question 38
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. 110
b. 90
c. This is an infinite loop
d. 100
Question 39
A value-returning method must specify this as its return type in the method header.
Select one:
a. any valid data type
b. a boolean
c. an int
d. a double
Question 40
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);

Select one:
a. 3
b. 4
c. 5
d. 6
Question 1
Any method that calls a method with a throws clause in its header must
Select one:
a. Both of the above
b. have the same throws clause
c. handle the potential exception
d. do nothing, the called program will take care of the throws clause
Question 2
The major components of a typical computer system consist of:
Select one:
a. All of the above
b. Input/output devices
c. The CPU
d. Main memory
e. Secondary storage devices
Question 3
Methods are commonly used to
Select one:
a. break a problem down into small manageable pieces
b. emphasize certain parts of the logic
c. document the program
d. speed up the compilation of a program
Question 4
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 1
b. 2
c. Neither 1 or 2
d. 1 and 2
Question 5
What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales > 1000)
bonus = 100;

if (sales > 750)


bonus = 50;
if (sales > 500)
bonus = 25;
else
bonus = 0;
Select one:
a. 25
b. 100
c. 500
d. 0
Question 6
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
b. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
c. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
Question 7
The expression in a return statement can be any expression that has a value.
Select one:
a. False
b. True
Question 8
What is the value of x after the following code has been executed?
int x = 75;
int y = 90;
if ( x != y)
x += y;
Select one:
a. 15
b. 90
c. 75
d. 165
Question 9
What is wrong with the following method call?
displayValue (double x);
Select one:
a. displayValue will not accept a parameter.
b. x should be a String.
c. Do not include the data type in the method call.
d. There is nothing wrong with the statement.

Question 10
Two ways of concatenating two Strings are
Select one:
a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Question 11
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
Select one:
a. 5.60
b. 5.0
c. 5.6
d. 3.0
Question 12
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct("5", "40");
b. showProduct(3.3, 55);
c. showProduct(10.0, 4.6);
d. showProduct(10, 4.5);
Question 13
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Select one:
a. 90
b. 110
c. This is an infinite loop
d. 100
Question 14
If the following Java statements are executed, what will be displayed?

System.out.print("The top three winners are\n");


System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");
Select one:
a. The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
b. The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
c. The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
d. The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
Question 15
In an if/else statement, if the boolean expression is false,
Select one:
a. no statements or blocks are executed
b. all statements or blocks are executed
c. the first statement or block is executed
d. the statement or block following the else is executed
Question 16
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0;
Select one:
a. 0
b. .01
c. .05
d. .03
Question 17
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
Select one:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.

b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question 18
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. while loop
b. if statement
c. do-while loop
d. for loop
Question 19
Two or more methods in a class may have the same name as long as
Select one:
a. you cannot have two methods with the same name
b. they have different return types, but the same parameter list
c. they have different return types
d. they have different parameter lists
Question 20
To add a tool tip to a component use
Select one:
a. the setToolTipText method.
b. the addToolTipText method.
c. the toolTipText method.
d. the appendToolTipText method.
Question 21
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
Select one:
a. x = 27, y = 3, z = 18
b. x = 27, y = 2, z = 18
c. Nothing. There is an error in the code!
d. x = 27, y = 3.333, z = 18
Question 22

In a switch statement, if two different values for the CaseExpression would result in the same code being
executed, you must have two copies of the code, one after each CaseExpression.
Select one:
a. False
b. True
Question 23
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is
hidden, but not closed.
Select one:
a. JFrame. HIDE_ON_CLOSE
b. JFrame.HIDE_NOT_CLOSE
c. HIDE_ON_CLOSE
d. JFrame.EXIT_ON_CLOSE
Question 24
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. (str1.compareToIgnoreCase(str2) == 0)
b. Only a
c. a and b
d. (str1.equalsIgnoreCase(str2))
Question 25
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
}
while (x <= 100);
Select one:
a. 1
b. 3
c. 4
d. 5
Question 26
A method that stores a value in a class's field or in some other way changes the value of a field is known as a
mutator method.
Select one:
a. True
b. False
Question 27
How many times will the following do-while loop be executed?
int x = 11;
do

{
x += 20;
} while (x > 100);
Select one:
a. 4
b. 1
c. 5
d. 0
Question 28
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
Select one:
a. True
b. False
Question 29
Byte code instructions are:
Select one:
a. Another name for source code
b. Read and interpreted by the JVM
c. Machine code instructions
d. Syntax errors
Question 30
When you write a change listener class method for a slider, it must implement the ChangeListener interface
which is in the javax.swing.event package.
Select one:
a. True
b. False
Question 31
When using the StringBuilder class's insert method, you can insert
Select one:
a. any primitive type
b. a String object
c. a char array
d. All of the above
Question 32
This is a value that is written into the code of a program.
Select one:
a. operator
b. variable
c. literal
d. assignment statement

Question 33
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(Character.toUpperCase(str.charAt(m)));
m++;
}
Select one:
a. 456
b. ABC456
c. ABC
d. abc456
Question 34
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18.0
b. This is an error
c. 8.0
d. 18 (as an integer)
Question 35
Key words are:
Select one:
a. Words or names defined by the programmer
b. The data names in your program
c. Symbols or words that perform operations on one or more operands
d. Words that have a special meaning in the programming language
Question 36
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
Select one:
a. 19
b. 5.25
c. 3
d. 7
Question 37
The scope of a private instance field is
Select one:

a. inside the parentheses of a method header


b. the instance methods of the same class
c. the method in which they are defined
d. inside the class, but not inside any method
Question 38
Which of the following is not involved in finding the classes when developing an object-oriented application?
Select one:
a. Write the code.
b. Refine the list of nouns to include only those that are relevant to the problem.
c. Identify all the nouns.
d. Describe the problem domain.
Question 39
If a loop does not contain within itself a way to terminate, it is called a
Select one:
a. infinite loop
b. do-while loop
c. for loop
d. while loop
Question 40
This is a value that signals when the end of a list of values has been reacheD.
Select one:
a. Final value
b. End value
c. Sentinel
d. Terminal value
Question 1
An access specifier indicates how the class may be accessed.
Select one:
a. True
b. False
Question 2
What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
Select one:
a. 100
b. 35
c. 80

d. 55
Question 3
What is wrong with the following method call?
displayValue (double x);
Select one:
a. Do not include the data type in the method call.
b. There is nothing wrong with the statement.
c. x should be a String.
d. displayValue will not accept a parameter.
Question 4
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. Neither 1 or 2
b. 1
c. 1 and 2
d. 2
Question 5
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
Select one:
a. control is returned to method B
b. control is returned to method C
c. control is returned to method A
d. the program terminates
Question 6
Two ways of concatenating two Strings are
Select one:
a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Question 7
A classs responsibilities include
Select one:
a. both A and B
b. the things a class is responsible for doing
c. neither A or B
d. the things a class is responsible for knowing
Question 8

This is a sum of numbers that accumulates with each iteration of a loop.


Select one:
a. Grand finale
b. Running total
c. Final total
d. Galloping total
Question 9
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValue(b,a); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a long
c. displayValues(a,b); // where a is a short and b is a byte
d. displayValues(a,b); // where a is an int and b is a byte
Question 10
What is the result of the following expression?
25 - 7 * 3 + 12 / 3
Select one:
a. 6
b. 8
c. 12
d. 10
Question 11
Event listeners must
Select one:
a. implement an interface
b. exit the application once it has handled the event
c. be included in private inner classes
d. not receive any arguments
Question 12
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Select one:
a. There are 583 hens in the hen housE.
b. There are 5785 hens in the hen housE.
c. There are 5785
hens in the hen housE.
d. There are x5\nhens in the hen housE.
Question 13
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are
equal?

(1) (str1 == str2)


(2) str1.equals(str2)
(3) (str1.compareTo(str2) == 0)
Select one:
a. 1 and 2
b. 2 and 3
c. 1 and 3
d. 1, 2, and 3 will all work
Question 14
In Java, when a character is stored in memory, it is actually stored as a
Select one:

_____.

a. ASCII character code


b. EBCDIC character code
c. Morse code
d. Unicode number
Question 15
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
Select one:
a. False
b. True
Question 16
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 105
b. 7
c. 8
d. 12
Question 17
A file must always be opened before using it and closed when the program is finished using it.
Select one:
a. True
b. False
Question 18
To compile a program named First, use the following command
Select one:
a. javac First
b. compile First.javac
c. javac First.java
d. java First.java

Question 19
The _________ statement is used to make simple decisions in Java.
Select one:
a. branch
b. for
c. do/while
d. if
Question 20
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Select one:
a. Click(radio);
b. Click(radio, true);
c. radio.Click();
d. radio.doClick();
Question 21
In the following code the setPreferredSize method sets the size of the text, "Have a good day".
label = new Jlabel("Have a good day", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
Select one:
a. True
b. False
Question 22
If x has been declared an int, which of the following statements is invalid?
Select one:
a. x = 592;
b. x = -58932;
c. x = 0;
False, because 0 is an integer. The correct anser would be 1,000 because it's a double.
d. x = 1,000;
Question 23
When testing for character values, the switch statement does not test for the case of the character.
Select one:
a. True
b. False
Question 24
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
Select one:
a. x = 12, y = 5
b. x = 16, y = 4

c. x = 17, y = 4
d. x = 17, y = 5
Question 25
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Select one:
a. None of the other three options.
b. "$", "&", and "#"
c. "red", "green", "blue"and "orange"
d. "[", "$", "&", "#", and "]"
Question 26
A method that gets a value from a class's field but does not change it is known as a mutator method.
Select one:
a. False
b. True
Question 27
RAM is usually:
Select one:
a. An input/output device
b. Secondary storage
c. A static type of memory, used for permanent storage
d. A volatile type of memory, used only for temporary storage
Question 28
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a void method
c. a local variable
d. a complex method
Question 29
When saving a Java source file, save it with an extension of
Select one:
a. .src
b. .java
c. .class
d. .javac
Question 30
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?

PrintWriter diskOut = new PrintWriter("DiskFilE.txt");


Select one:
a. PrintWriter.println("Calvin");
b. diskOut.println("Calvin");
c. DiskFilE.println("Calvin");
d. System.out.println(diskOut, "Calvin");
Question 31
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Select one:
a. 0
b. 10
c. 11
d. 1
Question 32
Colons are used to indicate the end of a Java statement.
Select one:
a. False
b. True
Question 33
The contents of a variable cannot be changed while the program is running.
Select one:
a. True
b. False
Question 34
What is the value of x after the following code has been executed?
int x = 75;
int y = 90;
if ( x != y)
x += y;
Select one:
a. 165
b. 75
c. 90
d. 15
Question 35
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.

c. The text field x will have the value true.


d. The text field x have the value "trueTiny Tim"
Question 36
Assume that the following method header is for a method in class A.
public void displayValue(int value)
Assume that the following code segments appear in another method, also in class A. Which contains a legal call
to the displayValue method?
Select one:
a. int x = 7;
void displayValue(x);
b. int x = 7;
displayValue(int x);
c. int x = 7;
displayValue(x);
d. int x = 7;
displayValue(x)
Question 37
When an argument value is passed to a method, the receiving parameter variable is
Select one:
a. declared within the body of the method
b. uses the declaration of the argument
c. declared in the calling method
d. declared in the method header inside the parentheses
Question 38
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
Select one:
a. token
b. delimiter
c. buffer
d. separator
Question 39
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, Panel panel = new Panel(bGroup);
b. use the statement, panel.add(bGroup);
c. use the statement, bGroup.add(panel);
d. add each button to panel one at a time, e.g. panel.add(button1);
Question 40
The following package is automatically imported into all Java programs.
Select one:

a. java.util
b. java.lang
c. java.java
d. java.default
Question 1
After the header, the body of the method appears inside a set of
Select one:
a. brackets, []
b. double quotes, ""
c. paretheses, ()
d. braces, {}
Question 2
In an if/else statement, if the boolean expression is false,
Select one:
a. the statement or block following the else is executed
b. all statements or blocks are executed
c. the first statement or block is executed
d. no statements or blocks are executed
Question 3
You cannot assign a value to a wrapper class object.
Select one:
a. True
b. False
Question 4
What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 8.0
b. 4
c. 8.25
d. 8
Question 5
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18 (as an integer)

b. This is an error
c. 8.0
d. 18.0
Question 6
Colons are used to indicate the end of a Java statement.
Select one:
a. False
b. True
Question 7
A constructor is a method that is automatically called when an object is created.
Select one:
a. False
b. True
Question 8
The header of a value-returning method must specify this.
Select one:
a. All of the above
b. The data type of the return value
c. The name of the variable in the calling program that will receive the returned value
d. The method's local variable names
Question 9
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 499
b. The boolean condition can never be true
c. Numbers in the range 100 - 500
d. Numbers less than 100 or greater than 500
Question 10
Which of the following is not a primitive data type?
Select one:
a. String
b. float
c. short
d. long

Question 11
Syntax is:
Select one:
a. Punctuation
b. Rules that must be followed when writing a program
c. Words that have a special meaning in the programming language
d. Symbols or words that perform operations
Question 12
What will be the values of ans, x, and y after the following statements are executed?
int ans = 0, x = 15, y =25;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Select one:
a. ans = 25, x = -10, y = 25
b. ans = 25, x = 15, y = 40
c. ans = 35, x = 15, y = 40
d. ans = 0, x = 15, y = 25
Question 13
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter
variable.
Select one:
a. False
b. True
Question 14
A parameter variables scope is the method in which the parameter is declareD.
Select one:
a. True
b. False
Feedback
The correct answer is: True
Question 15
To use the StringTokenizer class you must have the following import statement.
Select one:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;

d. import javA. String;


Question 16
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
Select one:
a. 80
b. 30
c. No value, this is a syntax error.
d. 50
Question 17
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(Character.toUpperCase(str.charAt(m)));
m++;
}
Select one:
a. 456
b. ABC456
c. ABC
d. abc456
Question 18
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. unconditional import
b. an explicit import
c. conditional import
d. a wildcard import
Question 19
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 12
b. 105
c. 8

d. 7
Question 20
Instance methods do not have the key word static in their headers.
Select one:
a. True
b. False
Question 21
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Select one:
a. 90
b. 110
c. 100
d. This is an infinite loop
Question 22
What is the result of the following expression?
10 + 5 * 3 - 20
Select one:
a. -50
b. 25
c. -5
False Answer!
d. 5
Question 23
If a loop does not contain within itself a way to terminate, it is called a
Select one:
a. for loop
b. while loop
c. do-while loop
d. infinite loop
Question 24
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. the last line of code will cause an error
b. neither num or str will be changed
c. num will be set to 560

d. str will have a value of 560


Question 25
Local variables
Select one:
a. may have the same name as local variables in other methods
b. lose the values stored in them between calls to the method in which the variable is declared
c. are hidden from other methods
d. All of the above
Question 26
A file must always be opened before using it and closed when the program is finished using it.
Select one:
a. True
b. False
Question 27
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. 90
b. 110
c. 100
d. This is an infinite loop
Question 28
One of the design tools used by programmers when creating a model of the program is:
Select one:
a. ALU
b. Pseudocode
c. Compiler
d. Disk drive
Question 29
To add a tool tip to a component use
Select one:
a. the setToolTipText method.
b. the addToolTipText method.
c. the toolTipText method.
d. the appendToolTipText method.
Question 30
Which of the following would be a valid method call for the following method?

public static void showProduct(double num1, int num2)


{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10.0, 4.6);
b. showProduct(10, 4.5);
c. showProduct("5", "40");
d. showProduct(3.3, 55);
Question 31
In the following code the setPreferredSize method sets the size of the text, "Have a good day".
label = new Jlabel("Have a good day", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
Select one:
a. True
b. False
Feedback
The correct answer is: False
Question 32
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Select one:
a. Click(radio, true);
b. radio.Click();
c. radio.doClick();
d. Click(radio);
Question 33
If x has been declared an int, which of the following statements is invalid?
Select one:
a. x = 1,000;
True, because 1,000 is a double.
b. x = 0;
c. x = 592;
d. x = -58932;
Question 34
You can use the PrintWriter class to open a file for writing and write data to it.
Select one:
a. False
b. True
Question 35
What will be printed when the following code is executed?

int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 20
b. x = 30
c. x = 40
d. x is unknown when the last statement is executed
Question 36
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Select one:
a. False
b. True
Question 37
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Question 38
The _________ statement is used to make simple decisions in Java.
Select one:
a. do/while
b. branch
c. if
d. for
Question 39
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
Select one:
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question 40
The primitive data types only allow a _____ to hold a single value.

Select one:
a. class
b. variable
c. literal
d. object
Question 1
A method that gets a value from a class's field but does not change it is known as a mutator method.
Select one:
a. True
b. False
Question 2
What does the following code display?
double x = 12.3798146;
System.out.printf("%.2f\n", x);
Select one:
a. 1238
b. 123798146
c. %12.38
d. 12.38
Question 3
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Select one:
a. The quick brown fox
jumped over the
slow moving hen.
b. The quick brown fox jumped over the
slow moving hen.
c. Nothing. This is an error.
d. The quick brown fox jumped over the \nslow moving hen.
Question 4
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?
PrintWriter diskOut = new PrintWriter("DiskFilE.txt");
Select one:
a. System.out.println(diskOut, "Calvin");
b. DiskFilE.println("Calvin");
c. PrintWriter.println("Calvin");
d. diskOut.println("Calvin");
Question 5
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:

a. a and b
b. (str1.compareToIgnoreCase(str2) == 0)
c. (str1.equalsIgnoreCase(str2))
d. Only a
Question 6
Internally, the central processing unit (CPU) consists of two parts:
Select one:
a. The arithmetic and login unit (ALU) and main memory
b. The input and output devices
c. The control unit and main memory
d. The control unit and the arithmetic and logic unit (ALU)
Question 7
The FlowLayout manager does not allow the programmer to align components.
Select one:
a. True
b. False
Question 8
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Select one:
a. panel.attachLayout(GridLayout(2,3));
b. panel.addLayout(new (GridLayout(2,3));
c. panel.GridLayout(2,3);
d. panel.setLayout(new (GridLayout(2,3));
Question 9
A classs responsibilities include
Select one:
a. both A and B
b. the things a class is responsible for knowing
c. neither A or B
d. the things a class is responsible for doing
Question 10
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
Select one:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.

c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question 11
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
Select one:
a. False
b. True
Question 12
The scope of a private instance field is
Select one:
a. inside the class, but not inside any method
b. the instance methods of the same class
c. inside the parentheses of a method header
d. the method in which they are defined
Question 13
This is a set of programming language statements that, together, perform a specific task.
Select one:
a. Procedure
b. Compiler
c. Pseudocode
d. Object
Question 14
Every Java application program must have
Select one:
a. comments
b. a method named main
c. integer variables
d. a class named MAIN
Question 15
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is an int and b is a byte
b. displayValues(a,b); // where a is a short and b is a byte
c. displayValue(b,a); // where a is a short and b is a long
d. displayValues(a,b); // where a is a short and b is a long
Question 16
This is a variable whose content is read only and cannot be changed during the program's execution.
Select one:

a. named constant
b. operator
c. reserved word
d. literal
Question 17
Each byte is assigned a unique number known as an address.
Select one:
a. True
b. False
Question 18
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
Select one:
a. 7
b. 3
c. 19
d. 5.25
Question 19
The Character wrapper class provides numerous methods for
Select one:
a. testing String objects
b. testing and converting char variables
c. converting String variables
d. adding two char variables
Question 20
Look at the following statement.
import java.util.*;
This is an example of
Select one:
a. an explicit import
b. unconditional import
c. a wildcard import
d. conditional import
Question 21
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.

d. sets the value of textList to SINGLE_INTERVAL_SELECTION.


Question 22
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one
for each delimiter character.
Select one:
a. True
b. False
Question 23
This is a group of related classes.
Select one:
a. archive
b. package
c. collection
d. attachment
Question 24
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18.0
b. This is an error
c. 8.0
d. 18 (as an integer)
Question 25
Breaking a program down into small manageable methods
Select one:
a. makes problems more easily solved
b. allows for code reuse
c. simplifies programs
d. all of the above
Question 26
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a complex method
b. a local variable
c. a value-returning method

d. a void method
Question 27
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
}
while (x <= 100);
Select one:
a. 3
b. 1
c. 5
d. 4
Question 28
To use the Color class, which is used to set the foreground and background of various objects, use the following
import statement
Select one:
a. import java.swing;
b. import java.awt;
c. import java.awt.event.*;
d. import java.awt.*;
Question 29
You can use this method to determine whether a file exists.
Select one:
a. The PrintWriter class's fileExists method
b. The File class's exists method
c. The File class's canOpen method
d. The Scanner class's exists method
Question 30
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
Select one:
a. False
b. True
Question 31
In an if/else statement, if the boolean expression is false,
Select one:
a. all statements or blocks are executed
b. the statement or block following the else is executed
c. the first statement or block is executed
d. no statements or blocks are executed

Question 32
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Select one:
a. ans = 60, x = 50, y =100
b. ans = 60, x =0, y =50
c. ans = 45, x = 50, y = 50
d. ans = 45, x = 50, y = 0
Question 33
This type of loop will always be executed at least once.
Select one:
a. post-test loop
b. sentinel loop
c. pre-test loop
d. for loop
Question 34
This type of method performs a task and sends a value back to the code that called it.
Select one:
a. void
b. value-returning
c. local
d. complex
Question 35
What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales > 1000)
bonus = 100;
if (sales > 750)
bonus = 50;
if (sales > 500)
bonus = 25;
else
bonus = 0;
Select one:
a. 500
b. 100

c. 25
d. 0
Question 36
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
Select one:
a. Nothing, this is an error
b. 94516
c. 9 45 16
d. 9 45 16
Question 37
You should always document a method by writing comments that appear
Select one:
a. only if the method is more than five lines long.
b. just after the methods definition.
c. just before the methods definition.
d. at the end of the file.
Question 38
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
Select one:
a. 10
b. 200
c. The loop will not be executed, the initial value of x > 5.
d. This is an infinite loop.
Question 39
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Select one:

a. diddle
b. diddl
c. , didd
d. Iddle
Question 40
In the following Java statement what value is stored in the variable name?
String name = "John Doe";
Select one:
a. The memory address where name is located
b. name
c. The memory address where "John Doe" is located
d. John Doe
Question 1
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 37, y = 5
b. x = 32, y = 4
c. x = 160, y = 80
d. x = 9, y = 52
Question 2
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter = new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
Select one:
a. 0,045,678.26
b. 45678.259
c. 45,678.3
d. 45,678.26
Question 3
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
Select one:
a. False
b. True
Question 4
In the following code, Integer.parseInt(str), is an example of ________.

int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a local variable
c. a complex method
d. a void method
Question 5
When saving a Java source file, save it with an extension of
Select one:
a. .javac
b. .src
c. .class
d. .java
Question 6
In the following Java statement what value is stored in the variable name?
String name = "John Doe";
Select one:
a. The memory address where name is located
b. The memory address where "John Doe" is located
c. name
d. John Doe
Question 7
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
Select one:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question 8
StringBuilder objects are immutable.
Select one:
a. True
b. False
Question 9

What will display when the following code is executed:


JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 10
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10, 4.5);
b. showProduct(10.0, 4);
c. showProduct(33.0, 55.0);
d. showProduct(5.5, 4.0);
Question 11
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
Select one:
a. False
b. True
Question 12
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is
hidden, but not closed.
Select one:
a. JFrame. HIDE_ON_CLOSE
b. HIDE_ON_CLOSE
c. JFrame.HIDE_NOT_CLOSE
d. JFrame.EXIT_ON_CLOSE
Question 13
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. if statement
b. for loop
c. while loop
d. do-while loop
Question 14

When a method tests an argument and returns a true or false value, it should return
Select one:
a. a boolean value
b. a zero for false and a non-zero for true
c. a zero for true and a one for false
d. a method should not be used for this type test
Question 15
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Select one:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question 16
A classs responsibilities include
Select one:
a. the things a class is responsible for doing
b. both A and B
c. neither A or B
d. the things a class is responsible for knowing
Question 17
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
char cust = 'N';
if (purchase > 1000)
if (cust == 'Y')
discountRate = .05;
else
discountRate = .04;
else if (purchase > 750)
if (cust == 'Y')
discountRate = .04;
else
discountRate = .03;
else
discountRate = 0;
Select one:
a. .04
b. .05
c. .03
d. 0
Question 18
The expression in a return statement can be any expression that has a value.

Select one:
a. True
b. False
Question 19
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 1 and 2
b. 2
c. Neither 1 or 2
d. 1
Question 20
Methods are commonly used to
Select one:
a. break a problem down into small manageable pieces
b. speed up the compilation of a program
c. emphasize certain parts of the logic
d. document the program
Question 21
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Select one:
a. "[", "$", "&", "#", and "]"
b. "red", "green", "blue"and "orange"
c. None of the other three options.
d. "$", "&", and "#"
Question 22
The scope of a public instance field is
Select one:
a. inside the parentheses of a method header
b. inside the class, but not inside any method
c. the instance methods and methods outside the class
d. only the class in which it is defined
Question 23
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);
Select one:
a. 4

b. 6
c. 3
d. 5
Question 24
What will be displayed as a result of executing the following code?
int x = 8;
String msg = "I am enjoying javA.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " +
ltr);
System.out.println("msg has " + strSize +
" characters.");
Select one:
a. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = y
msg has 19 characters.
b. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 20 characters.
c. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 19 characters.
d. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = j
msg has 20 characters.
Question 25
This is a boolean variable that signals when some condition exists in the program
Select one:
a. Case
b. Flag
c. Sentinel
d. Block
Question 26
What is the result of the following expression?

25 / 4 + 4 * 10 % 3
Select one:
a. 3
b. 5.25
c. 7
d. 19
Question 27
Both character literals and string literals can be assigned to a char variable.
Select one:
a. True
b. False
Question 28
What does the following code display?
int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);
Select one:
a. 9 12
b. %9 %12
c. %d 9
d. %d %d
Question 29
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Select one:
a. a void method
b. a complex method
c. a value-returning method
d. a local variable
Question 30
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
Select one:
a. 24
b. 30
c. 28
d. 35
Question 31
Each byte is assigned a unique number known as an address.
Select one:

a. False
b. True
Question 32
An important style rule you should adopt for writing if statements is to write the conditionally executed
statement on the line after the if statement.
Select one:
a. False
b. True
Question 33
Which of the following statements will create a reference, str, to the String, Hello, World?
Select one:
a. str = "Hello, World";
b. string str = "Hello, World";
c. String str = new "Hello, World";
d. String str = "Hello, World";
Question 34
Colons are used to indicate the end of a Java statement.
Select one:
a. False
b. True
Question 35
Java source files end with the .class extension.
Select one:
a. True
b. False
Question 36
Two or more methods in a class may have the same name as long as
Select one:
a. they have different return types, but the same parameter list
b. they have different parameter lists
c. they have different return types
d. you cannot have two methods with the same name
Question 37
In an if/else statement, if the boolean expression is false,
Select one:
a. the statement or block following the else is executed
b. all statements or blocks are executed
c. the first statement or block is executed
d. no statements or blocks are executed
Question 38
What will be the values of x and y as a result of the following code?

int x = 12, y = 5;
x += y--;
Select one:
a. x = 16, y = 4
b. x = 17, y = 4
c. x = 12, y = 5
d. x = 17, y = 5
Question 39
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
Select one:
a. token
b. delimiter
c. buffer
d. separator
Question 40
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
Select one:
a. True
b. False
Question1
Instance methods do not have the key word static in their headers.
Whlen Sie eine Antwort:
a. False
b. True
Question2
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Whlen Sie eine Antwort:
a. displayValue(b,a); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a byte
c. displayValues(a,b); // where a is a short and b is a long
d. displayValues(a,b); // where a is an int and b is a byte
Question3
A classs responsibilities include
Whlen Sie eine Antwort:
a. the things a class is responsible for doing
b. neither A or B
c. both A and B
d. the things a class is responsible for knowing

Question4
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Whlen Sie eine Antwort:
a. True
b. False
Question5
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the data items is
Whlen Sie eine Antwort:
a. token
b. delimiter
c. buffer
d. separator
Question6
To document the return value of a method, use this in a documentation comment.
Whlen Sie eine Antwort:
a. The @return tag
b. The @param tag
c. The @comment tag
d. The @returnValue tag
Question7
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Whlen Sie eine Antwort:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question8
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Whlen Sie eine Antwort:
a. ans = 45, x = 50, y = 0
b. ans = 60, x = 50, y =100

c. ans = 60, x =0, y =50


d. ans = 45, x = 50, y = 50
Question9
Look at the following statement.
import java.util.*;
This is an example of
Whlen Sie eine Antwort:
a. a wildcard import
b. unconditional import
c. conditional import
d. an explicit import
Question10
The expression tested by an if statement must evaluate to
Whlen Sie eine Antwort:
a. true or false
b. +1 or -1
c. 0 or 1
d. t or f
Question11
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Whlen Sie eine Antwort:
a. import PrintWriter;
b. import javax.swing.*;
c. import javA.io.*;
d. import javA.filE.*;
Question12
Key words are:
Whlen Sie eine Antwort:
a. Words that have a special meaning in the programming language
b. The data names in your program
c. Words or names defined by the programmer
d. Symbols or words that perform operations on one or more operands
Question13
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Whlen Sie eine Antwort:
a. 90

b. 130
c. 210
d. 110
Question14
A variable's scope is the part of the program that has access to the variable.
Whlen Sie eine Antwort:
a. True
b. False
Question15
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Whlen Sie eine Antwort:
a. a void method
b. a complex method
c. a local variable
d. a value-returning method
Question16
This is a group of related classes.
Whlen Sie eine Antwort:
a. archive
b. package
c. attachment
d. collection
Question17
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing,
and closing the window.
Whlen Sie eine Antwort:
a. Dialog box
b. Frame
c. Pane
d. Container
Question18
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Whlen Sie eine Antwort:
a. a void method
b. a complex method
c. a local variable

d. a value-returning method
Question19
What will happen when the following statement is executed?
x.setEditable(false);
Whlen Sie eine Antwort:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question20
What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales > 1000)
bonus = 100;
if (sales > 750)
bonus = 50;
if (sales > 500)
bonus = 25;
else
bonus = 0;
Whlen Sie eine Antwort:
a. 0
b. 25
c. 100
d. 500
Question21
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;
else if (sales < 7500)
bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
Whlen Sie eine Antwort:
a. 750
b. 1250
c. 500
d. 1000
e. 200
Question22
The ___________ is normally considered the standard output and standard input devices, and usually refer to
the monitor and keyboarD.

Whlen Sie eine Antwort:


a. console
b. CPU
c. CRT
d. secondary storage devices
Question23
You can use the PrintWriter class to open a file for writing and write data to it.
Whlen Sie eine Antwort:
a. False
b. True
Question24
Another term for programs is:
Whlen Sie eine Antwort:
a. Peopleware
b. Firmware
c. Hardware
d. Software
Question25
Which of the following is not a part of the method header?
Whlen Sie eine Antwort:
a. method name
b. parentheses
c. semicolon
d. return type
Question26
In the following Java statement what value is stored in the variable name?
String name = "John Doe";
Whlen Sie eine Antwort:
a. The memory address where "John Doe" is located
b. John Doe
c. The memory address where name is located
d. name
Question27
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;

}
}
Whlen Sie eine Antwort:
a. Nothing, this is an error
b. 9 45 16
c. 9 45 16
d. 94516
Question28
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);
Whlen Sie eine Antwort:
a. 4
b. 5
c. 6
d. 3
Question29
Methods that operate on an object's fields are called
Whlen Sie eine Antwort:
a. instance methods
b. instance variables
c. public methods
d. private methods
Question30
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Whlen Sie eine Antwort:
a. diddle
b. diddl
c. , didd
d. Iddle
Question31
A for loop normally performs which of these steps?
Whlen Sie eine Antwort:
a. all of the above
b. updates the control variable during each iteration
c. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
d. None of the above
e. initializes a control variable to a starting value

Question32
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL
the world's alphabets.
Whlen Sie eine Antwort:
a. False
b. True
Question33
When testing for character values, the switch statement does not test for the case of the character.
Whlen Sie eine Antwort:
a. True
b. False
Question34
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Whlen Sie eine Antwort:
a. 1
b. 11
c. 10
d. 0
Question35
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.
Whlen Sie eine Antwort:
a. True
b. False
Question36
What will be the results of executing the following code, if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,"Select color", Color.blue);
panel.setForeground(selectedColor);
Whlen Sie eine Antwort:
a. The foreground color will remain unchanged.
b. The foreground color will be set to white.
c. The foreground color will be set to black.
d. The foreground color will be set to blue.
Question37
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Whlen Sie eine Antwort:
a. There are x5\nhens in the hen housE.
b. There are 5785
hens in the hen housE.

c. There are 583 hens in the hen housE.


d. There are 5785 hens in the hen housE.
Question38
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
Whlen Sie eine Antwort:
a. 5.25
b. 3
c. 7
d. 19
Question39
Java was developed by
Whlen Sie eine Antwort:
a. Microsoft
b. Hewlett-Packard
c. Sun Microsystems
d. IBM
Question40
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchangeD.
Whlen Sie eine Antwort:
a. True
b. False
Question1
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 18.0
b. 8.0
c. This is an error
d. 18 (as an integer)
Question2
What will be displayed as a result of executing the following code?
int x = 8;
String msg = "I am enjoying javA.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " +

ltr);
System.out.println("msg has " + strSize +
" characters.");
a. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 19 characters.
b. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 20 characters.
c. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = j
msg has 20 characters.
d. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = y
msg has 19 characters.
Question3
Which of the following statements creates a class that is extended from the JFrame class?
Whlen Sie eine Antwort:
a. public class DerivedClass extends JFrame{}
b. JFrame DerivedClass = new JFrame();
c. JFrame(DerivedClass);
d. class JFrame DerivedClass;
Question4
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
Whlen Sie eine Antwort:
a. 1
b. 5
c. 4
d. 0
Question5
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
Whlen Sie eine Antwort:

a. an ItemEvent object as an argurment.


b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question6
A loop that executes as long as a particular condition exists is called a[n]
Whlen Sie eine Antwort:
a. count-controlled loop
b. sentinel loop
c. infinite loop
d. conditional loop
Question7
Suppose you are at an operating system command line, and you are going to use the following command to
compile a program: javac MyClass.java, Before entering the command, you must:
Whlen Sie eine Antwort:
a. Save the program with the .comp extension
b. Make sure you are in the same directory or folder where MyClass.java is located
c. Close all other Windows on your computer system
d. Execute the javA.sun.com program
Question8
Which of the following is not a class used in constructing a menu system?
Whlen Sie eine Antwort:
a. JMenuItem
b. JCheckBoxMenuItem
c. JButton
d. JRadioButtonMenuItem
Question9
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Whlen Sie eine Antwort:
a. 100
b. 90
c. 110
d. This is an infinite loop
Question10
A class specifies the ________ and ________ that a particular type of object has.
Whlen Sie eine Antwort:

a. fields; object names


b. relationships; object names
c. relationships; methods
d. fields; methods
Question11
Which of the following does not describe a valid comment in Java?
Whlen Sie eine Antwort:
a. Multi-line comments, start with /* and end with */
b. Documentation comments, any comments starting with /** and ending with */
c. Single line comments, two forward slashes - //
d. Multi-line comments, start with */ and end with /*
Question12
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
Whlen Sie eine Antwort:
a. 9 45 16
b. Nothing, this is an error
c. 94516
d. 9 45 16
Question13
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Whlen Sie eine Antwort:
a. Numbers in the range 100 - 499
b. Numbers less than 100 or greater than 500
c. Numbers greater than 500

d. Numbers in the range 100 - 500


Question14
StringBuilder objects are immutable.
Whlen Sie eine Antwort:
a. True
b. False
Question15
Constants, variables, and the values of expressions may be passed as arguments to a methoD.
Whlen Sie eine Antwort:
a. True
b. False
Question16
Another term for an object of a class is
Whlen Sie eine Antwort:
a. instance
b. method
c. access specifier
d. member
Question17
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL
the world's alphabets.
Whlen Sie eine Antwort:
a. True
b. False
Question18
The scope of a private instance field is
Whlen Sie eine Antwort:
a. the method in which they are defined
b. inside the parentheses of a method header
c. inside the class, but not inside any method
d. the instance methods of the same class
Question19
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Whlen Sie eine Antwort:
a. 8
b. 7
c. 12
d. 105
Question20

What will the following code do when it is executed?


JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
Whlen Sie eine Antwort:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question21
Computers can do many different jobs because they are:
Whlen Sie eine Antwort:
a. Hardware
b. Programmable
c. Software
d. Electronic
Question22
In the method header the static method modifier means the method is available to code outside the class.
Whlen Sie eine Antwort:
a. True
b. False
Question23
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Whlen Sie eine Antwort:
a. ans = 60, x = 50, y =100
b. ans = 60, x =0, y =50
c. ans = 45, x = 50, y = 50
d. ans = 45, x = 50, y = 0
Question24
What will be the result of the following code?

int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Whlen Sie eine Antwort:
a. str will have a value of 560
b. neither num or str will be changed
c. num will be set to 560
d. the last line of code will cause an error
Question25
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
Whlen Sie eine Antwort:
a. False
b. True
Question26
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Whlen Sie eine Antwort:
a. x = 20
b. x = 40
c. x is unknown when the last statement is executed
d. x = 30
Question27
Look at the following statement.
import java.util.Scanner;
This is an example of
Whlen Sie eine Antwort:
a. conditional import
b. an explicit import
c. a wildcard import
d. unconditional import
Question28
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
Whlen Sie eine Antwort:
a. False
b. True

Question29
A runtime error is usually the result of:
Whlen Sie eine Antwort:
a. A syntax error
b. A logical error
c. Bad data
d. A compilation error
Question30
When an object, such as a String, is passed as an argument, it is
Whlen Sie eine Antwort:
a. passed by value like any other parameter value
b. necessary to know exactly how long the string is when writing the program
c. encrypted
d. actually a reference to the object that is passed
Question31
Which Scanner class method reads a String?
Whlen Sie eine Antwort:
a. getString()
b. nextString()
c. nextLine()
d. readString()
Question32
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 100;
if (purchase > 1000)
discountRate = .05;
else if (purchase > 750)
discountRate = .03;
else if (purchase > 500)
discountRate = .01;
Whlen Sie eine Antwort:
a. .03
b. .05
c. 0.0
d. .01
Question33
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);

}
Whlen Sie eine Antwort:
a. showProduct("5", "40");
b. showProduct(10.0, 4.6);
c. showProduct(3.3, 55);
d. showProduct(10, 4.5);
Question34
In all but rare cases, loops must contain within themselves
Whlen Sie eine Antwort:
a. if statements
b. nested loops
c. a way to terminate
d. arithmetic statements
Question35
What will happen when the following statement is executed?
x.setEditable(false);
Whlen Sie eine Antwort:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question36
Enclosing a group of statements inside a set of braces creates a
Whlen Sie eine Antwort:
a. Nothing, it is just for readability
b. loop
c. block of statements
d. boolean expression
Question37
The following package is automatically imported into all Java programs.
Whlen Sie eine Antwort:
a. java.default
b. java.java
c. java.lang
d. java.util
Question38
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one
for each delimiter character.
Whlen Sie eine Antwort:
a. True

b. False
Question39
Before entering a loop to compute a running total, the program should first do this.
Whlen Sie eine Antwort:
a. Set the accumulator where the total will be kept to an initial value, usually zero
b. Know exactly how many values there are to total
c. Read all the values into main memory
d. Set all variables to zero
Question40
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Whlen Sie eine Antwort:
a. "red", "green", "blue"and "orange"
b. None of the other three options.
c. "[", "$", "&", "#", and "]"
d. "$", "&", and "#"
Question1
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while
loops shows the correct way to read data from the file until the end of the file is reached?
Whlen Sie eine Antwort:
a. while (inputFile.hasNext()) { }
b. while (inputFile.nextLine == " ") { }
c. while (!inputFile.EOF) { }
d. while (inputFile != null) { }
Question2
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
Whlen Sie eine Antwort:
a. 30
b. No value, this is a syntax error.
c. 80
d. 50
Question3
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Whlen Sie eine Antwort:

a. diddle
b. diddl
c. , didd
d. Iddle
Question4
Because Java byte code is the same on all computers, compiled Java programs
Whlen Sie eine Antwort:
a. Are non-existent
b. Must be re-compiled for each different machine it is run on
c. Are highly portable
d. Cannot run on Linux systems
Question5
In a switch statement, if two different values for the CaseExpression would result in the same code being
executed, you must have two copies of the code, one after each CaseExpression.
Whlen Sie eine Antwort:
a. True
b. False
Question6
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.
Whlen Sie eine Antwort:
a. False
b. True
Question7
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
Whlen Sie eine Antwort:
a. x = 27, y = 3.333, z = 18
b. x = 27, y = 3, z = 18
c. Nothing. There is an error in the code!
d. x = 27, y = 2, z = 18
Question8
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");

timeOfDayButtonGroup = new ButtonGroup();


dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Whlen Sie eine Antwort:
a. 2
b. 4
c. 1
d. 3
Question9
The _________ statement is used to make simple decisions in Java.
Whlen Sie eine Antwort:
a. for
b. branch
c. if
d. do/while
Question10
This type of loop will always be executed at least once.
Whlen Sie eine Antwort:
a. pre-test loop
b. sentinel loop
c. post-test loop
d. for loop
Question11
A method that stores a value in a class's field or in some other way changes the value of a field is known as a
mutator method.
Whlen Sie eine Antwort:
a. False
b. True
Question12
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster
if the subexpression that is most likely false is on the left of the && operator.
Whlen Sie eine Antwort:
a. False
b. True
Question13
The expression in a return statement can be any expression that has a value.
Whlen Sie eine Antwort:

a. True
b. False
Question14
The getSelectedIndex method returns
Whlen Sie eine Antwort:
a. the index of the selected item. (A)
b. -1 if no item is selected. (B)
c. Both (A) and (B).
d. Neither (A) or (B).
Question15
Syntax is:
Whlen Sie eine Antwort:
a. Rules that must be followed when writing a program
b. Symbols or words that perform operations
c. Punctuation
d. Words that have a special meaning in the programming language
Question16
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
Whlen Sie eine Antwort:
a. x = 12, y = 5
b. x = 17, y = 4
c. x = 16, y = 4
d. x = 17, y = 5
Question17
In Java the variable named one is the same as the variable named OnE.
Whlen Sie eine Antwort:
a. False
b. True
Question18
Which Scanner class method reads a String?
Whlen Sie eine Antwort:
a. nextLine()
b. nextString()
c. readString()
d. getString()
Question19
What will be the values of ans, x, and y after the following statements are executed?
int ans = 0, x = 15, y =25;

if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Whlen Sie eine Antwort:
a. ans = 25, x = 15, y = 40
b. ans = 25, x = -10, y = 25
c. ans = 0, x = 15, y = 25
d. ans = 35, x = 15, y = 40
Question20
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
Whlen Sie eine Antwort:
a. 3.0
b. 5.6
c. 5.0
d. 5.60
Question21
In GUI terminology, a container that can be displayed as a window is known as a _______________.
Whlen Sie eine Antwort:
a. message dialog
b. buffer
c. frame
d. Swing package
Question22
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
Whlen Sie eine Antwort:
a. This is an infinite loop
b. 110
c. 210
d. 90

Question23
What is wrong with the following method call?
displayValue (double x);
Whlen Sie eine Antwort:
a. x should be a String.
b. Do not include the data type in the method call.
c. displayValue will not accept a parameter.
d. There is nothing wrong with the statement.
Question24
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Whlen Sie eine Antwort:
a. num will be set to 560
b. the last line of code will cause an error
c. str will have a value of 560
d. neither num or str will be changed
Question25
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Whlen Sie eine Antwort:
a. a complex method
b. a value-returning method
c. a void method
d. a local variable
Question26
Overloading means multiple methods in the same class
Whlen Sie eine Antwort:
a. have the same name, but different parameter lists
b. have the same name, but different return types
c. have different names, but the same parameter list
d. perform the same function
Question27
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
Whlen Sie eine Antwort:

a. 200
b. 10
c. This is an infinite loop.
d. The loop will not be executed, the initial value of x > 5.
Question28
Which of the following is not a valid comment statement?
Whlen Sie eine Antwort:
a. // comment 1
b. */ comment 3 /*
c. /** comment 4 */
d. /* comment 2 */
Question29
Colons are used to indicate the end of a Java statement.
Whlen Sie eine Antwort:
a. True
b. False
Question30
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Whlen Sie eine Antwort:
a. 22, y = 26
b. Nothing, this is an error
c. x = 22, y = 4
d. x = 22, y = 88
Question31
A constructor is a method that
Whlen Sie eine Antwort:
a. returns an object of the class.
b. never receives any arguments.
c. performs initialization or setup operations.
d. with the name ClassName.constructor.
Question32
Another term for an object of a class is
Whlen Sie eine Antwort:
a. instance
b. method
c. member

d. access specifier
Question33
In the following code the setPreferredSize method sets the size of the text, "Have a good day".
label = new Jlabel("Have a good day", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
Whlen Sie eine Antwort:
a. True
b. False
Question34
Assuming that inputFile references a Scanner object that was used to open a file, which of the following
statements will read an int from the file?
Whlen Sie eine Antwort:
a. int number = inputFilE.readInt();
b. int number = inputFilE.integer();
c. int number = inputFilE.nextInt();
d. int number = inputFilE.next();
Question35
Look at the following statement.
import java.util.*;
This is an example of
Whlen Sie eine Antwort:
a. conditional import
b. a wildcard import
c. an explicit import
d. unconditional import
Question36
To use the StringTokenizer class you must have the following import statement.
Whlen Sie eine Antwort:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;
d. import javA. String;
Question37
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing,
and closing the window.
Whlen Sie eine Antwort:
a. Frame
b. Container
c. Pane
d. Dialog box
Question38
What would be the value of bonus after the following statements are executed?

int bonus, sales = 85000;


char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Whlen Sie eine Antwort:
a. 1250
b. 1500
c. 1000
d. 2000
Question39
StringBuilder objects are immutable.
Whlen Sie eine Antwort:
a. True
b. False
Question40
This part of a method is a collection of statements that are performed when the method is executed.
Whlen Sie eine Antwort:
a. method body
b. method header
c. method modifier
d. return type
Question1
What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time <= 119 ? rate * 2 :
time / 60.0 * rate;
Whlen Sie eine Antwort:
a. 7.00
b. 14.00
c. 21.00
d. 28.00
Question2
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";

Whlen Sie eine Antwort:


a. 1 and 2
b. 1
c. Neither 1 or 2
d. 2
Question3
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Whlen Sie eine Antwort:
a. True
b. False
Question4
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Whlen Sie eine Antwort:
a. radio.doClick();
b. Click(radio);
c. radio.Click();
d. Click(radio, true);
Feedback
Die richtige Antwort lautet: radio.doClick();
Question5
A flag may have the values:
Whlen Sie eine Antwort:
a. true or false
b. 1 or -1
c. 0 or 1
d. of any character
Question6
A method that stores a value in a class's field or in some other way changes the value of a field is known as a
mutator method.
Whlen Sie eine Antwort:
a. True
b. False
Question7
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
Whlen Sie eine Antwort:
a. True
b. False
Question8
What will be returned from the following method?

public static double methodA()


{
double a = 8.5 + 9.5;
return a;
}
Whlen Sie eine Antwort:
a. 18 (as an integer)
b. 18.0
c. 8
d. This is an error
Question9
What does the following code display?
int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);
Whlen Sie eine Antwort:
a. %d %d
b. %d 9
c. 9 12
d. %9 %12
Question10
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Whlen Sie eine Antwort:
a. True
b. False
Question11
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
Whlen Sie eine Antwort:
a. 35
b. 28
c. 24
d. 30
Question12
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
Whlen Sie eine Antwort:
a. True
b. False
Question13
You cannot assign a value to a wrapper class object.
Whlen Sie eine Antwort:

a. True
b. False
Question14
A common technique for writing an event listener class is to write it as a private inner class inside the class that
creates the GUI.
Whlen Sie eine Antwort:
a. True
b. False
Question15
Internally, the central processing unit (CPU) consists of two parts:
Whlen Sie eine Antwort:
a. The arithmetic and login unit (ALU) and main memory
b. The control unit and the arithmetic and logic unit (ALU)
c. The input and output devices
d. The control unit and main memory
Question16
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Whlen Sie eine Antwort:
a. import PrintWriter;
b. import javA.io.*;
c. import javax.swing.*;
d. import javA.filE.*;
Question17
Variables of the boolean data type are useful for
Whlen Sie eine Antwort:
a. evaluating true/false conditions
b. evaluating scientific notation
c. working with very large integers
d. working with small integers
Question18
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);
Whlen Sie eine Antwort:
a. 6
b. 5
c. 3
d. 4
Question19

Two or more methods in a class may have the same name as long as
Whlen Sie eine Antwort:
a. they have different return types, but the same parameter list
b. they have different return types
c. they have different parameter lists
d. you cannot have two methods with the same name
Question20
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Whlen Sie eine Antwort:
a. 4
b. 2
c. 3
d. 1
Question21
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Whlen Sie eine Antwort:
a. a void method
b. a local variable
c. a complex method
d. a value-returning method
Question22
Which Scanner class method reads an int?
Whlen Sie eine Antwort:
a. getInt()
b. nextInt()
c. read_int()

d. readInt()
Question23
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Whlen Sie eine Antwort:
a. displayValues(a,b); // where a is an int and b is a byte
b. displayValue(b,a); // where a is a short and b is a long
c. displayValues(a,b); // where a is a short and b is a long
d. displayValues(a,b); // where a is a short and b is a byte
Question24
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Whlen Sie eine Antwort:
a. Nothing, this is an error
b. x = 22, y = 88
c. 22, y = 26
d. x = 22, y = 4
Question25
The term "default constructor" is applied to the first constructor written by the author of a class.
Whlen Sie eine Antwort:
a. False
b. True
Question26
You should always document a method by writing comments that appear
Whlen Sie eine Antwort:
a. just after the methods definition.
b. at the end of the file.
c. only if the method is more than five lines long.
d. just before the methods definition.
Question27
A byte is a collection of:
Whlen Sie eine Antwort:
a. Eight bits
b. A dollar
c. Six bits
d. Four bits
Question28
These operators are used to determine whether a specific relationship exists between two values.
Whlen Sie eine Antwort:

a. Assignment
b. Relational
c. Syntactical
d. Arithmetic
Question29
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
Whlen Sie eine Antwort:
a. Nothing, this is an error
b. 9 45 16
c. 9 45 16
d. 94516
Question30
In a @return tag statement the description
Whlen Sie eine Antwort:
a. describes the return value
b. cannot be longer than one line
c. must be longer than one line
d. describes the parameter values
Question31
A loop that executes as long as a particular condition exists is called a[n]
Whlen Sie eine Antwort:
a. count-controlled loop
b. conditional loop
c. sentinel loop
d. infinite loop
Question32
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;

y += 20;
}
Whlen Sie eine Antwort:
a. 130
b. 210
c. 90
d. 110
Question33
The major components of a typical computer system consist of:
Whlen Sie eine Antwort:
a. The CPU
b. All of the above
c. Main memory
d. Secondary storage devices
e. Input/output devices
Question34
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
Whlen Sie eine Antwort:
a. 2 and 3
b. 2
c. 1, 2, and 3 will all work
d. 3
Question35
After the header, the body of the method appears inside a set of
Whlen Sie eine Antwort:
a. braces, {}
b. brackets, []
c. paretheses, ()
d. double quotes, ""
Question36
A for loop normally performs which of these steps?
Whlen Sie eine Antwort:
a. all of the above
b. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
c. initializes a control variable to a starting value

d. None of the above


e. updates the control variable during each iteration
Question37
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Whlen Sie eine Antwort:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question38
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(Character.toUpperCase(str.charAt(m)));
m++;
}
Whlen Sie eine Antwort:
a. 456
b. ABC456
c. ABC
d. abc456
Question39
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Whlen Sie eine Antwort:
a. There are 5785
hens in the hen housE.
b. There are 5785 hens in the hen housE.
c. There are 583 hens in the hen housE.
d. There are x5\nhens in the hen housE.
Question40
Constants, variables, and the values of expressions may be passed as arguments to a methoD.
Whlen Sie eine Antwort:
a. True
b. False
Question1

Methods that operate on an object's fields are called


Whlen Sie eine Antwort:
a. instance methods
b. private methods
c. instance variables
d. public methods
Question2
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
Whlen Sie eine Antwort:
a. Invalid for statement
b. 25
c. 30
d. 40
Question3
Which of the following expressions will determine whether x is less than or equal to y?
Whlen Sie eine Antwort:
a. x > y
b. x =< y
c. x >= y
d. x <= y
Question4
RAM is usually:
Whlen Sie eine Antwort:
a. An input/output device
b. Secondary storage
c. A static type of memory, used for permanent storage
d. A volatile type of memory, used only for temporary storage
Question5
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
Whlen Sie eine Antwort:
a. control is returned to method B
b. control is returned to method A
c. the program terminates
d. control is returned to method C
Question6
Which Scanner class method reads a String?
Whlen Sie eine Antwort:

a. readString()
b. getString()
c. nextLine()
d. nextString()
Question7
Methods are commonly used to
Whlen Sie eine Antwort:
a. speed up the compilation of a program
b. emphasize certain parts of the logic
c. document the program
d. break a problem down into small manageable pieces
Question8
Look at the following statement.
import java.util.*;
This is an example of
Whlen Sie eine Antwort:
a. conditional import
b. an explicit import
c. unconditional import
d. a wildcard import
Question9
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Whlen Sie eine Antwort:
a. 18.0
b. This is an error
c. 8.0
d. 18 (as an integer)
Question10
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);
Whlen Sie eine Antwort:
a. 10
b. 200

c. This is an infinite loop.


d. The loop will not be executed, the initial value of x > 5.
Question11
What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time <= 119 ? rate * 2 :
time / 60.0 * rate;
Whlen Sie eine Antwort:
a. 14.00
b. 28.00
c. 21.00
d. 7.00
Question12
What is wrong with the following method call?
displayValue (double x);
Whlen Sie eine Antwort:
a. displayValue will not accept a parameter.
b. There is nothing wrong with the statement.
c. x should be a String.
d. Do not include the data type in the method call.
Question13
You must call a method to get the value of a wrapper class object.
Whlen Sie eine Antwort:
a. True
b. False
Question14
This is a named storage location in the computer's memory.
Whlen Sie eine Antwort:
a. Literal
b. Constant
c. Operator
d. Variable
Question15
You cannot assign a value to a wrapper class object.
Whlen Sie eine Antwort:
a. True
b. False
Question16
What will be displayed after the following statements have been executed?

final double x;
x = 54.3;
System.out.println("x = " + x );
Whlen Sie eine Antwort:
a. Nothing, there is an error in the code.
b. x = 54.3
c. x
d. x = 108.6
Question17
Which of the following is included in a method call?
Whlen Sie eine Antwort:
a. parentheses
b. return type
c. return variable
d. method modifiers
Question18
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Whlen Sie eine Antwort:
a. 10
b. 0
c. 1
d. 11
Question19
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Whlen Sie eine Antwort:
a. the last line of code will cause an error
b. neither num or str will be changed
c. str will have a value of 560
d. num will be set to 560
Question20
To use the Color class, which is used to set the foreground and background of various objects, use the following
import statement
Whlen Sie eine Antwort:
a. import java.awt;
b. import java.swing;
c. import java.awt.*;

d. import java.awt.event.*;
Question21
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Whlen Sie eine Antwort:
a. panel.attachLayout(GridLayout(2,3));
b. panel.GridLayout(2,3);
c. panel.addLayout(new (GridLayout(2,3));
d. panel.setLayout(new (GridLayout(2,3));
Question22
The scope of a public instance field is
Whlen Sie eine Antwort:
a. only the class in which it is defined
b. the instance methods and methods outside the class
c. inside the parentheses of a method header
d. inside the class, but not inside any method
Question23
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Whlen Sie eine Antwort:
a. There are x5\nhens in the hen housE.
b. There are 583 hens in the hen housE.
c. There are 5785
hens in the hen housE.
d. There are 5785 hens in the hen housE.
Question24
In a switch statement, if two different values for the CaseExpression would result in the same code being
executed, you must have two copies of the code, one after each CaseExpression.
Whlen Sie eine Antwort:
a. False
b. True
Question25
What will be the value of x after the following code is executed?
int x = 75;
int y = 60;
if (x > y)
x = x - y;
Whlen Sie eine Antwort:
a. 60
b. 135
c. 15

d. 75
Question26
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Whlen Sie eine Antwort:
a. No value, there is a syntax error
b. 10
c. 145
d. 20
Question27
What will be the results of executing the following code, if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,"Select color", Color.blue);
panel.setForeground(selectedColor);
Whlen Sie eine Antwort:
a. The foreground color will remain unchanged.
b. The foreground color will be set to white.
c. The foreground color will be set to black.
d. The foreground color will be set to blue.
Question28
Application software refers to programs that make the computer useful to the user.
Whlen Sie eine Antwort:
a. True
b. False
Question29
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
Whlen Sie eine Antwort:
a. 3

b. 4
c. 2
d. 1
Question30
This type of loop will always be executed at least once.
Whlen Sie eine Antwort:
a. pre-test loop
b. sentinel loop
c. for loop
d. post-test loop
Question31
After the header, the body of the method appears inside a set of
Whlen Sie eine Antwort:
a. braces, {}
b. paretheses, ()
c. brackets, []
d. double quotes, ""
Question32
To compile a program named First, use the following command
Whlen Sie eine Antwort:
a. compile First.javac
b. java First.java
c. javac First.java
d. javac First
Question33
Colons are used to indicate the end of a Java statement.
Whlen Sie eine Antwort:
a. True
b. False
Question34
In all but rare cases, loops must contain within themselves
Whlen Sie eine Antwort:
a. arithmetic statements
b. nested loops
c. if statements
d. a way to terminate
Question35
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;

y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
Whlen Sie eine Antwort:
a. Nothing. There is an error in the code!
b. x = 27, y = 2, z = 18
c. x = 27, y = 3.333, z = 18
d. x = 27, y = 3, z = 18
Question36
One or more objects may be created from a
Whlen Sie eine Antwort:
a. class
b. field
c. instance
d. method
Question37
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
Whlen Sie eine Antwort:
a. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);
b. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");
c. File file = new File("MyFilE.txt");
d. Scanner inputFile = new Scanner("MyFilE.txt");
PrintWriter outFile = new PrintWriter(fwriter);
Question38
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
Whlen Sie eine Antwort:
a. radio.Click();
b. Click(radio);
c. Click(radio, true);
d. radio.doClick();
Question39
The _________ statement is used to make simple decisions in Java.
Whlen Sie eine Antwort:
a. if
b. do/while
c. for
d. branch
Question40

For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
Whlen Sie eine Antwort:
a. 1
b. 7
c. 5
d. 3
Question 1
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 160, y = 80
b. x = 37, y = 5
c. x = 32, y = 4
d. x = 9, y = 52
Question 2
Compiled byte code is also called source code.
Select one:
a. False
b. True
Question 3
Methods that operate on an object's fields are called
Select one:
a. public methods
b. instance methods
c. private methods
d. instance variables
Question 4
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 inches thick.

Question 5
The expression tested by an if statement must evaluate to
Select one:
a. true or false
b. 0 or 1
c. +1 or -1
d. t or f
Question 6
A for loop normally performs which of these steps?
Select one:
a. None of the above
b. all of the above
c. initializes a control variable to a starting value
d. updates the control variable during each iteration
e. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
Question 7
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers less than 100 or greater than 500
b. Numbers greater than 500
c. Numbers in the range 100 - 500
d. Numbers in the range 100 - 499
Question 8
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
Select one:
a. x = 17, y = 5
b. x = 17, y = 4
c. x = 12, y = 5
d. x = 16, y = 4
Question 9
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.

Select one:
a. False
b. True
Question 10
A flag may have the values:
Select one:
a. 1 or -1
b. 0 or 1
c. true or false
d. of any character
Question 11
Two ways of concatenating two Strings are
Select one:
a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Question 12
Question text
A method that stores a value in a class's field or in some other way changes the value of a field is known as a
mutator method.
Select one:
a. False
b. True
Question 13
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. This is an error
b. 18 (as an integer)
c. 8
d. 18.0
Question 14
In Java the variable named one is the same as the variable named OnE.
Select one:
a. False
b. True
Question 15

Key words are:


Select one:
a. The data names in your program
b. Words that have a special meaning in the programming language
c. Symbols or words that perform operations on one or more operands
d. Words or names defined by the programmer
Question 16
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. str will have a value of 560
b. the last line of code will cause an error
c. neither num or str will be changed
d. num will be set to 560
Question 17
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 1 and 2
b. Neither 1 or 2
c. 1
d. 2
Question 18
Which Scanner class method reads a String?
Select one:
a. nextString()
b. getString()
c. nextLine()
d. readString()
Question 19
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Select one:
a. There are 583 hens in the hen housE.
b. There are 5785 hens in the hen housE.
c. There are 5785
hens in the hen housE.

d. There are x5\nhens in the hen housE.


Question 20
When a method tests an argument and returns a true or false value, it should return
Select one:
a. a zero for true and a one for false
b. a method should not be used for this type test
c. a boolean value
d. a zero for false and a non-zero for true
Question 21
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. 10
b. 20
c. No value, there is a syntax error
d. 145
Question 22
What is wrong with the following method call?
displayValue (double x);
Select one:
a. There is nothing wrong with the statement.
b. x should be a String.
c. displayValue will not accept a parameter.
d. Do not include the data type in the method call.
Question 23
Java was developed by
Select one:
a. Microsoft
b. Sun Microsystems
c. IBM
d. Hewlett-Packard
Question 24
You should always document a method by writing comments that appear
Select one:
a. just after the methods definition.
b. only if the method is more than five lines long.
c. just before the methods definition.
d. at the end of the file.

Question 25
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 100;
if (purchase > 1000)
discountRate = .05;
else if (purchase > 750)
discountRate = .03;
else if (purchase > 500)
discountRate = .01;
Select one:
a. 0.0
b. .03
c. .01
d. .05
Question 26
To add a tool tip to a component use
Select one:
a. the setToolTipText method.
b. the addToolTipText method.
c. the toolTipText method.
d. the appendToolTipText method.
Question 27
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. Nothing, this is an error
b. x = 22, y = 4
c. 22, y = 26
d. x = 22, y = 88
Question 28
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
Select one:
a. False
b. True
Question 29
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)

discountRate = .01;
else
discountRate = 0;
Select one:
a. .05
b. 0
c. .01
d. .03
Question 30
Which of the following statements creates a class that is extended from the JFrame class?
Select one:
a. class JFrame DerivedClass;
b. public class DerivedClass extends JFrame{}
c. JFrame DerivedClass = new JFrame();
d. JFrame(DerivedClass);
Question 31
When an argument value is passed to a method, the receiving parameter variable is
Select one:
a. uses the declaration of the argument
b. declared in the calling method
c. declared in the method header inside the parentheses
d. declared within the body of the method
Question 32
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Select one:
a. False
b. True
Question 33
A do-while loop must be terminated with a semicolon.
Select one:
a. True
b. False
Question 34
Two or more methods in a class may have the same name as long as
Select one:
a. you cannot have two methods with the same name
b. they have different return types
c. they have different return types, but the same parameter list
d. they have different parameter lists
Question 35

For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
Select one:
a. 3
b. 5
c. 1
d. 7
Question 36
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, panel.add(bGroup);
b. add each button to panel one at a time, e.g. panel.add(button1);
c. use the statement, Panel panel = new Panel(bGroup);
d. use the statement, bGroup.add(panel);
Question 37
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 38
StringBuilder objects are immutable.
Select one:
a. True
b. False
Question 39
What will be printed after the following code is executed?
for (int number = 5; number <= 15; number +=3)
System.out.print(number + ", ");
Select one:
a. This is an invalid for statement
b. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

c. 5, 8, 11, 14,
d. 5, 8, 11, 14, 17,
Question 40
Which of the following expressions will determine whether x is less than or equal to y?
Select one:
a. x >= y
b. x > y
c. x <= y
d. x =< y
Question 1
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. assume
b. link
c. import
d. use
Question 2
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);
Select one:
a. 4
b. 5
c. 3
d. 6
Question 3
This is a software entity that contains data and procedures.
Select one:
a. Method
b. Program
c. Object
d. Class
Question 4
Only constants and variables may be passed as arguments to methods.
Select one:
a. True
b. False
Question 5
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");

Select one:
a. There are 5785
hens in the hen housE.
b. There are 5785 hens in the hen housE.
c. There are 583 hens in the hen housE.
d. There are x5\nhens in the hen housE.
Question 6
An access specifier indicates how the class may be accessed.
Select one:
a. False
b. True
Question 7
A flag may have the values:
Select one:
a. 0 or 1
b. 1 or -1
c. of any character
d. true or false
Question 8
Enclosing a group of statements inside a set of braces creates a
Select one:
a. boolean expression
b. Nothing, it is just for readability
c. block of statements
d. loop
Question 9
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a complex method
c. a local variable
d. a void method
Question 10
To use the Color class, which is used to set the foreground and background of various objects, use the following
import statement
Select one:
a. import java.awt;

b. import java.awt.event.*;
c. import java.awt.*;
d. import java.swing;
Question 11
Which of the following is not involved in finding the classes when developing an object-oriented application?
Select one:
a. Identify all the nouns.
b. Describe the problem domain.
c. Write the code.
d. Refine the list of nouns to include only those that are relevant to the problem.
Question 12
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. unconditional import
b. conditional import
c. an explicit import
d. a wildcard import
Question 13
Before entering a loop to compute a running total, the program should first do this.
Select one:
a. Read all the values into main memory
b. Set all variables to zero
c. Know exactly how many values there are to total
d. Set the accumulator where the total will be kept to an initial value, usually zero
Question 14
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);
Select one:
a. This is an infinite loop.
b. 10
c. The loop will not be executed, the initial value of x > 5.
d. 200
Question 15
In a general sense, a method is
Select one:

a. a statement inside a loop


b. a collection of statements that performs a specific task
c. a comment
d. a plan
Question 16
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Select one:
a. import javA.io.*;
b. import javA.filE.*;
c. import javax.swing.*;
d. import PrintWriter;
Question 17
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Question 18
The contents of a variable cannot be changed while the program is running.
Select one:
a. True
b. False
Question 19
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers less than 100 or greater than 500
b. Numbers in the range 100 - 500
c. The boolean condition can never be true
d. Numbers in the range 100 - 499
Question 20
To use the StringTokenizer class you must have the following import statement.

Select one:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;
d. import javA. String;
Question 21
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(33.0, 55.0);
b. showProduct(10, 4.5);
c. showProduct(10.0, 4);
d. showProduct(5.5, 4.0);
Feedback
Die Antwort ist falsch
The correct answer is: showProduct(10, 4.5);
Question 22
Correct
Mark 1.00 out of 1.00

Flag question
Question text
Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44;
Select one:
a. True
b. False
Feedback
Die Antwort ist richtig
The correct answer is: False
Question 23
Correct
Mark 1.00 out of 1.00

Flag question
Question text

Assuming that inputFile references a Scanner object that was used to open a file, which of the following
statements will read an int from the file?
Select one:
a. int number = inputFilE.next();
b. int number = inputFilE.readInt();
c. int number = inputFilE.integer();
d. int number = inputFilE.nextInt();
Correct
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
b. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
c. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
d. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
Question 25
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. Nothing, this is an error
b. x = 22, y = 4
c. x = 22, y = 88
d. 22, y = 26
Question 26
One of the design tools used by programmers when creating a model of the program is:
Select one:
a. Compiler
b. Pseudocode
c. ALU
d. Disk drive
Question 27
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, Panel panel = new Panel(bGroup);
b. add each button to panel one at a time, e.g. panel.add(button1);
c. use the statement, bGroup.add(panel);
d. use the statement, panel.add(bGroup);
Question 28

What is the result of the following expression?


17 % 3 * 2 - 12 + 15
Select one:
a. 12
b. 105
c. 8
d. 7
Question 29
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
Select one:
a. using the public access specifier on the class methods
b. using the private access specifier on the class fields
c. using the private access specifier on the class definition
d. using the private access specifier on the class methods
Question 30
What will be the value of x after the following code is executed?
int x = 75;
int y = 60;
if (x > y)
x = x - y;
Select one:
a. 60
b. 15
c. 135
d. 75
Question 31
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
Select one:
a. True
b. False
Question 32
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;

else
bonus = 0;
Select one:
a. 1500
b. 1000
c. 1250
d. 2000
Question 33
What does the following code display?
int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);
Select one:
a. %d %d
b. %9 %12
c. %d 9
d. 9 12
Question 34
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is a short and b is a byte
b. displayValues(a,b); // where a is a short and b is a long
c. displayValues(a,b); // where a is an int and b is a byte
d. displayValue(b,a); // where a is a short and b is a long
Question 35
For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
Select one:
a. 3
b. 5
c. 7
d. 1
Question 36
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchangeD.
Select one:
a. True
b. False
Question 37

The primitive data types only allow a _____ to hold a single value.
Select one:
a. literal
b. class
c. variable
d. object
Question 38
You should always document a method by writing comments that appear
Select one:
a. just after the methods definition.
b. just before the methods definition.
c. at the end of the file.
d. only if the method is more than five lines long.
Question 39
Which of the following is a valid Java statement?
Select one:
a. string str = "John Doe";
b. String str = 'John Doe';
c. String str = "John Doe";
d. string str = 'John Doe';
Question 40
Which of the following statements creates a class that is extended from the JFrame class?
Select one:
a. JFrame(DerivedClass);
b. JFrame DerivedClass = new JFrame();
c. public class DerivedClass extends JFrame{}
d. class JFrame DerivedClass;
Question 1
All Java statements end with semicolons.
Select one:
a. False
b. True
Question 2
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(5.5, 4.0);

b. showProduct(10, 4.5);
c. showProduct(10.0, 4);
d. showProduct(33.0, 55.0);
Question 3
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
Question 4
If a loop does not contain within itself a way to terminate, it is called a
Select one:
a. for loop
b. while loop
c. infinite loop
d. do-while loop
Question 5
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");

Select one:
a. "$", "&", and "#"
b. None of the other three options.
c. "red", "green", "blue"and "orange"
d. "[", "$", "&", "#", and "]"
Question 6
Which of the following correctly tests the char variable chr to determine whether it is not equal to the
character B?
Select one:
a. if (chr > 'B')
b. if (chr != 'B')
c. if (chr < 'B')
d. if (chr != "B")
Question 7
The lifetime of a method's local variable is
Select one:
a. only while the method is executing
b. the duration of the class to which the method belongs
c. the duration of the method that called the local variable's method
d. the duration of the program
Question 8
Which of the following is not a part of the method header?
Select one:
a. method name
b. parentheses
c. semicolon
d. return type
Question 9
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. Nothing, this is an error
b. x = 22, y = 4
c. 22, y = 26
d. x = 22, y = 88
Question 10
A flag may have the values:
Select one:
a. 1 or -1

b. true or false
c. of any character
d. 0 or 1
Question 11
You can use this method to determine whether a file exists.
Select one:
a. The File class's canOpen method
b. The PrintWriter class's fileExists method
c. The File class's exists method
d. The Scanner class's exists method
Question 12
Which of the following is not part of the programming process?
Select one:
a. Testing
b. Design
c. All the above are parts of the programming process
d. Debugging
Question 13
When an application uses many components, instead of extending just one class from the JFrame class, a
better approach is to
Select one:
a. reconsider the design of the application
b. just go ahead and do it in one large class
c. break the application into several smaller applications
d. encapsulate smaller groups of related components and their event listeners into their own classes
Question 14
Look at the following statement.
import java.util.*;
This is an example of
Select one:
a. a wildcard import
b. conditional import
c. an explicit import
d. unconditional import
Question 15
Which of the following is not a primitive data type?
Select one:
a. short
b. String

c. float
d. long
Question 16
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
Select one:
a. ans = 60, x =0, y =50
b. ans = 45, x = 50, y = 50
c. ans = 60, x = 50, y =100
d. ans = 45, x = 50, y = 0
Question 17
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.
Select one:
a. True
b. False
Question 18
StringBuilder objects are immutable.
Select one:
a. True
b. False
Question 19
What will be the value of ans after the following code has been executed?
int ans = 10;
int x = 65;
int y = 55;
if (x >= y)
ans = x + y;
Select one:
a. 120
b. No value, there is a syntax error
c. 100
d. 10
Question 20
In GUI terminology, a container that can be displayed as a window is known as a _______________.
Select one:

a. message dialog
b. Swing package
c. buffer
d. frame
Question 21
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
Select one:
a. 10
b. The loop will not be executed, the initial value of x > 5.
c. This is an infinite loop.
d. 200
Question 22
This is a group of related classes.
Select one:
a. collection
b. package
c. archive
d. attachment
Question 23
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 24
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Select one:
a. False
b. True
Question 25
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;

return a;
}
Select one:
a. 18.0
b. This is an error
c. 8
d. 18 (as an integer)
Question 26
A loop that repeats a specific number of times is known as a[n]
Select one:
a. infinite loop
b. counter-controlled loop
c. conditional loop
d. sentinel loop
Question 27
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. neither num or str will be changed
b. str will have a value of 560
c. the last line of code will cause an error
d. num will be set to 560
Question 28
In Java the variable named one is the same as the variable named OnE.
Select one:
a. True
b. False
Question 29
Logical errors are mistakes that cause the program to produce erroneous results.
Select one:
a. False
b. True
Question 30
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Select one:
a. This is an infinite loop

b. 100
c. 110
d. 90
Question 31
Enclosing a group of statements inside a set of braces creates a
Select one:
a. boolean expression
b. block of statements
c. loop
d. Nothing, it is just for readability
Question 32
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 9, y = 52
b. x = 32, y = 4
c. x = 160, y = 80
d. x = 37, y = 5
Question 33
What would be the value of x after the following statements were executed?
int x = 10;
switch (x)
{
case 10:
x += 15;
case 12:
x -= 5;
break;
default:
x *= 3;
}
Select one:
a. 5
b. 20
c. 30
d. 25
Question 34
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);

Select one:
a. 200
b. 10
c. The loop will not be executed, the initial value of x > 5.
d. This is an infinite loop.
Question 35
This type of method performs a task and then terminates.
Select one:
a. local
b. value-returning
c. simple
d. void
Question 36
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
Select one:
a. False
b. True
Question 37
When you are writing a program with String objects that may have unwanted spaces at the beginning or end of
the strings, use this method to delete them.
Select one:
a. replace
b. trim
c. valueOf
d. substring
Question 38
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter
variable.
Select one:
a. True
b. False
Question 39
The major components of a typical computer system consist of:
Select one:
a. Main memory
b. The CPU
c. Secondary storage devices
d. All of the above
e. Input/output devices

Question 40
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
c. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
d. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
Question 1
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. import
b. assume
c. link
d. use
Question 2
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Select one:
a. a value-returning method
b. a void method
c. a complex method
d. a local variable
Question 3
An operating system can be categorized according to:
Select one:
a. The number of tasks they can perform at one time
b. Neither of the above
c. Both of the above
d. The number of users they can accommodate
Question 4
Instance methods do not have the key word static in their headers.
Select one:
a. True
b. False
Question 5
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?
PrintWriter diskOut = new PrintWriter("DiskFilE.txt");
Select one:
a. diskOut.println("Calvin");

b. System.out.println(diskOut, "Calvin");
c. DiskFilE.println("Calvin");
d. PrintWriter.println("Calvin");
Question 6
Which of the following is a valid Java statement?
Select one:
a. string str = "John Doe";
b. String str = 'John Doe';
c. String str = "John Doe";
d. string str = 'John Doe';
Question 7
To use the Color class, which is used to set the foreground and background of various objects, use the following
import statement
Select one:
a. import java.awt.*;
b. import java.awt;
c. import java.swing;
d. import java.awt.event.*;
Question 8
This type of loop will always be executed at least once.
Select one:
a. for loop
b. pre-test loop
c. sentinel loop
d. post-test loop
Question 9
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Question 10
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Select one:
a. diddle
b. diddl

c. , didd
d. Iddle
Question 11
Which of the following are pre-test loops?
Select one:
a. while, do-while
b. for, do-while
c. while, for, do-while
d. while, for
Question 12
The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are
read.
Select one:
a. True
b. False
Question 13
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a byte
c. displayValue(b,a); // where a is a short and b is a long
d. displayValues(a,b); // where a is an int and b is a byte
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. a and b
b. (str1.compareToIgnoreCase(str2) == 0)
c. Only a
d. (str1.equalsIgnoreCase(str2))
Question 15
What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 8.0
b. 8
c. 4
d. 8.25
Question 16

The String classs valueOf() method accepts a string representation as an argument and returns its equivalent
integer value.
Select one:
a. True
b. False
Question 17
Colons are used to indicate the end of a Java statement.
Select one:
a. True
b. False
Question 18
What is the value of x after the following code has been executed?
int x = 75;
int y = 90;
if ( x != y)
x += y;
Select one:
a. 75
b. 165
c. 15
d. 90
Question 19
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter = new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
Select one:
a. 45678.259
b. 45,678.26
c. 0,045,678.26
d. 45,678.3
Question 20
If a loop does not contain within itself a way to terminate, it is called a
Select one:
a. for loop
b. do-while loop
c. infinite loop
d. while loop
Question 21
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:

a. x
b. Nothing, there is an error in the code.
c. x = 54.3
d. x = 108.6
Question 22
The _________ statement is used to make simple decisions in Java.
Select one:
a. for
b. if
c. do/while
d. branch
Question 23
What is the result of the following expression?
10 + 5 * 3 - 20
Select one:
a. 5
b. 25
c. -5
d. -50
Question 24
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
Select one:
a. True
b. False
Question 25
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
Select one:
a. True
b. False
Question 26
Which of the following is not part of a method call?
Select one:
a. method name
b. all of the above are part of a method call
c. parentheses
d. return type
Question 27

Named constants are initialized with a value, that value cannot be changed during the execution of the
program.
Select one:
a. False
b. True
Question 28
A class specifies the ________ and ________ that a particular type of object has.
Select one:
a. fields; methods
b. relationships; object names
c. fields; object names
d. relationships; methods
Question 29
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. str will have a value of 560
b. the last line of code will cause an error
c. num will be set to 560
d. neither num or str will be changed
Question 30
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Select one:
a. 210
b. 110
c. 90
d. 130
Question 31
Variables are classified according to their
Select one:
a. value
b. names
c. data type
d. location in the program
Question 32

What will display when the following code is executed:


JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 33
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. Neither 1 or 2
b. 2
c. 1 and 2
d. 1
Question 34
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
Select one:
a. using the private access specifier on the class fields
b. using the private access specifier on the class methods
c. using the private access specifier on the class definition
d. using the public access specifier on the class methods
Question 35
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. No value, there is a syntax error
b. 10
c. 145
d. 20
Question 36
In a @return tag statement the description
Select one:
a. cannot be longer than one line
b. describes the return value
c. describes the parameter values
d. must be longer than one line

Question 37
Event listeners must
Select one:
a. be included in private inner classes
b. implement an interface
c. exit the application once it has handled the event
d. not receive any arguments
Question 38
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.
Select one:
a. True
b. False
Question 39
What will be printed after the following code is executed?
for (int number = 5; number <= 15; number +=3)
System.out.print(number + ", ");
Select one:
a. This is an invalid for statement
b. 5, 8, 11, 14, 17,
c. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
d. 5, 8, 11, 14,
Question 40
The expression tested by an if statement must evaluate to
Select one:
a. 0 or 1
b. true or false
c. +1 or -1
d. t or f
Question 1
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Select one:
a. a local variable
b. a value-returning method
c. a complex method
d. a void method
Question 2
The contents of a variable cannot be changed while the program is running.
Select one:
a. True

b. False
Question 3
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct("5", "40");
b. showProduct(3.3, 55);
c. showProduct(10, 4.5);
d. showProduct(10.0, 4.6);
Question 4
You should not define a class field that is dependent upon the values of other class fields...
Select one:
a. because it is redundant
b. in order to avoid having stale data
c. because it should be defined in another class
d. in order to keep it current
Question 5
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a complex method
c. a void method
d. a local variable
Question 6
A loop that repeats a specific number of times is known as a[n]
Select one:
a. conditional loop
b. infinite loop
c. counter-controlled loop
d. sentinel loop
Question 7
The boolean data type may contain values in the following range of values
Select one:
a. - 32,768 to +32,767

b. - 2,147,483,648 to +2,147,483,647
c. true or false
d. -128 to + 127
Question 8
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Select one:
a. 130
b. 210
c. 110
Question 9
What will be the value of x after the following code is executed?
int x, y = 15, z = 3;
x = (y--) / (++z);
Select one:
a. 3
b. 5
c. 6
d. 4
Question 10
Methods are commonly used to
Select one:
a. break a problem down into small manageable pieces
b. emphasize certain parts of the logic
c. document the program
d. speed up the compilation of a program
Question 11
The Character wrapper class provides numerous methods for
Select one:
a. testing String objects
b. testing and converting char variables
c. converting String variables
d. adding two char variables
Question 12
Which of the following is the correct boolean expression to test for: int x being a value between, but not
including, 500 and 650, or int y not equal to 1000?
Select one:
a. ((x < 500 && x > 650) || !(y == 1000))

b. ((x > 500 AND x < 650) OR !(y.equal(1000)))


c. ((x > 500 && x < 650) || (y != 1000))
d. ((x >= 500 && x <= 650) && (y != 1000))
Question 13
Each byte is assigned a unique number known as an address.
Select one:
a. True
b. False
Question 14
This is a cross between human language and a programming language.
Select one:
a. The compiler
b. The Java Virtual Machine
c. Java
d. Pseudocode
Question 15
Which of the following is included in a method call?
Select one:
a. return variable
b. parentheses
c. method modifiers
d. return type
Question 16
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 30
b. x = 40
c. x = 20
d. x is unknown when the last statement is executed
Question 17
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;

x -=y;
}
else
{
ans = y + 10;
y += x;
}
Select one:
a. ans = 45, x = 50, y = 50
b. ans = 60, x = 50, y =100
c. ans = 45, x = 50, y = 0
d. ans = 60, x =0, y =50
Question 18
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Select one:
a. diddle
b. diddl
c. , didd
d. Iddle
Question 19
When saving a Java source file, save it with an extension of
Select one:
a. .javac
b. .java
c. .class
d. .src
Question 20
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Select one:
a. The quick brown fox jumped over the \nslow moving hen.
b. Nothing. This is an error.
c. The quick brown fox
jumped over the
slow moving hen.
d. The quick brown fox jumped over the
slow moving hen.
Question 21
Instance methods should be declared static.
Select one:

a. True
b. False
Question 22
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 32, y = 4
b. x = 9, y = 52
c. x = 37, y = 5
d. x = 160, y = 80
Question 23
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Select one:
a. True
b. False
Question 24
When using the BorderLayout manager, how many components can each region hold?
Select one:
a. No limit
b. 2
c. 1
d. 5
Question 25
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
Select one:
a. True
b. False
Question 26
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, Panel panel = new Panel(bGroup);
b. add each button to panel one at a time, e.g. panel.add(button1);
c. use the statement, panel.add(bGroup);
d. use the statement, bGroup.add(panel);
Question 27
One or more objects may be created from a
Select one:

a. field
b. class
c. method
d. instance
Question 28
Which of the following is not part of a method call?
Select one:
a. method name
b. all of the above are part of a method call
c. return type
d. parentheses
Question 29
What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 30
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one
for each delimiter character.
Select one:
a. True
b. False
Question 31
This is a sum of numbers that accumulates with each iteration of a loop.
Select one:
a. Grand finale
b. Galloping total
c. Final total
d. Running total
Question 32
What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time <= 119 ? rate * 2 :
time / 60.0 * rate;
Select one:
a. 28.00
b. 14.00

c. 21.00
d. 7.00
Question 33
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. a wildcard import
b. an explicit import
c. conditional import
d. unconditional import
Question 34
The scope of a public instance field is
Select one:
a. inside the class, but not inside any method
b. only the class in which it is defined
c. inside the parentheses of a method header
d. the instance methods and methods outside the class
Question 35
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 500
b. Numbers in the range 100 - 499
c. Numbers less than 100 or greater than 500
d. Numbers greater than 500
Question 36
This is a value that signals when the end of a list of values has been reacheD.
Select one:
a. Terminal value
b. Sentinel
c. Final value
d. End value
Question 37
What will display when the following code is executed?
imagePanel = new JPanel();

imageLabel = new JLabel();


imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 38
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 12
b. 7
c. 105
d. 8
Question 39
Which of the following expressions will determine whether x is less than or equal to y?
Select one:
a. x <= y
b. x > y
c. x >= y
d. x =< y
Question 40
In Java, when a character is stored in memory, it is actually stored as a
Select one:

_____.

a. ASCII character code


b. Unicode number
c. EBCDIC character code
d. Morse code
Question 1
What will be the value of ans after the following code has been executed?
int ans = 10;
int x = 65;
int y = 55;
if (x >= y)
ans = x + y;
Select one:
a. No value, there is a syntax error
b. 100

c. 10
d. 120
Question 2
Question text
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18 (as an integer)
b. This is an error
c. 8.0
d. 18.0
Question 3
Question text
Constants, variables, and the values of expressions may be passed as arguments to a methoD.
Select one:
a. False
b. True
Question 4
Question text
When using the StringBuilder class's insert method, you can insert
Select one:
a. any primitive type
b. a String object
c. a char array
d. All of the above
Question 5
Question text
In all but rare cases, loops must contain within themselves
Select one:
a. nested loops
b. a way to terminate
c. if statements
d. arithmetic statements
Question 6
Question text
Programming style includes techniques for consistently putting spaces and indentation in a program so visual
cues are createD.
Select one:
a. False
b. True
Question 7

Question text
The expression in a return statement can be any expression that has a value.
Select one:
a. False
b. True
Question 8
Question text
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. This is an infinite loop
b. 90
c. 110
d. 100
Question 9
Question text
The scope of a public instance field is
Select one:
a. inside the parentheses of a method header
b. the instance methods and methods outside the class
c. inside the class, but not inside any method
d. only the class in which it is defined
Question 10
Question text
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Select one:
a. The quick brown fox
jumped over the
slow moving hen.
b. The quick brown fox jumped over the \nslow moving hen.
c. Nothing. This is an error.
d. The quick brown fox jumped over the
slow moving hen.
Question 11
Question text
In Java, when a character is stored in memory, it is actually stored as a
Select one:
a. Unicode number
b. ASCII character code
c. EBCDIC character code
d. Morse code

_____.

Question 12
Question text
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a complex method
c. a void method
d. a local variable
Question 13
Question text
When you write a change listener class method for a slider, it must implement the ChangeListener interface
which is in the javax.swing.event package.
Select one:
a. True
b. False
Question 14
Question text
Suppose you are at an operating system command line, and you are going to use the following command to
compile a program: javac MyClass.java, Before entering the command, you must:
Select one:
a. Execute the javA.sun.com program
b. Close all other Windows on your computer system
c. Make sure you are in the same directory or folder where MyClass.java is located
d. Save the program with the .comp extension
Question 15
Question text
A file must always be opened before using it and closed when the program is finished using it.
Select one:
a. False
b. True
Question 16
Question text
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
Select one:
a. 2 and 3
b. 2
c. 3
d. 1, 2, and 3 will all work
Question 17
Question text

Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
Select one:
a. True
b. False
Question 18
Question text
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
Select one:
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question 19
Question text
A constructor
Select one:
a. has return type of void
b. always has an access specifier of private
c. has the same name as the class
d. always accepts two arguments
Question 20
Question text
The original name for Java was
Select one:
a. HotJava
b. Elm
c. Java
d. Oak
Question 21
Question text
These operators are used to determine whether a specific relationship exists between two values.
Select one:
a. Assignment
b. Relational
c. Arithmetic
d. Syntactical
Question 22
Question text
This is a group of related classes.
Select one:
a. attachment
b. archive

c. collection
d. package
Question 23
Question text
What will happen when the following statement is executed?
x.setEditable(false);
Select one:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question 24
Question text
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 25
Question text
Event listeners must
Select one:
a. not receive any arguments
b. exit the application once it has handled the event
c. implement an interface
d. be included in private inner classes
Question 26
Question text
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. neither num or str will be changed
b. str will have a value of 560
c. the last line of code will cause an error
d. num will be set to 560
Question 27
Question text

A loop that executes as long as a particular condition exists is called a[n]


Select one:
a. infinite loop
b. count-controlled loop
c. sentinel loop
d. conditional loop
Question 28
Question text
Which of the following is not part of a method call?
Select one:
a. all of the above are part of a method call
b. method name
c. parentheses
d. return type
Question 29
Question text
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0;
Select one:
a. .05
b. 0
c. .01
d. .03
Question 30
Question text
To use the StringTokenizer class you must have the following import statement.
Select one:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;
d. import javA. String;
Question 31
Question text
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
Select one:
a. 28

b. 35
c. 24
d. 30
Question 32
Question text
What is the result of the following expression?
10 + 5 * 3 - 20
Select one:
a. -50
b. -5
c. 25
d. 5
Question 33
Question text
What will be the value of matches after the following code is executed?
boolean matches;
String[] productCodes = {"456HI345", "3456hj"};
matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3);
Select one:
a. 56H
b. 56h
c. true
d. false
Question 34
Question text
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
}
while (x <= 100);
Select one:
a. 4
b. 1
c. 3
d. 5
Question 35
Question text
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
Select one:
a. using the public access specifier on the class methods
b. using the private access specifier on the class fields
c. using the private access specifier on the class definition

d. using the private access specifier on the class methods


Question 36
Question text
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Select one:
a. False
b. True
Question 37
Question text
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. a wildcard import
b. unconditional import
c. an explicit import
d. conditional import
Question 38
Question text
What will be displayed as a result of executing the following code?
int x = 8;
String msg = "I am enjoying javA.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " +
ltr);
System.out.println("msg has " + strSize +
" characters.");
Select one:
a. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 20 characters.
b. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = y
msg has 19 characters.
c. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 19 characters.
d. I am enjoying javA.
I AM ENJOYING JAVA.

i am enjoying javA.
Character at index x = j
msg has 20 characters.
Question 39
Question text
Key words are:
Select one:
a. The data names in your program
b. Words that have a special meaning in the programming language
c. Symbols or words that perform operations on one or more operands
d. Words or names defined by the programmer
Question 40
Question text
Which of the following is not a rule that must be followed when naming identifiers?
Select one:
a. Uppercase and lowercase characters are distinct.
b. After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9.
c. Identifiers can contain spaces.
d. The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign.
Question 41
RAM is usually:
Select one:
a. Secondary storage
b. A static type of memory, used for permanent storage
c. An input/output device
d. A volatile type of memory, used only for temporary storage
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18.0
b. 8
c. This is an error
d. 18 (as an integer)
The String classs valueOf() method accepts a string representation as an argument and returns its equivalent
integer value.
Select one:
a. True

b. False
Which of the following is not a class used in constructing a menu system?
Select one:
a. JMenuItem
b. JCheckBoxMenuItem
c. JButton
d. JRadioButtonMenuItem
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
Select one:
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Two ways of concatenating two Strings are
Select one:
a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
Select one:
a. using the public access specifier on the class methods
b. using the private access specifier on the class fields
c. using the private access specifier on the class definition
d. using the private access specifier on the class methods
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
Select one:
a. 28
b. 30
c. 35
d. 24

What will be the result of executing the following statement?


panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
d. The JPanel referenced by panel will have a blue line border that is 5 characters thick.

If chr is a character variable, which of the following if statements is written correctly?


Select one:
a. if (chr = 'a')
b. if (chr == 'a')
c. if (chr = "a")
d. if (chr == "a")
Methods that operate on an object's fields are called
Select one:
a. public methods
b. private methods
c. instance methods
d. instance variables
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 500
b. Numbers greater than 500
c. Numbers less than 100 or greater than 500
d. Numbers in the range 100 - 499
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
Select one:
a. Scanner inputFile = new Scanner("MyFilE.txt");
PrintWriter outFile = new PrintWriter(fwriter);
b. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");

c. File file = new File("MyFilE.txt");


d. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);

Class objects normally have __________ that perform useful operations on their data, but primitive variables
do not.
Select one:
a. instances
b. fields
c. methods
d. relationships

What will be returned from the following method?


public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. 18.0
b. 8.0
c. This is an error
d. 18 (as an integer)
A computer program is:
Select one:
a. A set of instructions that enable the computer to solve a problem or perform a task.
b. A flow chart
c. Main memory
d. Pseudocode
Logical errors are mistakes that cause the program to produce erroneous results.
Select one:
a. True
b. False
What would be the value of x after the following statements were executed?
int x = 10;
switch (x)
{
case 10:
x += 15;

case 12:
x -= 5;
break;
default:
x *= 3;
}
Select one:
a. 30
b. 5
c. 25
d. 20

When a method tests an argument and returns a true or false value, it should return
Select one:
a. a zero for true and a one for false
b. a method should not be used for this type test
c. a zero for false and a non-zero for true
d. a boolean value

In the following code, Integer.parseInt(str), is an example of ________.


int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a value-returning method
b. a void method
c. a complex method
d. a local variable

What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:
a. x = 108.6
b. x
c. Nothing, there is an error in the code.
d. x = 54.3
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:

a. a and b
b. Only a
c. (str1.equalsIgnoreCase(str2))
d. (str1.compareToIgnoreCase(str2) == 0)
This type of loop will always be executed at least once.
Select one:
a. post-test loop
b. sentinel loop
c. for loop
d. pre-test loop
Named constants are initialized with a value, that value cannot be changed during the execution of the
program.
Select one:
a. True
b. False
This layout manager arranges components in five regions.
Select one:
a. RegionLayout
b. GridLayout
c. FlowLayout
d. BorderLayout
This type of method performs a task and then terminates.
Select one:
a. local
b. void
c. value-returning
d. simple
An important style rule you should adopt for writing if statements is to write the conditionally executed
statement on the line after the if statement.
Select one:
a. True
b. False
This type of method performs a task and sends a value back to the code that called it.
Select one:
a. local
b. void

c. complex
d. value-returning
What will be printed after the following code is executed?
for (int number = 5; number <= 15; number +=3)
System.out.print(number + ", ");
Select one:
a. 5, 8, 11, 14, 17,
b. 5, 8, 11, 14,
c. This is an invalid for statement
d. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
Select one:
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
Select one:
a. 35
b. 100
c. 80
d. 55
A loop that executes as long as a particular condition exists is called a[n]
Select one:
a. sentinel loop
b. count-controlled loop
c. conditional loop
d. infinite loop
A variable's scope is the part of the program that has access to the variable.
Select one:
a. False

b. True
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. a wildcard import
b. an explicit import
c. unconditional import
d. conditional import
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Select one:
a. diddle
b. diddl
c. , didd
d. Iddle
Character literals are enclosed in _____; string literals are enclosed in _____.
Select one:
a. double quotes; single quotes
b. double quotes; double quotes
c. single quotes; double quotes
d. single quotes; single quotes

What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 8
b. 8.0
c. 4
d. 8.25
A classs responsibilities include
Select one:
a. both A and B
b. the things a class is responsible for knowing
c. neither A or B

d. the things a class is responsible for doing

This type of loop is ideal in situations where you always want the loop to iterate at least once.
Select one:
a. while loop
b. if statement
c. for loop
d. do-while loop
Which of the following correctly tests the char variable chr to determine whether it is not equal to the
character B?
Select one:
a. if (chr != "B")
b. if (chr != 'B')
c. if (chr > 'B')
d. if (chr < 'B')
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 20
b. x = 40
c. x = 30
d. x is unknown when the last statement is executed
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
Select one:
a. x = 12, y = 5
b. x = 16, y = 4
c. x = 17, y = 5
d. x = 17, y = 4
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");

int number = keyboarD.nextInt();


while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 500
b. Numbers less than 100 or greater than 500
c. Numbers in the range 100 - 499
d. The boolean condition can never be true
What will happen when the following statement is executed?
x.setEditable(false);
Select one:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.

Which of the following will format .1278 to display as 12.8%?


Select one:
a. 000.0%
b. ##0.0%
c. #0.00%
d. ###.##%
Look at the following statement.
import java.util.Scanner;
This is an example of

Select one:
a. conditional import
b. unconditional import
c. an explicit import
d. a wildcard import
Which Scanner class method reads an int?
Select one:
a. readInt()
b. nextInt()
c. read_int()
d. getInt()
Question 11
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(33.0, 55.0);
b. showProduct(10, 4.5);
c. showProduct(5.5, 4.0);
d. showProduct(10.0, 4);
Question 12
Question text
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
Select one:
a. Nothing, this is an error
b. 9 45 16
c. 94516

d. 9 45 16
Question 13
Question text
You must have a return statement in a value-returning method.
Select one:
a. True
b. False
Question 14
Question text
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a void method
b. a local variable
c. a complex method
d. a value-returning method
Question 15
Question text
When saving a Java source file, save it with an extension of
Select one:
a. .src
b. .javac
c. .class
d. .java
Question 16
Question text
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
Select one:
a. Space
b. Tab
c. Semicolon
d. Newline
Question 17
Question text
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. 145
b. 20

c. 10
d. No value, there is a syntax error
Question 18
Question text
A for loop normally performs which of these steps?
Select one:
a. initializes a control variable to a starting value
b. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
c. updates the control variable during each iteration
d. None of the above
e. all of the above
Question 19
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10.0, 4.6);
b. showProduct("5", "40");
c. showProduct(10, 4.5);
d. showProduct(3.3, 55);
Question 20
Question text
Suppose you are at an operating system command line, and you are going to use the following command to
compile a program: javac MyClass.java, Before entering the command, you must:
Select one:
a. Close all other Windows on your computer system
b. Execute the javA.sun.com program
c. Make sure you are in the same directory or folder where MyClass.java is located
d. Save the program with the .comp extension
Question 21
Question text
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Select one:
a. True
b. False
Question 22
Question text
Which of the following statements creates a class that is extended from the JFrame class?

Select one:
a. JFrame DerivedClass = new JFrame();
b. JFrame(DerivedClass);
c. class JFrame DerivedClass;
d. public class DerivedClass extends JFrame{}
Question 23
Question text
A constructor
Select one:
a. has the same name as the class
b. always has an access specifier of private
c. has return type of void
d. always accepts two arguments
Question 24
Question text
Byte code instructions are:
Select one:
a. Read and interpreted by the JVM
b. Another name for source code
c. Machine code instructions
d. Syntax errors
Question 25
Question text
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string
before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last
token.
Select one:
a. True
b. False
Question 26
Question text
Another term for an object of a class is
Select one:
a. access specifier
b. instance
c. method
d. member
Question 27
Question text
What is the result of the following expression?
25 - 7 * 3 + 12 / 3
Select one:
a. 12

b. 6
c. 10
d. 8
Question 28
Question text
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. add each button to panel one at a time, e.g. panel.add(button1);
b. use the statement, bGroup.add(panel);
c. use the statement, panel.add(bGroup);
d. use the statement, Panel panel = new Panel(bGroup);
Question 29
Question text
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Select one:
a. panel.addLayout(new (GridLayout(2,3));
b. panel.GridLayout(2,3);
c. panel.attachLayout(GridLayout(2,3));
d. panel.setLayout(new (GridLayout(2,3));
Question 30
Question text
For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
Select one:
a. 3
b. 5
c. 1
d. 7
Question 31
Question text
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
Select one:
a. There are 583 hens in the hen housE.
b. There are 5785 hens in the hen housE.

c. There are 5785


hens in the hen housE.
d. There are x5\nhens in the hen housE.
Question 32
Question text
Because Java byte code is the same on all computers, compiled Java programs
Select one:
a. Are non-existent
b. Must be re-compiled for each different machine it is run on
c. Cannot run on Linux systems
d. Are highly portable
Question 33
Question text
In a @return tag statement the description
Select one:
a. cannot be longer than one line
b. describes the parameter values
c. describes the return value
d. must be longer than one line
Question 34
Question text
Enclosing a group of statements inside a set of braces creates a
Select one:
a. loop
b. Nothing, it is just for readability
c. boolean expression
d. block of statements
Question 35
Question text
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. for loop
b. while loop
c. if statement
d. do-while loop
Question 36
Question text
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Select one:
a. 10

b. 1
c. 11
d. 0
Question 37
Question text
One or more objects may be created from a
Select one:
a. method
b. class
c. field
d. instance
Question 38
Question text
You should always document a method by writing comments that appear
Select one:
a. at the end of the file.
b. only if the method is more than five lines long.
c. just before the methods definition.
d. just after the methods definition.
Question 39
Question text
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;
else if (sales < 7500)
bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
Select one:
a. 200
b. 500
c. 1250
d. 1000
e. 750
Question 40
Question text
Which Scanner class method reads a String?
Select one:
a. getString()

b. nextString()
c. readString()
d. nextLine()

JYGALYBEG
Question 1
Question text
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
Select one:
a. 90
b. 210
c. This is an infinite loop
d. 110
Question 2
Question text
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.

Character at index x = e
msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
Question 3
Question text
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
Select one:
a. 5.0
b. 5.6
c. 3.0
d. 5.60
Question 4
Question text
Which of the following will run the compiled program ReadIt?
Select one:
a. run ReadIt
b. java ReadIt.java
c. go ReadIt
d. java ReadIt
Question 5
Question text
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 6
Question text
This type of method performs a task and sends a value back to the code that called it.
Select one:
a. complex
b. value-returning
c. local
d. void
Question 7
Question text
Constants, variables, and the values of expressions may be passed as arguments to a methoD.

Select one:
a. True
b. False
Question 8
Question text
Two or more methods in a class may have the same name as long as
Select one:
a. they have different return types, but the same parameter list
b. they have different return types
c. they have different parameter lists
d. you cannot have two methods with the same name
Question 9
Question text
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are
equal?
(1) (str1 == str2)
(2) str1.equals(str2)
(3) (str1.compareTo(str2) == 0)
Select one:
a. 1 and 2
b. 2 and 3
c. 1 and 3
d. 1, 2, and 3 will all work
Question 10
Question text
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:
a. x
b. Nothing, there is an error in the code.
c. x = 54.3
d. x = 108.6
Question 11
Question text
In the programming process which of the following is not involved in defining what the program is to do:
Select one:
a. Input
b. Purpose
c. Process
d. Compile code
e. Output
Question 12
Question text

What will be the value of x after the following code is executed?


int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. 90
b. This is an infinite loop
c. 110
d. 100
Question 13
Question text
What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
Select one:
a. 35
b. 55
c. 100
d. 80
Question 14
Question text
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 1 and 2
b. 2
c. Neither 1 or 2
d. 1
Question 15
Question text
A method that gets a value from a class's field but does not change it is known as a mutator method.
Select one:
a. True
b. False
Question 16
Question text
When testing for character values, the switch statement does not test for the case of the character.
Select one:
a. True
b. False
Question 17
Question text

To print "Hello, world" on the monitor, use the following Java statement
Select one:
a. System.out.println{"Hello, world"}
b. SystemOutPrintln("Hello, world");
c. Print "Hello, world";
d. System.out.println("Hello, world");
Question 18
Question text
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is
hidden, but not closed.
Select one:
a. JFrame.HIDE_NOT_CLOSE
b. JFrame.EXIT_ON_CLOSE
c. JFrame. HIDE_ON_CLOSE
d. HIDE_ON_CLOSE
Question 19
Question text
To use the ActionListener interface, as well as other event listener interfaces, you must have the following
import statement in your code:
Select one:
a. import java.awt;
b. import java.swing;
c. import java.awt.event.*;
d. import java.awt.*;
Question 20
Question text
A do-while loop is a pre-test loop.
Select one:
a. False
b. True
Question 21
Question text
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use
Select one:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
Question 22
Question text
What is the value of ans after the following code has been executed?
int x = 40;
int y = 40;
int ans = 0;

if (x = y)
ans = x + 10;
Select one:
a. 30
b. No value, this is a syntax error.
c. 50
d. 80
Question 23
Question text
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Select one:
a. displayValues(a,b); // where a is a short and b is a long
b. displayValues(a,b); // where a is an int and b is a byte
c. displayValue(b,a); // where a is a short and b is a long
d. displayValues(a,b); // where a is a short and b is a byte
Question 24
Question text
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
Select one:
a. Space
b. Tab
c. Semicolon
d. Newline
Question 25
Question text
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question 26
Question text
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. import
b. use
c. assume
d. link
Question 27
Not answered
Question text
Which of the following would be a valid method call for the following method?

public static void showProduct(double num1, int num2)


{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct("5", "40");
b. showProduct(3.3, 55);
c. showProduct(10.0, 4.6);
d. showProduct(10, 4.5);
Question 28
Question text
This is a boolean variable that signals when some condition exists in the program
Select one:
a. Sentinel
b. Block
c. Flag
d. Case
Question 29
Question text
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
Select one:
a. True
b. False
Question 30
Question text
The _________ statement is used to make simple decisions in Java.
Select one:
a. for
b. if
c. branch
d. do/while
Question 31
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10, 4.5);
b. showProduct(33.0, 55.0);

c. showProduct(5.5, 4.0);
d. showProduct(10.0, 4);
Question 32
Question text
Class objects normally have __________ that perform useful operations on their data, but primitive variables
do not.
Select one:
a. methods
b. relationships
c. instances
d. fields
Question 33
Question text
To use the StringTokenizer class you must have the following import statement.
Select one:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;
d. import javA. String;
Question 34
Question text
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
Select one:
a. x = 12, y = 5
b. x = 17, y = 5
c. x = 16, y = 4
d. x = 17, y = 4
Question 35
Question text
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 36
Question text
In the following Java statement what value is stored in the variable name?

String name = "John Doe";


Select one:
a. The memory address where "John Doe" is located
b. name
c. John Doe
d. The memory address where name is located
Question 37
Question text
An operating system can be categorized according to:
Select one:
a. The number of users they can accommodate
b. Both of the above
c. The number of tasks they can perform at one time
d. Neither of the above
Question 38
Question text
The lifetime of a method's local variable is
Select one:
a. the duration of the class to which the method belongs
b. the duration of the method that called the local variable's method
c. only while the method is executing
d. the duration of the program
Question 39
Question text
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while
loops shows the correct way to read data from the file until the end of the file is reached?
Select one:
a. while (inputFile != null) { }
b. while (inputFile.nextLine == " ") { }
c. while (inputFile.hasNext()) { }
d. while (!inputFile.EOF) { }
Question 40
Question text
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
Select one:
a. Scanner inputFile = new Scanner("MyFilE.txt");
PrintWriter outFile = new PrintWriter(fwriter);
b. File file = new File("MyFilE.txt");
c. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);
d. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");
Question 1
Question text

What will be returned from the following method?


public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. This is an error
b. 8.0
c. 18 (as an integer)
d. 18.0
Question 2
Question text
Syntax is:
Select one:
a. Words that have a special meaning in the programming language
b. Punctuation
c. Rules that must be followed when writing a program
d. Symbols or words that perform operations
Question 3
Question text
When an application uses many components, instead of extending just one class from the JFrame class, a
better approach is to
Select one:
a. just go ahead and do it in one large class
b. reconsider the design of the application
c. break the application into several smaller applications
d. encapsulate smaller groups of related components and their event listeners into their own classes
Question 4
Question text
In the method header the static method modifier means the method is available to code outside the class.
Select one:
a. False
b. True
Question 5
Question text
If the following Java statements are executed, what will be displayed?
System.out.print("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");
Select one:
a. The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator

b. The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
c. The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
d. The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
Question 6
Question text
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. the last line of code will cause an error
b. num will be set to 560
c. neither num or str will be changed
d. str will have a value of 560
Question 7
Question text
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
}
while (x <= 100);
Select one:
a. 4
b. 1
c. 5
d. 3
Question 8
Question text
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Select one:
a. 130
b. 110
c. 210
d. 90
Question 9

Question text
A for loop normally performs which of these steps?
Select one:
a. initializes a control variable to a starting value
b. all of the above
c. None of the above
d. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
e. updates the control variable during each iteration
Question 10
Question text
RAM is usually:
Select one:
a. A static type of memory, used for permanent storage
b. Secondary storage
c. A volatile type of memory, used only for temporary storage
d. An input/output device
Question 11
Question text
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 20
b. x = 40
c. x is unknown when the last statement is executed
d. x = 30
Question 12
Question text
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
char cust = 'N';
if (purchase > 1000)
if (cust == 'Y')
discountRate = .05;
else
discountRate = .04;
else if (purchase > 750)
if (cust == 'Y')
discountRate = .04;
else

discountRate = .03;
else
discountRate = 0;
Select one:
a. .04
b. .03
c. 0
d. .05
Question 13
Question text
An important style rule you should adopt for writing if statements is to write the conditionally executed
statement on the line after the if statement.
Select one:
a. True
b. False
Question 14
Question text
You must call a method to get the value of a wrapper class object.
Select one:
a. True
b. False
Question 15
Question text
What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 16
Question text
All Java statements end with semicolons.
Select one:
a. True
b. False
Question 17
Question text
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. Neither 1 or 2
b. 2

c. 1
d. 1 and 2
Question 18
Question text
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Select one:
a. diddle
b. diddl
c. , didd
d. Iddle
Question 19
Question text
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
Select one:
a. 5.0
b. 5.60
c. 5.6
d. 3.0
Question 20
Question text
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 21
Question text
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing,
and closing the window.
Select one:
a. Dialog box
b. Container

c. Pane
d. Frame
Question 22
Question text
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
Select one:
a. 2 and 3
b. 2
c. 3
d. 1, 2, and 3 will all work
Question 23
Question text
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Select one:
a. import javA.filE.*;
b. import javA.io.*;
c. import PrintWriter;
d. import javax.swing.*;
Question 24
Question text
Values stored in local variables
Select one:
a. retain their values from the last call to the method in which they are declared
b. may be referenced by the calling method
c. are lost between calls to the method in which they are declared
d. may be referenced by any other method, if the method in which they are declared is a public method
Question 25
Question text
It is common practice in object-oriented programming to make all of a class's
Select one:
a. fields public
b. methods private
c. fields private
d. fields and methods public
Question 26
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{

int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(33.0, 55.0);
b. showProduct(10.0, 4);
c. showProduct(5.5, 4.0);
d. showProduct(10, 4.5);
Question 27
Question text
If chr is a character variable, which of the following if statements is written correctly?
Select one:
a. if (chr == "a")
b. if (chr = "a")
c. if (chr == 'a')
d. if (chr = 'a')
Question 28
Question text
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
Select one:
a. Invalid for statement
b. 40
c. 30
d. 25
Question 29
Question text
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 8
b. 12
c. 105
d. 7
Question 30
Question text
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:

a. x = 160, y = 80
b. x = 37, y = 5
c. x = 9, y = 52
d. x = 32, y = 4
Question 31
Question text
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter
variable.
Select one:
a. False
b. True
Question 32
Question text
Which of the following will run the compiled program ReadIt?
Select one:
a. go ReadIt
b. java ReadIt
c. run ReadIt
d. java ReadIt.java
Question 33
Question text
To add a tool tip to a component use
Select one:
a. the setToolTipText method.
b. the addToolTipText method.
c. the toolTipText method.
d. the appendToolTipText method.
Question 34
Question text
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. Only a
b. a and b
c. (str1.compareToIgnoreCase(str2) == 0)
d. (str1.equalsIgnoreCase(str2))
Question 35
Correct
Question text
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Select one:
a. False

b. True
Question 36
Question text
This type of loop is ideal in situations where you always want the loop to iterate at least once.
Select one:
a. for loop
b. do-while loop
c. while loop
d. if statement
Question 37
Question text
Variables of the boolean data type are useful for
Select one:
a. working with very large integers
b. evaluating true/false conditions
c. evaluating scientific notation
d. working with small integers
Question 38
Question text
To use the StringTokenizer class you must have the following import statement.
Select one:
a. import javA. util.StringTokenizer;
b. import javA. util.String;
c. import javA. StringTokenizer;
d. import javA. String;
Question 39
Question text
Which of the following is not involved in finding the classes when developing an object-oriented application?
Select one:
a. Refine the list of nouns to include only those that are relevant to the problem.
b. Describe the problem domain.
c. Write the code.
d. Identify all the nouns.
Question 40
Question text
Assume that the following method header is for a method in class A.
public void displayValue(int value)
Assume that the following code segments appear in another method, also in class A. Which contains a legal call
to the displayValue method?
Select one:
a. int x = 7;
displayValue(int x);

b. int x = 7;
displayValue(x)
c. int x = 7;
displayValue(x);
d. int x = 7;
void displayValue(x);

Question 1
Question text
A for loop normally performs which of these steps?
Select one:
a. updates the control variable during each iteration
b. tests the control variable by comparing it to a maximum/minimum value and terminate when the
variable reaches that value
c. all of the above
d. None of the above
e. initializes a control variable to a starting value
Question 2
Question text
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Select one:
a. True
b. False
Question 3
Question text
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
Select one:
a. 2
b. 1 and 2
c. 1
d. Neither 1 or 2
Question 4
Question text
You should always document a method by writing comments that appear
Select one:
a. only if the method is more than five lines long.

b. at the end of the file.


c. just after the methods definition.
d. just before the methods definition.
Question 5
Question text
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
Select one:
a. Space
b. Tab
c. Semicolon
d. Newline
Question 6
Question text
What will happen when the following statement is executed?
x.setEditable(false);
Select one:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question 7
Question text
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a void method
b. a complex method
c. a value-returning method
d. a local variable
Question 8
Question text
What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 9
Question text

Variables are classified according to their


Select one:
a. names
b. value
c. location in the program
d. data type
Question 10
Question text
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers in the range 100 - 500
b. The boolean condition can never be true
c. Numbers in the range 100 - 499
d. Numbers less than 100 or greater than 500
Question 11
Question text
Which of the following is not a valid comment statement?
Select one:
a. /* comment 2 */
b. // comment 1
c. */ comment 3 /*
d. /** comment 4 */
Question 12
Question text
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:
a. x = 108.6
b. x
c. x = 54.3
d. Nothing, there is an error in the code.
Question 13
Question text
int x = 6;

String msg = "I am enjoying this class.";


String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
Question 14
Question text
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Select one:
a. 110
b. 100
c. 90
d. This is an infinite loop
Question 15
Question text
The String classs valueOf() method accepts a string representation as an argument and returns its equivalent
integer value.
Select one:

a. True
b. False
Question 16
Question text
A common technique for writing an event listener class is to write it as a private inner class inside the class that
creates the GUI.
Select one:
a. False
b. True
Question 17
Question text
Local variables can be initialized with
Select one:
a. the results of an arithmetic operation
b. parameter values
c. constants
d. any of the above
Question 18
Question text
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
Select one:
a. use the statement, bGroup.add(panel);
b. use the statement, Panel panel = new Panel(bGroup);
c. add each button to panel one at a time, e.g. panel.add(button1);
d. use the statement, panel.add(bGroup);
Question 19
Question text
When an argument is passed to a method,
Select one:
a. its value may be changed within the called method
b. values may not be passed to methods
c. the method must not assign another value to the parameter that receives the argument
d. its value is copied into the methods parameter variable
Question 20
Question text
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. 110

b. 90
c. This is an infinite loop
d. 100
Question 21
Question text
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Select one:
a. 1000
b. 1250
c. 1500
d. 2000
Question 22
Question text
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question 23
Question text
The ___________ is normally considered the standard output and standard input devices, and usually refer to
the monitor and keyboarD.
Select one:
a. CPU
b. secondary storage devices
c. console
d. CRT
Question 24
Question text
What is wrong with the following method call?
displayValue (double x);

Select one:
a. There is nothing wrong with the statement.
b. x should be a String.
c. displayValue will not accept a parameter.
d. Do not include the data type in the method call.
Question 25
Question text
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.
Select one:
a. False
b. True
Question 26
Question text
Which of the following is the correct boolean expression to test for: int x being a value between, but not
including, 500 and 650, or int y not equal to 1000?
Select one:
a. ((x >= 500 && x <= 650) && (y != 1000))
b. ((x > 500 && x < 650) || (y != 1000))
c. ((x > 500 AND x < 650) OR !(y.equal(1000)))
d. ((x < 500 && x > 650) || !(y == 1000))
Feedback
The correct answer is: ((x > 500 && x < 650) || (y != 1000))
Question 27
Question text
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
Select one:
a. True
b. False
Question 28
Question text
A method that gets a value from a class's field but does not change it is known as a mutator method.
Select one:
a. True
b. False
Question 29
Question text
Application software refers to:
Select one:
a. The programs that make the computer useful to the user
b. Pseudocode
c. The operating system
d. Key words

Question 30
Question text
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
Select one:
a. x = 20
b. x = 40
c. x = 30
d. x is unknown when the last statement is executed
Question 31
Question text
What will be the value of ans after the following code has been executed?
int ans = 10;
int x = 65;
int y = 55;
if (x >= y)
ans = x + y;
Select one:
a. 10
b. 120
c. 100
d. No value, there is a syntax error
Question 32
Question text
This is a value that signals when the end of a list of values has been reacheD.
Select one:
a. Terminal value
b. Sentinel
c. Final value
d. End value
Question 33
Question text
Another term for an object of a class is
Select one:
a. method
b. access specifier
c. member
d. instance

Question 34
Question text
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
Select one:
a. a complex method
b. a local variable
c. a void method
d. a value-returning method
Question 35
Question text
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
Select one:
a. x = 37, y = 5
b. x = 32, y = 4
c. x = 160, y = 80
d. x = 9, y = 52
Question 36
Question text
Suppose you are at an operating system command line, and you are going to use the following command to
compile a program: javac MyClass.java, Before entering the command, you must:
Select one:
a. Save the program with the .comp extension
b. Make sure you are in the same directory or folder where MyClass.java is located
c. Close all other Windows on your computer system
d. Execute the javA.sun.com program
is: Make sure you are in the same directory or folder where MyClass.java is located
Question 37
Question text
This is a boolean variable that signals when some condition exists in the program
Select one:
a. Sentinel
b. Case
c. Flag
d. Block
Question 38
Question text
The _________ statement is used to make simple decisions in Java.
Select one:

a. if
b. branch
c. do/while
d. for
Question 39
Question text
A classs responsibilities include
Select one:
a. neither A or B
b. both A and B
c. the things a class is responsible for doing
d. the things a class is responsible for knowing
Question 40
Question text
Which of the following will run the compiled program ReadIt?
Select one:
a. go ReadIt
b. java ReadIt
c. run ReadIt
d. java ReadIt.java
Question 1
Question text
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Select one:
a. 1250
b. 2000
c. 1500
d. 1000
Question 2
Question text

What will be the value of x after the following code is executed?


int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. 90
b. 110
c. This is an infinite loop
d. 100
Question 3
Question text
Which of the following is a valid Java statement?
Select one:
a. String str = 'John Doe';
b. String str = "John Doe";
c. string str = 'John Doe';
d. string str = "John Doe";
Question 4
Question text
Quite often you have to use this statement to make a group of classes available to a program.
Select one:
a. use
b. link
c. import
d. assume
Question 5
Question text
Instance methods should be declared static.
Select one:
a. True
b. False
Question 6
Question text
What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 8
b. 8.0
c. 4

d. 8.25
Question 7
Question text
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?
PrintWriter diskOut = new PrintWriter("DiskFilE.txt");
Select one:
a. PrintWriter.println("Calvin");
b. DiskFilE.println("Calvin");
c. diskOut.println("Calvin");
d. System.out.println(diskOut, "Calvin");
Question 8
Question text
What will happen when the following statement is executed?
x.setEditable(false);
Select one:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question 9
Question text
Event listeners must
Select one:
a. exit the application once it has handled the event
b. not receive any arguments
c. be included in private inner classes
d. implement an interface
Question 10
Question text
What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
Select one:
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question 11
Question text
A common technique for writing an event listener class is to write it as a private inner class inside the class that
creates the GUI.
Select one:
a. False

b. True
Question 12
Question text
RAM is usually:
Select one:
a. A volatile type of memory, used only for temporary storage
b. A static type of memory, used for permanent storage
c. An input/output device
d. Secondary storage
Question 13
Question text
A flag may have the values:
Select one:
a. true or false
b. of any character
c. 0 or 1
d. 1 or -1
Question 14
Question text
Two ways of concatenating two Strings are
Select one:
a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Question 15
Question text
This is a value that signals when the end of a list of values has been reacheD.
Select one:
a. Final value
b. Sentinel
c. Terminal value
d. End value
Question 16
Question text
The purpose of validating the results of the program is:
Select one:
a. To create a model of the program
b. To correct syntax errors
c. To determine whether the program solves the original problem
d. To correct runtime errors

Question 17
Question text
Both character literals and string literals can be assigned to a char variable.
Select one:
a. False
b. True
Question 18
Question text
Look at the following statement.
import java.util.*;
This is an example of
Select one:
a. a wildcard import
b. conditional import
c. unconditional import
d. an explicit import
Question 19
Question text
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Select one:
a. The quick brown fox jumped over the
slow moving hen.
b. The quick brown fox
jumped over the
slow moving hen.
c. Nothing. This is an error.
d. The quick brown fox jumped over the \nslow moving hen.
Question 20
Question text
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question 21
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}

Select one:
a. showProduct(3.3, 55);
b. showProduct(10.0, 4.6);
c. showProduct("5", "40");
d. showProduct(10, 4.5);
Question 22
Question text
The expression tested by an if statement must evaluate to
Select one:
a. 0 or 1
b. true or false
c. t or f
d. +1 or -1
Question 23
Question text
What will be the value of ans after the following code has been executed?
int ans = 10;
int x = 65;
int y = 55;
if (x >= y)
ans = x + y;
Select one:
a. 10
b. 120
c. No value, there is a syntax error
d. 100
Question 24
Question text
In a @return tag statement the description
Select one:
a. cannot be longer than one line
b. must be longer than one line
c. describes the parameter values
d. describes the return value
Feedback
The correct answer is: describes the return value
Question 25
Question text
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:

a. This is an error
b. 18 (as an integer)
c. 18.0
d. 8
Question 26
Question text
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
Select one:
a. a local variable
b. a complex method
c. a value-returning method
d. a void method
Question 27
Question text
Only constants and variables may be passed as arguments to methods.
Select one:
a. False
b. True
Question 28
Question text
What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
Select one:
a. 80
b. 35
c. 100
d. 55
Question 29
Question text
Key words are:
Select one:
a. Words that have a special meaning in the programming language
b. Symbols or words that perform operations on one or more operands
c. Words or names defined by the programmer
d. The data names in your program
Question 30
Question text

A constructor is a method that is automatically called when an object is created.


Select one:
a. True
b. False
Question 31
Question text
This type of loop is ideal in situations where you always want the loop to iterate at least once.
Select one:
a. do-while loop
b. for loop
c. while loop
d. if statement
Question 32
Question text
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
Question 33

Question text
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers less than 100 or greater than 500
b. Numbers in the range 100 - 499
c. Numbers greater than 500
d. Numbers in the range 100 - 500
Question 34
Question text
All Java statements end with semicolons.
Select one:
a. True
b. False
Question 35
Question text
Constants, variables, and the values of expressions may be passed as arguments to a methoD.
Select one:
a. False
b. True
Question 36
Question text
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. (str1.compareToIgnoreCase(str2) == 0)
b. a and b
c. (str1.equalsIgnoreCase(str2))
d. Only a
Question 37
Question text
The getSelectedIndex method returns
Select one:
a. the index of the selected item. (A)
b. -1 if no item is selected. (B)
c. Both (A) and (B).
d. Neither (A) or (B).
Question 38

Question text
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. for loop
b. while loop
c. do-while loop
d. if statement
Question 39
Question text
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
Select one:
a. token
b. delimiter
c. buffer
d. separator
Question 40
Question text
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Select one:
a. True
b. False

Question 1
Question text
This type of loop is ideal in situations where you always want the loop to iterate at least once.
Select one:
a. if statement
b. while loop
c. do-while loop
d. for loop
Question 2
Question text
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
Select one:
a. 25
b. 30
c. 40

d. Invalid for statement


Question 3
Question text
The _________ statement is used to make simple decisions in Java.
Select one:
a. if
b. for
c. do/while
d. branch
Question 4
Question text
To compile a program named First, use the following command
Select one:
a. compile First.javac
b. java First.java
c. javac First.java
d. javac First
Question 5
Question text
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
Select one:
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.

d. I am enjoying this class.


I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
Question 6
Question text
Which of the following is the correct boolean expression to test for: int x being a value between, but not
including, 500 and 650, or int y not equal to 1000?
Select one:
a. ((x >= 500 && x <= 650) && (y != 1000))
b. ((x < 500 && x > 650) || !(y == 1000))
c. ((x > 500 AND x < 650) OR !(y.equal(1000)))
d. ((x > 500 && x < 650) || (y != 1000))
Question 7
Question text
The primitive data types only allow a _____ to hold a single value.
Select one:
a. literal
b. object
c. class
d. variable
Question 8
Question text
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Select one:
a. 105
b. 12
c. 7
d. 8
Question 9
Question text
Variables are:
Select one:
a. Symbolic names made up by the programmer whose values cannot be changed
b. Operators that perform operations on one or more operands
c. Reserved words
d. Symbolic names made up by the programmer that represents locations in the computer's RAM
Question 10
Question text
Two ways of concatenating two Strings are
Select one:

a. Use the concat() method or use the + between the two Strings
b. Use the concatenate() method or use the + between the two Strings
c. Use the contenate() method or the concat() method
d. Use the concat() method or the trim() method
Question 11
Question text
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster
if the subexpression that is most likely false is on the left of the && operator.
Select one:
a. True
b. False
Question 12
Question text
This is a set of programming language statements that, together, perform a specific task.
Select one:
a. Pseudocode
b. Compiler
c. Procedure
d. Object
Question 13
Question text
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Select one:
a. True
b. False
Question 14
Question text
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Select one:
a. This is an error
b. 18.0
c. 18 (as an integer)
d. 8
Question 15
Question text
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)

{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
Select one:
a. Nothing, this is an error
b. 9 45 16
c. 9 45 16
d. 94516
Question 16
Question text
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Select one:
a. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
Question 17
Question text
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is
hidden, but not closed.
Select one:
a. JFrame.EXIT_ON_CLOSE
b. JFrame. HIDE_ON_CLOSE
c. HIDE_ON_CLOSE
d. JFrame.HIDE_NOT_CLOSE
Question 18
Question text
A loop that executes as long as a particular condition exists is called a[n]
Select one:
a. sentinel loop
b. count-controlled loop
c. conditional loop
d. infinite loop
Question 19
Question text
Which of the following is not part of a method call?
Select one:

a. return type
b. method name
c. parentheses
d. all of the above are part of a method call
Question 20
Question text
This refers to the combining of data and code into a single object.
Select one:
a. Data hiding
b. Encapsulation
c. Object
d. Abstraction
Question 21
Question text
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
Select one:
a. 28
b. 30
c. 35
d. 24
Question 22
Question text
What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
Select one:
a. 100
b. 80
c. 55
d. 35
Question 23
Question text
In a @return tag statement the description
Select one:
a. must be longer than one line
b. describes the return value
c. describes the parameter values
d. cannot be longer than one line

Question 24
Question text
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
Select one:
a. 2000
b. 1500
c. 1250
d. 1000
Question 25
Question text
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Select one:
a. This is an infinite loop
b. 110
c. 90
d. 100
Question 26
Question text
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
Select one:
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question 27
Question text
One of the design tools used by programmers when creating a model of the program is:
Select one:

a. ALU
b. Compiler
c. Pseudocode
d. Disk drive
Question 28
Question text
When an object, such as a String, is passed as an argument, it is
Select one:
a. passed by value like any other parameter value
b. encrypted
c. necessary to know exactly how long the string is when writing the program
d. actually a reference to the object that is passed
Question 29
Question text
Assuming that inputFile references a Scanner object that was used to open a file, which of the following
statements will read an int from the file?
Select one:
a. int number = inputFilE.nextInt();
b. int number = inputFilE.next();
c. int number = inputFilE.readInt();
d. int number = inputFilE.integer();
Question 30
Question text
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
Select one:
a. neither num or str will be changed
b. str will have a value of 560
c. num will be set to 560
d. the last line of code will cause an error
Question 31
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(3.3, 55);

b. showProduct(10.0, 4.6);
c. showProduct(10, 4.5);
d. showProduct("5", "40");
Question 32
Question text
What will be the value of matches after the following code is executed?
boolean matches;
String[] productCodes = {"456HI345", "3456hj"};
matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3);
Select one:
a. 56H
b. 56h
c. true
d. false
Question 33
Question text
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
Select one:
a. Space
b. Tab
c. Semicolon
d. Newline
Question 34
Question text
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Select one:
a. False
b. True
Question 35
Question text
Which of the following is not involved in finding the classes when developing an object-oriented application?
Select one:
a. Identify all the nouns.
b. Refine the list of nouns to include only those that are relevant to the problem.
c. Describe the problem domain.
d. Write the code.
Question 36
Question text
What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time <= 119 ? rate * 2 :
time / 60.0 * rate;
Select one:

a. 21.00
b. 14.00
c. 7.00
d. 28.00
Question 37
Question text
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
Select one:
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
F
Question 38
Question text
Overloading means multiple methods in the same class
Select one:
a. have the same name, but different parameter lists
b. have different names, but the same parameter list
c. have the same name, but different return types
d. perform the same function
Question 39
Question text
Look at the following statement.
import java.util.*;
This is an example of
Select one:
a. unconditional import
b. conditional import
c. a wildcard import
d. an explicit import
Question 40
Question text
Instance methods should be declared static.
Select one:
a. False
b. True

Question 1
Question text
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter = new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
Select one:
a. 45,678.26
b. 0,045,678.26
c. 45,678.3
d. 45678.259
Question 2
Question text
Java source files end with the .class extension.
Select one:
a. True
b. False
Question 3
Question text
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
Select one:
a. x
b. x = 108.6
c. Nothing, there is an error in the code.
d. x = 54.3
Question 4
Question text
When an objects internal data is hidden from outside code and access to that...
Select one:
a. True
b. False
Question 5
Question text
RAM is usually:
Select one:
a. Secondary storage
b. An input/output device
c. A static type of memory, used for permanent storage
d. A volatile type of memory, used only for temporary storage

Question 6
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct("5", "40");
b. showProduct(10.0, 4.6);
c. showProduct(3.3, 55);
d. showProduct(10, 4.5);
Question 7
Question text
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
Select one:
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.
c. The SunnyFace image will resize itself to fit on imageLabel.
d. The SunnyFace image will resize itself to fit on imagePanel.
Question 8
Question text
This type of loop is ideal in situations where the exact number of iterations is known.
Select one:
a. if statement
b. while loop
c. do-while loop
d. for loop
Question 9
Question text
What is the result of the following expression?
25 - 7 * 3 + 12 / 3
Select one:
a. 12
b. 8
c. 6

d. 10
Question 10
Question text
Another term for an object of a class is
Select one:
a. access specifier
b. member
c. method
d. instance
Question 11
Question text
The process of breaking a problem down into smaller pieces is called
Select one:
a. functional decomposition
b. scientific method
c. whole-into-part
d. top-down programming
Question 12
Question text
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is
hidden, but not closed.
Select one:
a. JFrame. HIDE_ON_CLOSE
b. JFrame.HIDE_NOT_CLOSE
c. HIDE_ON_CLOSE
d. JFrame.EXIT_ON_CLOSE
Question 13
Question text
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Select one:
a. None of the other three options.
b. "red", "green", "blue"and "orange"
c. "[", "$", "&", "#", and "]"
d. "$", "&", and "#"
Question 14
Question text
This type of loop will always be executed at least once.
Select one:
a. post-test loop
b. for loop

c. pre-test loop
d. sentinel loop
Question 15
Question text
When you write a change listener class method for a slider, it must implement the ChangeListener interface
which is in the javax.swing.event package.
Select one:
a. True
b. False
Question 16
Question text
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
Select one:
a. Invalid for statement
b. 30
c. 40
d. 25
Question 17
Question text
Which of the following does not describe a valid comment in Java?
Select one:
a. Documentation comments, any comments starting with /** and ending with */
b. Multi-line comments, start with */ and end with /*
c. Single line comments, two forward slashes - //
d. Multi-line comments, start with /* and end with */
Question 18
Question text
Look at the following statement.
import java.util.Scanner;
This is an example of
Select one:
a. conditional import
b. a wildcard import
c. unconditional import
d. an explicit import
Question 19
Question text
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Select one:

a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question 20
Question text
If chr is a character variable, which of the following if statements is written correctly?
Select one:
a. if (chr == "a")
b. if (chr = "a")
c. if (chr == 'a')
d. if (chr = 'a')
Question 21
Question text
What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
Select one:
a. 4
b. 8
c. 8.0
d. 8.25
Question 22
Question text
Which of the following is not a part of the method header?
Select one:
a. method name
b. return type
c. semicolon
d. parentheses
Question 23
Question text
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.
Select one:
a. True
b. False
Question 24
Question text
A constructor is a method that
Select one:

a. never receives any arguments.


b. returns an object of the class.
c. performs initialization or setup operations.
d. with the name ClassName.constructor.
Question 25
Question text
When testing for character values, the switch statement does not test for the case of the character.
Select one:
a. True
b. False
Question 26
Question text
Given the following statement, which statement will write "Calvin" to the file DiskFilE.txt?
PrintWriter diskOut = new PrintWriter("DiskFilE.txt");
Select one:
a. System.out.println(diskOut, "Calvin");
b. PrintWriter.println("Calvin");
c. DiskFilE.println("Calvin");
d. diskOut.println("Calvin");
Question 27
Question text
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
Select one:
a. showProduct(10.0, 4);
b. showProduct(10, 4.5);
c. showProduct(33.0, 55.0);
d. showProduct(5.5, 4.0);
Question 28
Question text
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
Select one:
a. 10
b. 20
c. 145

d. No value, there is a syntax error


Question 29
Question text
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many
characters.
Select one:
a. 0 characters
b. 8 characters
c. 16 characters
d. 32 characters
Question 30
Question text
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
Select one:
a. Numbers less than 100 or greater than 500
b. Numbers in the range 100 - 500
c. Numbers in the range 100 - 499
d. Numbers greater than 500
Question 31
Question text
Every Java application program must have
Select one:
a. a class named MAIN
b. integer variables
c. a method named main
d. comments
Question 32
Question text
The scope of a private instance field is
Select one:
a. the method in which they are defined
b. the instance methods of the same class
c. inside the parentheses of a method header
d. inside the class, but not inside any method
Question 33
Question text

In the following code, System.out.println(num) is an example of _________.


double num = 5.4;
System.out.println(num);
num = 0.0;
Select one:
a. a local variable
b. a void method
c. a complex method
d. a value-returning method
Question 34
Question text
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter = new DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));
Select one:
a. 45,678.3
b. 45,678.26
c. 45678.259
d. 45,678.259
Question 35
Question text
Assuming that inputFile references a Scanner object that was used to open a file, which of the following
statements will read an int from the file?
Select one:
a. int number = inputFilE.integer();
b. int number = inputFilE.next();
c. int number = inputFilE.nextInt();
d. int number = inputFilE.readInt();
Question 36
Question text
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
Select one:
a. Only a
b. a and b
c. (str1.equalsIgnoreCase(str2))
d. (str1.compareToIgnoreCase(str2) == 0)
Question 37
Question text
The Character wrapper class provides numerous methods for
Select one:
a. testing String objects

b. testing and converting char variables


c. converting String variables
d. adding two char variables
Question 38
Question text
Which of the following statements will create a reference, str, to the String, Hello, World?
Select one:
a. str = "Hello, World";
b. String str = "Hello, World";
c. string str = "Hello, World";
d. String str = new "Hello, World";
Question 39
Question text
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Select one:
a. panel.addLayout(new (GridLayout(2,3));
b. panel.attachLayout(GridLayout(2,3));
c. panel.setLayout(new (GridLayout(2,3));
d. panel.GridLayout(2,3);
Question 40
Question text
A variable's scope is the part of the program that has access to the variable.
Select one:
a. False
b. True

ANNA
Question1
A do-while loop is a pre-test loop.
a. False
b. True
Question2
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
a. Numbers less than 100 or greater than 500

b. The boolean condition can never be true


c. Numbers in the range 100 - 499
d. Numbers in the range 100 - 500
Question3
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
a. using the private access specifier on the class methods
b. using the private access specifier on the class fields
c. using the private access specifier on the class definition
d. using the public access specifier on the class methods
Question4
Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44;
Whlen Sie eine Antwort:
a. True
b. False
Question5
Which of the following statements creates a class that is extended from the JFrame class?
a. public class DerivedClass extends JFrame{}
b. JFrame(DerivedClass);
c. class JFrame DerivedClass;
d. JFrame DerivedClass = new JFrame();
Question6
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
a. displayValues(a,b); // where a is a short and b is a byte
b. displayValues(a,b); // where a is an int and b is a byte
c. displayValues(a,b); // where a is a short and b is a long
d. displayValue(b,a); // where a is a short and b is a long
Question7
It is common practice in object-oriented programming to make all of a class's
Whlen Sie eine Antwort:
a. fields private
b. fields and methods public
c. methods private
d. fields public
Question8
In an if/else statement, if the boolean expression is false,
a. all statements or blocks are executed

b. no statements or blocks are executed


c. the first statement or block is executed
d. the statement or block following the else is executed
Question9
Internally, the central processing unit (CPU) consists of two parts:
Whlen Sie eine Antwort:
a. The input and output devices
b. The control unit and the arithmetic and logic unit (ALU)
c. The control unit and main memory
d. The arithmetic and login unit (ALU) and main memory
Question10
An important style rule you should adopt for writing if statements is to write the conditionally executed
statement on the line after the if statement.
a. False
b. True
Question11
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
a. There are 583 hens in the hen housE.
b. There are 5785
hens in the hen housE.
c. There are 5785 hens in the hen housE.
d. There are x5\nhens in the hen housE.
Question12
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
a. Nothing, this is an error
b. 9 45 16
c. 94516
d. 9 45 16
Question13
These are used to indicate the end of a Java statement.
Whlen Sie eine Antwort:

a. Colons
b. Semicolons
c. Periods
d. Asterisks
Question14
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
a. 90
b. 130
c. 110
d. 210
Question15
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
a. 3
b. 1, 2, and 3 will all work
c. 2
d. 2 and 3
Question16
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 8
b. 18 (as an integer)
c. This is an error
d. 18.0
Question17
Whlen Sie eine Antwort:
a. Words that have a special meaning in the programming language
b. Words or names defined by the programmer
c. The data names in your program

d. Symbols or words that perform operations on one or more operands


Question18
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
a. No value, there is a syntax error
b. 145
c. 10
d. 20
Question19
You must call a method to get the value of a wrapper class object.
Whlen Sie eine Antwort:
a. True
b. False
Question20
When an argument is passed to a method,
Whlen Sie eine Antwort:
a. values may not be passed to methods
b. its value is copied into the methods parameter variable
c. its value may be changed within the called method
d. the method must not assign another value to the parameter that receives the argument
Question21
The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.
setLayout(new FlowLayout());
a. False
b. True
Question22
This refers to the combining of data and code into a single object.
a. Data hiding
b. Abstraction
c. Object
d. Encapsulation
Question23
What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
a. x = 160, y = 80
b. x = 9, y = 52

c. x = 32, y = 4
d. x = 37, y = 5
Question24
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the spaces or other characters is
a. token
b. delimiter
c. buffer
d. separator
Question25
Which of the following is a valid Java statement?
a. String str = 'John Doe';
b. string str = "John Doe";
c. String str = "John Doe";
d. string str = 'John Doe';
Question26
Look at the following statement.
import java.util.Scanner;
This is an example of
a. a wildcard import
b. conditional import
c. unconditional import
d. an explicit import
Question27
3

Local variables
a. lose the values stored in them between calls to the method in which the variable is declared
b. are hidden from other methods
c. All of the above
d. may have the same name as local variables in other methods
Question28
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(Character.toUpperCase(str.charAt(m)));
m++;
}
a. 456
b. ABC456

c. ABC
d. abc456
Question29
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
a. a complex method
b. a value-returning method
c. a void method
d. a local variable
Question30
The lifetime of a method's local variable is
a. the duration of the program
b. the duration of the class to which the method belongs
c. the duration of the method that called the local variable's method
d. only while the method is executing
Question31
A sentinel value _________ and signals that there are no more values to be entered.
a. is a special value that cannot be mistaken as a member of the list
b. indicates the start of a list
c. is a different data type than the values being processed
d. guards the list
Question32
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Whlen Sie eine Antwort:
a. True
b. False
Question33
The scope of a public instance field is
Whlen Sie eine Antwort:
a. only the class in which it is defined
b. the instance methods and methods outside the class
c. inside the class, but not inside any method
d. inside the parentheses of a method header
Question34
The ___________ is normally considered the standard output and standard input devices, and usually refer to
the monitor and keyboarD.
a. CRT
b. console

c. CPU
d. secondary storage devices
Question35
What will be the results of executing the following code, if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,"Select color", Color.blue);
panel.setForeground(selectedColor);
a. The foreground color will remain unchanged.
b. The foreground color will be set to white.
c. The foreground color will be set to black.
d. The foreground color will be set to blue.
Question36
This type of loop will always be executed at least once.
a. sentinel loop
b. post-test loop
c. for loop
d. pre-test loop
Question37
The following statement
textList.setSelectionMode(ListSelectModel.SINGLE_INTERVAL_SELECTION);
a. sets the textList component to single selection mode.
b. sets the textList component to ListSelectModel.
c. sets the textList component to single interval selection mode.
d. sets the value of textList to SINGLE_INTERVAL_SELECTION.
Question38
To use the ActionListener interface, as well as other event listener interfaces, you must have the following
import statement in your code:
a. import java.awt.*;
b. import java.awt.event.*;
c. import java.swing;
d. import java.awt;
Question39
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
char cust = 'N';
if (purchase > 1000)
if (cust == 'Y')
discountRate = .05;
else
discountRate = .04;
else if (purchase > 750)
if (cust == 'Y')

discountRate = .04;
else
discountRate = .03;
else
discountRate = 0;
a. .04
b. .05
c. 0
d. .03
Question40
Falsch
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
a. 110
b. 90
c. This is an infinite loop
d. 100
Question1
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
a. 5.6
b. 5.60
c. 5.0
d. 3.0
Question2
The expression tested by an if statement must evaluate to
a. t or f
b. true or false
c. +1 or -1
d. 0 or 1
Question3
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
a. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
rage 1
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);

a. 5.6
b. 5.60
c. 5.0
d. 3.0
Question2
The expression tested by an if statement must evaluate to
a. t or f
b. true or false
c. +1 or -1
d. 0 or 1
Question3
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
a. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
Question4
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
a. Nothing, this is an error
b. 9 45 16
c. 9 45 16
d. 94516
Question5
Methods that operate on an object's fields are called
a. private methods
b. public methods
c. instance variables
d. instance methods
Question6

Look at the following statement.


import java.util.Scanner;
This is an example of
a. conditional import
b. unconditional import
c. a wildcard import
d. an explicit import
Question7
Before entering a loop to compute a running total, the program should first do this.
Whlen Sie eine Antwort:
a. Read all the values into main memory
b. Set the accumulator where the total will be kept to an initial value, usually zero
c. Know exactly how many values there are to total
d. Set all variables to zero
Question8
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
a. panel.addLayout(new (GridLayout(2,3));
b. panel.setLayout(new (GridLayout(2,3));
c. panel.GridLayout(2,3);
d. panel.attachLayout(GridLayout(2,3));
Question9
Which of the following is not a valid comment statement?
a. // comment 1
b. */ comment 3 /*
c. /* comment 2 */
d. /** comment 4 */
Question10
3

Application software refers to:


a. Key words
b. The programs that make the computer useful to the user
c. Pseudocode
d. The operating system
Question11
To compile a program named First, use the following command
a. javac First
b. javac First.java
c. compile First.javac

d. java First.java
Question12
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
a. ans = 60, x =0, y =50
b. ans = 60, x = 50, y =100
c. ans = 45, x = 50, y = 0
d. ans = 45, x = 50, y = 50
Question13
What would be the value of x after the following statements were executed?
int x = 10;
switch (x)
{
case 10:
x += 15;
case 12:
x -= 5;
break;
default:
x *= 3;
}
a. 30
b. 20
c. 25
d. 5
Question14
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
a. num will be set to 560
b. neither num or str will be changed
c. the last line of code will cause an error
d. str will have a value of 560
Question15
Any method that calls a method with a throws clause in its header must
a. have the same throws clause

b. Both of the above


c. handle the potential exception
d. do nothing, the called program will take care of the throws clause
Question16
The getSelectedIndex method returns
a. the index of the selected item. (A)
b. -1 if no item is selected. (B)
c. Both (A) and (B).
d. Neither (A) or (B).
Question17
In a @return tag statement the description
a. cannot be longer than one line
b. describes the return value
c. must be longer than one line
d. describes the parameter values
Question18
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
a. 10
b. This is an infinite loop.
c. 200
d. The loop will not be executed, the initial value of x > 5.
Question19
When using the StringBuilder class's insert method, you can insert
a. any primitive type
b. a String object
c. a char array
d. All of the above
Question20
An access specifier indicates how the class may be accessed.
a. True
b. False
Question21
The process of breaking a problem down into smaller pieces is called
Whlen Sie eine Antwort:
a. whole-into-part

b. scientific method
c. functional decomposition
d. top-down programming
Question22
This is a value that signals when the end of a list of values has been reacheD.
a. Terminal value
b. End value
c. Final value
d. Sentinel
Question23
A method that stores a value in a class's field or in some other way changes the value of a field is known as a
mutator method.
a. True
b. False
Question24
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 18 (as an integer)
b. 18.0
c. 8.0
d. This is an error
Question25
An operating system can be categorized according to:
a. Both of the above
b. Neither of the above
c. The number of users they can accommodate
d. The number of tasks they can perform at one time
Question26
In all but rare cases, loops must contain within themselves
a. arithmetic statements
b. if statements
c. a way to terminate
d. nested loops
Question27
The Character wrapper class provides numerous methods for
a. testing String objects

b. testing and converting char variables


c. converting String variables
d. adding two char variables
Question28
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
a. There are x5\nhens in the hen housE.
b. There are 5785
hens in the hen housE.
c. There are 583 hens in the hen housE.
d. There are 5785 hens in the hen housE.
Question29
What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
a. A label with the text "It is a beautiful day." to the left of the SunnyFace image.
b. A label with the text "It is a beautiful day." to the right of the SunnyFace image.
c. A label with the text "It is a beautiful day." below the SunnyFace image.
d. A label with the text "It is a beautiful day." above the SunnyFace image.
Question30
The scope of a private instance field is
a. the instance methods of the same class
b. the method in which they are defined
c. inside the parentheses of a method header
d. inside the class, but not inside any method
Question31
This is a software entity that contains data and procedures.
a. Program
b. Method
c. Class
d. Object
Question32
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
a. False
b. True
Question33
If the following Java statements are executed, what will be displayed?
System.out.print("The top three winners are\n");
System.out.print("Jody, the Giant\n");

System.out.print("Buffy, the Barbarian");


System.out.println("Adelle, the Alligator");
a. The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
b. The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
c. The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
d. The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
Question34
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
a. 2 and 3
b. 1, 2, and 3 will all work
c. 3
d. 2
Question35
A common technique for writing an event listener class is to write it as a private inner class inside the class that
creates the GUI.
Whlen Sie eine Antwort:
a. True
b. False
Question36
This is a boolean variable that signals when some condition exists in the program
Whlen Sie eine Antwort:
a. Case
b. Block
c. Flag
d. Sentinel
Question37
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
Whlen Sie eine Antwort:
a. Invalid for statement
b. 25

c. 40
d. 30
Question38
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
a. showProduct(10.0, 4);
b. showProduct(5.5, 4.0);
c. showProduct(33.0, 55.0);
d. showProduct(10, 4.5);
Question39
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);
a. The loop will not be executed, the initial value of x > 5.
b. This is an infinite loop.
c. 10
d. 200
Question40
To convert the int variable number to a string, use the following statement.
Whlen Sie eine Antwort:
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question1
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
a. No value, there is a syntax error
b. 145
c. 20
d. 10
Question2
This is a sum of numbers that accumulates with each iteration of a loop.

a. Galloping total
b. Final total
c. Grand finale
d. Running total
Question3
When using the BorderLayout manager, how many components can each region hold?
a. 2
b. 5
c. 1
d. No limit
Question4
A value-returning method must specify this as its return type in the method header.
a. an int
b. any valid data type
c. a double
d. a boolean
Question5
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
Whlen Sie eine Antwort:
a. diddle
b. diddl
c. , didd
d. Iddle
Question6
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);

a. x = 27, y = 3, z = 18
b. Nothing. There is an error in the code!
c. x = 27, y = 2, z = 18
d. x = 27, y = 3.333, z = 18
Question7
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing

a. an ItemEvent object as an argurment.


b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question8
Which of the following statements correctly creates a Scanner object for keyboard input?
a. Keyboard scanner = new Keyboard(System.in);
b. Scanner keyboard(System.in);
c. Scanner kbd = new Scanner(System.keyboard);
d. Scanner keyboard = new Scanner(System.in);
Question9
Software refers to:
a. Programs
b. Peopleware
c. The physical components that a computer is made of.
d. Firmware
Question10
The Character wrapper class provides numerous methods for
a. testing String objects
b. testing and converting char variables
c. converting String variables
d. adding two char variables
Question11
In an if/else statement, if the boolean expression is false,
a. the statement or block following the else is executed
b. all statements or blocks are executed
c. the first statement or block is executed
d. no statements or blocks are executed
Question12
What will be returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 18 (as an integer)
b. 18.0
c. This is an error

d. 8
Question13
Before entering a loop to compute a running total, the program should first do this.
Whlen Sie eine Antwort:
a. Set all variables to zero
b. Read all the values into main memory
c. Set the accumulator where the total will be kept to an initial value, usually zero
d. Know exactly how many values there are to total
Question14
If the following Java statements are executed, what will be displayed?
System.out.print("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");
a. The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
b. The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
c. The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
d. The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
Question15
Event listeners must
a. be included in private inner classes
b. implement an interface
c. exit the application once it has handled the event
d. not receive any arguments
Question16
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.
d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Feedback

Question17
Which of the following is the correct boolean expression to test for: int x being a value between, but not
including, 500 and 650, or int y not equal to 1000?
a. ((x < 500 && x > 650) || !(y == 1000))
b. ((x >= 500 && x <= 650) && (y != 1000))
c. ((x > 500 AND x < 650) OR !(y.equal(1000)))
d. ((x > 500 && x < 650) || (y != 1000))
Feedback
Die richtige Antwort lautet: ((x > 500 && x < 650) || (y != 1000))
Question18
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question19
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL
the world's alphabets.
a. False
b. True
Question20
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Whlen Sie eine Antwort:
a. The quick brown fox
jumped over the
slow moving hen.
b. Nothing. This is an error.
c. The quick brown fox jumped over the \nslow moving hen.
d. The quick brown fox jumped over the
slow moving hen.
Question21
A parameter variables scope is the method in which the parameter is declareD.
Whlen Sie eine Antwort:
a. False
b. True
Question22
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;

else if (sales < 7500)


bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
a. 200
b. 1250
c. 500
d. 1000
e. 750
Question23
What does the following code display?
int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);
a. %d %d
b. 9 12
c. %d 9
d. %9 %12
Question24
Overloading means multiple methods in the same class
a. have the same name, but different parameter lists
b. have the same name, but different return types
c. perform the same function
d. have different names, but the same parameter list
Question25
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one
for each delimiter character.
a. True
b. False
Question26
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.
Whlen Sie eine Antwort:
a. False
b. True
Question27
You should always document a method by writing comments that appear
a. at the end of the file.
b. just after the methods definition.

c. only if the method is more than five lines long.


d. just before the methods definition.
Question28
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Whlen Sie eine Antwort:
a. displayValues(a,b); // where a is a short and b is a long
b. displayValue(b,a); // where a is a short and b is a long
c. displayValues(a,b); // where a is a short and b is a byte
d. displayValues(a,b); // where a is an int and b is a byte
Question29
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
a. showProduct(10.0, 4);
b. showProduct(33.0, 55.0);
c. showProduct(5.5, 4.0);
d. showProduct(10, 4.5);
Question30
The scope of a private instance field is
a. the method in which they are defined
b. the instance methods of the same class
c. inside the class, but not inside any method
d. inside the parentheses of a method header
Question31
What will be displayed after the following statements have been executed?
final double x;
x = 54.3;
System.out.println("x = " + x );
a. x
b. x = 54.3
c. x = 108.6
d. Nothing, there is an error in the code.
Question32
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
a. 1

b. 1 and 2
c. Neither 1 or 2
d. 2
Question33
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Whlen Sie eine Antwort:
a. True
b. False
Question34
Instance methods do not have the key word static in their headers.
a. False
b. True
Question35
This is a cross between human language and a programming language.
a. The Java Virtual Machine
b. The compiler
c. Java
d. Pseudocode
Question36
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
a. The boolean condition can never be true
b. Numbers in the range 100 - 500
c. Numbers less than 100 or greater than 500
d. Numbers in the range 100 - 499
Question37
When the break statement is encountered in a loop, all the statements in the body of the loop that appear
after it are ignored, and the loop prepares for the next iteration.
a. True
b. False
Question38
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
a. 1

b. 10
c. 0
d. 11
Question39
What will be the value of x after the following code is executed?
int x, y = 4, z = 6;
x = (y++) * (++z);
a. 30
b. 24
c. 28
d. 35
Question40
Colons are used to indicate the end of a Java statement.
a. False
b. True

String msg = "I am enjoying this class.";


String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 25characters.

Question2
Every Java application program must have
a. comments
b. a method named main
c. integer variables
d. a class named MAIN
Question3
Fragetext
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
a. 90
b. 210
c. 110
d. 130
Question4
Fragetext
The following package is automatically imported into all Java programs.
a. java.java
b. java.default
c. java.lang
d. java.util
Question5
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if ( x == y);
ans *= 2;
a. No value, there is a syntax error
b. 20
c. 10
d. 145
Question6
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
a. Space
b. Tab
c. Semicolon
d. Newline
Question7

What will be the result of executing the following statement?


panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
a. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
Question8
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter = new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
a. 45,678.26
b. 45678.259
c. 45,678.3
d. 0,045,678.26
Question9
In the following code the setPreferredSize method sets the size of the text, "Have a good day".
label = new Jlabel("Have a good day", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
a. True
b. False
Question10
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
a. None of the other three options.
b. "red", "green", "blue"and "orange"
c. "[", "$", "&", "#", and "]"
d. "$", "&", and "#"
Question11
This layout manager arranges components in five regions.
a. RegionLayout
b. GridLayout
c. BorderLayout
d. FlowLayout
Question12
Methods that operate on an object's fields are called
a. instance methods
b. private methods
c. instance variables

d. public methods
Question13
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string
before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last
token.
a. True
b. False
Question14
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
a. a complex method
b. a local variable
c. a value-returning method
d. a void method
Question15
What is the value of x after the following code has been executed?
int x = 75;
int y = 90;
if ( x != y)
x += y;
a. 75
b. 90
c. 165
d. 15
Question16
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 8.0
b. This is an error
c. 18.0
d. 18 (as an integer)
Question17
Which of the following will run the compiled program ReadIt?
a. java ReadIt.java
b. java ReadIt
c. go ReadIt

d. run ReadIt
Question18
In GUI terminology, a container that can be displayed as a window is known as a _______________.
a. Swing package
b. message dialog
c. buffer
d. frame
Question19
Look at the following statement.
import java.util.*;
This is an example of
a. a wildcard import
b. conditional import
c. unconditional import
d. an explicit import
Question20
A sentinel value _________ and signals that there are no more values to be entered.
a. indicates the start of a list
b. is a special value that cannot be mistaken as a member of the list
c. is a different data type than the values being processed
d. guards the list
Question21
When a local variable in an instance method has the same name as an instance field, the instance field hides
the local variable.
a. True
b. False
Question22
Which of the following will compile a program called ReadIt?
Whlen Sie eine Antwort:
a. javac ReadIt.javac
b. javac ReadIt.java
c. java ReadIt.java
d. java ReadIt.javac
Question23
Functional decomposition is
a. the backbone of the scientific method
b. the process of decomposing functions
c. the process of breaking a problem down into smaller pieces

d. the process of dead plants decomposing and turning back into soil
Question24
If the following Java statements are executed, what will be displayed?
System.out.print("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");
a. The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
b. The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
c. The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
d. The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
Question25
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
a. Nothing, this is an error
b. x = 22, y = 88
c. 22, y = 26
d. x = 22, y = 4
Question26
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
a. use the statement, Panel panel = new Panel(bGroup);
b. use the statement, panel.add(bGroup);
c. add each button to panel one at a time, e.g. panel.add(button1);
d. use the statement, bGroup.add(panel);
Question27
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1
and str2?
a. Only a
b. (str1.equalsIgnoreCase(str2))
c. a and b
d. (str1.compareToIgnoreCase(str2) == 0)
Question28
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.

a. True
b. False
Question29
You must have a return statement in a value-returning method.
a. True
b. False
Question30
Java source files end with the .class extension.
a. True
b. False
Question31
If chr is a character variable, which of the following if statements is written correctly?
a. if (chr = "a")
b. if (chr == 'a')
c. if (chr = 'a')
d. if (chr == "a")
Question32
These operators are used to determine whether a specific relationship exists between two values.
a. Relational
b. Syntactical
c. Assignment
d. Arithmetic
Question33
What is the result of the following expression?
25 / 4 + 4 * 10 % 3
a. 19
b. 3
c. 5.25
d. 7
Question34
Which of the following is not involved in finding the classes when developing an object-oriented application?
a. Write the code.
b. Refine the list of nouns to include only those that are relevant to the problem.
c. Describe the problem domain.
d. Identify all the nouns.
Question35
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
a. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);

b. Scanner inputFile = new Scanner("MyFilE.txt");


PrintWriter outFile = new PrintWriter(fwriter);
c. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");
d. File file = new File("MyFilE.txt");
Question36
You can use the PrintWriter class to open a file for writing and write data to it.
a. False
b. True
Question37
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x > 5);
a. 200
b. 10
c. This is an infinite loop.
d. The loop will not be executed, the initial value of x > 5.
Question38
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
a. displayValue(b,a); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a long
c. displayValues(a,b); // where a is a short and b is a byte
d. displayValues(a,b); // where a is an int and b is a byte
Question39
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
a. Invalid for statement
b. 30
c. 25
d. 40
Question40
The ___________ is normally considered the standard output and standard input devices, and usually refer to
the monitor and keyboarD.
a. CRT
b. secondary storage devices
c. console

d. CPU
What will be the values of ans, x, and y after the following statements are executed?
int ans = 0, x = 15, y =25;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
a. ans = 25, x = -10, y = 25
b. ans = 0, x = 15, y = 25
c. ans = 25, x = 15, y = 40
d. ans = 35, x = 15, y = 40
Question2
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y =50;
if ( x >= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
a. ans = 60, x =0, y =50
b. ans = 60, x = 50, y =100
c. ans = 45, x = 50, y = 50
d. ans = 45, x = 50, y = 0
Question3
These are used to indicate the end of a Java statement.
a. Semicolons
b. Colons
c. Periods
d. Asterisks
Question4
Falsch
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string
before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last
token.

a. True
b. False
Question5
What is wrong with the following method call?
displayValue (double x);
a. x should be a String.
b. displayValue will not accept a parameter.
c. There is nothing wrong with the statement.
d. Do not include the data type in the method call.
Question6
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 18 (as an integer)
b. This is an error
c. 18.0
d. 8.0
Question7
What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales > 1000)
bonus = 100;
if (sales > 750)
bonus = 50;
if (sales > 500)
bonus = 25;
else
bonus = 0;
a. 25
b. 100
c. 500
d. 0
Question8
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
a. False
b. True
Question9
If method A calls method B, and method B calls method C, and method C calls method D, when method D
finishes, what happens?
a. control is returned to method A

b. control is returned to method C


c. control is returned to method B
d. the program terminates
Question10
What is the result of the following expression?
17 % 3 * 2 - 12 + 15
Whlen Sie eine Antwort:
a. 8
b. 12
c. 7
d. 105
Question11
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
a. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
c. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
d. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
Question12
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter
variable.
a. False
b. True
Question13
The _________ statement is used to make simple decisions in Java.
a. branch
b. for
c. if
d. do/while
Question14
You must have a return statement in a value-returning method.
a. False
b. True
Question15
A Java program must have at least one of these:
a. Comment
b. System.out.println(); statement
c. Class definition

d. Variable
Question16
The FlowLayout manager does not allow the programmer to align components.
a. False
b. True
Question17
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
a. 25
b. Invalid for statement
c. 30
d. 40
Question18
This is a value that signals when the end of a list of values has been reacheD.
a. End value
b. Sentinel
c. Terminal value
d. Final value
Question19
The scope of a private instance field is
a. the method in which they are defined
b. inside the parentheses of a method header
c. the instance methods of the same class
d. inside the class, but not inside any method
Question20
This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing,
and closing the window.
Whlen Sie eine Antwort:
a. Container
b. Dialog box
c. Pane
d. Frame
Question21
Methods that operate on an object's fields are called
a. instance variables
b. private methods
c. instance methods

d. public methods
Question22
A flag may have the values:
a. true or false
b. 0 or 1
c. of any character
d. 1 or -1
Question23
Which of the following is not a primitive data type?
a. String
b. short
c. long
d. float
Question24
You cannot assign a value to a wrapper class object.
Whlen Sie eine Antwort:
a. True
b. False
Question25
RAM is usually:
a. Secondary storage
b. An input/output device
c. A static type of memory, used for permanent storage
d. A volatile type of memory, used only for temporary storage
Question26
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question27
What is the result of the following expression?
25 - 7 * 3 + 12 / 3
a. 8
b. 6
c. 10
d. 12

Question28
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
Whlen Sie eine Antwort:
a. 90
b. 110
c. This is an infinite loop
d. 100
Question29
Fragetext
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
a. displayValues(a,b); // where a is a short and b is a long
b. displayValue(b,a); // where a is a short and b is a long
c. displayValues(a,b); // where a is an int and b is a byte
d. displayValues(a,b); // where a is a short and b is a byte
Question30
What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
a. 3.0
b. 5.0
c. 5.60
d. 5.6
Question31
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
a. 2
b. 1 and 2
c. 1
d. Neither 1 or 2
Question32
Which of the following will compile a program called ReadIt?
a. javac ReadIt.java
b. java ReadIt.java
c. java ReadIt.javac

d. javac ReadIt.javac
Question33
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
a. 90
b. 210
c. 110
d. 130
Question34
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
a. True
b. False
Question35
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
a. True
b. False
Question36
This type of loop will always be executed at least once.
a. sentinel loop
b. pre-test loop
c. for loop
d. post-test loop
Question37
A constructor is a method that
a. with the name ClassName.constructor.
b. performs initialization or setup operations.
c. never receives any arguments.
d. returns an object of the class.
Question38
If panel references a JPanel object, which of the following statements adds the GridLayout to it?
Whlen Sie eine Antwort:
a. panel.attachLayout(GridLayout(2,3));
b. panel.addLayout(new (GridLayout(2,3));
c. panel.GridLayout(2,3);
d. panel.setLayout(new (GridLayout(2,3));

Question39
To convert the int variable number to a string, use the following statement.
a. String str = Integer.toString(number);
b. String str = integer.toString(number);
c. String str = integer(number);
d. String str = number.Integer.toString(str);
Question40
When a method tests an argument and returns a true or false value, it should return
a. a zero for true and a one for false
b. a boolean value
c. a method should not be used for this type test
d. a zero for false and a non-zero for true
Which of the following statements will create a reference, str, to the String, Hello, World?
a. String str = "Hello, World";
b. string str = "Hello, World";
c. str = "Hello, World";
d. String str = new "Hello, World";
Question2
Application software refers to programs that make the computer useful to the user.
a. True
b. False
Question3
Which of the following is not involved in finding the classes when developing an object-oriented application?
a. Refine the list of nouns to include only those that are relevant to the problem.
b. Write the code.
c. Describe the problem domain.
d. Identify all the nouns.
Question4
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter
variable.
a. False
b. True
Question5
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for
special purposes.
a. False
b. True
Question6
What will be the value of x after the following code is executed?

int x = 10;
do
{
x *= 20;
} while (x > 5);
a. 10
b. 200
c. The loop will not be executed, the initial value of x > 5.
d. This is an infinite loop.
Question7
What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales > 1000)
bonus = 100;
if (sales > 750)
bonus = 50;
if (sales > 500)
bonus = 25;
else
bonus = 0;
a. 500
b. 25
c. 100
d. 0
Question8
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
a. a local variable
b. a value-returning method
c. a void method
d. a complex method
Question9
It is common practice in object-oriented programming to make all of a class's
a. fields private
b. fields and methods public
c. fields public
d. methods private
Question10
These operators are used to determine whether a specific relationship exists between two values.
a. Arithmetic
b. Syntactical

c. Relational
d. Assignment
Question11
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
a. False
b. True
Question12
Which Scanner class method reads a String?
a. nextString()
b. nextLine()
c. readString()
d. getString()
Question13
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}
a. showProduct("5", "40");
b. showProduct(10.0, 4.6);
c. showProduct(3.3, 55);
d. showProduct(10, 4.5);
Question14
What will be the value of matches after the following code is executed?
boolean matches;
String[] productCodes = {"456HI345", "3456hj"};
matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3);
a. 56H
b. 56h
c. true
d. false
Question15
The boolean data type may contain values in the following range of values
a. - 32,768 to +32,767
b. - 2,147,483,648 to +2,147,483,647
c. true or false
d. -128 to + 127
Question16

What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time <= 119 ? rate * 2 :
time / 60.0 * rate;
Whlen Sie eine Antwort:
a. 21.00
b. 28.00
c. 14.00
d. 7.00
Question17
Look at the following statement.
import java.util.*;
This is an example of
a. unconditional import
b. a wildcard import
c. an explicit import
d. conditional import
Question18
The GridLayout manager limits each cell to only one component. To put two or more components in a cell, do
this.
a. Resize the components to fit in the cell
b. Resize the cells so they can hold more
c. You can nest panels inside the cells, and add other components to the panels
d. The statement is false. The GridLayout manager does not have this restriction
Question19
Which of the following are pre-test loops?
a. for, do-while
b. while, for
c. while, do-while
d. while, for, do-while
Question20
What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
a. It will create a JScrollPane object for the JTextArea object referenced by message and display a
horizontal scroll bar on the text area.
b. It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical
scroll bar on the text area.
c. It will create a JScrollPane object for the JTextArea object referenced by message and display both
vertical and horizontal scroll bars on the text area.

d. It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll
bars on the text area.
Question21
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
Whlen Sie eine Antwort:
a. True
b. False
F
Question22
One of the design tools used by programmers when creating a model of the program is:
a. Compiler
b. Pseudocode
c. ALU
d. Disk drive
Question23
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
a. Numbers less than 100 or greater than 500
b. The boolean condition can never be true
c. Numbers in the range 100 - 499
d. Numbers in the range 100 - 500
Question24
What will be displayed as a result of executing the following code?
int x = 8;
String msg = "I am enjoying javA.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " +
ltr);
System.out.println("msg has " + strSize +
" characters.");
a. I am enjoying javA.
I AM ENJOYING JAVA.

i am enjoying javA.
Character at index x = y
msg has 19 characters.
b. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 20 characters.
c. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = o
msg has 19 characters.
d. I am enjoying javA.
I AM ENJOYING JAVA.
i am enjoying javA.
Character at index x = j
msg has 20 characters.
Question25
What will be the displayed when the following code is executed?
final int x = 22, y = 4;
y += x;
System.out.println("x = " + x + ", y = " + y);
a. Nothing, this is an error
b. x = 22, y = 4
c. x = 22, y = 88
d. 22, y = 26
Question26
Syntax is:
Whlen Sie eine Antwort:
a. Rules that must be followed when writing a program
b. Symbols or words that perform operations
c. Words that have a special meaning in the programming language
d. Punctuation
Question27
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
a. use the statement, panel.add(bGroup);
b. use the statement, bGroup.add(panel);
c. use the statement, Panel panel = new Panel(bGroup);
d. add each button to panel one at a time, e.g. panel.add(button1);
Question28
What will be displayed after the following statements have been executed?

final double x;
x = 54.3;
System.out.println("x = " + x );
Whlen Sie eine Antwort:
a. x
b. x = 108.6
c. x = 54.3
d. Nothing, there is an error in the code.
Question29
When using the PrintWriter class, which of the following import statements would you write near the top of
your program?
Whlen Sie eine Antwort:
a. import PrintWriter;
b. import javA.filE.*;
c. import javA.io.*;
d. import javax.swing.*;
Question30
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
a. True
b. False
Question31
Functional decomposition is
a. the backbone of the scientific method
b. the process of decomposing functions
c. the process of breaking a problem down into smaller pieces
d. the process of dead plants decomposing and turning back into soil
Question32
If chr is a character variable, which of the following if statements is written correctly?
a. if (chr == 'a')
b. if (chr = 'a')
c. if (chr == "a")
d. if (chr = "a")
Question33
When using the BorderLayout manager, how many components can each region hold?
a. 2
b. No limit
c. 5
d. 1

Question34
What will happen when the following statement is executed?
x.setEditable(false);
Whlen Sie eine Antwort:
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question35
Fragetext
In a @return tag statement the description
a. describes the return value
b. must be longer than one line
c. cannot be longer than one line
d. describes the parameter values
Question36
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
a. showProduct(10.0, 4);
b. showProduct(33.0, 55.0);
c. showProduct(10, 4.5);
d. showProduct(5.5, 4.0);
Question37
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;
else if (sales < 7500)
bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
a. 200
b. 750
c. 500
d. 1000
e. 1250

Question38
In a general sense, a method is
a. a comment
b. a collection of statements that performs a specific task
c. a statement inside a loop
d. a plan
Question39
When you are writing a program with String objects that may have unwanted spaces at the beginning or end of
the strings, use this method to delete them.
a. replace
b. trim
c. valueOf
d. substring
Question40
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
a. 100
b. 90
c. 110
d. This is an infinite loop
What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0;
a. .05
b. .03
c. .01
d. 0
Question2
Look at the following statement.
import java.util.Scanner;
This is an example of

a. unconditional import
b. a wildcard import
c. conditional import
d. an explicit import
Question3
In the following code, System.out.println(num) is an example of _________.
double num = 5.4;
System.out.println(num);
num = 0.0;
a. a void method
b. a complex method
c. a value-returning method
d. a local variable
F
Question4
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
a. Scanner inputFile = new Scanner("MyFilE.txt");
PrintWriter outFile = new PrintWriter(fwriter);
b. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);
c. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");
d. File file = new File("MyFilE.txt");
Question5
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
a. True
b. False
Question6
For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
a. 7
b. 3
c. 1
d. 5
Question7
Because Java byte code is the same on all computers, compiled Java programs
a. Cannot run on Linux systems

b. Are non-existent
c. Must be re-compiled for each different machine it is run on
d. Are highly portable
Question8
This type of method performs a task and sends a value back to the code that called it.
a. complex
b. local
c. value-returning
d. void
Question9
What does the following code display?
double x = 12.3798146;
System.out.printf("%.2f\n", x);
a. 12.38
b. 1238
c. %12.38
d. 123798146
Question10
In a @return tag statement the description
a. cannot be longer than one line
b. describes the return value
c. must be longer than one line
d. describes the parameter values
Question11
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
a. This is an infinite loop
b. 90
c. 110
d. 210
Question12
Event listeners must
Whlen Sie eine Antwort:
a. implement an interface
b. exit the application once it has handled the event
c. be included in private inner classes

d. not receive any arguments


Question13
This refers to the combining of data and code into a single object.
a. Abstraction
b. Encapsulation
c. Object
d. Data hiding
Question14
In all but rare cases, loops must contain within themselves
a. nested loops
b. a way to terminate
c. arithmetic statements
d. if statements
Question15
What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);
a. This is an infinite loop.
b. 200
c. The loop will not be executed, the initial value of x > 5.
d. 10
Question16
A file must always be opened before using it and closed when the program is finished using it.
a. False
b. True
Question17
A constructor
a. always has an access specifier of private
b. has return type of void
c. always accepts two arguments
d. has the same name as the class
Question18
When an application uses many components, instead of extending just one class from the JFrame class, a
better approach is to
a. just go ahead and do it in one large class
b. encapsulate smaller groups of related components and their event listeners into their own
classes

c. break the application into several smaller applications


d. reconsider the design of the application
Question19
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
a. a void method
b. a value-returning method
c. a complex method
d. a local variable
Question20
Which of the following is valid?
a) float y;
y = 54.9;
b) float y;
double z;
z = 934.21;
y = z;
c) float w;
w = 1.0f;
d) float v;
v = 1.0;
a. Answer a)
b. Answer b)
c. Answer c)
d. Answer d)
Question21
One of the design tools used by programmers when creating a model of the program is:
Whlen Sie eine Antwort:
a. Disk drive
b. Compiler
c. Pseudocode
d. ALU
Question22
This is a value that is written into the code of a program.
Whlen Sie eine Antwort:
a. variable
b. assignment statement
c. operator
d. literal
Question23

Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster
if the subexpression that is most likely false is on the left of the && operator.
Whlen Sie eine Antwort:
a. True
b. False
Question24
In an if/else statement, if the boolean expression is false,
a. the first statement or block is executed
b. all statements or blocks are executed
c. the statement or block following the else is executed
d. no statements or blocks are executed
Question25
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
Whlen Sie eine Antwort:
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question26
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
a. Nothing, this is an error
b. 94516
c. 9 45 16
d. 9 45 16
Question27
Breaking a program down into small manageable methods
a. simplifies programs
b. all of the above
c. makes problems more easily solved

d. allows for code reuse


Question28
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchangeD.
a. True
b. False
Question29
What is the result of the following expression?
10 + 5 * 3 - 20
a. -5
b. -50
c. 5
True
d. 25
Question30
In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboarD.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboarD.nextInt();
}
a. The boolean condition can never be true
b. Numbers in the range 100 - 500
c. Numbers less than 100 or greater than 500
d. Numbers in the range 100 - 499
Question31
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
a. displayValue(b,a); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a byte
c. displayValues(a,b); // where a is an int and b is a byte
d. displayValues(a,b); // where a is a short and b is a long
Question32
What will be printed when the following code is executed?
int y = 10;
if ( y == 10)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);

a. x = 40
b. x = 30
c. x is unknown when the last statement is executed
d. x = 20
Question33
In the following Java statement what value is stored in the variable name?
String name = "John Doe";
a. The memory address where name is located
b. John Doe
c. The memory address where "John Doe" is located
d. name
Question34
A classs responsibilities include
a. both A and B
b. the things a class is responsible for doing
c. the things a class is responsible for knowing
d. neither A or B
Question35
A flag may have the values:
Whlen Sie eine Antwort:
a. 1 or -1
b. 0 or 1
c. of any character
d. true or false
Question36
What will be the result of executing the following statement?
panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
Whlen Sie eine Antwort:
a. The JPanel referenced by panel will have a blue line border that is 5 inches thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
Question37
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
a. x = 27, y = 3, z = 18

b. x = 27, y = 3.333, z = 18
c. Nothing. There is an error in the code!
d. x = 27, y = 2, z = 18
Question38
Which of the following is not involved in finding the classes when developing an object-oriented application?
a. Write the code.
b. Describe the problem domain.
c. Refine the list of nouns to include only those that are relevant to the problem.
d. Identify all the nouns.
Question39
Which of the following is not a class used in constructing a menu system?
Whlen Sie eine Antwort:
a. JMenuItem
b. JCheckBoxMenuItem
c. JButton
d. JRadioButtonMenuItem
Question40
An operating system can be categorized according to:
Whlen Sie eine Antwort:
a. Both of the above
b. The number of tasks they can perform at one time
c. The number of users they can accommodate
d. Neither of the above
When testing for character values, the switch statement does not test for the case of the character.
Whlen Sie eine Antwort:
a. True
b. False
Question2
A constructor
a. has the same name as the class
b. always has an access specifier of private
c. has return type of void
d. always accepts two arguments
Question3
In the programming process which of the following is not involved in defining what the program is to do:
a. Compile code
b. Purpose

c. Input
d. Output
e. Process
Question4
Given the following method header, which of the method calls would be an error?
public void displayValues(int x, int y)
Whlen Sie eine Antwort:
a. displayValue(b,a); // where a is a short and b is a long
b. displayValues(a,b); // where a is a short and b is a long
c. displayValues(a,b); // where a is an int and b is a byte
d. displayValues(a,b); // where a is a short and b is a byte
Question5
Byte code instructions are:
a. Syntax errors
b. Machine code instructions
c. Another name for source code
d. Read and interpreted by the JVM
Question6
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than
str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)
a. 2 and 3
b. 3
c. 1, 2, and 3 will all work
d. 2
Question7
A classs responsibilities include
Whlen Sie eine Antwort:
a. the things a class is responsible for knowing
b. both A and B
c. neither A or B
d. the things a class is responsible for doing
Question8
Which of the following statements will create a reference, str, to the string, Hello, world?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
a. Neither 1 or 2
b. 2

c. 1
d. 1 and 2
Question9
What is the value of x after the following code has been executed?
int x = 75;
int y = 90;
if ( x != y)
x += y;
Whlen Sie eine Antwort:
a. 165
b. 75
c. 15
d. 90
Question10
The scope of a public instance field is
a. the instance methods and methods outside the class
b. inside the class, but not inside any method
c. inside the parentheses of a method header
d. only the class in which it is defined
Question11
What will be displayed after the following statements have been executed?
int x = 15, y = 20, z = 32;
x += 12;
y /= 6;
z -= 14;
System.out.println("x = " +x ", y = " +y ", z = " +z);
a. Nothing. There is an error in the code!
b. x = 27, y = 2, z = 18
c. x = 27, y = 3, z = 18
d. x = 27, y = 3.333, z = 18
Question12
When an argument is passed to a method,
a. its value may be changed within the called method
b. its value is copied into the methods parameter variable
c. values may not be passed to methods
d. the method must not assign another value to the parameter that receives the argument
Question13
In a string that contains a series of words or other items of data separated by spaces or other characters, the
programming term for the data items is
a. token

b. delimiter
c. buffer
d. separator
Question14
What would be printed out as a result of the following code?
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
a. The quick brown fox
jumped over the
slow moving hen.
b. The quick brown fox jumped over the
slow moving hen.
c. Nothing. This is an error.
d. The quick brown fox jumped over the \nslow moving hen.
Question15
A parameter variables scope is the method in which the parameter is declareD.
a. True
b. False
Question16
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
a. neither num or str will be changed
b. the last line of code will cause an error
c. num will be set to 560
d. str will have a value of 560
Question17
Fragetext
Both character literals and string literals can be assigned to a char variable.
a. True
b. False
Feedback
Die richtige Antwort lautet: False
Question18
What will display when the following code is executed?
imagePanel = new JPanel();
imageLabel = new JLabel();
imagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif");
imageLabel.setIcon(sunnyFaceImage);
pack();
a. The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
b. imagePanel will resize itself to accommodate the SunnyFace image.

c. The SunnyFace image will resize itself to fit on imageLabel.


d. The SunnyFace image will resize itself to fit on imagePanel.
Question19
What will happen when the following statement is executed?
x.setEditable(false);
a. The boolean variable x will be set to false.
b. The text field x will be made read-only.
c. The text field x will be editable.
d. The boolean variable x will be editable.
Question20
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}
Whlen Sie eine Antwort:
a. 130
b. 110
c. 90
d. 210
Feedback
Question21
The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are
read.
a. False
b. True
Question22
When using the StringBuilder class's insert method, you can insert
Whlen Sie eine Antwort:
a. any primitive type
b. a String object
c. a char array
Question23
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Whlen Sie eine Antwort:
a. False
b. True
Question24
What does the following code display?

int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);
Whlen Sie eine Antwort:
a. %d 9
b. %9 %12
c. %d %d
d. 9 12
Question25
Which of the following will open a file named MyFilE.txt and allow you to read data from it?
a. Scanner inputFile = new Scanner("MyFilE.txt");
PrintWriter outFile = new PrintWriter(fwriter);
b. File file = new File("MyFilE.txt");
c. D. PrintWriter inputFile = new PrintWriter("MyFilE.txt");
d. File file = new File("MyFilE.txt");
Scanner inputFile = new Scanner(file);
Question26
Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
a. radio.Click();
b. Click(radio);
c. Click(radio, true);
d. radio.doClick();
Question27
The if/else statement will execute one group of statements if its boolean expression is true or another group if
its boolean expression is false.
a. True
b. False
Question28
How many times will the following for loop be executed?
for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
Whlen Sie eine Antwort:
a. 10
b. 1
c. 0
d. 11
Question29
A do-while loop is a pre-test loop.
Whlen Sie eine Antwort:
a. True

b. False
Question30
This is a value that is written into the code of a program.
a. assignment statement
b. variable
c. literal
d. operator
Question31
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100);
{
x += 10;
}
Whlen Sie eine Antwort:
a. 100
b. 110
c. 90
d. This is an infinite loop
Question32
To compile a program named First, use the following command
a. compile First.javac
b. javac First.java
c. javac First
d. java First.java
Question33
int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
char ltr = msg.charAt(x);
int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");
a. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 25 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS.

i am enjoying this class.


Character at index x = n
msg has 25characters.
c. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = e
msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS.
i am enjoying this class.
Character at index x = n
msg has 24 characters.
Question34
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
a. a value-returning method
b. a void method
c. a complex method
d. a local variable
Question35
Before entering a loop to compute a running total, the program should first do this.
a. Read all the values into main memory
b. Know exactly how many values there are to total
c. Set the accumulator where the total will be kept to an initial value, usually zero
d. Set all variables to zero
Question36
The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object
that was generated in response to an event.
Whlen Sie eine Antwort:
a. False
b. True
Question37
Which of the following statements creates a class that is extended from the JFrame class?
Whlen Sie eine Antwort:
a. JFrame DerivedClass = new JFrame();
b. public class DerivedClass extends JFrame{}
c. class JFrame DerivedClass;
d. JFrame(DerivedClass);
Question38

For the following code, how many times would the while loop execute?
StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great.");
while (strToken.hasMoreTokens())
{
System.out.println(strToken.nextToken());
}
a. 7
b. 3
c. 5
d. 1
Question39
Data hiding, which means that critical data stored inside the object is protected from code outside the object is
accomplished in Java by
a. using the public access specifier on the class methods
b. using the private access specifier on the class methods
c. using the private access specifier on the class definition
d. using the private access specifier on the class fields
Question40
The process of breaking a problem down into smaller pieces is called
Whlen Sie eine Antwort:
a. top-down programming
b. scientific method
c. whole-into-part
d. functional decomposition
Logical errors are mistakes that cause the program to produce erroneous results.
a. True
b. False
Question2
Fragetext
When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
Question3
What is the result of the following expression?
25 - 7 * 3 + 12 / 3
a. 10
b. 8

c. 12
d. 6
Question4
This refers to the combining of data and code into a single object.
a. Encapsulation
b. Data hiding
c. Object
d. Abstraction
Question5
What would be the value of discountRate after the following statements are executed?
double discountRate;
char custType = 'B';
switch (custType)
{
case 'A':
discountRate = .08;
break;
case 'B':
discountRate = .06;
case 'C':
discountRate = .04;
default:
discountRate = 0.0;
}
a. .06
b. .08
c. 0.0
d. .04
Question6
Look at the following statement.
import java.util.Scanner;
This is an example of
Whlen Sie eine Antwort:
a. conditional import
b. unconditional import
c. an explicit import
d. a wildcard import
Question7
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " + product);
}

a. showProduct("5", "40");
b. showProduct(10.0, 4.6);
c. showProduct(10, 4.5);
d. showProduct(3.3, 55);
Question8
What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales < 5000)
bonus = 200;
else if (sales < 7500)
bonus = 500;
else if (sales < 10000)
bonus = 750;
else if (sales < 20000)
bonus = 1000;
else
bonus = 1250;
a. 1250
b. 500
c. 750
d. 1000
e. 200
Question9
Which of the following is not a valid comment statement?
a. */ comment 3 /*
b. /* comment 2 */
c. /** comment 4 */
d. // comment 1
Question10
In the method header the static method modifier means the method is available to code outside the class.
a. True
b. False
Question11
You can use the PrintWriter class to open a file for writing and write data to it.
a. False
b. True
Question12
A value-returning method must specify this as its return type in the method header.
a. an int
b. any valid data type
c. a double

d. a boolean
Question13
The expression tested by an if statement must evaluate to
a. t or f
b. +1 or -1
c. true or false
d. 0 or 1
Question14
Which of the following statements will create a reference, str, to the String, Hello, World?
Whlen Sie eine Antwort:
a. String str = "Hello, World";
b. str = "Hello, World";
c. String str = new "Hello, World";
d. string str = "Hello, World";
Question15
The GridLayout manager limits each cell to only one component. To put two or more components in a cell, do
this.
Whlen Sie eine Antwort:
a. Resize the components to fit in the cell
b. The statement is false. The GridLayout manager does not have this restriction
c. You can nest panels inside the cells, and add other components to the panels
d. Resize the cells so they can hold more
Question16
What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
a. The text field x will have the value "Tiny Tim" and be read only.
b. The text field x will have the value "Tiny Tim" and the user will be able to change its value.
c. The text field x will have the value true.
d. The text field x have the value "trueTiny Tim"
Question17
A method that gets a value from a class's field but does not change it is known as a mutator method.
a. True
b. False
Question18
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one
for each delimiter character.
a. True

b. False
Feedback
Die richtige Antwort lautet: False
Question19
What would be displayed as a result of the following code?
int x = 578;
System.out.print("There are " + x + 5 + "\n" + "hens in the hen housE.");
a. There are x5\nhens in the hen housE.
b. There are 5785 hens in the hen housE.
c. There are 583 hens in the hen housE.
d. There are 5785
hens in the hen housE.
Question20
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
a. This is an infinite loop
b. 110
c. 210
d. 90
Question21
What will be returned from the following method?
public static int methodA()
{
double a = 8.5 + 9.5;
return a;
}
a. 8.0
b. 18.0
c. This is an error
d. 18 (as an integer)
Question22
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);

timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
a. 2
b. 4
c. 1
d. 3
Question23
Richtig
Erreichte Punkte 1,00 von 1,00

Questionmarkieren
Fragetext
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster
if the subexpression that is most likely false is on the left of the && operator.
Whlen Sie eine Antwort:
a. True
b. False
Question24
What will be displayed as a result of executing the following code?
public class test
{
public static void main(String[] args)
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}
a. 9 45 16
b. Nothing, this is an error
c. 9 45 16
d. 94516
Question25
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
a. diddle

b. diddl
c. , didd
d. Iddle
Question26
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y--;
a. x = 17, y = 5
b. x = 16, y = 4
c. x = 17, y = 4
d. x = 12, y = 5
Question27
What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
a. 1000
b. 2000
c. 1250
d. 1500
Question28
This type of loop is ideal in situations where you always want the loop to iterate at least once.
Whlen Sie eine Antwort:
a. do-while loop
b. if statement
c. for loop
d. while loop
Question29
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}

a. 100
b. 90
c. 110
d. This is an infinite loop
Question30
Variables of the boolean data type are useful for
a. working with very large integers
b. evaluating scientific notation
c. evaluating true/false conditions
d. working with small integers
Question31
In the following code, Integer.parseInt(str), is an example of ________.
int num;
string str = "555";
num = Integer.parseInt(str) + 5;
a. a value-returning method
b. a local variable
c. a complex method
d. a void method
Question32
Richtig
Erreichte Punkte 1,00 von 1,00
Which of the following are pre-test loops?
a. while, for, do-while
b. while, for
c. for, do-while
d. while, do-while
Question33
The data contained in an object is known as:
a. Attributes
b. Atriums
c. Classes
d. Methods
Question34
Class names and key words are examples of variables.
a. True
b. False
Question35
Local variables can be initialized with
Whlen Sie eine Antwort:

a. any of the above


b. the results of an arithmetic operation
c. parameter values
d. constants
Question36
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which
contains several button components. If you want to add the buttons to the panel...
a. add each button to panel one at a time, e.g. panel.add(button1);
b. use the statement, panel.add(bGroup);
c. use the statement, bGroup.add(panel);
d. use the statement, Panel panel = new Panel(bGroup);
Question37
In Java, when a character is stored in memory, it is actually stored as a
Whlen Sie eine Antwort:

_____.

a. Morse code
b. EBCDIC character code
c. ASCII character code
d. Unicode number
Question38
The scope of a private instance field is
a. the instance methods of the same class
b. inside the parentheses of a method header
c. the method in which they are defined
d. inside the class, but not inside any method
Question39
Syntax is:
a. Symbols or words that perform operations
b. Punctuation
c. Words that have a special meaning in the programming language
d. Rules that must be followed when writing a program
Question40
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
a. True
b. False

You might also like