Sunteți pe pagina 1din 62

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); becareful: if there is semi column, its infinite loop
{

x += 10;
}
Select one:
a. 100
b. 90
c. This is an infinite loop X
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 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 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 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 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 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. Becareful, which one has new line
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 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 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 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 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
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 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 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 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 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 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 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 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 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 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 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 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 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 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 23
One or more objects may be created from a
Select one:
a. field
b. instance
c. method
d. class
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 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 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 37
Logical errors are mistakes that cause the program to produce erroneous results.
Select one:
a. True
b. False
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 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 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 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 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 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 20
The data contained in an object is known as:
Select one:
a. Methods
b. Atriums
c. Attributes
d. Classes
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;
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 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 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 35
Which Scanner class method reads a String?
Select one:
a. readString()
b. getString()
c. nextString()
d. nextLine()
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 7
A constructor is a method that is automatically called when an object is created.
Select one:
a. False
b. True
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 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
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 20
Instance methods do not have the key word static in their headers.
Select one:
a. True
b. False
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 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 27
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100) becarefule, no semi column in the while line so its 100
{
x += 10;
}
Select one:
a. 90
b. 110
c. 100
d. This is an infinite loop
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
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
a. token
b. delimiter
c. buffer
d. separator
Question6
To document the return value of a method, use this in a documentation comment.
a. The @return tag
b. The @param tag
c. The @comment tag
d. The @returnValue tag
Question12
Key words are:
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
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.
a. Dialog box
b. Frame
c. Pane
d. Container
Question22
The ___________ is normally considered the standard output and standard input devices, and usually refer to
the monitor and keyboarD.
a. console
b. CPU
c. CRT
d. secondary storage devices

Question24
Another term for programs is:
a. Peopleware
b. Firmware
c. Hardware
d. Software
Question25
Which of the following is not a part of the method header?
a. method name
b. parentheses
c. semicolon
d. return type
Question29
Methods that operate on an object's fields are called
a. instance methods
b. instance variables
c. public methods
d. private methods
Question33
When testing for character values, the switch statement does not test for the case of the character.
a. True
b. False
Question35
In the method header, the method modifier public means that the method belongs to the class, not a specific
object.
a. True
b. False
Question39
Java was developed by
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.
a. True
b. False
Question6
A loop that executes as long as a particular condition exists is called a[n]
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:
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
Question10
A class specifies the ________ and ________ that a particular type of object has.
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?
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 /*
Question21
Computers can do many different jobs because they are:
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.
a. True
b. False
Question29
A runtime error is usually the result of:
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


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
Question39
Before entering a loop to compute a running total, the program should first do this.
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
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?
a. while (inputFile.hasNext()) { }
b. while (inputFile.nextLine == " ") { }
c. while (!inputFile.EOF) { }
d. while (inputFile != null) { }
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.
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.
a. False
b. True
Question14
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 Java the variable named one is the same as the variable named OnE.
a. False
b. True
Question28
Which of the following is not a valid comment statement?
a. // comment 1

b. */ comment 3 /*
c. /** comment 4 */
d. /* comment 2 */
Question31
A constructor is a method that
a. returns an object of the class.
b. never receives any arguments.
c. performs initialization or setup operations.
d. with the name ClassName.constructor.
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;
a. 1250
b. 1500
c. 1000
d. 2000
Question40
This part of a method is a collection of statements that are performed when the method is executed.
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;
a. 7.00
b. 14.00

c. 21.00
d. 28.00
Question7
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is
returneD.
a. True
b. False
Question10
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
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.
a. True
b. False
Question17
Variables of the boolean data type are useful for
a. evaluating true/false conditions
b. evaluating scientific notation
c. working with very large integers
d. working with small integers
Question22
Which Scanner class method reads an int?
a. getInt()
b. nextInt()
c. read_int()
d. readInt()
Question27
A byte is a collection of:
a. Eight bits
b. A dollar
c. Six bits
d. Four bits
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. 2
c. 1, 2, and 3 will all work
d. 3
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;
a. Invalid for statement
b. 25
c. 30
d. 40
Question13
You must call a method to get the value of a wrapper class object.
a. True
b. False
Question14
This is a named storage location in the computer's memory.
a. Literal
b. Constant
c. Operator
d. Variable
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;
a. 60
b. 135
c. 15
d. 75
Question37
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. 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);
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());
}
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 33
A do-while loop must be terminated with a semicolon.
Select one:
a. True
b. False
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 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 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 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 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 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 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 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 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 24
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Select one:
a. False
b. True
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 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 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 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 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 31
Variables are classified according to their
Select one:
a. value
b. names
c. data type
d. location in the program
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 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 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 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 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 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 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 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 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
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")
This layout manager arranges components in five regions.
Select one:
a. RegionLayout
b. GridLayout
c. FlowLayout
d. BorderLayout
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
Which of the following will format .1278 to display as 12.8%?
Select one:
a. 000.0%
b. ##0.0%
c. #0.00%
d. ###.##%
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 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 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 25
Question text
To convert the int variable number to a string, use the following statement.
Select one:
a. String str = Integer.toString(number); I is capital
b. String str = integer.toString(number);

c. String str = integer(number);


d. String str = number.Integer.toString(str);
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 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 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 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 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 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 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 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 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";


Question13
These are used to indicate the end of a Java statement.
a. Colons
b. Semicolons
c. Periods
d. Asterisks
Question10
Application software refers to:
a. Key words
b. The programs that make the computer useful to the user
c. Pseudocode
d. The operating system
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);
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))
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
Which of the following will compile a program called ReadIt?
a. javac ReadIt.javac
b. javac ReadIt.java
c. java ReadIt.java
d. java ReadIt.javac
Question15
A Java program must have at least one of these:
a. Comment
b. System.out.println(); statement
c. Class definition
d. Variable
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
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.
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
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

correct answer

XX wrong answer

c. 110
d. 210
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)
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
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
Question34
Class names and key words are examples of variables.
a. True
b. False

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. This is an infinite loop
b. 100
c. 110
d. 90
Feedback
Die Antwort ist falsch
EN: it is an endless loop! just after 'while (x < 100)' there is a ';', do you see it now? the next
lines of code will never be reached.
--DE: bereits nach 'while' ist die schleife zu Ende! es gibt keine Erhhung von x.
Die richtige Antwort lautet: This is an infinite loop
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. 0.0
b. .01
c. .05
d. .03
Feedback
Die Antwort ist falsch
Da purchase keine der Bedingungen erfllt bleibt der Wert fr discountRate gleich: 0.0
Die richtige Antwort lautet: 0.0

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. 8.0
c. 18 (as an integer)
d. This is an error
Feedback
Die Antwort ist falsch
Die richtige Antwort lautet: This is an error
When an object is created, the attributes associated with the object are called
Whlen Sie eine Antwort:
a. instance fields
b. instance methods
c. fixed attributes
d. class instances
Feedback
Die richtige Antwort lautet: instance fields

S-ar putea să vă placă și