100% found this document useful (1 vote)
2K views

Oracle Fondation 2

When a program runs without debug mode, breakpoints will stop program execution at the first breakpoint but not affect execution otherwise.

Uploaded by

illiyine vierda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Oracle Fondation 2

When a program runs without debug mode, breakpoints will stop program execution at the first breakpoint but not affect execution otherwise.

Uploaded by

illiyine vierda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 49

When the

program Mark for Review


runs (1) Points
normally
(when not in
debug
mode),
which
statement is
true about
breakpoints?
Any Breakpoint will stop program execution.

Breakpoints will stop program execution at the


first breakpoint.
Breakpoints will not have any effect on program
execution. (*)
Breakpoints will stop program execution at the
last breakpoint.
Correct

2. Which two are the correct syntax for adding


comments? Mark for Review
(1) Points
(Choose all correct answers)
Start with two slashes and a star (//*). End with
a star-slash (*/).
Start with two slashes (//). End when the line
ends. (*)
Start with a slash-star (/*). End with a star-slash
(*/). (*)
Start with a slash- star (/*). End with slash-star
(/*).
Start with two slashes (//). End with two slashes
(//).
Incorrect. Refer to Section 2 Lesson 2.

3. A Java program can be written in the single line.


Mark for Review
(1) Points
True (*)

False

Correct

4. Java mostly reads code line-by-line.


Mark for Review
(1) Points
True (*)

False

Correct

5. Which of the following 2 statements are true about


whitespace? Mark for Review
(1) Points
(Choose all correct answers)
Whitespace increases execution time of your
program.
Whitespace helps to keep your code organized.
(*)
Whitespace eliminates typing mistakes while
programming.
Whitespace makes your code more readable. (*)

Whitespace reduces the performance of the


program.
6. Which of
the Mark for Review
following (1) Points
two
features
are
supported
by the
NetBeans
IDE.
(Choose all correct answers)
NetBeans provides a shortcut to format whitespace. (*)

NetBeans automatically runs the program once all the braces in the
code are matched.
Once NetBeans spots a problem, it won’t allow you to continue coding
until the progrblem is fixed.
NetBeans highlights matching braces. (*)

Incorrect. Refer to Section 2 Lesson 2.

7. There are several fields and methods in a Shirt class. Which of the following
could be a method in the Shirt class? Mark for Review
(1) Points
price

color

size

getShirtSize() (*)

Correct

8. In object oriented programming, an object comprises of properties and


behaviors where properties represented as fields of the object and behavior Mark for Review
is represented as method. (1) Points

True (*)

False

Correct

9. In the code example below, identify any methods:


Mark for Review
public class Employee { (1) Points
public String name = " Duke";
public int empId = 12105;
public float salary;

public void displaySalary(){


System.out.println("Employee Salary: "+salary);
}
}
name

salary

displaySalary() (*)

empId

Correct

10. Which of the following language is called a procedural language?


Mark for Review
(1) Points
Java

C++

C (*)

Java C

Incorrect. Refer to Section 2 Lesson 3.

11. You have a


beautiful Mark for Review
garden at (1) Points
home. On
Sunday,
you start
budding
your rose
plant to
make few
more
samples of
rose plants
to plant in
the garden.
Can you
categorize
how this
scenario
could be
represented
by classes
and
instances?
Samples are the class and the rose plant is the instances of samples.

Rose plant is the class and the samples generated from the rose
plant are instances of that class. (*)
Rose plant is the object and samples are not instances of the plant
because they have not grown yet.
Samples of the rose plant are called classes and not the actual rose
plant.
Correct

12. A software feature may allow the user to perform a specific task.
Mark for Review
(1) Points
True (*)
False

Correct

13. If the requirement step of the Spiral Model of development is forgotten,


which of the following could occur? Mark for Review
(1) Points
Code becomes messy.

Solutions seem elusive.

The Program gives inaccurate results.

Required software features are missing from the program. (*)

Correct

14. During the Testing phase of software development, which of the


following are the tasks undertaken by the programmer? Mark for Review
(1) Points
(Choose all correct answers)
Finding the bugs. (*)

Fixing the bugs. (*)

Planning the order to implement features.

Listing required features.

Correct

15. You’d like to see a movie with a few friends. You write an email to
confirm plans. Mark for Review
(1) Points
Hi Friends,
There’s a new movie “Attack of the Duke!” premiering this Friday at
Oracle Cinema at 4:30 PM. The cinema is at the corner of South Street
and Walnut Ave. Subway would be the best way to get there.

Would any of you be interested in going?

Which of the following are requirements for this plan?


Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30 PM.
(*)
Reach the cinema by 4:00 PM.

Double check the location by verifying you’re on South Street and


Walnut Ave.
Travel via subway.

Correct

1. During the
Design phase of Mark for Review
software (1) Points
development,
the programmer
implements
features
gathered during
the Requirement
phase.
True

False (*)

Correct
2. During the Testing phase of software development, which of the
following are the tasks undertaken by the programmer? Mark for Review
(1) Points
(Choose all correct answers)
Fixing the bugs. (*)

Finding the bugs. (*)

Listing required features.

Planning the order to implement features.

Correct
3. The Spiral Model reflects an iterative development process.
Mark for Review
(1) Points
True (*)

False

Correct
4. You’d like to see a movie with a few friends. You write an email to
confirm plans. Mark for Review
(1) Points
Hi Friends,
There’s a new movie “Attack of the Duke!” premiering this Friday at
Oracle Cinema at 4:30 PM. The cinema is at the corner of South
Street and Walnut Ave. Subway would be the best way to get there.

Would any of you be interested in going?

Which of the following are requirements for this plan?


Double check the location by verifying you’re on South Street
and Walnut Ave.
Travel via subway.

Reach the cinema by 4:00 PM.

Watch “Attack of the Duke!” on Friday at Oracle Cinema at


4:30 PM. (*)
Correct
5. A breakpoint can be set by clicking a number in the left margin of
the IDE. Clicking again removes the breakpoint. Mark for Review
(1) Points
True (*)

False

Correct
6. Which of the
following Mark for Review
three (1) Points
statements
are true about
breakpoint?
(Choose all correct answers)
They abruptly ends the code execution.

They pause code execution. (*)

They help with debugging. (*)

They insert break statements.

They can be used to check the current state of the program (*)

Correct
7. Java mostly reads code line-by-line.
Mark for Review
(1) Points
True (*)

False

Correct
8. What is the purpose of adding comments in the code?
Mark for Review
(1) Points
Provide good look and feel of the code.

Provide an explanation about the code to the programmer. (*)

It increases the execution time of the code.

To provide better security to the program.

Correct
9. You can set any number of breakpoints for your program.
Mark for Review
(1) Points
True (*)

False

Correct
10. Which of the following 2 statements are true about whitespace?
Mark for Review
(1) Points
(Choose all correct answers)
Whitespace reduces the performance of the program.

Whitespace helps to keep your code organized. (*)

Whitespace eliminates typing mistakes while programming.

Whitespace makes your code more readable. (*)

Whitespace increases execution time of your program.

Correct
11. In object
oriented Mark for Review
programming, (1) Points
there is an
emphasis on
which of the
following two:
(Choose all correct answers)
Modeling objects. (*)

Writing algorithms.

Creation of procedures.

Object interaction without a prescribed order. (*)

Correct
12. You have a beautiful garden at home. On Sunday, you start
budding your rose plant to make few more samples of rose Mark for Review
plants to plant in the garden. Can you categorize how this (1) Points
scenario could be represented by classes and instances?
Rose plant is the class and the samples generated from the
rose plant are instances of that class. (*)
Rose plant is the object and samples are not instances of
the plant because they have not grown yet.
Samples of the rose plant are called classes and not the
actual rose plant.
Samples are the class and the rose plant is the instances of
samples.
Correct
13. In the code example below, identify any methods:
Mark for Review
public class Employee { (1) Points
public String name = " Duke";
public int empId = 12105;
public float salary;

public void displaySalary(){


System.out.println("Employee Salary: "+salary);
}
}
displaySalary() (*)

name

empId

salary

Correct
14. In object oriented programming, an object comprises of
properties and behaviors where properties represented as fields Mark for Review
of the object and behavior is represented as method. (1) Points

True (*)

False

Correct
15. An object may interact with another object by invoking methods.
Mark for Review
(1) Points
True (*)
False
Correct
1. Which two are
recommended Mark for Review
practices for (1) Points
naming final
variables?
(Choose all correct answers)
Capitalize every letter (*)

Separate words with an underscore (*)

Capitalize first letter

Separate words with an space

Correct
2. What is the range of the byte data type?
Mark for Review
(1) Points
–27 to 27–1 (*)

–215 to 215–1

–231 to 231–1

–263 to 263–1

Correct
3. This declaration represents a long data type.
long a = 123L; Mark for Review
(1) Points
True (*)

False

Correct
4. Which of the following data types is the largest?
Mark for Review
(1) Points
byte

short

int

long (*)

Incorrect. Refer to Section 3 Lesson 2.


5. How many bits are in a byte?
Mark for Review
(1) Points
2

8 (*)

Correct
6. Which keyword
makes a variable’s Mark for Review
value (1) Points
unchangeable?
const

final (*)

static

break

Correct
7. Which data type is most commonly used to represent numeric
data? Mark for Review
(1) Points
int (*)

float

String

short

Correct
8. Assuming x is an int, which of the following are ways to increment
the value of x by 1? Mark for Review
(1) Points
(Choose all correct answers)
x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)

Correct
9. Identify the variable declared in the given code.
Mark for Review
public class Welcome { (1) Points
public static void main(String args[]) {
int a = 2;
System.out.println("a is " + a);
}
}
Welcome

a (*)

int

Correct
10. Which is valid syntax to declare and initialize a String variable?
Mark for Review
(1) Points
String x= “Java”; (*)
String “x” = Java;

String “x” = “Java”;

String x = Java;

Correct
11. Assigning a
value to the Mark for Review
variable is called (1) Points
“initialization”.
True (*)

False

Correct
12. Identify the names of two variables used in the given code.
Mark for Review
public class Variables { (1) Points
public static void main(String args[]) {
String strVal = "Hello";
int intVal = 0;
System.out.println("Integer: " +intVal)
}
}
(Choose all correct answers)
String

intVal (*)

int

strVal (*)

Hello

Incorrect. Refer to Section 3 Lesson 1.


13. What is the output?
Mark for Review
public class Hello { (1) Points
public static void main(String args[]) {
String str = ”Hello”;
str = ”World”;
System.out.println(str);
}
}
World (*)

Hello

Hello
World
Hello World

Incorrect. Refer to Section 3 Lesson 1.


14. Which two are valid?
Mark for Review
(1) Points
(Choose all correct answers)
double doubleVar1; doubleVar2 = 3.1.
double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)

double doubleVar1, doubleVar2 = 3.1; (*)

double doubleVar1, double doubleVar2 = 3.1;

Incorrect. Refer to Section 3 Lesson 1.


15. Java is a strongly typed language; therefore you must declare a
data type for all variables. Mark for Review
(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 1.


1. How
many Mark for Review
bits are (1) Points
in a
byte?
2

8 (*)

Correct
2. Assuming x is an int, which of the following are ways to increment the value
of x by 1? Mark for Review
(1) Points
(Choose all correct answers)
x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)

Correct
3. Which of the following data types is the largest?
Mark for Review
(1) Points
byte

short

int

long (*)

Correct
4. Which two are mathematical operators?
Mark for Review
(1) Points
(Choose all correct answers)
+ (*)

– (*)

Correct
5. This declaration represents a long data type.
long a = 123L; Mark for Review
(1) Points
True (*)

False

Correct
6. Which keyword
makes a variable’s Mark for Review
value (1) Points
unchangeable?
const

final (*)

static

break

Correct
7. Which data type is most commonly used to represent numeric
data? Mark for Review
(1) Points
int (*)

float

String
short

Correct
8. What is the output? public static void main(String args[]) {
int x = 100; Mark for Review
int y = x; (1) Points
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct
9. Which is valid syntax to declare and initialize a String variable?
Mark for Review
(1) Points
String “x” = Java;

String x = Java;

String “x” = “Java”;

String x= “Java”; (*)

Incorrect. Refer to Section 3 Lesson 1.


10. Which two data types are appropriate for their variable?
Mark for Review
(1) Points
(Choose all correct answers)
int averageDollarAmount = 19.95;

double checkingAmount = 1500; (*)

String firstName = “Alex”; (*)

boolean age = 20;

Incorrect. Refer to Section 3 Lesson 1.


11. Which two
statements Mark for Review
will not (1) Points
compile?
(Choose all correct answers)
int abc = 10;

double double=10; (*)

int age=20;

int break=10; (*)

double salary = 20000.34;

Incorrect. Refer to Section 3 Lesson 1.


12. Identify the names of two variables used in the given code.
Mark for Review
public class Variables { (1) Points
public static void main(String args[]) {
String strVal = "Hello";
int intVal = 0;
System.out.println("Integer: " +intVal)
}
}
(Choose all correct answers)
Hello

intVal (*)

int

strVal (*)

String

Correct
13. Assigning a value to the variable is called “initialization”.
Mark for Review
(1) Points
True (*)

False

Correct
14. Which two are valid?
Mark for Review
(1) Points
(Choose all correct answers)
double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)

double doubleVar1; doubleVar2 = 3.1.

double doubleVar1, double doubleVar2 = 3.1;

double doubleVar1, doubleVar2 = 3.1; (*)

Correct
15. Which of the following two statements are true about variables?
Mark for Review
(1) Points
(Choose all correct answers)
They make code more flexible. (*)

The allow code to be edited more efficiently. (*)

Variables will be ignored by compiler.

The value assigned to a variable may never change.

Correct
1. char is the
primitive Mark for Review
textual (1) Points
data type
in Java.
True (*)

False

Correct
2. Which two statements compile?
Mark for Review
(1) Points
(Choose all correct answers)
String name = “J”; (*)

String name = ‘Java’;

String name = new String ( ‘Java’);

String name = “Java”; (*)

Incorrect. Refer to Section 3 Lesson 3.


3. A character preceded by backslash is called an escape sequence.
Mark for Review
(1) Points
True (*)

False

Correct
4. What is the output?
Mark for Review
public static void main(String args[]) { (1) Points
String greet1 = "Hello";
String greet2 = "World";
String message2 = greet1 +" " +greet2 +" " +2016 +"!";
System.out.println(message2);
}
Hello World

Hello World 2016 ! (*)

“Hello” “World” “2016” “!”

“Hello World 2016”

Incorrect. Refer to Section 3 Lesson 3.


5. A String can be created by combining multiple String Literals.
Mark for Review
(1) Points
True (*)

False

Correct
6. Which two
statements are Mark for Review
true about (1) Points
String
concatenation.
(Choose all correct answers)
String concatenation cannot be done with more than two String
Literals.
String concatenation can be done with String variables and
String Literals. (*)
Strings can be combined using the ‘+’ operator (*)

String concatenation cannot be done with numbers.

Incorrect. Refer to Section 3 Lesson 3.


7. System.in readies Scanner to collect input from the console.
Mark for Review
(1) Points
True (*)

False

Correct
8. Which two statements are true about the Scanner class?
Mark for Review
(1) Points
(Choose all correct answers)
A Scanner object doesn’t have fields and methods.
A Scanner’s delimiter can be changed. (*)

A Scanner object opens a stream for collecting input. (*)

Scanners cannot read text files.

Incorrect. Refer to Section 3 Lesson 5.


9. The Scanner class accepts input in which form?
Mark for Review
(1) Points
Future

Tokens (*)

Callables

Integer

Incorrect. Refer to Section 3 Lesson 5.


10. The Java compiler automatically promotes byte, short, and chars data
type values to int data type. Mark for Review
(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 4.


11. What is
parsing? Mark for Review
(1) Points
Reading text from numeric data

Converting numeric data to a specified numeric data type

Converting text to numeric data (*)

Converting numeric data to text

Incorrect. Refer to Section 3 Lesson 4.


12. A double with the value of 20.5 is cast to an int. What is the value of the
int? Mark for Review
(1) Points
21

20 (*)

25

20.5

Incorrect. Refer to Section 3 Lesson 4.


13. A short data type can be promoted to which of the following types?
Mark for Review
(1) Points
(Choose all correct answers)
int (*)

double (*)
boolean
long (*)

byte

Incorrect. Refer to Section 3 Lesson 4.


14. What is the correct way to cast a long to an int?
Mark for Review
(1) Points
int longToInt = 20L(int);

int longToInt = 20L;

int longToInt = (int)20L; (*)

int longToInt = int 20L;

Incorrect. Refer to Section 3 Lesson 4.


15. Which is a valid way to parse a String as an int?
Mark for Review
(1) Points
nt intVar1 = (int)"100";

int intVar1 = Integer.parseInt("One Hundred");

int intVar1 = "100";

int intVar1 = Integer.parseInt("100"); (*)

Correct
1. When the
result of an Mark for Review
expression (1) Points
is assigned
to a
temporary
memory
location,
what is the
size of
memory
allocated?
The size of the smallest data type used in the expression.

A default size is allocated.

The size of the any data type used in the expression.

The size of the largest data type used in the expression. (*)

Incorrect. Refer to Section 3 Lesson 4.


2. A double with the value of 20.5 is cast to an int. What is the value of the
int? Mark for Review
(1) Points
20.5

20 (*)

21

25

Correct
3. Which exception occurs because a String cannot be parsed as an int?
Mark for Review
(1) Points
NumberFormatException (*)

ArithmeticException

NullPointerException

ValueNotFoundException

Incorrect. Refer to Section 3 Lesson 4.


4. A short data type can be promoted to which of the following types?
Mark for Review
(1) Points
(Choose all correct answers)
double (*)

int (*)

boolean

byte

long (*)

Correct
5. Which is a valid way to parse a String as an int?
Mark for Review
(1) Points
int intVar1 = Integer.parseInt("100"); (*)

int intVar1 = Integer.parseInt("One Hundred");

nt intVar1 = (int)"100";

int intVar1 = "100";

Correct
6. The Java
compiler Mark for Review
automatically (1) Points
promotes
byte, short,
and chars
data type
values to int
data type.
True (*)

False

Correct
7. It's best-practice to close the Scanner stream when finished
Mark for Review
(1) Points
True (*)

False

Correct
8. The Scanner class considers space as the default delimiter while
reading the input. Mark for Review
(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 5.


9. Which two statements are true about the Scanner class?
Mark for Review
(1) Points
(Choose all correct answers)
A Scanner object opens a stream for collecting input. (*)

Scanners cannot read text files.

A Scanner’s delimiter can be changed. (*)

A Scanner object doesn’t have fields and methods.

Correct
10. char is the primitive textual data type in Java.
Mark for Review
(1) Points
True (*)

False

Correct
11. Which two
statements are Mark for Review
true about (1) Points
String
concatenation.
(Choose all correct answers)
Strings can be combined using the ‘+’ operator (*)
String concatenation cannot be done with numbers.

String concatenation can be done with String variables and


String Literals. (*)
String concatenation cannot be done with more than two String
Literals.
Correct
12. A String can be created by combining multiple String Literals.
Mark for Review
(1) Points
True (*)

False

Correct
13. Char data types cannot handle multiple characters.
Mark for Review
(1) Points
True (*)
False
Correct
14. An Object cannot have String objects as properties.
Mark for Review
(1) Points
True

False (*)

Correct
15. A character preceded by backslash is called an escape sequence.
Mark for Review
(1) Points
True (*)

False

Correct
1. Methods
allow all Mark for Review
instance of (1) Points
a class to
share
same
behaviors.
True (*)

False

Correct
2. Which of the following statements are true?
Mark for Review
(1) Points
(Choose all correct answers)
Methods can be written with any number of parameters. (*)

Methods can never be written with more than four parameters.

Parameter values can never be used within the method code block.

Parameter values can be used within the method code block. (*)

Methods cannot be written with parameters.

Correct
3. In Java, methods usually hold the properties of an object.
Mark for Review
(1) Points
True

False (*)

Correct
4. An argument is a value that's passed during a method call
Mark for Review
(1) Points
True (*)

False
Correct
5. Once an object is instantiated, how might its fields and methods be
accessed in Java? Mark for Review
(1) Points
Using the double-colon(::) operator

Using the comma(,) operator

Using the colon(:) operator

Using the dot(.) operator (*)

Incorrect. Refer to Section 4 Lesson 1.


6. void
type Mark for Review
methods (1) Points
don’t
return
any
values
True (*)

False

Incorrect. Refer to Section 4 Lesson 1.


7. Which of the following scenarios would be ideal for writing a method?
Mark for Review
(1) Points
When you don’t want to repeat similar lines of code to describe an
object’s behavior. (*)
When you don’t find similar lines of code to describe an object’s
behavior.
For every five to six lines of code.

To group similar data types together

Incorrect. Refer to Section 4 Lesson 1.


8. Which of the following are the arguments in the following method?
Mark for Review
Employee emp = new Employee(); (1) Points
emp.calculateSalary(100000, 3.2, 15);
emp.calculateSalary(100000, 3.2, 15);

calculateSalary(100000, 3.2, 15);

emp

100000, 3.2, 15 (*)

Incorrect. Refer to Section 4 Lesson 1.


9. Which package is implicitly imported?
Mark for Review
(1) Points
java.math

ava.awt

java.io
java.lang (*)
Incorrect. Refer to Section 4 Lesson 2.
10. Import statements are placed above the class definition.
Mark for Review
(1) Points
True (*)

False

Correct
11. Which two
are valid Mark for Review
import (1) Points
statements
of the
Scanner
class?
(Choose all correct answers)
import java.util.*; (*)

import java.util;

import java.util.Scanner; (*)

import java.*;

Incorrect. Refer to Section 4 Lesson 2.


12. The classes of the Java class library are organized into packages.
Mark for Review
(1) Points
True (*)

False

Correct
13. Given the import statement:
import java.awt.font.TextLayout; Mark for Review
which is the package name? (1) Points

java

java.awt

awt.font

java.awt.font (*)

Incorrect. Refer to Section 4 Lesson 2.


14. The JFrame and JOptionPane classes are in the javax.swing package.
Which two will import those classes? Mark for Review
(1) Points
(Choose all correct answers)
import javax.swing.J*;

import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing.*; (*)

import javax.swing;

Incorrect. Refer to Section 4 Lesson 2.


15. The import statement consists of two parts.
Mark for Review
import package.className; (1) Points

One is the package name and the other is the classname.


True (*)

False

Incorrect. Refer to Section 4 Lesson 2.


1. An
argument is Mark for Review
a value (1) Points
that's
passed
during a
method call

True (*)

False

Correct

2. Object instantiation is done using what keyword?


Mark for Review
(1) Points
void

System

instance

new (*)

Incorrect. Refer to Section 4 Lesson 1.

3. Which of the following are the arguments in the following method?


Mark for Review
Employee emp = new Employee(); (1) Points
emp.calculateSalary(100000, 3.2, 15);
100000, 3.2, 15 (*)

emp.calculateSalary(100000, 3.2, 15);

calculateSalary(100000, 3.2, 15);

emp

Correct

4. Which is a valid way of calling the testMethod in the TestClass? Assume a


testInstance has been created. Mark for Review
(1) Points
public void testMethod(int x, double y){
System.out.println(x/y);
}

testInstance.testMethod(3.5, 10);

testInstance.testMethod(3.5);

testInstance.testMethod(10);
testInstance.testMethod(10, 3.5, 0);
testInstance.testMethod(10, 3.5); (*)

Correct

5. Once an object is instantiated, how might its fields and methods be


accessed in Java? Mark for Review
(1) Points

Using the double-colon(::) operator

Using the dot(.) operator (*)

Using the comma(,) operator

Using the colon(:) operator

Correct
6. Which of
the Mark for Review
following (1) Points
scenarios
would be
ideal for
writing a
method?

To group similar data types together

When you don’t want to repeat similar lines of code to describe an


object’s behavior. (*)
When you don’t find similar lines of code to describe an object’s
behavior.
For every five to six lines of code.

Correct

7. void type methods don’t return any values


Mark for Review
(1) Points
True (*)

False

Correct

8. Methods allow all instance of a class to share same behaviors.


Mark for Review
(1) Points
True (*)

False

Correct

9. Which is a risk of using fully qualified class names when importing?


Mark for Review
(1) Points
Memory usage is increased.

Code readability is reduced. (*)

The compiler runs longer.


Performance of the code is reduced.

Correct
10. Which two are valid import statements of the Scanner class?
Mark for Review
(1) Points

(Choose all correct answers)


import java.util;

import java.util.Scanner; (*)

import java.*;

import java.util.*; (*)

Correct
11. The JFrame
and Mark for Review
JOptionPane (1) Points
classes are in
the javax.swing
package.
Which two will
import those
classes?
(Choose all correct answers)

import javax.swing;

import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing.J*;

import javax.swing.*; (*)

Incorrect. Refer to Section 4 Lesson


2.
12. Import statements are placed above the class definition.
Mark for Review
(1) Points
True (*)

False

Correct

13. The classes of the Java class library are organized into packages.
Mark for Review
(1) Points
True (*)

False

Correct

14. Which package is implicitly imported?


Mark for Review
(1) Points

ava.awt

java.math
java.lang (*)

java.io
Correct

15. The import statement consists of two parts.


Mark for Review
import package.className; (1) Points

One is the package name and the other is the classname.


True (*)

False

Correct
1. What is the output?
Mark for Review
public static void main(String args[]) { (1) Points
char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants")
;
}
}
Consonants (*)

Vowels

Compilation error

Vowels

Correct

2. What is the output?


Mark for
public static void main(String args[]) { Review
char grade ='E'; (1) Points
if (grade == 'A') {
System.out.println("Excellent performer");
}else if (grade == 'B') {
System.out.println("Good Performer");
}else if (grade == 'C') {
System.out.println("Average Performer");
}else {
System.out.println("Below Average
Performer");
}
}
Excellent performer

Below Performer

Not a Good Performer

Below Average Performer (*)

Correct
3. What is the output?
Mark for
char grade = 'A'; Review
switch (grade) { (1) Points
case 'A':
System.out.println("Congratulations!"); cas
e 'B':
System.out.println("Good work");
case 'C':
System.out.println("Average");
case 'D':
System.out.println("Barely passing");
case 'F':
System.out.println("Failed");
}

Congratulations!

Congratulations! Good Work Average Barely


Passing Failed (*)
Failed

Correct

4. Which two of the following data types can be


used in a switch statement? Mark for
Review
(1) Points
(Choose all correct answers)
String (*)

boolean

float

int (*)

Correct

5. What are the possible values of a boolean data


type in Java? Mark for
Review
(1) Points

0/1

yes/no

true/false (*)

good/bad

Correct
6. A String
comparison Mark for Review
with == (1) Points
compares
the Strings’
locations in
memory and
not the
content of
the String.
True (*)

False

Correct

7. An if/else statement is used when you need to choose between two


alternatives. Mark for Review
(1) Points

True (*)

False

Correct

8. Which are used in a boolean expression?


Mark for Review
(1) Points
(Choose all correct answers)

Variables (*)

Operators (*)

Errors

Loops

Correct

9. Which operator is used to test if both sides of a boolean expression are


equal? Mark for Review
(1) Points
=

== (*)

>=

<=

Correct

10. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

No output

Bob is 43 (*)

Bob is 50

Bob is 43 Bob is 50

Correct
1. Which of
the Mark for
following Review
language (1) Points
is called a
procedural
language?
Java

Java C

C (*)

C++

Correct

2. You design a Circle class with various fields and methods. Which of the
following could be fields in this class? Distinguish which of these are Mark for Review
between the properties and behavior. (1) Points

(Choose all correct answers)

calculateDiameter()

radius (*)

color (*)

calculateCircumference()

calculateArea()

Correct

3. There are several fields and methods in a Shirt class. Which of the following
could be a method in the Shirt class? Mark for Review
(1) Points
getShirtSize() (*)

size

color

price

Correct

4. If the requirement step of the Spiral Model of development is forgotten,


which of the following could occur? Mark for Review
(1) Points
The Program gives inaccurate results.

Code becomes messy.

Required software features are missing from the program. (*)

Solutions seem elusive.

Incorrect. Refer to Section 2 Lesson 1.

5. The Spiral Model reflects an iterative development process.


Mark for Review
(1) Points
True (*)

False

Correct
6. You’d like to
see a movie Mark for
with a few Review
friends. You (1) Points
write an
email to
confirm
plans.

Hi Friends,
There’s a
new movie
“Attack of the
Duke!”
premiering
this Friday at
Oracle
Cinema at
4:30 PM. The
cinema is at
the corner of
South Street
and Walnut
Ave. Subway
would be the
best way to
get there.

Would any of
you be
interested in
going?

Which of the
following are
requirements
for this plan?
Double check the location by verifying you’re on South Street and
Walnut Ave.
Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30 PM.
(*)
Travel via subway.

Reach the cinema by 4:00 PM.

Correct

7. Which two are the correct syntax for adding comments?


Mark for Review
(1) Points
(Choose all correct answers)
Start with two slashes (//). End with two slashes (//).

Start with a slash- star (/*). End with slash-star (/*).

Start with a slash-star (/*). End with a star-slash (*/). (*)

Start with two slashes (//). End when the line ends. (*)

Start with two slashes and a star (//*). End with a star-slash (*/).

Incorrect. Refer to Section 2 Lesson 2.


8. You can set any number of breakpoints for your program.
Mark for Review
(1) Points
True (*)

False

Correct

9. A Java program can be written in the single line.


Mark for Review
(1) Points

True (*)

False

Correct

Section 3
(Answer all questions in this section)

10. Which two are valid assignments of a?


Mark for Review
(1) Points

(Choose all correct answers)


int a; a = 10; (*)

int a = 10; (*)

int a = 10

int a = “10”;

Correct
11. Assigning a
value to the Mark for
variable is Review
called (1) Points
“initialization”.
True (*)

False

Correct

12. Java is a strongly typed language; therefore you must declare a data
type for all variables. Mark for
Review
(1) Points

True (*)

False

Correct

13. Which two statements compile?


Mark for
Review
(1) Points
(Choose all correct answers)
char size = ”m”;

String size = ‘M’;

char size = ’m’; (*)

String size = “M”; (*)

Incorrect. Refer to Section 3 Lesson 3.

14. An Object cannot have String objects as properties.


Mark for
Review
(1) Points
True

False (*)

Correct

15. Given the expression:


Mark for
String message = ”Hello World”; Review
(1) Points
Which is the String Literal?

Hello World (*)

String message

message

String message = ”Hello World”;

Correct
16. What
is the Mark for
range Review
of the (1) Points
byte
data
type?
–27 to 27–1 (*)

–215 to 215–1

–231 to 231–1

–263 to 263–1

Correct

17. What is the output?


Mark for
public class Person { Review
public static void main(String args[]) { (1) Points
int age = 20;
System.out.println("Value of age: " +age);
age = 5 + 3;
System.out.println("Value of age: " +age);
age = age + 1;
age++;
System.out.println("Value of age: " +age);
}
}
Value of age: 20
Value of age: 8
Value of age: 10 (*)
Value of age: 20
Value of age: 28
Value of age: 38
Value of age: 20
Value of age: 208
Value of age: 20810
Value of age: 20
Value of age: 8
Value of age: 9
Correct

18. Which data type is most commonly used to represent numeric data?
Mark for
Review
(1) Points

int (*)

float

String
short

Correct

19. You write a statement that assigns a value to a String variable as shown below.
Mark for
String input = ”This is Java Program”; Review
(1) Points
This way of assigning values to variables is known as hard-coding.
True (*)

False

Correct

20. The Scanner class accepts input in which form?


Mark for
Review
(1) Points
Integer

Tokens (*)

Callables

Future

Correct
21. The
Scanner Mark for
class Review
considers (1) Points
space as
the
default
delimiter
while
reading
the
input.
True (*)

False

Correct

22. Which is a valid way to parse a String as an int?


Mark for
Review
(1) Points

int intVar1 = "100";

int intVar1 = Integer.parseInt("One Hundred");

int intVar1 = Integer.parseInt("100"); (*)

nt intVar1 = (int)"100";

Correct

23. Which two statements are true about type casting?


Mark for
Review
(1) Points
(Choose all correct answers)
Type casting lowers the range of possible values. (*)

Type casting retains the size of the value or the original data type.

Type casting cannot be performed on equations.

Type casting changes the type of the value stored. (*)

Correct

24. A double with the value of 20.5 is cast to an int. What is the value of the
int? Mark for
Review
(1) Points

20 (*)

25

20.5

21

Correct

Section 4
(Answer all questions in this section)

25. The replaceFirst() method replaces only the first occurrence of matching
character pattern in a string. Mark for
Review
(1) Points
True (*)

False

Correct
26. A String is
a sequence Mark for
characters. Review
(1) Points

True (*)

False

Correct

27. The indexOf() method returns the index value of a character in the string.
Mark for
Review
(1) Points
True (*)

False

Correct

28. What is the output?


Mark for
public static void main(String args[]) { Review
String alphaNumeric = "Java World!" + 8; (1) Points
System.out.println(alphaNumeric);
}

Compilation error.

Java World!8 (*)

Java World! + 8

Java World! 8

Incorrect. Refer to Section 4 Lesson 3.

29. You need to generate random integer values between 0 and 80


(inclusive). Which statement should you use? Mark for
Review
(1) Points
nextInt();

nextInt(81); (*)

nextInt(80);

nextInt(0-79);

Incorrect. Refer to Section 4 Lesson 4.

30. Which values are returned by the method nextBoolean();


Mark for
Review
(1) Points
Returns the next value.

An integer value.
Either a true or false. (*)

Nothing is returned.

Incorrect. Refer to Section 4 Lesson 4.


31. You need
to generate Mark for
random Review
integer (1) Points
values in
the range 2
through 10.
This code
fragment
will produce
the desired
result.

Random r
= new
Random();
r.nextInt(9)
+ 2;
True (*)

False

Correct

32. The import statement consists of two parts.


Mark for
import package.className; Review
(1) Points
One is the package name and the other is the classname.
True (*)

False

Correct

33. Which of the following wild card character is used to import all the classes
in a particular package? Mark for
Review
(1) Points

* (*)

Correct

34. Which two are valid import statements of the Scanner class?
Mark for
Review
(1) Points
(Choose all correct answers)
import java.util.Scanner; (*)

import java.util.*; (*)

import java.util;

import java.*;

Correct
35. Which package is implicitly imported?
Mark for
Review
(1) Points
java.math

ava.awt

java.io

java.lang (*)

Correct
36. In Java,
methods Mark for
usually Review
hold the (1) Points
properties
of an
object.
True
False (*)

Incorrect. Refer to Section 4 Lesson 1.

37. Which of the following two operations are appropriate for the main
method? Mark for
Review
(1) Points
(Choose all correct answers)
Calling an instance object’s field and methods. (*)

Assigning memory to the variables

Creating instances of objects (*)

Calling local variables declared within a class’s method

Incorrect. Refer to Section 4 Lesson 1.

38. Which of the following statements are true?


Mark for
Review
(1) Points
(Choose all correct answers)
Parameter values can never be used within the method code block.

Methods can never be written with more than four parameters.

Methods can be written with any number of parameters. (*)

Parameter values can be used within the method code block. (*)

Methods cannot be written with parameters.

Incorrect. Refer to Section 4 Lesson 1.

39. How many arguments does the following method accept?


Mark for
public void simpleInterest(double principal, int noofYears, double Review
interestRate){ (1) Points
System.out.println(“The interest rate is ” +interestRate );
}
3 (*)

Incorrect. Refer to Section 4 Lesson 1.

40. A constant field, like Math.PI is used to represent a fixed value.


Mark for
Review
(1) Points
True (*)

False

Correct
41. What is the
approximate Mark for
value of PI? Review
(1) Points
0

The value varies.

2.718

3.141 (*)

Incorrect. Refer to Section 4 Lesson 5.

Section 5
(Answer all questions in this section)
42. What is the output?
Mark for
public static void main(String args[]) { Review
char grade ='E'; (1) Points
if (grade == 'A') {
System.out.println("Excellent performer");
}else if (grade == 'B') {
System.out.println("Good Performer");
}else if (grade == 'C') {
System.out.println("Average Performer");
}else {
System.out.println("Below Average Performer");
}
}
Below Average Performer (*)

Excellent performer

Below Performer

Not a Good Performer

Incorrect. Refer to Section 5 Lesson 3.


43. What is the output?
Mark for
char grade = 'A'; Review
switch (grade) { (1) Points
case 'A':
System.out.println("Congratulations!"); case 'B':
System.out.println("Good work");
case 'C':
System.out.println("Average");
case 'D':
System.out.println("Barely passing");
case 'F':
System.out.println("Failed");
}
Congratulations! Good Work Average Barely Passing Failed (*)

Failed

Congratulations!

Correct

44. An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print? Mark for
Review
int rating; (1) Points
int experience;
if (rating > 1 && experience == 5) {
System.out.println (“Eligible for a bonus”);
}
5 rating and 1 experience

5 experience and 2 or more rating (*)

5 experience and 1 rating

Less than 5 experience and 1 rating.

Incorrect. Refer to Section 5 Lesson 2.

45. What is the result?


Mark for
public static void main(String[] args) { Review
int point = 10; (1) Points
String s = (point == 1 ? "point" : "points");
System.out.println("I scored " +point +" " +s );
}
Compilation error

I scored 10 points (*)

I scored 1 point 10 points

I scored 1 point

Correct
41. What is the
approximate Mark for
value of PI? Review
(1) Points

0
The value varies.
2.718

3.141 (*)

Incorrect. Refer to Section 4 Lesson 5.

Section 5
(Answer all questions in this section)
42. What is the output?
Mark for
public static void main(String args[]) { Review
char grade ='E'; (1) Points
if (grade == 'A') {
System.out.println("Excellent performer");
}else if (grade == 'B') {
System.out.println("Good Performer");
}else if (grade == 'C') {
System.out.println("Average Performer");
}else {
System.out.println("Below Average Performer");
}
}
Below Average Performer (*)

Excellent performer

Below Performer

Not a Good Performer

Incorrect. Refer to Section 5 Lesson 3.

43. What is the output?


Mark for
char grade = 'A'; Review
switch (grade) { (1) Points
case 'A':
System.out.println("Congratulations!"); case 'B':
System.out.println("Good work");
case 'C':
System.out.println("Average");
case 'D':
System.out.println("Barely passing");
case 'F':
System.out.println("Failed");
}
Congratulations! Good Work Average Barely Passing Failed (*)

Failed

Congratulations!

Correct

44. An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print? Mark for
Review
int rating; (1) Points
int experience;
if (rating > 1 && experience == 5) {
System.out.println (“Eligible for a bonus”);
}
5 rating and 1 experience

5 experience and 2 or more rating (*)

5 experience and 1 rating

Less than 5 experience and 1 rating.

Incorrect. Refer to Section 5 Lesson 2.

45. What is the result?


Mark for
public static void main(String[] args) { Review
int point = 10; (1) Points
String s = (point == 1 ? "point" : "points");
System.out.println("I scored " +point +" " +s );
}
Compilation error

I scored 10 points (*)

I scored 1 point 10 points

I scored 1 point

Correct
46. In a boolean
expression which Mark for
uses the && Review
operator, what (1) Points
would make this
expression
evaluate to true?

boolean x =
(firstCondition &&
secondCondition);
If both the first condition and second condition are false

If the first condition is false, but the second condition is true

If both the first condition and second condition are true (*)

If the first condition is true, but the second condition is false

Incorrect. Refer to Section 5 Lesson 2.

47. What is the output?


Mark for
public static void main(String[] args) { Review
String name = "Java"; (1) Points
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

True (*)

False

JavaProgramming

Java Programming

Correct
48. An if/else statement is used when you need to choose between
two alternatives. Mark for
Review
(1) Points
True (*)

False

Incorrect. Refer to Section 5 Lesson 1.

49. How should Strings be compared?


Mark for
Review
(1) Points

~=

==

The equals() method (*)

Incorrect. Refer to Section 5 Lesson 1.

50. A String comparison with == compares the Strings’ locations in


memory and not the content of the String. Mark for
Review
(1) Points
True (*)

False

Correct
1. What is the result?
Mark for Review
public static void main(String[] (1) Points
args) {
for (;;) {
System.out.println("Welcom
e to Java");
}
}

No error and no output.

Program prints “Welcome to Java” an infinite


number of times. (*)
Compilation error as expressions are missing in
the for loop.
Program prints “Welcome to Java” once.

Correct

2. Which statement will produce the output: 2, 4, 6, 8,


10? Mark for
Review
(1) Points
for (int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 0; i < 8; i += 2) {
System.out.print(i + " ");
}
for (int i = 1; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 2; i <= 10; i += 2) {
System.out.print(i + " ");
} (*)
Correct

3. A for loop is also called a definite loop


Mark for
Review
(1) Points
True (*)

False

Correct

4. Each expression in the header section of a for loop is


optional. Mark for
Review
(1) Points
True (*)

False

Correct

5. You want to compute the sum of all the marks of a


given subject. Which approach will you choose? Mark for
Review
(1) Points
if/else statement

Looping (*)

switch statement

if statement

Incorrect. Refer to Section


6 Lesson 1.
6. Given:
Mark for Review
for(int i (1) Points
= 0; i
> 10;
i++){ }
What
type of
variable
is i?

Global

Local (*)

Static

Member

Correct
7. After the loop is terminated, the statement immediately following the loop
body is executed. Mark for Review
(1) Points
True (*)

False

Correct

8. A pre-test loop evaluates the condition prior to execution of the loop.


Mark for Review
(1) Points

True (*)

False

Correct

9. Which of the two are pre-test loops?


Mark for Review
(1) Points
(Choose all correct answers)

while (*)

for (*)

forEach

do-while

Correct

10. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int num = 1;
while (num >= 200){
System.out.print(num + "" "");
num = num * 5;
}
}
1 5 25 125 175

No output. (*)

5 25 125

1 5 25 125

Correct
11. A while
loop is Mark for Review
often (1) Points
used
with
Scanner
input as
you
don't
know
many
times
you'll
need to
re-
prompt
the
user if
they
type
bad
data.
True (*)

False

Correct

12. Which loop type is considered to be a post-test loop?


Mark for Review
(1) Points
while

forEach

do-while (*)

for

Incorrect. Refer to Section 6 Lesson 2.

13. Which two statements are true about the break statement?
Mark for Review
(1) Points
(Choose all correct answers)
The execution of the program will continue with the statement following
the loop-statement. (*)
The execution of the program will stop at the statement following the
loop-statement.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately and comes out of the program.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately. (*)
Incorrect. Refer to Section 6 Lesson 3.

14. A continue statement is used to skip the remaining statements in the body of
a loop and continue with the next iteration of the loop. Mark for Review
(1) Points
True (*)

False

Correct

15. The purpose of adding comments is to increase the ability to understand the
logic easily. Mark for Review
(1) Points

True (*)

False

Incorrect. Refer to Section 6 Lesson 3.


1. The
structure Mark for Review
of a class (1) Points
consists of
properties
and
behaviors.
True (*)

False

Correct

2. You have created an Employee class with all required fields and methods.
10 employees join the company. Should you copy and paste the Employee Mark for Review
class for all 10 employees? (1) Points

True

False (*)

Incorrect. Refer to Section 7 Lesson 1.

3. Which two statements are true about the main method?


Mark for Review
(1) Points
(Choose all correct answers)
The main method should store the properties and behaviors of objects.

The main method should be able to freely manipulate an object’s


fields.
The main method should be as simple as possible. (*)

The main method is commonly used to instantiate objects. (*)

Incorrect. Refer to Section 7 Lesson 1.

4. What will happen when you try to access an object reference with a null
value? Mark for Review
(1) Points
NullPointerException. (*)

The value null is retrieved from the memory location.

An empty object is returned.

You will get a compilation error.

Incorrect. Refer to Section 7 Lesson 3.

5. Which statement is true about the default constructor of a class?


Mark for Review
(1) Points
Java automatically provides a constructor for every class. (*)

You must write a default constructor.

The default constructor always returns void.

Default constructor should have at least one argument.

Incorrect. Refer to Section 7 Lesson 3.


6. An object
reference Mark for Review
with a (1) Points
null
value
points to
an empty
location
in
memory.
True (*)

False

Incorrect. Refer to Section 7 Lesson 3.

7. Which has a default value of null?


Mark for Review
(1) Points

boolean

int

String (*)

double

Incorrect. Refer to Section 7 Lesson 3.

8. If fields aren't initialized, they take on a default value.


Mark for Review
(1) Points
True (*)

False

Correct

9. You create an Employee object with a String employeeName field. What is


the default value for employeeName? Mark for Review
(1) Points
null (*)

A space

“Name”

“default”

Incorrect. Refer to Section 7 Lesson 3.

10. Which type of memory is allocated for the code below?


Mark for Review
int x = 1; (1) Points
int y = 2;
x=y;
No memory is allocated

Heap memory

PileDriver memory

Stack memory (*)

Incorrect. Refer to Section 7 Lesson 2.


11. Which two
statements Mark for Review
are true (1) Points
about
objects of
the same
class?
(Choose all correct answers)
All objects are equal.

All objects of the same class have the same methods. (*)

Each new instance of an object will have a different location in


memory. (*)
Each object will have the same reference variable to the location in
memory.
Correct

12. Which keyword is used to allocate memory for a newly created object?
Mark for Review
(1) Points
new (*)

store

address
memory

Correct

13. Java developers don't need to know an object’s location in memory.


Mark for Review
(1) Points

True (*)

False

Incorrect. Refer to Section 7 Lesson 2.

14. What is the output of the following code?


Mark for Review
String s1 = "Hello"; (1) Points
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);
s1: Hello
s2: Hello
s1: Welcome!
s2: Welcome! (*)
s1: Hello
s2: Welcome!
s1: Welcome!
s2: Hello

Correct

15. In this statement, identify the type of the variable s.


Mark for Review
Student s = new Student(); (1) Points

null

Class
Student (*)
String

Incorrect. Refer to Section 7 Lesson 2.

You might also like