You are on page 1of 38

Test: JFo Section 2 Quiz

Section 2 Quiz
(Answer all questions in this section)

1. You’d like to see a movie with a few friends. You 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?

Mark for Review

(1) Points

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

Reach the cinema by 4:00 PM.

Travel via subway.

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


Correct

2. Which of the following are adequate definitions for components of the Spiral
Model of Development?

Mark for Review

(1) Points

Develop: Collect all specified instructions

Test: Run the code and verify results(*)

Requirements: Start the development


Design: Plan the approach(*)

Correct

3. If the requirement step of the Spiral Model of development is forgotten, which of
the following could occur?

Mark for Review

(1) Points

Solutions seem elusive.

Code becomes messy.

The Program gives inaccurate results.

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


Correct

4. During the Design phase of software development, the programmer implements


features gathered during the Requirement phase.

Mark for Review

(1) Points

True

False (*)
Correct

5. When the program runs normally (when not in debug mode), which statement is
true about breakpoints?

Mark for Review

(1) Points
Breakpoints will not have any effect on program execution. (*)

Breakpoints will stop program execution at the first breakpoint.

Any Breakpoint will stop program execution.

Breakpoints will stop program execution at the last breakpoint.


Correct

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


Mark for Review

(1) Points
True (*)
False
Correct

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


Mark for Review

(1) Points
True (*)
False
Correct

8. Which of the following two features are supported by the NetBeans IDE.
Mark for Review

(1) Points
NetBeans automatically runs the program once all the braces in the code are matched.
NetBeans highlights matching braces.(*)

NetBeans provides a shortcut to format whitespace.(*)

Once NetBeans spots a problem, it won’t allow you to continue coding until the progrblem is fixed.
Correct

9. Which of the following are considered Whitespace?


Mark for Review

(1) Points
Space in the print statements.
Indentation before the code.(*)

Blank lines in the code.(*)

Space between words.(*)

Space between the [ ] braces.


Correct

10. Which of the following three statements are true about breakpoint?


Mark for Review

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

They abruptly ends the code execution.


They pause code execution.(*)

They help with debugging.(*)

They insert break statements.


Incorrect. Refer to Section 2 Lesson 2.
Previous
11. An object may interact with another object by invoking methods.
Mark for Review

(1) Points
True (*)
False
Correct

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


Mark for Review

(1) Points
C++
C (*)
Java C
Java
Correct

13. 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 between
the properties and behavior.
Mark for Review

(1) Points
radius(*)

calculateDiameter()
calculateArea()
calculateCircumference()
color(*)
Correct

14. 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
size
getShirtSize() (*)
color
price
Correct

15. In object oriented programming, there is an emphasis on which of the


following two:
Mark for Review

(1) Points
Object interaction without a prescribed order.(*)

Modeling objects.(*)

Writing algorithms.
Creation of procedures.
Correct
Previous

Test: JFo Java Foundations Midterm Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 2
(Answer all questions in this section)

1. Which of the following are adequate definitions for components of the Spiral
Model of Development?

Mark for Review

(1) Points

Design: Plan the approach(*)

Develop: Collect all specified instructions

Requirements: Start the development

Test: Run the code and verify results(*)

Correct

2. The Spiral Model reflects an iterative development process.

Mark for Review

(1) Points

True (*)

False
Correct

3. During the Testing phase of software development, which of the following are the
tasks undertaken by the programmer?

Mark for Review

(1) Points

Fixing the bugs.(*)

Planning the order to implement features.


Listing required features.

Finding the bugs.(*)

Correct

4. Which of the following two features are supported by the NetBeans IDE.

Mark for Review

(1) Points

Once NetBeans spots a problem, it won’t allow you to continue coding until the progrblem is fixed.

NetBeans provides a shortcut to format whitespace.(*)

NetBeans automatically runs the program once all the braces in the code are matched.

NetBeans highlights matching braces.(*)

Correct

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

Mark for Review

(1) Points

True (*)

False
Correct
6. You can set any number of breakpoints for your program.

Mark for Review

(1) Points

True (*)

False
Correct

7. In object oriented programming, an object comprises of properties and behaviors


where properties represented as fields of the object and behavior is represented as
method.

Mark for Review

(1) Points

True (*)

False
Correct

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

Mark for Review

(1) Points

C++

Java

C (*)

Java C
Correct

9. 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 between the properties
and behavior.

Mark for Review

(1) Points

calculateArea()
calculateDiameter()

color(*)

calculateCircumference()

radius(*)

Correct

Section 3
(Answer all questions in this section)

10. 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

21

25

20 (*)
Correct
Previous

Section 3
(Answer all questions in this section)

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

Mark for Review

(1) Points

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

nt intVar1 = (int)"100";

int intVar1 = "100";

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


Correct

12. What is parsing?

Mark for Review

(1) Points

Converting numeric data to a specified numeric data type

Reading text from numeric data

Converting numeric data to text

Converting text to numeric data (*)


Correct

13. The print() method prints to the console and automatically creates a line.

Mark for Review

(1) Points

True

False (*)
Correct

14. Which two statements are true about String concatenation.

Mark for Review

(1) Points

String concatenation can be done with String variables and String Literals.(*)

String concatenation cannot be done with more than two String Literals.

Strings can be combined using the ‘+’ operator(*)


String concatenation cannot be done with numbers.

Correct

15. A character preceded by backslash is called an escape sequence.

Mark for Review

(1) Points

True (*)

False
Correct
Previous

16. Assigning a value to the variable is called “initialization”.


Mark for Review

(1) Points
True (*)
False
Correct

17. Identify the names of two variables used in the given code.

public class Variables {


  public static void main(String args[]) {
   String strVal = "Hello";
  int intVal = 0;
   System.out.println("Integer: " +intVal)
 }
}
Mark for Review

(1) Points
Hello
strVal(*)

String
int
intVal(*)
Correct

18. Java is a strongly typed language; therefore you must declare a data


type for all variables.
Mark for Review

(1) Points
True (*)
False
Correct

19. Which two statements are true about the Scanner class?


Mark for Review

(1) Points
A Scanner object doesn’t have fields and methods.
A Scanner object opens a stream for collecting input.(*)

Scanners cannot read text files.


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

20. The Scanner class considers space as the default delimiter while reading
the input.
Mark for Review

(1) Points
True (*)
False
Correct
Previous
21. It's best-practice to close the Scanner stream when finished

Mark for Review

(1) Points

True (*)
False
Correct

22. Which keyword makes a variable’s value unchangeable?

Mark for Review

(1) Points

const

final (*)

static

break
Correct

23. 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

24. What is the output? public static void main(String args[]) {


  int x = 100;
  int y = x;
  y++;
  System.out.println("Value of x is " + x);
  System.out.println("Value of y is " + y);
}

Mark for Review

(1) Points

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

Section 4
(Answer all questions in this section)

25. You need to generate random integer values between 0 and 80 (inclusive).


Which statement should you use?

Mark for Review

(1) Points

nextInt(81); (*)

nextInt();

nextInt(80);

nextInt(0-79);
Correct
Previous

26. 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.
Correct

27. Using the Random class requires an import statement.


Mark for Review

(1) Points
True (*)
False
Correct

28. Which is NOT true?


Mark for Review

(1) Points
Static methods can be invoked through an instance of a class
Static methods can be invoked through the class name.
A class can have multiple static methods.
Static methods must be of return void. (*)
Correct

29. The Math class methods can be called without creating an instance of a


Math object.
Mark for Review

(1) Points
True (*)
False
Correct

30. The replaceFirst() method replaces only the first occurrence of matching


character pattern in a string.
Mark for Review

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

(1) Points
True (*)
False
Correct

32. The String class must be imported using java.lang.String;


Mark for Review

(1) Points
True
False (*)
Correct

33. Which method returns the length of a String?


Mark for Review

(1) Points
charAt()
length() (*)
findLength ()
compareTo()
Correct

34. The classes of the Java class library are organized into packages.
Mark for Review

(1) Points
True (*)
False
Correct
35. The JFrame and JOptionPane classes are in the javax.swing package.
Which two will import those classes?
Mark for Review

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

import javax.swing.*;(*)

import javax.swing;
Correct
Previous
36. Which statement is true about packages?
Mark for Review

(1) Points
A package doesn’t contain a group of related classes.
A package makes it difficult to locate the related classes.
A package contains a group of related classes. (*)
Packages of the Java class library do not contain related classes.
Correct

37. Which package is implicitly imported?


Mark for Review

(1) Points
java.math
java.io
java.lang (*)
ava.awt
Correct

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

Employee emp = new Employee();


emp.calculateSalary(100000, 3.2, 15);
Mark for Review

(1) Points
emp
calculateSalary(100000, 3.2, 15);
100000, 3.2, 15 (*)
emp.calculateSalary(100000, 3.2, 15);
Incorrect. Refer to Section 4 Lesson 1.

39. Object instantiation is done using what keyword?


Mark for Review

(1) Points
new (*)
instance
System
void
Correct

40. You’re designing banking software and need to store 10000 customer


accounts with information on the accountholder’s name, balance, and
interest rate. The best approach is store 30000 separate variables in the
main method.
Mark for Review

(1) Points
True
False (*)
Correct
Previous
41. 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. (*)

For every five to six lines of code.

To group similar data types together


When you don’t find similar lines of code to describe an object’s behavior.
Correct

Section 5
(Answer all questions in this section)

42. In Java, an if statement can be nested inside another if statement.

Mark for Review

(1) Points

True (*)

False
Correct

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


Under what conditions does “Eligible for a bonus” print?

int rating;
int experience;
if (rating > 1 && experience == 5) {
   System.out.println (“Eligible for a bonus”);
}

Mark for Review

(1) Points

5 experience and 1 rating

Less than 5 experience and 1 rating.

5 rating and 1 experience

5 experience and 2 or more rating (*)


Correct

44. Which two are not logical operators?


Mark for Review

(1) Points

&&

%(*)

+(*)

||

Correct

45. The equal sign (=) is used to make an assignment, whereas the == sign merely
makes a comparison and returns a boolean.

Mark for Review

(1) Points

True (*)

False
Correct
Previous

Section 5
(Answer all questions in this section)

46. What are the possible values of a boolean data type in Java?

Mark for Review

(1) Points

good/bad

0/1
yes/no

true/false (*)
Correct

47. Which operator is used to test if both sides of a boolean expression are equal?

Mark for Review

(1) Points

>=

== (*)

<=

=
Correct

48. Which three are conditional statements?

Mark for Review

(1) Points

for loop

do while loop

if/else statement(*)

if statement(*)

switch statement(*)

Correct

49. Which two of the following data types can be used in a switch statement?
Mark for Review

(1) Points

String(*)

int(*)

boolean

float

Correct

50. Which two statements are true about the default statement?

Mark for Review

(1) Points

When the input does not match any of the cases, the default statement is executed.(*)

The default statement is optional in switch statement.(*)

A default statement is executed by default when the program is executed.

A default statement is required in every switch statement.

Correct
Previous

Test: JFo Java Foundations Final Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 6
(Answer all questions in this section)

1. The only way to exit a loop is for the loop condition to evaluate to false.

Mark for Review


(1) Points

True

False (*)
Correct

2. Which two statements are true about the break statement?

Mark for Review

(1) Points

When a break statement is executed inside a loop, the loop-statement is terminated immediately.(*)

The execution of the program will stop at the statement following the loop-statement.

The execution of the program will continue with 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.

Correct

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

Mark for Review

(1) Points

True (*)

False
Correct

4. Given:

for(int i = 0; i > 10; i++){ }


What type of variable is i?
Mark for Review

(1) Points

Static

Global

Local (*)

Member
Correct

5. When is an update expression in a for loop executed?

Mark for Review

(1) Points

Before the first iteration through the loop.

After two iterations through the loop.

Before each iteration through the loop.

After each iteration through the loop. (*)


Correct
6. Which two are valid syntax to create a for loop?

Mark for Review

(1) Points
for(int i = 10 i >= 0; i++ ) {
     System.out.println("i="+i);

for(int i = 10, i >= 0, i++ ) {


     System.out.println("i="+i);

}
for(int i = 10; i >= 0; ) {
     System.out.println("i="+i);

}(*)

for(int i = 10; i >= 0; i++ ) {


     System.out.println("i="+i);

}(*)

Correct

7. Which statement is true?

Mark for Review

(1) Points

A while loop boolean expression is made up of a counter, increment, and test.

The counter which gets incremented determines the number of loop iterations is
within the parentheses of a while loop.

The boolean expression that determines the number of loop iterations is within the
parentheses of a while loop. (*)

A counter (i) is declared and initialized inside the while loop.


Correct

8. A post-test loop evaluates its condition at the end of the loop instead of the
beginning.

Mark for Review

(1) Points

True (*)

False
Correct

9. Which two statements are true about the while loop.


Mark for Review

(1) Points

If the condition of the loop is true initially, the statements are never executed.

If the condition of a pre-test loop is false, the statements in the loop are never executed.(*)

The statement in a while loop will execute zero or more times.(*)

The statements of a while loop will execute one or more times.

Correct

Section 7
(Answer all questions in this section)

10. Objects are stored within the heap memory.

Mark for Review

(1) Points

True (*)

False
Correct
Previous

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


Mark for Review

(1) Points
True (*)
False
Correct

12. In the following statements, how many employee objects are created?

Employee e1 = new Employee();


Employee e2 = new Employee();
Employee e3 = new Employee();
Mark for Review

(1) Points
3 (*)
1
0
2
Correct

13. Methods can call other methods in the same class.


Mark for Review

(1) Points
True (*)
False
Correct

14. Given the method:

void add(double a, double b)

Which method signature would not overload this method?


Mark for Review

(1) Points
void add(int a, int b)
void add(int a, int b, int c)
void add (double a, int b)
void add(String a, String b)
int add (double a, double b) (*)
Correct

15. Method overloading can be a useful technique for defining methods with


similar functionality or calculations.
Mark for Review

(1) Points
True (*)
False
Correct
Previous
16. Which two statements are true about getter methods?
Mark for Review

(1) Points
You must have a setter method if you have a getter method.
Getters usually accept no arguments.(*)

Getter methods typically return void.


Getters have a public access modifier.(*)
Correct

17. Which two are access modifiers?


Mark for Review

(1) Points
final
public(*)

private(*)

static
Correct

18. What is encapsulation?
Mark for Review

(1) Points
A technique for limiting one class’s visibility to another. (*)
A technique for including primitives within an ArrayList.
A technique for debugging.
A technique for writing more than one main method.
Correct

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


Mark for Review

(1) Points
The main method should be able to freely manipulate an object’s fields.
The main method is commonly used to instantiate objects.(*)
The main method should store the properties and behaviors of objects.
The main method should be as simple as possible.(*)
Incorrect. Refer to Section 7 Lesson 1.

20. Class name should follow Camel casing rules.


Mark for Review

(1) Points
True (*)
False
Correct
Previous
21. How can you retrieve a value from a method?
Mark for Review

(1) Points
Use a return statement and define the method’s return type as non-void (*)

Define a variable as a field member of the method


Define the method return type as void
Pass a variable as an argument to the method.
Correct

22. If you need to make a particular variable belong to a class rather than
any individual instance, what type of variable should you use?
Mark for Review

(1) Points
A private variable.
A local variable.
A static variable. (*)
A public variable.
Correct

23. You never need to instantiate a Math object.


Mark for Review

(1) Points
True (*)
False
Correct

24. 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”
Correct

25. An object reference with a null value points to an empty location in


memory.
Mark for Review

(1) Points
True (*)
False
Correct
Previous
26. 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.


Correct
27. How would you instantiate the Employee class from a main method located in
another class?

public class Employee{


   private String name;
   private double salary;

   public Employee(String n, double s){


     name = n;
     salary = s;
   }
}

Mark for Review

(1) Points

Employee emp1 = new Employee();

Employee emp1 = new Employee(50000);

Employee emp1 = new Employee(50000, "Syam");

Employee emp1 = new Employee("Syam", 50000); (*)


Correct

28. Which two statements are NOT true about constructors?

Mark for Review

(1) Points

A constructor method may return a value.(*)

A constructor method is called once for each instance of an object.

The constructor method is called during instantiation.

A constructor method has a void return type.(*)

Correct
Section 8
(Answer all questions in this section)

29. You can access elements in an ArrayList by their index.

Mark for Review

(1) Points

True (*)

False
Correct

30. A wrapper class encapsulates, or wraps, the primitive types within an object.

Mark for Review

(1) Points

True (*)

False
Correct
Previous

31. How could you declare an ArrayList so that it can store true or false
values?
Mark for Review

(1) Points
ArrayList<Boolean> arrList = new ArrayList<>(); (*)
ArrayList<boolean> arrList = new ArrayList<>();
ArrayList<true, false> arrList = new ArrayList<>();
ArrayList<True, False> arrList = new ArrayList<>();
Correct

32. Which of the following is not a wrapper class?


Mark for Review
(1) Points
String (*)
Byte
Integer
Boolean
Correct

33. What is an array?
Mark for Review

(1) Points
An array is a way to create multiple copies of a single value.
An array is an indexed container that holds a set of values of a multiple
types.
An array is an indexed container that holds a set of values of a single
type. (*)
An array is a Java primitive type.
Correct

34. Arrays are like variables which must be declared prior to use.


Mark for Review

(1) Points
True (*)
False
Correct

35. What is the output?


int[] arr = new int[2];
for(int i=0; i < arr.length; i++){
   System.out.print("hai ");
}
Mark for Review

(1) Points
12
hai hai hai
hai
hai hai (*)
Correct
Previous
36. What is the output?
int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);

Mark for Review

(1) Points
ArrayIndexOutOfBoundsException
1
0
10 (*)
Correct

37. Runtime errors can be caught by Java’s exception handling mechanism.


Mark for Review

(1) Points
True (*)
False
Correct

38. What are two disadvantages of adding print statements for debugging?


Mark for Review

(1) Points
Too many print statements lead to information overload.(*)

It’s tedious to remove print statements.(*)

Print statements cannot print the values of an object’s fields.


Print statements cannot print the values of variables.
Correct

39. Which is not a compilation error?


Mark for Review

(1) Points
int y;
y++; (*)
y = 3 + * 5;
int x=2
x = ( 3 + 5;
Correct

40. Testing and debugging are important activities in software development.


Mark for Review

(1) Points
True (*)
False
Correct
Previous
41. Which code goes in the try block?

Mark for Review

(1) Points

Any code that is likely to cause an exception. (*)

Any code that is safe from an exception.

Any code that can handle an exception.

Any code that is likely to print the exception details.


Correct

42. What is the output?

int[] array = {10, 20, 30};


int b = 0;
try{
   System.out.println("1");
   int c = (array[3] / b);
   System.out.println("2");
}
catch(ArithmeticException ex){
   System.out.println("Arithmetic Exception");
}
catch(ArrayIndexOutOfBoundsException ex){
   System.out.println("Array index out of bounds");
}

Mark for Review

(1) Points

1
Arithmetic Exception

1
Array index out of bounds (*)

1
2

Array index out of bounds

1
2
Array index out of bounds
Correct

Section 9
(Answer all questions in this section)

43. JavaFX Ensemble contains code examples of JavaFX features.

Mark for Review

(1) Points

True (*)

False
Correct

44. Which method helps to set the width of a rectangle’s outline?

Mark for Review


(1) Points

setX(double d)

setStroke(Paint paint)

setLayoutX(double d)

setStrokeWidth(double d) (*)
Correct

45. An Image is an object that describes the location of a graphics file.

Mark for Review

(1) Points

True (*)

False
Correct
Previous

46. Lambda Expressions provide much more effective and cleaner syntax for
working with GUI applications and sorting lists.
Mark for Review

(1) Points
True (*)
False
Correct

47. When you write code for MouseEvents, you are telling a Node to listen
for a particular event.
Mark for Review

(1) Points
True (*)
False
Correct

48. JavaFX is used to create GUI applications.


Mark for Review

(1) Points
True (*)
False
Correct

49. Which is not a JavaFX Node?


Mark for Review

(1) Points
Button
ScrollBar
ImageView
Object (*)
Correct

50. Which type of Root Node allows Nodes to be placed anywhere?


Mark for Review

(1) Points
Group (*)
TilePane
HBox
StackPane
Correct
Previous

You might also like