You are on page 1of 506

Which of the following statements about unit testing is/are true

I. When all unit tests succeed, you can have high confidence your code is solid.

II. If a unit test fails, you don?t proceed until the code is fixed and the test succeeds.

III. Unit testing can help developer find problems early in the development cycle

Mark for Review

(1) Points

I only

I and II only

II and III only (*)

I, II, and III

None of these

2. Which of the following statements about arrays and ArrayLists in Java are true?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points

I and III only (*)


II and IV only

I, II, and III only

I, II, III and IV

None of these

3. Which of the following statements about inheritance is false? Mark for Review

(1) Points

A subclass inherits all the members (fields, methods, and nested classes) from its superclass.

Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself.

Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among
several subclasses.

Through inheritance, a parent class is a more specialized form of the child class. (*)

4. In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false?
Mark for Review

(1) Points

True
False (*)

5. Which of the following is not a good technique to follow when reading code written by others? Mark for Review

(1) Points

Find the author of the code and ask him how it works. (*)

Learn the high level structure and starting point, and then figure out how it branches.

Build and run the code.

Perform testing.

Understand the constructs.

6. Examine the following code snippet. What is this an example of?

public class Car extends Vehicle {

public Car() {

...

} Mark for Review

(1) Points
Encapsulation

Polymorphism

Comments

Inheritance (*)

7. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

protected (*)

abstract

public (*)

final

8. Which statements are true?(Choose Three) Mark for Review


(1) Points

(Choose all correct answers)

In a constructor, you can call a superclass constructor. (*)

You can declare more than one constructor in a class declaration. (*)

Since a constructor can not return any value, it should be declared as void.

A constructor can not be overloaded.

You can use access modifiers to control which other classes can call the constructor. (*)

9. You declare a method:

public void act(Student s){}

Which of following arguments can be passed into the method? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

Type of Object class

Interface
Type of Student class (*)

Type of the subclass of Student (*)

10. What is the output from the following code snippet?

public static void main(String[] args){

List li=new ArrayList();

li.add(1);

li.add(2);

print(li);

public static void print(List list) {

for (Number n : list)

System.out.print(n + " ");

} Mark for Review

(1) Points

The code will not compile.


1 2 (*)

11. Examine the code below. Which statement about this code is true?

1.class Shape { }

2.class Circle extends Shape { }

3.class Rectangle extends Shape { }

4.class Node { }

5.public class Test{

6.public static void main(String[] args){

7.Node nc = new Node<>();

8.Node ns = nc;

} Mark for Review

(1) Points

The code compiles.

An error at line 8 causes compilation to fail. (*)

An error at line 7 causes compilation to fail.

An error at line 4 causes compilation to fail.


12. The following code will compile.

True or False?

class Node implements Comparable{

public int compareTo(T obj){return 1;}

class Test{

public static void main(String[] args){

Node nc=new Node<>();

Comparable com=nc;

Mark for Review

(1) Points

True (*)

False

13. Which of the following correctly initializes an object named cell of the class Telephones whose generic type is
Cellular? Mark for Review

(1) Points
Telephones cell = new Telephones(Cellular c);

Telephones(Cellular) cell = new Telephones(Cellular);

Telephones<> cell = new Telephones<>(Cellular c);

Telephones <Cellular> cell = new Telephones <Cellular>(); (*)

None of the these.

14. A HashMap can only store String types.

True or false? Mark for Review

(1) Points

True

False (*)

15. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.

True or false? Mark for Review

(1) Points
True (*)

False

16. Implementing the Comparable interface in your class allows you to define its sort order.

True or false? Mark for Review

(1) Points

True (*)

False

17. A HashMap can store duplicates.

True or false? Mark for Review

(1) Points

True

False (*)
18. Stacks are identical to Queues.

True or false? Mark for Review

(1) Points

True

False (*)

19. Which of the following correctly defines a queue? Mark for Review

(1) Points

Something that enables you to create a generic class without specifying a type between angle brackets <>.

It is a keyword in Java that restrict the use of the code to local users only.

A list of elements with a first in last out order.

A list of elements with a first in first out order. (*)


20. Where you enqueue an element in the list? Mark for Review

(1) Points

removes it from the front of the list

adds it to the start of the list

adds it to the end of the list (*)

removes it from the end of the list

21. Which of the following describes a deque. Mark for Review

(1) Points

It is pronounced "deck" for short.

It implements a stack.

Allows for insertion or deletion of elements from the first element added or the last one.
All of the above. (*)

22. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?

The steps are shown below:

{'M', 'S', 'A', 'T', 'H'}

{'M', 'A', 'S', 'T', 'H'}

{'A', 'M', 'S', 'T', 'H'}

{'A', 'M', 'S', 'H', 'T'}

{'A', 'M', 'H', 'S', 'T'}

{'A', 'H', 'M', 'S', 'T'} Mark for Review

(1) Points

Sequential Search

Bubble Sort (*)

Selection Sort

Binary Search

Merge Sort
23. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or
false? Mark for Review

(1) Points

True (*)

False

24. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.
25. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal
speed? Mark for Review

(1) Points

Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above

26. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.
27. A sequential search is an iteration through the array that stops at the index where the desired element is found.
True or false? Mark for Review

(1) Points

True (*)

False

28. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True or false? Mark for Review

(1) Points

True

False (*)
29. Which of the following is the correct lexicographical order for the conents of the following int array?

{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review

(1) Points

{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

30. Which of the following statements can be compiled?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

List<Object> list = new ArrayList<String>();

List<?> list = new ArrayList<String>(); (*)


List list = new ArrayList<String>(); (*)

List<String> list = new ArrayList<String>(); (*)

31. Which code inserted into the code below guarantees that the program will output [1,2]?

import java.util.*;

public class Example{

public static void main(String[] args){

//insert code here

set.add(2);

set.add(1);

System.out.println(set);

} Mark for Review

(1) Points

Set set = new SortedSet();

Set set = new HashSet();

Set set = new TreeSet(); (*)

List set = new SortedList();

Set set = new LinkedHashSet();


32. Sets may contain duplicates.

True or false? Mark for Review

(1) Points

True

False (*)

33. ArrayList and Arrays both require you to define their size before use.

True or false? Mark for Review

(1) Points

True

False (*)
34. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.

True or false? Mark for Review

(1) Points

True (*)

False

35. Which interface forms the root of the collections hierarchy? Mark for Review

(1) Points

java.util.Collections

java.util.Map

java.util.List

java.util.Collection (*)
6. Unit testing is the phase in software testing in which individual software modules are combined and tested as a
whole. True or false? Mark for Review

(1) Points

True

False (*)

7. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only

II only

I and II only (*)

I, II and III only

None of these
8.Which of the following are important to your survival as a programmer? Mark for Review

(1) Points

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)

9. Reading great code is just as important for a programmer as reading great books is for a writer. True or false? Mark
for Review

(1) Points

True (*)

False
10. The instanceof operator allows you to determine the type of an object.

True or false? Mark for Review

(1) Points

True (*)

False

36. The following code is valid when working with the Collection Interface.

Collection collection = new Collection()d;

True or false? Mark for Review

(1) Points

True

False (*)
37. Which one of the following statements is true? Mark for Review

(1) Points

A Java program can only contain one super class

A class is a template that defines the features of an object (*)

A class is a Java primitive

A class is an intance of an object

38. An interfaces can declare public constants.

True or False? Mark for Review

(1) Points

True (*)

False
39. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

40. In general, classes can be made immutable by placing a final key word before the class keyword.

True or false? Mark for Review

(1) Points

False

True (*)

41. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points
True

False (*)

42. The state of an object differentiates it from other objects of the same class.

True or False? Mark for Review

(1) Points

True (*)

False

43. A method with default access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)
44. You can always upcast a subclass to an interface provided you don't need to access any members of the concrete
class.

True or false? Mark for Review

(1) Points

True (*)

False

45. Virtual method invocation occurs: Mark for Review

(1) Points

When the method of a subclass is used on a superclass reference. (*)

When the method of a superclass is used on a superclass reference.

When the method of a subclass is used on a subclass reference.

Not part of polymorphism.


46. The instanceof operator works with class instances and primitive data types.

True or false? Mark for Review

(1) Points

True

False (*)

47. Upward casting an object instance means you can't access subclass specific methods.

True or false? Mark for Review

(1) Points

True (*)

False
48. Which two of the following statements are true? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

An abstract class can create subclass and be constructed.

An abstract class must be difined by using the abstract keyword. (*)

An abstract class must contain abstrct method.

An abstract class can define constructor. (*)

49. Java provides virtual method invocation as a feature and it doesn't require specialized coding.

True or false? Mark for Review

(1) Points

True (*)

False
50. The instanceof operator is a boolean comparison operator.

True or false? Mark for Review

(1) Points

True (*)

False

6. Unit testing is the phase in software testing in which individual software modules are combined and tested as a
whole. True or false? Mark for Review

(1) Points

True

False (*)
7. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only

II only

I and II only (*)

I, II and III only

None of these

8. Which of the following are important to your survival as a programmer? Mark for Review

(1) Points

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.


All of these. (*)

9. Reading great code is just as important for a programmer as reading great books is for a writer. True or false? Mark
for Review

(1) Points

True (*)

False

10. The instanceof operator allows you to determine the type of an object.

True or false? Mark for Review

(1) Points

True (*)

False
11. The instanceof operator is a boolean comparison operator.

True or false? Mark for Review

(1) Points

True (*)

False

12. Java provides virtual method invocation as a feature and it doesn't require specialized coding.

True or false? Mark for Review

(1) Points

True (*)

False

13. The instanceof operator works with class instances and primitive data types.

True or false? Mark for Review


(1) Points

True

False (*)

14. What is the result of the following code snippet??

1. abstract class AbstractBankAccount {

2. abstract int getBalance ();

3. )

4. public class CreditAccount extends AbstractBankAccount{

5. private int balance;

6. private int getBalance (){

7. return balance;

8. }

9.} Mark for Review

(1) Points

An error at line 6 causes compilation to fail. (*)

Compilation is successful.

An error at line 2 causes compilation to fail.


An error at line 4 causes compilation to fail.

15. Virtual method invocation occurs when you try to call a superclass method.

True or false? Mark for Review

(1) Points

True

False (*)

16. Virtual method invocation occurs: Mark for Review

(1) Points

When the method of a superclass is used on a superclass reference.

When the method of a subclass is used on a subclass reference.

Not part of polymorphism.

When the method of a subclass is used on a superclass reference. (*)


17. Which of the following describes a deque. Mark for Review

(1) Points

It is pronounced "deck" for short

It implements a stack.

Allows for insertion or deletion of elements from the first element added or the last one.

All of the above. (*)

18. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

Because you can remove elements from the end of it. (*)
Because you can remove elements from the beginning of it. (*)

Because you can not add element to the beginning of it.

Because you can add elements to the end of it. (*)

19. A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

20. Stacks are identical to Queues.

True or false? Mark for Review

(1) Points

True
False (*)

21. Which of the following is a list of elements that have a first in last out ordering. Mark for Review

(1) Points

Arrays

Stacks (*)

HashMaps

Enums

22. Which of the following correctly defines a queue? Mark for Review

(1) Points

A list of elements with a first in first out order. (*)

Something that enables you to create a generic class without specifying a type between angle brackets <>.

A list of elements with a first in last out order.


It is a keyword in Java that restrict the use of the code to local users only.

23. Which scenario best describes a queue? Mark for Review

(1) Points

A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom.

A row of books that you can take out of only the middle of the books first and work your way outward toward either
edge.

A line at the grocery store where the first person in the line is the first person to leave. (*)

All of the above describe a queue.

24. What are maps that link a Key to a Value? Mark for Review

(1) Points

HashMaps (*)

ArrayLists
Arrays

HashSets

25. The local petting zoo is writing a program to be able to collect group animals according to species to better keep
track of what animals they have.

Which of the following correctly defines a collection that may create these types of groupings for each species at the
zoo? Mark for Review

(1) Points

public class

animalCollection {...}(*) (*)

public class

animalCollection(AnimalType T) {...}

public class

animalCollection {...}

public class

animalCollection(animalType) {...}

None of the these.


26. Enumerations (enums) are useful for storing data : Mark for Review

(1) Points

You cannot store data in an enum.

When the class is a subclass of Object.

When you know all of the possibilities of the class (*)

When the class is constantly changing

27. Generic methods are required to be declared as static.

True or False? Mark for Review

(1) Points

True

False (*)
28. < ? > is an example of a bounded generic wildcard.

True or False? Mark for Review

(1) Points

True

False (*)

29. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value
in the first position, and repeating these steps for the remainder of the list.

True or false? Mark for Review

(1) Points

True (*)

False

30. Which of the following best describes lexicographical order? Mark for Review

(1) Points
A simple sorting algorithm that is inefficient on large arrays.

An order based on the ASCII value of characters. (*)

A complex sorting algorithm that is efficient on large arrays.

The order of indicies after an array has been sorted.

31. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal
speed? Mark for Review

(1) Points

Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above


32. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

33. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True or false? Mark for Review

(1) Points

True

False (*)
34. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

35.Of the options below, what is the fastest run-time? Mark for Review

(1) Points

n*log(n)

log(n) (*)

n^2
36. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?

The steps are shown below:

{'M', 'S', 'A', 'T', 'H'}

{'M', 'A', 'S', 'T', 'H'}

{'A', 'M', 'S', 'T', 'H'}

{'A', 'M', 'S', 'H', 'T'}

{'A', 'M', 'H', 'S', 'T'}

{'A', 'H', 'M', 'S', 'T'} Mark for Review

(1) Points

Binary Search

Selection Sort

Merge Sort

Sequential Search

Bubble Sort (*)

37. In general, classes can be made immutable by placing a final key word before the class keyword.
True or false? Mark for Review

(1) Points

False

True (*)

38. You can only implement one interface in a class.

True or False? Mark for Review

(1) Points

True

False (*)

39. Classes define and implement what? Mark for Review

(1) Points

All method definitions without any implementations


Constants and all methods with implementations

All methods with implementations

Some methods with implementations

Variables and methods (*)

40. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

41. Modeling classes for a business problem requires understanding of the business not Java. True or false? Mark for
Review

(1) Points
True

False (*)

42. A method with default access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

43. Which two statements are equivalent to line 2?

(Choose Two) 1. public interface Account{

2. int accountID=100;

3. } Mark for Review

(1) Points

(Choose all correct answers)

static int accountID=100; (*)


private int accountID=100;

protected int accountID=100;

Abstract int accountID=100;

Final int accountID=100; (*)

44. What is a set? Mark for Review

(1) Points

A collection of elements that contains duplicates.

A collection of elements that does not contain duplicates. (*)

Something that enables you to create a generic class without specifying a type between angle brackets <>.

A keyword in Java that initializes an ArrayList.

45. Which of the following statements can be compiled?(Choose Three) Mark for Review

(1) Points
(Choose all correct answers)

List<Object> list = new ArrayList<String>();

List<String> list = new ArrayList<String>(); (*)

List list = new ArrayList<String>(); (*)

List<?> list = new ArrayList<String>(); (*)

6. Choose the best definiton for a collection. Mark for Review

(1) Points

It is an interface in the java.util package that is used to define a group of objects. (*)

It enables you to create a generic class without specifying a type between angle brackets <>.

It is a special type of class that is associated with one or more non-specified Java type.

It is a subclass of List.
47. Sets may contain duplicates.

True or false? Mark for Review

(1) Points

True

False (*)

48. Which is the correct way to initialize a HashSet? Mark for Review

(1) Points

ClassMates = public class

HashSet();

classMates = new HashSet[String]();

HashSet classMates =

new HashSet(); (*)

String classMates = new

String();
49. Which interface forms the root of the collections hierarchy? Mark for Review

(1) Points

java.util.Map

java.util.Collection (*)

java.util.Collections

java.util.List

50. What is the result from the following code snippet?

interface Shape {}

class Circle implements Shape{}

class Rectangle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls= new ArrayList<Shape>();//line 1

ls.add(new Circle());

ls.add(new Rectangle());// line 2

ls.add(new Integer(1));// line 3


System.out.println(ls.size());// line 4

} Mark for Review

(1) Points

3 (*)

Compilation error at line 1

Compilation error at line 4

Compilation error at line 2

Compilation error at line 3

1. Which statement is true when run the following statement?

1. String str = null;

2. if ((str != null) && (str.length() > 1)) {

3. System.out.println("great that number 1");

4. } else if ((str != null) & (str.length() < 2)) {

5. System.out.println("less than number 2");

6. } Mark for Review

(1) Points

The code compiles and will throw an exception at line 4. (*)


The code compiles and will throw an exception at line 5

The code does not compile.

The code compiles and will throw an exception at line 3.

The code compiles and will throw an exception at line 2.

2. A class can be extended by more than one class. True or False? Mark for Review

(1) Points

True (*)

False

3. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)


public (*)

protected (*)

abstract

final

4. Unit testing can help you isolate problem quickly. True or False? Mark for Review

(1) Points

True (*)

False

5. Which statement is true for the class java.util.ArrayList? Mark for Review

(1) Points

The elements in the collection are ordered. (*)


The elements in the collection are accessed using key.

The elements in the collection are synchronized.

The elements in the collection are immutable.

6. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is
combined with other components in the system. True or false? Mark for Review

(1) Points

True (*)

False

7. Which of the following statements about arrays and ArrayLists in Java are true?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points
I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of these

8. When an object is able to pass on its state and behaviors to its children, this is called: Mark for Review

(1) Points

Encapsulation

Isolation

Polymorphism

Inheritance (*)
9. Which of the following are important to your survival as a programmer? Mark for Review

(1) Points

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)

10. Which of the following best describes lexicographical order? Mark for Review

(1) Points

A complex sorting algorithm that is efficient on large arrays.

An order based on the ASCII value of characters. (*)

The order of indicies after an array has been sorted.

A simple sorting algorithm that is inefficient on large arrays.


11. Of the options below, what is the fastest run-time? Mark for Review

(1) Points

n^2

log(n) (*)

n*log(n)

12. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value
in the first position, and repeating these steps for the remainder of the list.

True or false? Mark for Review

(1) Points

True (*)
False

13. A sequential search is an iteration through the array that stops at the index where the desired element is found.

True or false? Mark for Review

(1) Points

True (*)

False

14. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True or false? Mark for Review

(1) Points

True

False (*)
15. Which of the following is the correct lexicographical order for the conents of the following int array?

{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review

(1) Points

{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

16. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

17. A sequential search is an iteration through the array that stops at the index where the desired element is found.
True or false? Mark for Review

(1) Points

True (*)

False

18. In general, classes can be made immutable by placing a final key word before the class keyword.

True or false? Mark for Review

(1) Points

True (*)

False
19. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

20. Classes define and implement what? Mark for Review

(1) Points

Some methods with implementations

All methods with implementations

All method definitions without any implementations

Variables and methods (*)


Constants and all methods with implementations

21. Interfaces define what? Mark for Review

(1) Points

Constants and all methods with implementations

Variables and methods

Some methods with implementations

All method definitions without any implementations (*)

All methods with implementations

22. Making a class immutable means: Mark for Review

(1) Points

That it cannot be extended. (*)


To create an instance of the class.

To create a sub class from a parent class

That it is directly subclassed from the Object class

23. Modeling classes for a business problem requires understanding of the business not Java. True or false? Mark for
Review

(1) Points

True

False (*)

24. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete
classes, subclasses, and enum classes. Mark for Review

(1) Points
True (*)

False

25. Which method will force a subclass to implement it? Mark for Review

(1) Points

Public native double act();

Abstract public void act(); (*)

Protected void act(String name){}

Static void act(String name) {}

Public double act();

26. Virtual method invocation occurs when you try to call a superclass method.

True or false? Mark for Review

(1) Points
True

False (*)

27. Virtual method invocation must be defined with the instanceof operator.

True or false? Mark for Review

(1) Points

True

False (*)

28. A upward cast means all instance variables of the subclass are permanently lost to the instance.

True or false? Mark for Review

(1) Points

True

False (*)
29. Calling a subclass method by referring to a superclass works because you have access to all specialized methods
through virtual method invocation.

True or false? Mark for Review

(1) Points

True

False (*)

30. Which line contains an compilation error?

interface Shape {}

interface InnerShape extends Shape{}

class Circle implements Shape{ }

class InnerCircle extends Circle{}

class Rectangle implements Shape{}

public class Tester {

public static void main(String[] args) {

Circle c= new Circle();

InnerCircle ic = new InnerCircle();


Rectangle rect = new Rectangle();

System.out.print(c instanceof InnerCircle); //Line 1

System.out.print(ic instanceof Circle); //Line 2

System.out.print(rect instanceof InnerCircle); //Line 3

System.out.print(rect instanceof Shape); //Line 4

} Mark for Review

(1) Points

Line 1

Line 3 (*)

Line 4

Line 2

31. Which two of the following statements are true? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

An abstract class must be difined by using the abstract keyword. (*)


An abstract class can define constructor. (*)

An abstract class must contain abstrct method.

An abstract class can create subclass and be constructed.

32. Which interface forms the root of the collections hierarchy? Mark for Review

(1) Points

java.util.Collection (*)

java.util.Map

java.util.List

java.util.Collections

33. Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review

(1) Points
vegetables[0] = "Cabbage";

vegetables += "Cabbage";

vegetables.add("Cabbage"); (*)

vegetables.get("Cabbage");

34. What is the result from the following code snippet?

interface Shape {}

class Circle implements Shape{}

class Rectangle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls= new ArrayList<Shape>();//line 1

ls.add(new Circle());

ls.add(new Rectangle());// line 2

ls.add(new Integer(1));// line 3

System.out.println(ls.size());// line 4

} Mark for Review

(1) Points
Compilation error at line 4

Compilation error at line 1

Compilation error at line 2

3 (*)

Compilation error at line 3

35. What is the output from the following code snippet?

Integer[] ar = {1, 2, 1, 3};

Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));

set.add(4);

for (Integer element : set) {

System.out.print(element);

} Mark for Review

(1) Points

1234 (*)

1213

11234
12134

36. Which of the following statements can be compiled?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

List<?> list = new ArrayList<String>(); (*)

List<String> list = new ArrayList<String>(); (*)

List<Object> list = new ArrayList<String>();

List list = new ArrayList<String>(); (*)

37. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.

True or false? Mark for Review

(1) Points
True (*)

False

38. Which class is an ordered collection that may contain duplicates? Mark for Review

(1) Points

enum

array

set

list (*)

39. A generic class is a type of class that associates one or more non-specific Java types with it.

True or False? Mark for Review

(1) Points
True (*)

False

40. Generic methods can only belong to generic classes.

True or False? Mark for Review

(1) Points

True

False (*)

41. What is the output from the following code snippet?

public static void main(String[] args){

List li=new ArrayList();

li.add(1);

li.add(2);

print(li);

public static void print(List list) {

for (Number n : list)


System.out.print(n + " ");

} Mark for Review

(1) Points

The code will not compile.

1 2 (*)

42. An example of an upper bounded wildcard is. Mark for Review

(1) Points

ArrayList<? super Animal>

ArrayList<T>

ArrayList<?>

ArrayList<? extends Animal> (*)


43. Implementing the Comparable interface in your class allows you to define its sort order.

True or false? Mark for Review

(1) Points

True (*)

False

44. A LinkedList is a list of elements that is dynamically stored.

True or false? Mark for Review

(1) Points

True (*)

False
45. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

Because you can not add element to the beginning of it.

Because you can remove elements from the end of it. (*)

Because you can add elements to the end of it. (*)

Because you can remove elements from the beginning of it. (*)

46. The Comparable interface includes a method called compareTo.

True or false? Mark for Review

(1) Points

True (*)

False
47. Which of the following methods adds a Key-Value map to a HashMap? Mark for Review

(1) Points

remove(Key, Value)

get(Key, Value)

put(Key, Value) (*)

add(Key, Value)

48. Which scenario best describes a queue? Mark for Review

(1) Points

A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom.

A row of books that you can take out of only the middle of the books first and work your way outward toward either
edge.

A line at the grocery store where the first person in the line is the first person to leave. (*)

All of the above describe a queue.


49. A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

50. Which of the following describes a deque. Mark for Review

(1) Points

It is pronounced "deck" for short.

It implements a stack.

Allows for insertion or deletion of elements from the first element added or the last one.

All of the above. (*)


Diposting oleh Unknown di 07.00

Kirimkan Ini lewat Email

BlogThis!

Berbagi ke Twitter

Berbagi ke Facebook

Bagikan ke Pinterest

1 komentar:

Редич Олександр Володимирович1 April 2020 05.08

interface Shape {}

interface InnerShape extends Shape{}

class Circle implements Shape{ }

class InnerCircle extends Circle{}

class Rectangle implements Shape{}

public class Tester {

public static void main(String[] args) {

Circle c= new Circle();

InnerCircle ic = new InnerCircle();

Rectangle rect = new Rectangle();

System.out.print(c instanceof InnerCircle); //Line 1

System.out.print(ic instanceof Circle); //Line 2

System.out.print(rect instanceof InnerCircle); //Line 3

System.out.print(rect instanceof Shape); //Line 4

Balas

Posting Lebih BaruBeranda

Langganan: Posting Komentar (Atom)


Mengenai Saya

Unknown

Lihat profil lengkapku

Arsip Blog

▼ 2017 (6)

► Juli (2)

▼ Mei (4)

QUIZ 3 OJP

OJP 2

OJP 3

OJP 1

Tema Sederhan

java programming

Section 1

(Answer all questions in this section)

10. The function of Garbage Collection in Java is: Mark for Review

(1) Points

The JVM uses GC to clear the program output.

The JVM GC deletes all unused Java files on the system.

Memory occupied by objects with no reference is automatically reclaimed for reuse. (*)

As a Java programmer, we have to call the GC function specifically in order to manage the Java Memory.

1. Which of the following statements is NOT true of the Java programming language? Mark for Review
(1) Points

All source code is written in plain text files with the extension .java.

Java source code files are compiled into .class files by the javac command.

The javac command can be used to run a Java application. (*)

A .class file contains platform independent bytecode.

Correct Correct

2. Which of the following statements describe the Java programming language? Mark for Review

(1) Points

Java is a high-level programming language.

The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.


All of the above (*)

Correct Correct

3. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){

int y=100;

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

Variable x resides in the stack area, and variable y resides in the heap of the JVM.

Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)

Variable x stays in the heap area, and variable y resides in the method area of the JVM.
Correct Correct

4. Which of the following converts a human-readable file into a platform-independent code file in Java? Mark for
Review

(1) Points

JRE

JDK

javac command (*)

java command

Incorrect Incorrect. Refer to Section 1 Lesson 1.

5. Java allows the same Java program to be executed on multiple operating systems. Mark for Review

(1) Points

True (*)
False

Correct Correct

6. Which of the following statements describe Java technology? Mark for Review

(1) Points

It is a programming language.

It is a development environment.

It is a deployment environment.

All of the above (*)

Incorrect Incorrect. Refer to Section 1 Lesson 1.

7. During runtime, the Java platform loads classes dynamically as required. Mark for Review

(1) Points

True (*)
False

Correct Correct

8. One of the primary goals of the Java platform is to provide an interpreted, just-in-time run time environment. Mark
for Review

(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 1 Lesson 1.

9. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]

Which of the following statements is TRUE? Mark for Review

(1) Points

Entire heap is 9350k.

Young Generation usage decreased by 3968k. (*)


The pause time spent in Young Generation is 0.0431096

The size of Eden space is 4032k.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

10. Given the following code snippet:

String str = new String("Hello");

The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark for Review

(1) Points

In the Heap area of the run-time data area in the JVM.

In the Method area of the run-time data area in the JVM.

In the Stack area of the run-time data area in the JVM.

In the constant pool area of the run-time data area in the JVM. (*)
Incorrect Incorrect. Refer to Section 1 Lesson 2.

11. Given the following code snippet:

String str = new String("Hello");

The str variable will be located in which memory area in the JVM during runtime? Mark for Review

(1) Points

str will stay in the heap area of the run-time data area in the JVM.

str will stay in the method area of the run-time data area in the JVM.

str will stay in the stack area of the run-time data area in the JVM. (*)

str will stay in the heap area of the constant pool run-time data area in the JVM.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

12. In which area of heap memory are newly created objects stored? Mark for Review

(1) Points

Survivor Space 0
Survivor Space 1

Eden (*)

Tenured

Incorrect Incorrect. Refer to Section 1 Lesson 2.

13. Which of the following allows the programmer to destroy an object referenced by x? Mark for Review

(1) Points

x.remove();

x.finalize();

x.delete();

Only the garbage collection system can destroy an object. (*)

Correct Correct
14. Which of following statements describes Parallel and Serial Garbage collection? Mark for Review

(1) Points

A Serial garbage collector uses multiple threads to manage heap space.

A Parallel garbage collector uses multiple threads to manage heap space. (*)

A Parallel garbage collector uses multiple threads to manage stack space.

A Serial garbage collector uses multiple threads to manage stack space.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

15. Which of the following statements is NOT TRUE for the JVM heap? Mark for Review

(1) Points

Java Developer can explicitly allocate and deallocate the Heap Memory. (*)

The Heap can be managed by the Garbage Collector.

The Heap can be shared among all Java threads.


Class instance and arrays are allocated in the Heap Memory.

Correct Correct

1. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){

int y=100;

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

Variable x resides in the stack area, and variable y resides in the heap of the JVM.

Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)

Variable x stays in the heap area, and variable y resides in the method area of the JVM.
Correct Correct

2. Which of the following statements describe the Java programming language? Mark for Review

(1) Points

Java is a high-level programming language.

The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.

All of the above (*)

Correct Correct

3. During runtime, the Java platform loads classes dynamically as required. Mark for Review

(1) Points

True (*)

False
Correct Correct

4. Which of the following statements is NOT TRUE about the JVM? Mark for Review

(1) Points

The JVM is a virtual Machine that acts as an intermediary layer between the Java Application and the Native Operating
System.

The JVM reads byte code from the class file, and generates machine code.

The JVM does not understand the Java language specification.

The JVM reads Java source code, and then translates it into byte code. (*)

Incorrect Incorrect. Refer to Section 1 Lesson 1.

5. Where does an object of a class get stored? Mark for Review

(1) Points

Stack area
Method area

In the file

In the database

Heap area (*)

6. Java allows the same Java program to be executed on multiple operating systems. Mark for Review

(1) Points

True (*)

False

Correct Correct

7. Which of the following converts a human-readable file into a platform-independent code file in Java? Mark for
Review

(1) Points

JRE
JDK

javac command (*)

java command

Correct Correct

8. One of the primary goals of the Java platform is to provide an interpreted, just-in-time run time environment. Mark
for Review

(1) Points

True (*)

False

Correct Correct

9. Which of following statements describes Parallel and Serial Garbage collection? Mark for Review

(1) Points
A Serial garbage collector uses multiple threads to manage heap space.

A Parallel garbage collector uses multiple threads to manage heap space. (*)

A Parallel garbage collector uses multiple threads to manage stack space.

A Serial garbage collector uses multiple threads to manage stack space.

Correct Correct

10. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]

Which of the following statements is TRUE? Mark for Review

(1) Points

Entire heap is 9350k.

Young Generation usage decreased by 3968k. (*)

The pause time spent in Young Generation is 0.0431096


The size of Eden space is 4032k.

Correct Correct

11. Which of the following statements is NOT TRUE for the JVM heap? Mark for Review

(1) Points

Java Developer can explicitly allocate and deallocate the Heap Memory. (*)

The Heap can be managed by the Garbage Collector.

The Heap can be shared among all Java threads.

Class instance and arrays are allocated in the Heap Memory.

Correct Correct

12. Given the following code snippet:

String str = new String("Hello");

The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark for Review

(1) Points
In the Heap area of the run-time data area in the JVM.

In the Method area of the run-time data area in the JVM.

In the Stack area of the run-time data area in the JVM.

In the constant pool area of the run-time data area in the JVM. (*)

Incorrect Incorrect. Refer to Section 1 Lesson 2.

13. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]

What estimated percentage of the Java objects will be promoted from Young space to Tenured space? Mark for Review

(1) Points

0.2

0.4

0.6 (*)
0.8

0.9

Incorrect Incorrect. Refer to Section 1 Lesson 2.

14. Which of the following allows the programmer to destroy an object referenced by x? Mark for Review

(1) Points

x.remove();

x.finalize();

x.delete();

Only the garbage collection system can destroy an object. (*)

Correct Correct

15. Given the following code snippet:


String str = new String("Hello");

The str variable will be located in which memory area in the JVM during runtime? Mark for Review

(1) Points

str will stay in the heap area of the run-time data area in the JVM.

str will stay in the method area of the run-time data area in the JVM.

str will stay in the stack area of the run-time data area in the JVM. (*)

str will stay in the heap area of the constant pool run-time data area in the JVM.

Correct Correct

Section 2

(Answer all questions in this section)

1. Which of the following commands allows a developer to see the effects of a running java application on memory and
CPU? Mark for Review

(1) Points

javac

jvisualvm (*)
java

javap

Correct Correct

2. HotSpot has an HSDIS plugin to allow disassembly of code. Mark for Review

(1) Points

True (*)

False

Correct Correct

3. Which of the following commands is used to launch a java program? Mark for Review

(1) Points

javac
jvisualvm

java (*)

javap

Incorrect Incorrect. Refer to Section 2 Lesson 1.

4. Before we can use the jsat tool we first have to use the jps tool to obtain JVM process id numbers. Mark for Review

(1) Points

True (*)

False

Correct Correct

5. Given the following information in the jdb tool, jdb paused at line 11:

9 public static void method1(){

10 x=100;

11 }
public static void method1();

Code:

0: bipush 100

2: putstatic #7 //Field x:I

5: return

Which statement is true?

Step completed: "thread-main", Example.method1(), line=11 bci=5

Mark for Review

(1) Points

The line=11 means the jdb executed line 11 bytecode in the method1 method.

The bci=5 means the jdb executed the last bytecode instruction in the method1 method. (*)

The bci=5 means the jdb executed 5 lines of the source code.

From the bytecode, we can assume the Variable x is an instance variable.

Correct Correct

6. The javac command can be used to display native code in Java Mark for Review

(1) Points
True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

7. The jsat tool can be used to monitor garbage collection information. Mark for Review

(1) Points

True (*)

False

3. Which of the following structures are contained in a Java class file? Mark for Review

(1) Points

minor_version

major_version

access_flags
All of the above (*)

The bytecode for a Java method is located in which structure in the Java class file? Mark for Review

(1) Points

magic

access_flags

method_info (*)

major_version

Which structure in the Java class file contains the line number information for the original source file? Mark for Review

(1) Points

method_info (*)

this_class

filed_info

cp_info

Which of the following commands can be used to translate Java source code into bytecode? Mark for Review

(1) Points
java

javac (*)

jdb

jstat

Correct Correct

8. Which of the following commands can be used to monitor the Java Virtual Machine statistics? Mark for Review

(1) Points

jstat (*)

javap

javac

jmap
Incorrect Incorrect. Refer to Section 2 Lesson 1.

9. Which of the following statements is NOT TRUE for the jdb command? Mark for Review

(1) Points

jdb can display the source code.

jdb can set the break pont for the program.

jdb can dump the stack of the current thread.

jdb can track the GC activity of the program. (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

10. The class file contains the definition it inherits from the superclass. Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 2.

11. Given the following instance variable:

public void foo(){

int i=888888;

Which of the following statements is NOT TRUE? Mark for Review

(1) Points

The variable i is a local variable.

The 888888 is an integer literal. After compile, the number will stay in the constant pool.

The variable i and the literal 888888 are stored in the method_info. (*)

The field descriptor for the variable i is I.

Correct Correct

12. The attributes_count item indicates how many attributes are contained within a method. Mark for Review
(1) Points

True (*)

False

10. Like in the Java source code file, one Java class file can contain multiple class definitions. Mark for Review

(1) Points

True

False (*)

Correct Correct

13. Given the following declaration of the method test:

public static void test(String s, int i);

Which of the following is the descriptor of the test method in the class file? Mark for Review

(1) Points

(java/lang/String;int)V

(Ljava/lang/String;I)V (*)
V(Ljava/lang/String;I)

(Ljava/lang/String;java.lang.Integer)V

Incorrect Incorrect. Refer to Section 2 Lesson 2.

14. Given the following class structure:

public class Shape{

void foo(){}

public class Circle extends Shape{

void draw(){}

Which of the following statements is TRUE? Mark for Review

(1) Points

The foo method definition appears in the Circle class.

The Circle class contains both the foo and draw method definitions.

The foo method definition is only contained in the Shape class. (*)
If a Circle object is instantiated, the constructor of Circle will call the constructor of Shape.

Incorrect Incorrect. Refer to Section 2 Lesson 2.

15. In a valid Java class file, the magic number is always: Mark for Review

(1) Points

42

CAFEBABE (*)

1.618

BABECAFE

Incorrect Incorrect. Refer to Section 2 Lesson 2.

Section 3

(Answer all questions in this section)

1. opcode invokespecial is used to invoke an instance initialization method. Mark for Review

(1) Points
True (*)

False

Correct Correct

2. Bytecode is an intermediate representation of a program, somewhere between source code and machine code.
Mark for Review

(1) Points

True (*)

False

Correct Correct

3. To inspect bytecode, which option is used with the javap command to disassemble the class file? Mark for Review

(1) Points

-a
-b

-c (*)

-d

Incorrect Incorrect. Refer to Section 3 Lesson 1.

4. Choose which opcode is used to load an int from the local variable to the operand stack. Mark for Review

(1) Points

aload

iload (*)

iaload

iconst

Incorrect Incorrect. Refer to Section 3 Lesson 1.


5. Java bytecode is generated by the javac command. Mark for Review

(1) Points

True (*)

False

Correct Correct

6. Choose which opcode is used to push an int constant 5 onto the operand stack. Mark for Review

(1) Points

iconst_5 (*)

idc5

iload_5

iaload_5

iinc5
Incorrect Incorrect. Refer to Section 3 Lesson 1.

7. .class files are loaded into memory all at once, when a Java application is launched. Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

8. The Java developer can define a number of additional or custom classloaders. Mark for Review

(1) Points

True (*)

False

Correct Correct
9. Which of the following statements is NOT TRUE for the Class.forName("HelloClass") method? (Choose three)

public class Foo{

public void test(){

Class.forName("HelloClass");

Mark for Review

(1) Points

(Choose all correct answers)

The forName() method does not initialize the HelloClass. (*)

The forName() method returns the Class object associated with the HelloClass.

The forName() method does not load the HelloClas class into the Java Runtime. (*)

In this example, the Class.forName("HelloClass") will use the ClassLoader which loads the Foo class.

The forName method will instantiate a HelloClass object. (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.


10. The process of linking involves which of the following processes? Mark for Review

(1) Points

verification

preparation

resolution

All of the above (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

11. In the ClassLoader hierarchy, which of the following is the only class loader that does NOT have a parent? Mark for
Review

(1) Points

custom class loader

application class loader

bootstrap class loader (*)


extension class loader

Incorrect Incorrect. Refer to Section 3 Lesson 2.

12. Which of the following exceptions is thrown by the loadClass() method of ClassLoader class? Mark for Review

(1) Points

IOException

SystemException

ClassFormatError

ClassNotFoundException (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

13. The same class cannot be loaded by the JVM more than one time. Mark for Review

(1) Points
True (*)

False

Correct Correct

14. Which of the following from ClassLoader will load the rt.jar, the Java core clsses which are present in the java.*
package? Mark for Review

(1) Points

Extension Class Loader

Custom Class Loader

Bootstrap Class Loader (*)

Application Class Loader

Incorrect Incorrect. Refer to Section 3 Lesson 2.


15. The System or Application ClassLoader loads Java classes from the System Classpath. This classpath is set by the
CLASSPATH environment variable. Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

Section 4

(Answer all questions in this section)

1. What is the output from the following code?

String s= "a,b,c";

Scanner sc = new Scanner (s);

while (sc.hasNext())

System.out.print (sc.next() +" "); Mark for Review

(1) Points

a,b

ac
a,b,c (*)

abc

Correct Correct

2. You declare a method:

public void act(Student s){}

Which of following arguments can be passed into the method? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

Type of Object class

Interface

Type of Student class (*)

Type of the subclass of Student (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.


3. Which three are valid declarations for a float value? (Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

float f = -1; (*)

float f = 2.0f; (*)

float f = 3.0L;

float f = 0x345; (*)

float f = 1.0;

Incorrect Incorrect. Refer to Section 4 Lesson 1.

4. Which two statements prevent a method from being overriden? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)


Void final act() {}

Final abstract void act() {}

Static final void act() {} (*)

Final void act() {} (*)

Static void act() {}

6. Which of the following operators are relational operators?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

"+="

"!=" (*)

">=" (*)

"="
Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. Which of the following operators are logic operators?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

&& (*)

<=

>

! (*)

9. What is the output from the following code snippet?

int i=0, j=0;

i=i++;

j=i++;
System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=1 j=0" (*)

The code will compile and print "i=1 j=1"

The code will not compile.

The code will compile and print "i=1 j=1"

The code will compile and print "i=0 j=0"

2. Which statement is a syntactically correct way to declare an Array? Mark for Review

(1) Points

int i[1];

int[5] id={1,2,3,4,5};

int i[1] id;


int id[]; (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

3. Using the code below, what will be the output if a Student object is instantiated?

public class Student

public Student()

System.out.print("1");

super();

System.out.print("2");

} Mark for Review

(1) Points

The code will not compile. (*)

12

1
Correct Correct

4. What is the final value of result from the following code snippet?

int i = 1;

int [] id = new int [3];

int result = id [i];

result = result + i; Mark for Review

(1) Points

The code will compile, result has the value of 0

The code will compile, result has the value of 2

The code will not compile, result has the value of 2

The code will compile, result has the value of 1 (*)

An exception is thrown.

Correct Correct
5. What is the output from the following code?

System.out.print("i=");

for (int i=0; i < l0; i++){

if(i==3)

break;

System.out.print(i);

} Mark for Review

(1) Points

i=0123456789

i=012 (*)

i=0123

i=012456789

Incorrect Incorrect. Refer to Section 4 Lesson 1.

6. Examine the following Classes:

Student and TestStudent

What is the output from the println statement in TestStudent?

public class Student {

private int studentId = 0;


public Student(){

studentId++;

public static int getStudentId(){

return studentId;

public class TestStudent {

public static void main(String[] args) {

Student s1 = new Student();

Student s2 = new Student();

Student s3 = new Student();

System.out.println(Student.getStudentId());

} Mark for Review

(1) Points

TestStudent will throw an exception

No output. Compilation of TestStudent fails (*)


Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. Which of following relationships does not use inheritance? Mark for Review

(1) Points

Car and Tire (*)

People and Student

Bank card and Credit Card

Animal and Cat

Correct Correct

8. Which statements are true?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

Since a constructor can not return any value, it should be declared as void.
You can use access modifiers to control which other classes can call the constructor. (*)

You can declare more than one constructor in a class declaration. (*)

A constructor can not be overloaded.

In a constructor, you can call a superclass constructor. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

9. What is the output from the following code snippet?

int i=0,j=0;

i=++i;

j=i++;

System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=1 j=2"

The code will compile and print "i=2 j=2"


The code does not compile.

The code will compile and print "i=1 j=1"

The code will compile and print "i=2 j=1" (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

10. Which two statements best describe data encapsulation? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

The access modifier to member data is private. (*)

Member data can be modified directly.

Methods provide for access and modification of data. (*)

The access modifier for methods is protected.


Incorrect Incorrect. Refer to Section 4 Lesson 1.

11. What is the output from the following code?

int x=0;

int y=5;

do{

++x;

y--;

}while(x<3);

System.out.println(x + " " + y); Mark for Review

(1) Points

22

3 2 (*)

23

33

Incorrect Incorrect. Refer to Section 4 Lesson 1.

12. The following code can be compiled, True/False?

byte b = 1;

b = b + 1; Mark for Review


(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

13. What is the output from the following code snippet?

int[] myarray={1,2,3,4,5};

int sum=0;

for (int x : myarray)

sum+=x;

System.out.println("sum= " + sum); Mark for Review

(1) Points

10

The code will not compile.

20
15 (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

14. Which of following statments are true when you create a object from class Object at runtime as seen below.
(Choose Three)

java.lang.Object obj = new java.lang.Object(); Mark for Review

(1) Points

(Choose all correct answers)

Memory is allocated for a new object, if available. (*)

Reference obj can be reassigned to any other type of object. (*)

This Object instance will not be created because you never defined class Object.

A new instance of class Object is created. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.


15. What is the output from the following code snippet?

public class Test {

public static void main(String[] args) {

System.out.println(1 + 2 + "java" + 3);

} Mark for Review

(1) Points

The code does not compile.

The code will compile and print "12java3"

The code will compile and print "6java"

The code will compile and print "3java3" (*)

The code will compile and print "java3"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

1. Which of following relationships does not use inheritance? Mark for Review

(1) Points

People and Student

Animal and Cat


Bank card and Credit Card

Car and Tire (*)

Correct Correct

2. What is the output from the following code?

int x=0;

int y=5;

do{

++x;

y--;

}while(x<3);

System.out.println(x + " " + y); Mark for Review

(1) Points

3 2 (*)

33

23
22

Incorrect Incorrect. Refer to Section 4 Lesson 1.

3. Which statement is incorrect regarding a constructor? Mark for Review

(1) Points

When no constructor is defined in the class, the compiler will create a default constructor.

The default constructor initializes the instance variables.

A constructor can not return value, it must be declared as void. (*)

The default constructor is the no-parameter constructor.

Correct Correct

4. What is the output from the following code snippet?

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

if (i == 3) {

break;

}
System.out.print(i); Mark for Review

(1) Points

The code will compile and print "123"

The code does not compile.

The code will compile and print "0123"

The code will compile and print "012" (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

5. A class can be extended by more than one class. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct
6. What is the output from the following code snippet?

String str1 = "java";

char[] c = {'j', 'a', 'v', 'a'};

System.out.println(str1.equals(c));

System.out.println(t == c); Mark for Review

(1) Points

The code will compile and print "true true"

The code will compile and print "false, true"

The code does not compile. (*)

The code will compile and print "false,false"

The code will compile and print "true, false"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. What is the output from the following code snippet?

int i=0,j=0;

i=++i;
j=i++;

System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=2 j=2"

The code will compile and print "i=2 j=1" (*)

The code will compile and print "i=1 j=2"

The code does not compile.

The code will compile and print "i=1 j=1"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

8. Which combination of the following overload the Student constructor?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

public Object Student(int x,int y){}


public Student(){} (*)

protected int Student(){}

public void Student(int x, int y){}

public Student(int x,int y){} (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

9. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

abstract

final

protected (*)
public (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

10. What is the output from the following code snippet?

String str1 = "java";

String str2 = "java";

System.out.println(str1.equals(str2) + "," + str1.equals(new String("hello"))); Mark for Review

(1) Points

The code will not compile.

The code will compile and print "true, false" (*)

The code will compile and print "false, true"

The code will compile and print "false, false"

The code will compile and print "true, true"

Incorrect Incorrect. Refer to Section 4 Lesson 1.


11. When you instantiate a subclass, the superclass constructor will be also invoked. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

12. Which statements are true?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

You can use access modifiers to control which other classes can call the constructor. (*)

Since a constructor can not return any value, it should be declared as void.

You can declare more than one constructor in a class declaration. (*)

A constructor can not be overloaded.


In a constructor, you can call a superclass constructor. (*)

Correct Correct

13. Which ofthe following declarations are wrong?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

abstract final class Hello{} (*)

public abstract class Student{}

protected private int id; (*)

abstract private void act(){} (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

14. Which statement is true when run the following statement?

1. String str = null;


2. if ((str != null) && (str.length() > 1)) {

3. System.out.println("great that number 1");

4. } else if ((str != null) & (str.length() < 2)) {

5. System.out.println("less than number 2");

6. } Mark for Review

(1) Points

The code compiles and will throw an exception at line 2.

The code compiles and will throw an exception at line 3.

The code compiles and will throw an exception at line 4. (*)

The code compiles and will throw an exception at line 5

The code does not compile.

Correct Correct

15. What is the output from the following code snippet?

int x = 1;

int y;

while(++x < 5)
y++;

System.out.println(y); Mark for Review

(1) Points

The code will not compile. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

Section 5

(Answer all questions in this section)

1. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

2. An interface can implement methods.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

3. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.

4. Unit testing can help you isolate problem quickly. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

5. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is
combined with other components in the system. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 5 Lesson 4


6. Which statement is true for the class java.util.ArrayList? Mark for Review

(1) Points

The elements in the collection are accessed using key.

The elements in the collection are ordered. (*)

The elements in the collection are immutable.

The elements in the collection are synchronized.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

7. Which of the following is the correct way to throw cumstom ServerException? Mark for Review

(1) Points

throw ServerException

throws ServerException

throw new ServerException() (*)


raise ServerException

Correct Correct

8. What symbol(s) is used to separate multiple exceptions in one catch statement? Mark for Review

(1) Points

A single vertical bar | (*)

&&

(==) (equals equals)

None, multiple exceptions can't be handled in one catch statement.

Incorrect Incorrect. Refer to Section 5 Lesson 3.

9. What is the output from the following code snippet?

class Shape{

public void paint(){System.out.print("Shape");}


class Circle extends Shape{

public void paint() throws Exception{

System.out.print("Circle ");

throw new Exception();

public static void main(String[] args){

try{new Circle().paint();}

catch(Exception e){System.out.println("Exception");

} Mark for Review

(1) Points

Circle

Shape

ShapeCircle

Exception

Compile fails (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.


10. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

11. Which three types of objects can be thrown using a throw statement? (Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

Error (*)

Event

Exception (*)

Throwable (*)
Object

Incorrect Incorrect. Refer to Section 5 Lesson 3.

12. The instanceof operator can find subclass objects when they are passed to method which declare a superclass type
parameter.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

13. The instanceof operator allows you to determine the type of an object.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

14. Which one of the following would allow you to define the abstract class Animal. Mark for Review

(1) Points

public abstract Animal {}

public Animal{}

public abstract Animal extends class{}

public abstract class Animal{} (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

15. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)
False

1. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

2. Which one of the following would allow you to define an interface for Animal? Mark for Review

(1) Points

public class Animal {}

public Animal extends Interface {}

public class Animal implements Interface {}

public interface Animal {} (*)


Incorrect Incorrect. Refer to Section 5 Lesson 2.

3. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

4. The instanceof operator can find subclass objects when they are passed to method which declare a superclass type
parameter.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

5. Which method will force a subclass to implement it? Mark for Review

(1) Points

Abstract public void act(); (*)

Public double act();

Protected void act(String name){}

Static void act(String name) {}

Public native double act();

Correct Correct

Section 5

(Answer all questions in this section)

1. What do Arrays and ArrayLists have in common?


I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only

II only

I and II only (*)

I, II and III only

None of these

Incorrect Incorrect. Refer to Section 5 Lesson 4.

2. Reading great code is just as important for a programmer as reading great books is for a writer. True or false? Mark
for Review

(1) Points

True (*)
False

Correct Correct

3. Unit testing can help you isolate problem quickly. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

4. What is the result from creating the following try-catch block?

1.try {

2.} catch (Exception e) {

3.} catch (ArithmeticException a) {

4.} Mark for Review


(1) Points

Compile fails at Line 3 (*)

Compile fails at Line 2

The code compiles

Compile fails at Line 1

Incorrect Incorrect. Refer to Section 5 Lesson 3.

5. What is one step you must do to create your own exception? Mark for Review

(1) Points

Create a new class that implements Exception.

Create a new class that extends Exception. (*)

Exceptions cannot be created. They are only built in to Java.


Declare the primitive data type Exception.

Correct Correct

. Which statement added at line one allows the code to compile and run?

//line one

public class Test (

public static void main (String[] args) {

java.io.PrintWriter out = new java.io.PrintWriter

(new java.io.OutputStreamWriter (System.out), true);

System.out.println("Java");

} Mark for Review

(1) Points

No statement is needed. (*)

import java.io.OutputStreamWriter

include java.io.*;

import java.io.PrintWriter;

import java.io.*;
Incorrect Incorrect. Refer to Section 5 Lesson 3.

7. This is correct syntax for catching an exception:

try(inputStream = "missingfile.txt");

catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

8. What is exception handling? Mark for Review

(1) Points

If your program exits before you expect it to.

When a file fails to open.


An error that occurs against the flow of your program.

A consistent way of handling various errors. (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

9. Virtual method invocation requires that the superclass method is defined as which of the following? Mark for
Review

(1) Points

A private final method.

A default final method.

A public final method.

A public static method.

A public method. (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.


10. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

11. Which line contains an compilation error?

interface Shape {}

interface InnerShape extends Shape{}

class Circle implements Shape{ }

class InnerCircle extends Circle{}

class Rectangle implements Shape{}

public class Tester {

public static void main(String[] args) {

Circle c= new Circle();

InnerCircle ic = new InnerCircle();

Rectangle rect = new Rectangle();

System.out.print(c instanceof InnerCircle); //Line 1

System.out.print(ic instanceof Circle); //Line 2

System.out.print(rect instanceof InnerCircle); //Line 3


System.out.print(rect instanceof Shape); //Line 4

} Mark for Review

(1) Points

Line 2

Line 3 (*)

Line 4

Line 1

Correct Correct

12. An abstract class can be instantiated.

True or false? Mark for Review

(1) Points

True

False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.

13. In general, classes can be made immutable by placing a final key word before the class keyword.

True or false? Mark for Review

(1) Points

False

True (*)

Correct Correct

14. The state of an object differentiates it from other objects of the same class.

True or False? Mark for Review

(1) Points

True (*)

False
Correct Correct

15. Which one of the following would allow you to define an interface for Animal? Mark for Review

(1) Points

public interface Animal {} (*)

public class Animal implements Interface {}

public class Animal {}

public Animal extends Interface {}

Correct Correct

ection 5

(Answer all questions in this section)

1. What is exception handling? Mark for Review

(1) Points

If your program exits before you expect it to.


A consistent way of handling various errors. (*)

When a file fails to open.

An error that occurs against the flow of your program.

Correct Correct

2. Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

can not create Exception object in the Test Class.


The class Test compiles if line 6 contains a throws statement. public static void main(String[] args) throws Exception{ (*)

The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }catch(Exception e){} (*)

Compilation succeeds

Incorrect Incorrect. Refer to Section 5 Lesson 3.

3. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

4. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points
True (*)

False

Incorrect Incorrect. Refer to Section 5 Lesson 3.

5. What is the output from the following code snippet?

public static void main(String[] args){

try{

String[] s=null;

s[0]="Java";

System.out.println(s[0]);

}catch(Exception e) {

System.out.println("Exception");

}catch(NullPointerException e){

System.out.println("NullPointerException");

} Mark for Review

(1) Points

NullPointerException

Compile fails (*)


Java

Exception

Incorrect Incorrect. Refer to Section 5 Lesson 3.

6. A upward cast means all instance variables of the subclass are permanently lost to the instance.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

7. The instanceof operator can find subclass objects when they are passed to method which declare a superclass type
parameter.

True or false? Mark for Review

(1) Points

True (*)
False

Correct Correct

8. A downward cast of a superclass to subclass allows you to access a subclass specialized method call.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

9. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(1) Points

True

False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.

10. Unit testing can help you isolate problem quickly. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

11. Which of the following statements about arrays and ArrayLists in Java are true?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points

I and III only (*)

II and IV only
I, II, and III only

I, II, III and IV

None of these

Incorrect Incorrect. Refer to Section 5 Lesson 4.

12. Which statement is true for the class java.util.ArrayList? Mark for Review

(1) Points

The elements in the collection are synchronized.

The elements in the collection are accessed using key.

The elements in the collection are ordered. (*)

The elements in the collection are immutable.

Incorrect Incorrect. Refer to Section 5 Lesson 4.


13. A method with default access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

14. Which two statements are equivalent to line 2?

(Choose Two)

1. public interface Account{

2. int accountID=100;

3. } Mark for Review

(1) Points

(Choose all correct answers)

static int accountID=100; (*)

private int accountID=100;


Final int accountID=100; (*)

Abstract int accountID=100;

protected int accountID=100;

Incorrect Incorrect. Refer to Section 5 Lesson 2.

15. Classes define and implement what? Mark for Review

(1) Points

All methods with implementations

Variables and methods (*)

Some methods with implementations

All method definitions without any implementations

Constants and all methods with implementations

1. Virtual method invocation must be defined with the instanceof operator.

True or false? Mark for Review


(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

2. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

3. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(1) Points
True

False (*)

Correct Correct

4. Which method will force a subclass to implement it? Mark for Review

(1) Points

Abstract public void act(); (*)

Protected void act(String name){}

Public double act();

Static void act(String name) {}

Public native double act();

Correct Correct
5. Methods can not throw exceptions.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

6. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

None of them execute since you cannot have multiple catch statements.
Incorrect Incorrect. Refer to Section 5 Lesson 3.

7. Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

can not create Exception object in the Test Class.

Compilation succeeds

The class Test compiles if line 6 contains a throws statement. public static void main(String[] args) throws Exception{ (*)

The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }catch(Exception e){} (*)
Correct Correct

8. This is correct syntax for catching an exception:

try(inputStream = "missingfile.txt");

catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

9. Multiple exceptions can be caught in one catch statement.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

10. You can only implement one interface in a class.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

11. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct
12. Which one of the following would allow you to define an interface for Animal? Mark for Review

(1) Points

public class Animal {}

public Animal extends Interface {}

public class Animal implements Interface {}

public interface Animal {} (*)

Correct Correct

13. Which of the following statements is false? Mark for Review

(1) Points

An ArrayList has a fixed length. (*)

An ArrayList can store multiple object types.

An ArrayList can grow and shrink dynamically as required.


In an Array you need to know the length and the current number of elements stored.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

Test: Java Programming Midterm Exam

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

Section 1

(Answer all questions in this section)

1. The function of Garbage Collection in Java is: Mark for Review

(1) Points

The JVM uses GC to clear the program output.

The JVM GC deletes all unused Java files on the system.

Memory occupied by objects with no reference is automatically reclaimed for reuse. (*)

As a Java programmer, we have to call the GC function specifically in order to manage the Java Memory.
Correct Correct

2. Which of the following allows the programmer to destroy an object referenced by x? Mark for Review

(1) Points

x.remove();

x.finalize();

x.delete();

Only the garbage collection system can destroy an object. (*)

Correct Correct

3. Given the following output from the Minor GC:

[PSYoungGen: 9200K->1008K(9216K)] 9980K->3251K(19456K), 0.0045753 secs] [Times:user=0.03 sys=0.03, real=0.00


secs]

Which of the following statements is TRUE? Mark for Review

(1) Points

The pause time spent in GC is 0.03.


The size of the entire heap is 19456k (*)

This is a major garbage collection process.

The size of the tenured space is 19456k.

Correct Correct

4. Java allows the same Java program to be executed on multiple operating systems. Mark for Review

(1) Points

True (*)

False

Correct Correct

5. Which of the following statements describe the Java programming language? Mark for Review

(1) Points
Java is a high-level programming language.

The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.

All of the above (*)

Correct Correct

Page 1 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 1

(Answer all questions in this section)

6. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){

int y=100;
}

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

Variable x resides in the stack area, and variable y resides in the heap of the JVM.

Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)

Variable x stays in the heap area, and variable y resides in the method area of the JVM.

Correct Correct

Section 2

(Answer all questions in this section)

7. The javac command can be used to display native code in Java Mark for Review

(1) Points
True

False (*)

Correct Correct

8. Which of the following commands can be used to translate Java source code into bytecode? Mark for Review

(1) Points

java

javac (*)

jdb

jstat

Correct Correct

9. Which of the following statements is NOT TRUE for the jdb command? Mark for Review

(1) Points
jdb can display the source code.

jdb can set the break pont for the program.

jdb can dump the stack of the current thread.

jdb can track the GC activity of the program. (*)

Correct Correct

10. Like in the Java source code file, one Java class file can contain multiple class definitions. Mark for Review

(1) Points

True

False (*)

Correct Correct
Previous Page 2 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 2

(Answer all questions in this section)

11. Which structure in the Java class file contains the line number information for the original source file? Mark for
Review

(1) Points

method_info (*)

this_class

filed_info

cp_info

Correct Correct

12. The attributes_count item indicates how many attributes are contained within a method. Mark for Review

(1) Points
True (*)

False

Correct Correct

Section 3

(Answer all questions in this section)

13. Which of the following opcode instructions would add 2 integer variables? Mark for Review

(1) Points

add

addi

iadd (*)
Incorrect Incorrect. Refer to Section 3 Lesson 1.

14. Choose which opcode is used to push an int constant 5 onto the operand stack. Mark for Review

(1) Points

iconst_5 (*)

idc5

iload_5

iaload_5

iinc5

Correct Correct

15. opcode invokespecial is used to invoke an instance initialization method. Mark for Review

(1) Points
True (*)

False

16. Which of the following is NOT a java class loader? Mark for Review

(1) Points

verification class loader (*)

application class loader

bootstrap class loader

extension class loader

Correct Correct

17. The Java developer can define a number of additional or custom classloaders. Mark for Review

(1) Points

True (*)

False
Correct Correct

18. Which of the following exceptions is thrown by the loadClass() method of ClassLoader class? Mark for Review

(1) Points

IOException

SystemException

ClassFormatError

ClassNotFoundException (*)

Correct Correct

Section 4

(Answer all questions in this section)

19. Which three are valid declarations for a float value? (Choose Three) Mark for Review
(1) Points

(Choose all correct answers)

float f = -1; (*)

float f = 0x345; (*)

float f = 3.0L;

float f = 2.0f; (*)

float f = 1.0;

Correct Correct

20. What is the final value of result from the following code snippet?

int i = 1;

int [] id = new int [3];

int result = id [i];

result = result + i; Mark for Review

(1) Points
The code will compile, result has the value of 0

The code will compile, result has the value of 1 (*)

The code will not compile, result has the value of 2

The code will compile, result has the value of 2

An exception is thrown.

Correct Correct

Previous Page 4 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 4

(Answer all questions in this section)

21. What is the output from the following code snippet?

String str1= "java";

String str2=new String("java");


System.out.println( str1==str2 );

System.out.println( str1==str2.intern() );

Mark for Review

(1) Points

The code does not compile.

The code will compile and print "true false"

The code will compile and print "false true" (*)

The code will compile and print "false false"

The code will compile and print "true true"

Correct Correct

22. What is the output from the following code snippet?

int[] myarray={1,2,3,4,5};

int sum=0;

for (int x : myarray)

sum+=x;

System.out.println("sum= " + sum); Mark for Review


(1) Points

The code will not compile.

10

15 (*)

20

Correct Correct

23. Examine the following Classes:

Student and TestStudent

What is the output from the println statement in TestStudent?

public class Student {

private int studentId = 0;

public Student(){

studentId++;

public static int getStudentId(){

return studentId;

}
}

public class TestStudent {

public static void main(String[] args) {

Student s1 = new Student();

Student s2 = new Student();

Student s3 = new Student();

System.out.println(Student.getStudentId());

} Mark for Review

(1) Points

No output. Compilation of TestStudent fails (*)

TestStudent will throw an exception

Correct Correct

24. Which ofthe following declarations are wrong?(Choose Three) Mark for Review

(1) Points
(Choose all correct answers)

abstract private void act(){} (*)

public abstract class Student{}

protected private int id; (*)

abstract final class Hello{} (*)

Correct Correct

25. Which of the following types are primitive data types? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

String

boolean (*)

double (*)
Integer

Correct Correct

Previous Page 5 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 5

(Answer all questions in this section)

26. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct
27. You can only implement one interface in a class.

True or False? Mark for Review

(1) Points

True

False (*)

Correct Correct

28. Interfaces define what? Mark for Review

(1) Points

Constants and all methods with implementations

Some methods with implementations

All method definitions without any implementations (*)

All methods with implementations


Variables and methods

Correct Correct

29. Modeling classes for a business problem requires understanding of the business not Java. True or false? Mark for
Review

(1) Points

True

False (*)

Correct Correct

30. Classes define and implement what? Mark for Review

(1) Points

Some methods with implementations

Constants and all methods with implementations


All methods with implementations

All method definitions without any implementations

Variables and methods (*)

Correct Correct

Previous Page 6 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 5

(Answer all questions in this section)

31. An interface can implement methods.

True or False? Mark for Review

(1) Points

True
False (*)

Correct Correct

32. When line 10 is executed, which method will be called?

1 class Account {

2 public void deposit(int amt, int amt1) { }

3 public void deposit(int amt){ }

4}

5 public class CreditAccount extends Account {

6 public void deposit() { }

7 public void deposit(int amt) {}

8 public static void main(String args[]){

9 Account account = new CreditAccount();

10 account.deposit(10);

11 }

12 } Mark for Review

(1) Points

line 7 (*)

line 2

line 3
line 6

Correct Correct

33. You can always upcast a subclass to an interface provided you don't need to access any members of the concrete
class.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

34. Which two of the following statements are true? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

An abstract class must contain abstrct method.


An abstract class can define constructor. (*)

An abstract class can create subclass and be constructed.

An abstract class must be difined by using the abstract keyword. (*)

Correct Correct

35. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

Previous Page 7 of 10 Next Summary


Test: Java Programming Midterm Exam

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

Section 5

(Answer all questions in this section)

36. Virtual method invocation must be defined with the instanceof operator.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

37. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(1) Points

True

False (*)
Correct Correct

38. Which of the following is the correct way to throw cumstom ServerException? Mark for Review

(1) Points

throw ServerException

throws ServerException

throw new ServerException() (*)

raise ServerException

Correct Correct

39. When will a finally statement be executed? Mark for Review

(1) Points

Always; no matter if an exception is thrown or not. (*)

Only if an exception is not thrown.


Never; it is there for visual purposes.

Only if multiple exceptions are caught and thrown.

Only if an exception is thrown.

Incorrect Incorrect. Refer to Section 5 Lesson 3.

40. What is the output from the following code snippet?

public static void main(String[] args){

try{

String[] s=null;

s[0]="Java";

System.out.println(s[0]);

}catch(Exception e) {

System.out.println("Exception");

}catch(NullPointerException e){

System.out.println("NullPointerException");

} Mark for Review

(1) Points

Exception
NullPointerException

Compile fails (*)

Java

Correct Correct

Previous Page 8 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 5

(Answer all questions in this section)

41. Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){


7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }catch(Exception e){} (*)

Compilation succeeds

can not create Exception object in the Test Class.

The class Test compiles if line 6 contains a throws statement. public static void main(String[] args) throws Exception{ (*)

Correct Correct

42. The finally clause only executes when an exception is not caught and thrown.

True or false? Mark for Review

(1) Points

True
False (*)

Correct Correct

43. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

None of them execute since you cannot have multiple catch statements.

Correct Correct

44. Methods can not throw exceptions.

True or false? Mark for Review

(1) Points
True

False (*)

Correct Correct

45. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only

II only

I and II only (*)

I, II and III only

None of these
Correct Correct

Previous Page 9 of 10 Next Summary

Test: Java Programming Midterm Exam

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

Section 5

(Answer all questions in this section)

46. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is
combined with other components in the system. True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

47. Why is it helpful for new programmers to read pre-written code?(Choose Two) Mark for Review

(1) Points
(Choose all correct answers)

It is not helpful to read code written by other programmers.

Learn new programming techniques. (*)

Understand code written by other programmers. (*)

Meet new programmers.

Correct Correct

48. Which of the following statements is false? Mark for Review

(1) Points

An ArrayList has a fixed length. (*)

An ArrayList can store multiple object types.

In an Array you need to know the length and the current number of elements stored.
An ArrayList can grow and shrink dynamically as required.

Correct Correct

49. Which of the following statements about unit testing is/are true

I. When all unit tests succeed, you can have high confidence your code is solid.

II. If a unit test fails, you don メ t proceed until the code is fixed and the test succeeds.

III. Unit testing can help developer find problems early in the development cycle

Mark for Review

(1) Points

I only

I and II only

II and III only (*)

I, II, and III

None of these
Correct Correct

50. Which of the following statements about arrays and ArrayLists in Java are true?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of these

14. Why is it helpful for new programmers to read pre-written code?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

Learn new programming techniques. (*)


Meet new programmers.

Understand code written by other programmers. (*)

It is not helpful to read code written by other programmers.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

15. Which of the following statements about inheritance is false? Mark for Review

(1) Points

A subclass inherits all the members (fields, methods, and nested classes) from its superclass.

Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself.

Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among
several subclasses.

Through inheritance, a parent class is a more specialized form of the child class. (*)
Incorrect Incorrect. Refer to Section 5 Lesson 4.

Section 6

(Answer all questions in this section)

1. A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

2. Which of the following is a list of elements that have a first in last out ordering. Mark for Review

(1) Points

Arrays

HashMaps

Enums
Stacks (*)

Incorrect Incorrect. Refer to Section 6 Lesson 3.

3. A HashMap can only store String types.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 3.

4. Which of the following correctly defines a queue? Mark for Review

(1) Points

A list of elements with a first in last out order.

A list of elements with a first in first out order. (*)


It is a keyword in Java that restrict the use of the code to local users only.

Something that enables you to create a generic class without specifying a type between angle brackets <>.

Incorrect Incorrect. Refer to Section 6 Lesson 3.

5. Which line contains an compilation error?

interface Shape {}

class Circle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls = new ArrayList(); // Line 1

List lc = new ArrayList(); // Line 2

Circle c = new Circle();

ls.add(c); // Line 3

lc.add(c); // Line 4

} Mark for Review

(1) Points

Line 2
Line 4

Line 1

Line 3 (*)

Incorrect Incorrect. Refer to Section 6 Lesson 2.

6. Which class is an ordered collection that may contain duplicates? Mark for Review

(1) Points

list (*)

enum

set

array

Incorrect Incorrect. Refer to Section 6 Lesson 2.

7. The following code is valid when working with the Collection Interface.
Collection collection = new Collection()d;

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

8. What is the output from the following code snippet?

public static void main(String[] args){

List li=new ArrayList();

li.add(1);

li.add(2);

print(li);

public static void print(List list) {

for (Number n : list)

System.out.print(n + " ");

} Mark for Review

(1) Points

1
The code will not compile.

1 2 (*)

Incorrect Incorrect. Refer to Section 6 Lesson 1.

9. < ? extends Animal > is an example of a bounded generic wildcard.

True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

10. What is the correct definition of Enumeration (or enum)? Mark for Review

(1) Points
Code that initializes an ArrayList

A list of elements that is dynamically stored.

A bounded generic class

A keyword that specifies a class whose objects are defined inside the class. (*)

Incorrect Incorrect. Refer to Section 6 Lesson 1.

11. Which of the following would initialize a generic class "Cell" using a String type?

I. Cell cell = new Cell(); .

II. Cell cell = new Cell(); .

III. Cell cell = new String;

Mark for Review

(1) Points

I and II (*)

II only

II and III
I only

III only

Incorrect Incorrect. Refer to Section 6 Lesson 1.

12. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

Incorrect Incorrect. Refer to Section 6 Lesson 4.


13. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal
speed? Mark for Review

(1) Points

Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above

Incorrect Incorrect. Refer to Section 6 Lesson 4.

14. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True or false? Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 4.

15. A sequential search is an iteration through the array that stops at the index where the desired element is found.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

Section 6

(Answer all questions in this section)

1. Which line contains an compilation error?

interface Shape {}

class Circle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls = new ArrayList(); // Line 1


List lc = new ArrayList(); // Line 2

Circle c = new Circle();

ls.add(c); // Line 3

lc.add(c); // Line 4

} Mark for Review

(1) Points

Line 3 (*)

Line 4

Line 1

Line 2

Correct Correct

2. Which of these could be a set? Why? Mark for Review

(1) Points

{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.

{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)

All of the above are sets because they are collections that can be made to fit any of the choices.

Incorrect Incorrect. Refer to Section 6 Lesson 2.

3. Which code inserted into the code below guarantees that the program will output [1,2]?

import java.util.*;

public class Example{

public static void main(String[] args){

//insert code here

set.add(2);

set.add(1);

System.out.println(set);

} Mark for Review

(1) Points

Set set = new SortedSet();

Set set = new TreeSet(); (*)


Set set = new LinkedHashSet();

Set set = new HashSet();

List set = new SortedList();

Incorrect Incorrect. Refer to Section 6 Lesson 2.

4. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or
false? Mark for Review

(1) Points

True (*)

False

Correct Correct

5. Selection sort is efficient for large arrays.

True or false? Mark for Review

(1) Points
True

False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 4.

6. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?
Mark for Review

(1) Points

Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above

Incorrect Incorrect. Refer to Section 6 Lesson 4.


7. A sequential search is an iteration through the array that stops at the index where the desired element is found.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

8. Enumerations (enums) are useful for storing data : Mark for Review

(1) Points

When you know all of the possibilities of the class (*)

When the class is constantly changing

When the class is a subclass of Object.

You cannot store data in an enum.


Incorrect Incorrect. Refer to Section 6 Lesson 1.

9. A generic class increases the risk of runtime class conversion exceptions.

True or False? Mark for Review

(1) Points

True

False (*)

Correct Correct

10. Generic methods are required to be declared as static.

True or False? Mark for Review

(1) Points

True

False (*)
Correct Correct

11. The following code will compile.

True or False?

class Node implements Comparable{

public int compareTo(T obj){return 1;}

class Test{

public static void main(String[] args){

Node nc=new Node<>();

Comparable com=nc;

Mark for Review

(1) Points

True (*)

False

Correct Correct

12. Which scenario best describes a stack? Mark for Review

(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)

A row of books that you can take out of only the middle of the books first and work your way outward toward either
edge.

A line at the grocery store where the first person in the line is the first person to leave.

All of the above describe a stack.

Incorrect Incorrect. Refer to Section 6 Lesson 3.

13. Where you enqueue an element in the list? Mark for Review

(1) Points

adds it to the end of the list (*)

adds it to the start of the list

removes it from the front of the list

removes it from the end of the list


Incorrect Incorrect. Refer to Section 6 Lesson 3.

14. A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

15. A LinkedList is a list of elements that is dynamically stored.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

1. All classes can by subclassed. Mark for Review

(1) Points

True

False (*)

5. What is special about including a resource in a try statement?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

The resources will auto-close. (*)

An error will be thrown if the resources does not open. (*)

The program will fail if the resource does not open

6. Why should you not use assertions to check parameters? Mark for Review

(1) Points

Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)
Not all methods have parameters, therefore assertions should never be used on parameters.

It is hard to assume expected values for parameters.

Assertions do not work on parameters

15. When an object is able to pass on its state and behaviors to its children, this is called: Mark for Review

(1) Points

Inheritance (*)

Encapsulation

Polymorphism

Isolation

Posted by karre resakl at 7:27 PM

Email This

BlogThis!

Share to Twitter

Share to Facebook

Share to Pinterest

84 comments:

UnknownDecember 21, 2018 at 5:41 AM


Section 6

(Answer all questions in this section)

1. An example of an upper bounded wildcard is.

ArrayList (*)

ArrayList

ArrayList

ArrayList

2.Enumerations (enums) are useful for storing data :

When the class is constantly changing

When you know all of the possibilities of the class (*)

When the class is a subclass of Object.


You cannot store data in an enum.

3. When would an enum (or enumeration) be used?

When you already know all the possibilities for objects of that class. (*)

When you wish to remove data from memory.

When you wish to initialize a HashSet.

When you want to be able to create any number of objects of that class.

4. Enumerations (enums) must be declared in their own class.

True

False (*)
5.Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True

False (*)

6.Which of the following best describes lexicographical order?

An order based on the ASCII value of characters. (*)

The order of indicies after an array has been sorted.

A simple sorting algorithm that is inefficient on large arrays.

A complex sorting algorithm that is efficient on large arrays.


7.Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or
false?

True (*)

False

8. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?

Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above


9.Which of the following correctly adds "Cabbage" to the ArrayList vegetables?

vegetables[0] = "Cabbage";

vegetables += "Cabbage";

vegetables.get("Cabbage");

vegetables.add("Cabbage"); (*)

10.Which interface forms the root of the collections hierarchy?

java.util.Map

java.util.List

java.util.Collection (*)
java.util.Collections

11. What is a set?

A collection of elements that does not contain duplicates. (*)

A keyword in Java that initializes an ArrayList.

Something that enables you to create a generic class without specifying a type between angle brackets <>.

A collection of elements that contains duplicates.

12. To allow our classes to have a natural order we could implement the Comparable interface.

True or false?

True (*)
False

13.Which of the following is a list of elements that have a first in last out ordering.

Stacks (*)

HashMaps

Enums

Arrays

14.Why can a LinkedList be considered a stack and a queue?(Choose Three)

Because you can add elements to the end of it. (*)

Because you can not add element to the beginning of it.


Because you can remove elements from the end of it. (*)

Because you can remove elements from the beginning of it. (*)

15.Which scenario best describes a stack?

A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)

A row of books that you can take out of only the middle of the books first and work your way outward toward either
edge.

A line at the grocery store where the first person in the line is the first person to leave.

All of the above describe a stack.

Reply

Replies

UnknownDecember 21, 2018 at 5:55 AM

16. A generic class is a type of class that associates one or more non-specific Java types with it.
True or False?

True (*)

False

17.The local petting zoo is writing a program to be able to collect group animals according to species to better keep track
of what animals they have.

Which of the following correctly defines a collection that may create these types of groupings for each species at the
zoo?

public class

animalCollection {ナ} (*)

public class

animalCollection(AnimalType T) {ナ}

public class

animalCollection {ナ}

public class

animalCollection(animalType) {ナ}

None of the these.


18.What is the result from the following code snippet?

public static void main(String[] args) {

List list1 = new ArrayList();

list1.add(new Gum());

List list2 = list1;

list2.add(new Integer(9));

System.out.println(list2.size());

The code will not compile.

an exception will be thrown at runtime

2 (*)

19.The Comparable interface defines the compareTo method.

True or false?

True (*)

False

20.Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {

2,//insert code here

3. s.put ("StudentID", 123);

4.}

(Choose all correct answers)

Map s= new SortedMap();

SortedMap s= new TreeMap(); (*)

ArrayList s= new ArrayList();

HashMap s= new HashMap(); (*)

21.Which is the correct way to initialize a HashSet?

HashSet classMates =

new HashSet(); (*)

ClassMates = public class

HashSet();
String classMates = new

String();

classMates = new HashSet[String]();

22.Choose the best definiton for a collection.

It enables you to create a generic class without specifying a type between angle brackets <>.

It is an interface in the java.util package that is used to define a group of objects. (*)

It is a special type of class that is associated with one or more non-specified Java type.

It is a subclass of List.

23.Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2
adjacent values if they are in the wrong order until all elements are in the correct order?

Merge Sort
Bubble Sort (*)

Binary Search

Sequential Search

Selection Sort

Reply

UnknownDecember 21, 2018 at 6:38 AM

Section 7

(Answer all questions in this section)

1. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review

(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.
Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

2. Which of the following methods for the String class take a regular expression as a parameter and returns true if the
string matches the expression? Mark for Review

(1) Points

compareTo(String regex)

equals(String regex)

matches(String regex) (*)

equalsIgnoreCase(String regex)

Incorrect. Refer to Section 3 Lesson 2.

3. What is the function of the asterisk (*) in regular expressions? Mark for Review
(1) Points

Indicates that the preceding character may occur 0 or 1 times in a proper match.

Indicates that the preceding character may occur 0 or more times in a proper match. (*)

The asterisk has no function in regular expressions.

Indicates that the preceding character may occur 1 or more times in a proper match.

Incorrect. Refer to Section 3 Lesson 2.

4. Which of the following correctly defines Matcher? Mark for Review

(1) Points

A regular expression symbol that represents any character.

A method of dividing a string into a set of sub-strings.

A class in the java.util.regex package that stores the format of a regular expression.

A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
Correct

5. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

6. Which of the following correctly defines Pattern? Mark for Review

(1) Points

A regular expression symbol that represents any character.

A method of dividing a string into a set of sub-strings.

A class in the java.util.regex package that stores the format of a regular expression. (*)

A class in the java.util.regex package that stores matches.


Incorrect. Refer to Section 3 Lesson 2.

7. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review

(1) Points

Matcher m = new Matcher();

Matcher m = str.matcher(p);

Matcher m = new Matcher(p,str);

Matcher m = p.matcher(str); (*)

Incorrect. Refer to Section 3 Lesson 2.

8. A linear recursion requires the method to call which direction? Mark for Review

(1) Points

Forward

Backward (*)
Both forward and backward

None of the above

Incorrect. Refer to Section 3 Lesson 3.

9. Which case does a recursive method call last? Mark for Review

(1) Points

Recursive Case

Convergence Case

Basic Case

Base Case (*)

None of the above

Correct
10. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review

(1) Points

True

False (*)

Correct

Reply

Replies

UnknownDecember 21, 2018 at 6:40 AM

11. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for Review

(1) Points

2 or more (*)

Correct
12. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply)
Mark for Review

(1) Points

(Choose all correct answers)

Parse the String. (*)

Read the String backwards (from last element to first element). (*)

Search for a specific character or String inside of the String. (*)

You don't use a FOR loop with Strings

Incorrect. Refer to Section 3 Lesson 1.

13. Split is a method for Strings that parses a string by a specified character, or, if unspecified, by spaces, and returns the
parsed elements in an array of Strings.

True or false? Mark for Review

(1) Points

True
False (*)

Correct

14. Which of the following correctly initializes a StringBuilder? Mark for Review

(1) Points

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

Incorrect. Refer to Section 3 Lesson 1.

15. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)

It returns an array of strings. (*)


It can be used with a string as a parameter. (*)

It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

Incorrect. Refer to Section 3 Lesson 1.

1. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

2. Which of the following methods for the String class take a regular expression as a parameter and returns true if the
string matches the expression? Mark for Review

(1) Points
compareTo(String regex)

matches(String regex) (*)

equals(String regex)

equalsIgnoreCase(String regex)

Incorrect. Refer to Section 3 Lesson 2.

Reply

UnknownDecember 21, 2018 at 6:41 AM

3. Which of the following does not correctly match the regular expression symbol to its proper function? Mark for
Review

(1) Points

"{x}" means there must be x occurrences of the preceding character in the string to be a match.

"?" means there may be zero or one occurrences of the preceding character in the string to be a match.

"+" means there may be zero or more occurrences of the preceding character in the string to be a match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a match.

"{x,y}" means there may be between x and y occurrences of the preceding character in the string to be a match.

Incorrect. Refer to Section 3 Lesson 2.

4. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all
of your contacts' first and last names are exactly five letters long.

Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group
for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for
Review

(1) Points

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.


Incorrect. Refer to Section 3 Lesson 2.

5. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

6. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may occur x or more times
to create a match.

True or false? Mark for Review

(1) Points

True

False (*)
Correct

7. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review

(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

8. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark
for Review

(1) Points

(Choose all correct answers)


Search for a specific character or String inside of the String. (*)

Parse the String. (*)

You don't use a FOR loop with Strings

Read the String backwards (from last element to first element). (*)

Incorrect. Refer to Section 3 Lesson 1.

9. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)

It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

It can be used with a string as a parameter. (*)


It returns an array of strings. (*)

Incorrect. Refer to Section 3 Lesson 1.

10. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review

(1) Points

length()

indexOf(String str)

charAt(int index)

delete(int start, int end) (*)

Incorrect. Refer to Section 3 Lesson 1.

Reply

UnknownDecember 21, 2018 at 6:41 AM

11. Which of the following methods are specific to StringBuilders? Mark for Review

(1) Points
append

delete

insert

replace

All of the above. (*)

Incorrect. Refer to Section 3 Lesson 1.

12. A non-linear recursive method can call how many copies of itself? Mark for Review

(1) Points

2 or more (*)

None

Correct
13. The base case condition can work with a constant or variable. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 3.

14. Forward thinking helps when creating linear recursive methods. True or false? Mark for Review

(1) Points

True

False (*)

Correct

15. A linear recursive method directly calls how many copies of itself in the recursive case? Mark for Review

(1) Points

0
1 (*)

2 or more

Incorrect. Refer to Section 3 Lesson 3.

1. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review

(1) Points

Matcher m = str.matcher(p);

Matcher m = p.matcher(str); (*)

Matcher m = new Matcher(p,str);

Matcher m = new Matcher();

Incorrect. Refer to Section 3 Lesson 2.

2. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review


(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

3. Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and
false otherwise. Which of the following code segments completes this task? Mark for Review

(1) Points

(Choose all correct answers)

return str.contains(".");

if( str.length() == 0 || str.length() == 1)


{ return true;}

return false; (*)

return str.matches(".?"); (*)

return str.matches("[a-z]*");

Incorrect. Refer to Section 3 Lesson 2.

4. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may occur x or more times
to create a match.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

5. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all
of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group
for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for
Review

(1) Points

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Incorrect. Refer to Section 3 Lesson 2.

Reply

UnknownDecember 21, 2018 at 6:42 AM

6. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false? Mark for Review

(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

7. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

8. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review

(1) Points

True
False (*)

Correct

9. Which case handles the last recursive call? Mark for Review

(1) Points

The primary case

The base case (*)

The convergence case

The recursive case

The secondary case

Incorrect. Refer to Section 3 Lesson 3.

10. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review

(1) Points
True

False (*)

Incorrect. Refer to Section 3 Lesson 3.

11. A linear recursive method directly calls how many copies of itself in the recursive case? Mark for Review

(1) Points

1 (*)

2 or more

Incorrect. Refer to Section 3 Lesson 3.

12. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)

It can be used with a string as a parameter. (*)


It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

It returns an array of strings. (*)

Incorrect. Refer to Section 3 Lesson 1.

Reply

UnknownDecember 21, 2018 at 6:44 AM

13. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply)
Mark for Review

(1) Points

(Choose all correct answers)

Read the String backwards (from last element to first element). (*)

Search for a specific character or String inside of the String. (*)

You don't use a FOR loop with Strings


Parse the String. (*)

Incorrect. Refer to Section 3 Lesson 1.

14. Which of the following correctly initializes a StringBuilder? Mark for Review

(1) Points

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

Incorrect. Refer to Section 3 Lesson 1.

15. Which of the following are true about parsing a String? Mark for Review

(1) Points

(Choose all correct answers)

It is not possible to parse a string using regular expressions.


It is a way of dividing a string into a set of sub-strings. (*)

It is possible to use a for loop to parse a string. (*)

It is possible to use the String.split() method to parse a string. (*)

Incorrect. Refer to Section 3 Lesson 1.

1. Which of the following correctly defines a StringBuilder? Mark for Review

(1) Points

A class that represents a string-like object. (*)

There is no such thing as a StringBuilder in Java.

A method that adds characters to a string.

A class inside the java.util.regex package.

Incorrect. Refer to Section 3 Lesson 1.


2. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark
for Review

(1) Points

(Choose all correct answers)

Search for a specific character or String inside of the String. (*)

Parse the String. (*)

Read the String backwards (from last element to first element). (*)

You don't use a FOR loop with Strings

Incorrect. Refer to Section 3 Lesson 1.

3. What class is the split() method a member of? Mark for Review

(1) Points

Parse

String (*)
Array

StringBuilder

Correct

4. Split is a method for Strings that parses a string by a specified character, or, if unspecified, by spaces, and returns the
parsed elements in an array of Strings.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

5. Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and
false otherwise. Which of the following code segments completes this task? Mark for Review

(1) Points

(Choose all correct answers)

return str.matches("[a-z]*");
if( str.length() == 0 || str.length() == 1)

{ return true;}

return false; (*)

return str.contains(".");

return str.matches(".?"); (*)

Incorrect. Refer to Section 3 Lesson 2.

Reply

Replies

UnknownDecember 21, 2018 at 6:44 AM

6. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all
of your contacts' first and last names are exactly five letters long.

Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group
for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for
Review

(1) Points

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");


Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Incorrect. Refer to Section 3 Lesson 2.

7. What does the dot (.) represent in regular expressions? Mark for Review

(1) Points

An indication for one or more occurrences of the preceding character.

A match for any character. (*)

A range specified between brackets that allows variability of a character.

Nothing, it is merely a dot.

Incorrect. Refer to Section 3 Lesson 2.


8. One benefit to using groups with regular expressions is that you can segment a matching string and recall the
segments (or groups) later in your program.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

9. A regular expression is a character or a sequence of characters that represent a string or multiple strings.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

10. Consider that you are writing a program for analyzing feedback on the video game you have developed. You have
completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note
that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the
user's input is a valid rating? Mark for Review
(1) Points

(Choose all correct answers)

return userI.matches("[1-5]"); (*)

return userI.matches("{1-5}");

return userI.matches("[1-5]{1}"); (*)

return userI.matches("[1-5].*");

Incorrect. Refer to Section 3 Lesson 2.

11. Which of the following correctly defines a repetition operator? Mark for Review

(1) Points

A symbol that represents any character in regular expressions.

A method that returns the number of occurrences of the specified character.

Any symbol in regular expressions that indicates the number of occurrences a specified character appears in a matching
string. (*)
None of the above.

Incorrect. Refer to Section 3 Lesson 2.

12. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 3.

13. Forward thinking helps when creating linear recursive methods. True or false? Mark for Review

(1) Points

True

False (*)

Correct
14. A linear recursive method can call how many copies of itself? Mark for Review

(1) Points

1 (*)

2 or more

None

Incorrect. Refer to Section 3 Lesson 3.

15. Which case does a recursive method call last? Mark for Review

(1) Points

Recursive Case

Convergence Case

Basic Case

Base Case (*)


None of the above

Incorrect. Refer to Section 3 Lesson 3.

Reply

UnknownDecember 21, 2018 at 7:02 AM

Section 8

(Answer all questions in this section)

1. Which of the following is an attribute of a three tier architecture application? Mark for Review

(1) Points

an application of that has a client and server only

a complex application that includes a client, a server and database (*)

an application of that runs on a single computer

None of the above

Incorrect. Refer to Section4 Lesson 1.


2. Java Web Start is used to deploy java applications.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 1.

3. The method for connecting a Java application to a database is by using: Mark for Review

(1) Points

jar files

JNLP

JDBC (*)

Java Web Start


None of the above

Incorrect. Refer to Section 4 Lesson 1.

4. Which of the following is not a reason to use a Java package? Mark for Review

(1) Points

It is a way to organize files when a project consists of multiple modules.

It is a way to help resolve naming conflicts when different packages have classes with the same names.

It is a way to protect data from being used by the non-authorized classes.

It is a way to allow programmers to receive packets of information from databases. (*)

None of the above

Incorrect. Refer to Section4 Lesson 1.

5. To deploy java applications you may use Java Web Start.

True or false? Mark for Review

(1) Points
True (*)

False

Correct

6. How would you make an instance of Car in a class that didn't import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car();

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car(); (*)

vehicle.Car c=new vehicle();

None of the above

Correct
7. How would you make an instance of Car in a class that did import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car(); (*)

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car();

vehicle.Car c=new vehicle();

None of the above

Incorrect. Refer to Section 4 Lesson 1.

8. Which of the following is an attribute of a two tier architecture application? Mark for Review

(1) Points

An application of that has a client and server only. (*)

A complex application that includes a client, a server and database.


An application of that runs on a single computer.

None of the above.

Incorrect. Refer to Section 4 Lesson 1.

9. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for
Review

(1) Points

(Choose all correct answers)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above


Incorrect. Refer to Section 4 Lesson 1.

10. If a class is in a package, the system's CLASSPATH must be altered to access the class.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

11. An example of two tier architecture would be a client application working with a server application.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section4 Lesson 1.

12. The method for connecting a java application to a database is JNLP.

True or false? Mark for Review


(1) Points

True

False (*)

Correct

13. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*

True or false? Mark for Review

(1) Points

True

False (*)

Reply

Replies

UnknownDecember 21, 2018 at 7:03 AM

14. Which of the following files are not required to be uploaded to a web server to deploy a java application/applet?
Mark for Review

(1) Points

jar files
JNLP files

html files

.java files (*)

None of the above

Incorrect. Refer to Section4 Lesson 1.

15. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark
for Review

(1) Points

Import

Export (*)

Switch Workspace

Properties
Incorrect. Refer to Section 4 Lesson 1.

1. Java Web Start is used to deploy java applications.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 1.

2. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*

True or false? Mark for Review

(1) Points

True

False (*)

Correct

3. A jar file is built on the ZIP file format and is used to deploy java applets.
True or false? Mark for Review

(1) Points

True (*)

False

Correct

4. To deploy java applications you may use Java Web Start.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section4 Lesson 1.

5. An example of two tier architecture would be a client application working with a server application.

True or false? Mark for Review

(1) Points
True (*)

False

Incorrect. Refer to Section4 Lesson 1.

6. Which of the following is not a reason to use a Java package? Mark for Review

(1) Points

It is a way to organize files when a project consists of multiple modules.

It is a way to help resolve naming conflicts when different packages have classes with the same names.

It is a way to protect data from being used by the non-authorized classes.

It is a way to allow programmers to receive packets of information from databases. (*)

None of the above

Correct

7. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark for
Review
(1) Points

Properties

Import

Switch Workspace

Export (*)

Incorrect. Refer to Section 4 Lesson 1.

8. How would you make an instance of Car in a class that did import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car(); (*)

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car();


vehicle.Car c=new vehicle();

None of the above

Incorrect. Refer to Section 4 Lesson 1.

9. Which of the following is an attribute of a three tier architecture application? Mark for Review

(1) Points

an application of that has a client and server only

a complex application that includes a client, a server and database (*)

an application of that runs on a single computer

None of the above

Correct

10. The method for connecting a java application to a database is JNLP.

True or false? Mark for Review

(1) Points
True

False (*)

UnknownDecember 21, 2018 at 7:04 AM

11. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for
Review

(1) Points

(Choose all correct answers)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above

Incorrect. Refer to Section 4 Lesson 1.


12. How would you make an instance of Car in a class that didn't import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car();

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car(); (*)

vehicle.Car c=new vehicle();

None of the above

Incorrect. Refer to Section4 Lesson 1.

13. If a class is in a package, the system's CLASSPATH must be altered to access the class.

True or false? Mark for Review

(1) Points

True
False (*)

Correct

14. Which of the following is an attribute of a two tier architecture application? Mark for Review

(1) Points

An application of that has a client and server only. (*)

A complex application that includes a client, a server and database.

An application of that runs on a single computer.

None of the above.

Incorrect. Refer to Section 4 Lesson 1.

15. The method for connecting a Java application to a database is by using: Mark for Review

(1) Points

jar files
JNLP

JDBC (*)

Java Web Start

None of the above

Correct

1. A jar file is built on the ZIP file format and is used to deploy java applets.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section4 Lesson 1.

2. An example of two tier architecture would be a client application working with a server application.

True or false? Mark for Review

(1) Points
True (*)

False

Incorrect. Refer to Section4 Lesson 1.

3. Which of the following is an attribute of a two tier architecture application? Mark for Review

(1) Points

An application of that has a client and server only. (*)

A complex application that includes a client, a server and database.

An application of that runs on a single computer.

None of the above.

Correct

4. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for
Review

(1) Points
(Choose all correct answers)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above

Incorrect. Refer to Section 4 Lesson 1.

5. How would you make an instance of Car in a class that didn't import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car();

vehicle.Car c=new Car();


vehicle.Car c=new vehicle.Car(); (*)

vehicle.Car c=new vehicle();

None of the above

Correct

6. Which of the following is an attribute of a three tier architecture application? Mark for Review

(1) Points

an application of that has a client and server only

a complex application that includes a client, a server and database (*)

an application of that runs on a single computer

None of the above

Incorrect. Refer to Section4 Lesson 1.

7. The method for connecting a Java application to a database is by using: Mark for Review
(1) Points

jar files

JNLP

JDBC (*)

Java Web Start

None of the above

Correct

8. If a class is in a package, the system's CLASSPATH must be altered to access the class.

True or false? Mark for Review

(1) Points

True

False (*)
Correct

UnknownDecember 21, 2018 at 7:04 AM

9. Which of the following files are not required to be uploaded to a web server to deploy a java application/applet? Mark
for Review

(1) Points

jar files

JNLP files

html files

.java files (*)

None of the above

Correct

10. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*

True or false? Mark for Review

(1) Points
True

False (*)

Correct

11. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark
for Review

(1) Points

Switch Workspace

Import

Properties

Export (*)

Incorrect. Refer to Section 4 Lesson 1.

12. Java Web Start is used to deploy java applications.

True or false? Mark for Review

(1) Points
True (*)

False

Correct

13. Which of the following is not a reason to use a Java package? Mark for Review

(1) Points

It is a way to organize files when a project consists of multiple modules.

It is a way to help resolve naming conflicts when different packages have classes with the same names.

It is a way to protect data from being used by the non-authorized classes.

It is a way to allow programmers to receive packets of information from databases. (*)

None of the above

Incorrect. Refer to Section4 Lesson 1.


14. To deploy java applications you may use Java Web Start.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

15. How would you make an instance of Car in a class that did import the vehicle package below?

Mark for Review

(1) Points

Car c = new Car(); (*)

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car();

vehicle.Car c=new vehicle();

None of the above


11. The BufferedInputStream is a direct subclass of what other class? Mark for Review

(1) Points

InputStream

FilterInputStream (*)

PipedInputStream

InputStream

FileInputStream

[Correct] Correct

12.The Files class provides a instance method that creates a new BufferedReader.

True or false? Mark for Review

(1) Points

True (*)
False

[Correct] Correct

13.The BufferedOutputStream is a direct subclass of what other class? Mark for Review

(1) Points

PrintStream

DigestOutputStream

FilterOutputStream (*)

OutputStream

ObjectOutputStream

[Correct] Correct
14.Which of the following static methods is not provided by the Files class to check file properties or duplication? Mark
for Review

(1) Points

Files.isWritable(Path p);

Files.isReadable(Path p);

Files.isArchived(Path p); (*)

Files.isHidden(Path p);

[Correct] Correct

15.The Paths class provides a static get() method to find a valid Path.

True or false? Mark for Review

(1) Points

True (*)

False
[Correct] Correct

Reply

UnknownDecember 21, 2018 at 7:20 AM

Section 9

(Answer all questions in this section)

1. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)

ResultSet rset = stmt.executeQuery(sqlQuery);

if(rs.next()){

//INSERT HERE

Mark for Review

(1) Points

(Choose all correct answers)

Object s = rs.getObject(1); (*)

String s = rs.getString(1);

String s = rs.getObject(0);
String s = rs.getString(0);

2. JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for
Review

(1) Points

True (*)

False

3. From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review

(1) Points

By making use of the execute(...) statement from DataStatement Object

By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement

By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)
By invoking the DeleteStatement or UpdateStatement JDBC object

4. Which type of Statement can execute parameterized queries? Mark for Review

(1) Points

ParameterizedStatement

CallableStatement and ParameterizedStatement

PreparedStatement (*)

All of the above

5. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored
procedure sayHello?

class Test{

public static void main(String[] args) {

try {
Connection conn = getConnection();

//INSERT CODE

cstat.setString(1, "Hello");

cstat.registerOutParameter(2, Types.NUMERIC);

cstat.setInt(2, 10);

catch(SQLException e){}

Mark for Review

(1) Points

CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");

CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");

CallableStatement cstat = con.prepareCall("{call sayHello}");

CallableStatement cstat = con.prepareCall("sayHello(?, ?)");

CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)


6. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does
the following output?

String sql = "select first_name from Employees order by first_name desc";

Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rset= stmt.executeQuery(sql);

rset.absolute(1);

rset.next();

System.out.println(rset.getString(1));

Mark for Review

(1) Points

B (*)

The code does not compile.

A SQLException is thrown.

7. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for
Review

(1) Points
!

? (*)

8. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object? Mark for
Review

(1) Points

(Choose all correct answers)

beforeFirst() (*)

absolute()

afterFirst()
afterLast()

beforeLast()

9. Which of the following is the correct order to close the database object? Mark for Review

(1) Points

ResultSet, Statement, Connection (*)

Connection, Statement, ResultSet

Statement, Connection, ResultSet

ResultSet, Connection, Statement

Statement,ᅠ ResultSet,ᅠ Connection

10. Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark
for Review
(1) Points

(Choose all correct answers)

Statement interface implementation (*)

Java.sql.Connection

Javax.sql.DataSource

Javax.sql.DataSource implementation (*)

Java.sql.DriverManager implementation

Reply

Replies

UnknownDecember 21, 2018 at 7:20 AM

11. Which of the following is NOT a JDBC interface used to execute SLQ statements? Mark for Review

(1) Points
Statement Interface

PreparedStatement Interface

PrePreparedStatement Interface (*)

CallableStatement Interface

12. You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review

(1) Points

True (*)

False

13.How many categories of JDBC drivers are there? Mark for Review

(1) Points

1
2

4 (*)

14.What type of JDBC driver will convert the database invocation directly into network protocol? Mark for Review

(1) Points

Type 1 driver

Type 2 driver

Type 3 driver

Type 4 driver (*)

15.To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review

(1) Points
Statement Interface

PreparedStatement Interface

PrePreparedStatement Interface

CallableStatement Interface (*)

UnknownDecember 21, 2018 at 7:32 AM

1. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)

ResultSet rset = stmt.executeQuery(sqlQuery);

if(rs.next()){

//INSERT HERE

Mark for Review

(1) Points

(Choose all correct answers)

Object s = rs.getObject(1); (*)

String s = rs.getString(1);
String s = rs.getObject(0);

String s = rs.getString(0);

2. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does
the following output?

String sql = "select first_name from Employees order by first_name desc";

Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rset= stmt.executeQuery(sql);

rset.absolute(1);

rset.next();

System.out.println(rset.getString(1));

Mark for Review

(1) Points

B (*)

C
The code does not compile.

A SQLException is thrown.

3. Which type of Statement can execute parameterized queries? Mark for Review

(1) Points

ParameterizedStatement

CallableStatement and ParameterizedStatement

PreparedStatement (*)

All of the above

4. Which the following statements is NOT TRUE about DataSource? Mark for Review

(1) Points

DataSource can be implemented as a pool of connections.


DataSource can participate in the Distributed transaction.

DataSource can manage a set of JDBC Drivers registered in the system. (*)

DataSource will typically be registered with a naming service.

5. JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for
Review

(1) Points

True (*)

False

6. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object? Mark for
Review

(1) Points

(Choose all correct answers)

beforeFirst() (*)
absolute()

afterFirst()

afterLast()

beforeLast()

7. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for
Review

(1) Points

? (*)

#
8. From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review

(1) Points

By making use of the execute(...) statement from DataStatement Object

By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement

By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)

By invoking the DeleteStatement or UpdateStatement JDBC object

9. Which of the following is a valid JDBC URL? Mark for Review

(1) Points

oracle:thin:localhost@dfot/dfot:1521:xe

jdbc::oracle-thin:dfot/dfot@oracle:1521:xe
jdbc:oracle:thin:dfot/dfot@localhost:1521:xe (*)

oracle:thin:jdbc:dfot/dfot@localhost:1521:xe

UnknownDecember 21, 2018 at 7:32 AM

10. To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review

(1) Points

Statement Interface

PreparedStatement Interface

PrePreparedStatement Interface

CallableStatement Interface (*)

11. Which of the following is the correct order to close the database object? Mark for Review

(1) Points
ResultSet, Statement, Connection (*)

Connection, Statement, ResultSet

Statement, Connection, ResultSet

ResultSet, Connection, Statement

Statement,ᅠ ResultSet,ᅠ Connection

12. The java.sql.DriverManager class will typically be registered with a naming service based on the Java Naming
Directory (JNDI) API. Mark for Review

(1) Points

True

False (*)

13. How many categories of JDBC drivers are there? Mark for Review
(1) Points

4 (*)

14. Given the following code, assume there are rows of data in the table EMP. What is the result?

1 Connection conn - new Connection(URL);

2 Statement stmt = conn.createStatement();

3 ResultSet result - stmt.executeQuery("select count(*) from EMP");

4 if(rs.next()){

5 System.out.println(rs.getInt(1));

6 } Mark for Review

(1) Points

Compiler error on line 2


Runtime error on line 3

Compiler error on line 1 (*)

15.You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review

(1) Points

True (*)

False

Reply

UnknownDecember 21, 2018 at 8:14 AM

Java Programming Final Exam

1.A sequential search is an iteration through the array that stops at the index where the desired element is found.

True or false? Mark for Review

(1) Points
True (*)

False

2.Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next
smallest value and swapping it into the next index and so on until the array is sorted.

True or false? Mark for Review

(1) Points

True

False (*)

3.Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

4.Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2
adjacent values if they are in the wrong order until all elements are in the correct order? Mark for Review

(1) Points

Sequential Search

Merge Sort

Bubble Sort (*)

Binary Search

Selection Sort
5.Binary searches can be performed on sorted and unsorted data.

True or false? Mark for Review

(1) Points

True

False (*)

6. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.
7.Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or
false? Mark for Review

(1) Points

True (*)

False

8.Stacks are identical to Queues.

True or false? Mark for Review

(1) Points

True

False (*)

9.FIFO stands for: Mark for Review

(1) Points
Fast In Fast Out

Fast Interface Fast Output

First Interface First Output

First In First Out (*)

10.The Comparable interface defines the compareTo method.

True or false? Mark for Review

(1) Points

True (*)

False

Reply

Replies

UnknownDecember 21, 2018 at 8:14 AM

11.The Comparable interface includes a method called compareTo.

True or false? Mark for Review

(1) Points
True (*)

False

12.A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

13.Which of the following is a list of elements that have a first in last out ordering. Mark for Review

(1) Points

Stacks (*)

Arrays
Enums

HashMaps

14.Which class is an ordered collection that may contain duplicates? Mark for Review

(1) Points

enum

set

array

list (*)

15.Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review

(1) Points
vegetables.get("Cabbage");

vegetables += "Cabbage";

vegetables[0] = "Cabbage";

vegetables.add("Cabbage"); (*)

16. ArrayList and Arrays both require you to define their size before use.

True or false? Mark for Review

(1) Points

True

False (*)

17.Which of these could be a set? Why? Mark for Review

(1) Points
{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same type.

{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.

{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)

All of the above are sets because they are collections that can be made to fit any of the choices.

18.Which is the correct way to initialize a HashSet? Mark for Review

(1) Points

ClassMates = public class

HashSet();

classMates = new HashSet[String]();

String classMates = new

String();

HashSet classMates =
new HashSet(); (*)

19.An example of an upper bounded wildcard is. Mark for Review

(1) Points

ArrayList

ArrayList

ArrayList

ArrayList (*)

20.Generic methods are required to be declared as static.

True or False? Mark for Review

(1) Points

True
False (*)

UnknownDecember 21, 2018 at 8:15 AM

21.The following code will compile.

True or False?

class Node implements Comparable{

public int compareTo(T obj){return 1;}

class Test{

public static void main(String[] args){

Node nc=new Node<>();

Comparable com=nc;

Mark for Review

(1) Points

True (*)

False

22.< ? extends Animal > would only allow classes or subclasses of Animal to be used.

True or False? Mark for Review

(1) Points
True (*)

False

23.public static void printArray(T[] array){ナ.

is an example of what? Mark for Review

(1) Points

A concreate method.

A generic method (*)

A generic class

A generic instance

24.What is the result from the following code snippet?

public static void main(String[] args) {

List list1 = new ArrayList();


list1.add(new Gum());

List list2 = list1;

list2.add(new Integer(9));

System.out.println(list2.size());

} Mark for Review

(1) Points

The code will not compile.

2 (*)

an exception will be thrown at runtime

25.Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.

True or false? Mark for Review

(1) Points

True (*)

False
26.Square brackets are a representation for any character in regular expressions "[ ]".

True or false? Mark for Review

(1) Points

True

False (*)

27.Which of the following correctly defines Pattern? Mark for Review

(1) Points

A regular expression symbol that represents any character.

A class in the java.util.regex package that stores the format of a regular expression. (*)

A class in the java.util.regex package that stores matches.

A method of dividing a string into a set of sub-strings.


28.What does the dot (.) represent in regular expressions? Mark for Review

(1) Points

An indication for one or more occurrences of the preceding character.

A match for any character. (*)

A range specified between brackets that allows variability of a character.

Nothing, it is merely a dot.

29.Which of the following correctly initializes a StringBuilder? Mark for Review

(1) Points

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)


None of the above.

30.What is the result from the following code?

public class Test {

public static void main(String[] args) {

String str = "91204";

str += 23;

System.out.print(str);

} Mark for Review

(1) Points

9120423 (*)

91227

Compile fails.

23
91204

UnknownDecember 21, 2018 at 8:15 AM

31.Which of the following correctly defines a StringBuilder? Mark for Review

(1) Points

A class inside the java.util.regex package.

There is no such thing as a StringBuilder in Java.

A method that adds characters to a string.

A class that represents a string-like object. (*)

32.The base case condition can work with a constant or variable.

True or false? Mark for Review

(1) Points

True (*)

False
33.A non-linear recursive method can call how many copies of itself? Mark for Review

(1) Points

2 or more (*)

None

34.Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?

public static int recur(int x, int y) {

if (x == 0) {

return y;

return recur(x - 1, x + y);

} Mark for Review

(1) Points

12
10

13 (*)

35.A linear recursion requires the method to call which direction? Mark for Review

(1) Points

Forward

Backward (*)

Both forward and backward

None of the above

36.If a programmer uses the line


import com.test.*,

there is no need to use

import com.test.code.*

True or false? Mark for Review

(1) Points

True

False (*)

37.An example of two tier architecture would be a client application working with a server application.

True or false? Mark for Review

(1) Points

True (*)

False

38.The method for connecting a java application to a database is JNLP.

True or false? Mark for Review

(1) Points
True

False (*)

39.Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.

True or false? Mark for Review

(1) Points

True (*)

False

40.The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False
UnknownDecember 21, 2018 at 8:15 AM

41.The System.in is what type of stream? Mark for Review

(1) Points

A BufferedReader stream

A Reader stream

A BufferedWriter stream

A PrintStream

An InputStream (*)

42.An ObjectInputStream lets you read a serialized object.

True or false? Mark for Review

(1) Points

True (*)

False
43.To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review

(1) Points

Statement Interface

PreparedStatement Interface

PrePreparedStatement Interface

CallableStatement Interface (*)

44.Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark for
Review

(1) Points

(Choose all correct answers)

Statement interface implementation (*)


Java.sql.Connection

Javax.sql.DataSource

Javax.sql.DataSource implementation (*)

Java.sql.DriverManager implementation

45.How many categories of JDBC drivers are there? Mark for Review

(1) Points

4 (*)
46.Given the following code, assume there are rows of data in the table EMP. What is the result?

1 Connection conn - new Connection(URL);

2 Statement stmt = conn.createStatement();

3 ResultSet result - stmt.executeQuery("select count(*) from EMP");

4 if(rs.next()){

5 System.out.println(rs.getInt(1));

6 } Mark for Review

(1) Points

Compiler error on line 2

Runtime error on line 3

Compiler error on line 1 (*)

47.Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does
the following output?
String sql = "select first_name from Employees order by first_name desc";

Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rset= stmt.executeQuery(sql);

rset.absolute(1);

rset.next();

System.out.println(rset.getString(1));

Mark for Review

(1) Points

B (*)

The code does not compile.

A SQLException is thrown.

48.From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review

(1) Points

By making use of the execute(...) statement from DataStatement Object


By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement

By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)

By invoking the DeleteStatement or UpdateStatement JDBC object

49.Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for
Review

(1) Points

? (*)

#
50.JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for
Review

(1) Points

True (*)

False

Reply

UnknownDecember 21, 2018 at 10:35 AM

11.Bytecode contains different opcodes for every type of loop written in source code.

True

False (*)

Reply

Replies

UnknownDecember 21, 2018 at 10:39 AM

3.Class Object is the root of the Java class hierarchy. True or False?

True (*)

False
UnknownDecember 21, 2018 at 10:45 AM

5. When do you use try-catch statements?

If you want to switch different values for a certain variable.

When you want to handle an exception. (*)

When you want to exit your code before an exception is caught.

Every time you would like to assign a new value to a variable that is being asserted.

7.The instanceof operator enables to discover the type of object it was invoked upon.

True or false?

True (*)

False

8.Java provides virtual method invocation as a feature and it doesn't require specialized coding.

True or false?
True (*)

False

13.Making a class immutable means:

That it is directly subclassed from the Object class

To create an instance of the class.

To create a sub class from a parent class

That it cannot be extended. (*)

15.Which one of the following statements is true?

A Java program can only contain one super class

A class is an intance of an object


A class is a Java primitive

A class is a template that defines the features of an object (*)

UnknownDecember 21, 2018 at 8:19 PM

17.Choose which opcode is used to fetch a field from object.

istore

idc

pop

bipush

getfield (*)

26.Arrays have built-in operations including add, clear, contains, get and remove. True or false?

True

False (*)
27.In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false?

True

False (*)

30. Which of the following is not a good technique to follow when reading code written by others?

Perform testing.

Build and run the code.

Find the author of the code and ask him how it works. (*)

Understand the constructs.

Learn the high level structure and starting point, and then figure out how it branches.
31. Which of the following are important to your survival as a programmer?

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)

36.When are control flow invariants used?

To test compilation errors in your code.

To test specific variable values of your code.

To test the correct flow of your code. (*)

To test run time errors in code.

44.The instanceof operator works with class instances and primitive data types.
True or false?

True

False (*)

49.An interfaces can declare public constants.

True or False?

True (*)

False

UnknownDecember 21, 2018 at 8:26 PM

4.Generic methods can only belong to generic classes.

True or False?

True

False (*)

8.Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?

The steps are shown below:


{'M', 'S', 'A', 'T', 'H'}

{'M', 'A', 'S', 'T', 'H'}

{'A', 'M', 'S', 'T', 'H'}

{'A', 'M', 'S', 'H', 'T'}

{'A', 'M', 'H', 'S', 'T'}

{'A', 'H', 'M', 'S', 'T'}

Sequential Search

Binary Search

Merge Sort

Bubble Sort (*)

Selection Sort

9.Which of the following describes a deque.

It is pronounced "deck" for short.

It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.

All of the above. (*)

13. A collection is an interface in the Java API.

True or false?

True (*)

False

14.Sets may contain duplicates.

True or false?

True

False (*)

UnknownDecember 21, 2018 at 8:32 PM

1. Which of the following methods are StringBuilder methods?


append

delete

insert

replace

All of the above. (*)

2. Which of the following correctly defines a StringBuilder?

A method that adds characters to a string.

There is no such thing as a StringBuilder in Java.

A class that represents a string-like object. (*)

A class inside the java.util.regex package.


3. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three)

(Choose all correct answers)

Parse the String. (*)

Read the String backwards (from last element to first element). (*)

Search for a specific character or String inside of the String. (*)

You don't use a FOR loop with Strings

4. Which of the following methods can be used to replace a segment in a string with a new string?

remove(String oldString, String newString)

replaceAll(String oldString, String newString) (*)

replaceAll(String newString)
substring(int start, int end, String newString)

None of the above. There is no replaceAll(String newString) method with one argument.

9. Consider that you are making a calendar and decide to write a segment of code that returns true if the string month is
April, May, June, or July. Which code segment correctly implements use of regular expressions to complete this task?

return month.matches("April|May|June|July"); (*)

return month.substring(0,3);

return month.equals("April, May, June, July");

return month.matches("April"|"May"|"June"|"July");

return month.compareTo("April, May, June, July");

Reply

UnknownDecember 21, 2018 at 8:37 PM

1. Which of the following is an absolute Windows path?


/

C:\Users\UserName\data (*)

data

\Users\UserName\data

/home/user/username

2. The way that you read from a file has changed since the introduction of Java 7.

True or false? Mark for Review

(1) Points

True (*)

False

3. Java 7 requires you create an instance of java.nio.file.File class.


True or false?

True

False (*)

4. The new Paths class lets you resolve .. (double dot) path notation.

True or false?

True (*)

False

5. An absolute path always starts from the drive letter or mount point.

True (*)

False
Reply

Replies

UnknownDecember 21, 2018 at 8:38 PM

6. Which of the following are files that must be uploaded to a web server to deploy a Java application/applet?(Choose
Three)

(Choose all correct answers)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above

7. A jar file is built on the ZIP file format and is used to deploy java applets.

True or false?
True (*)

False

8. Java Web Start is used to deploy Java applications.

True or false?

True (*)

False

9. If a programmer uses the line

import com.test.*,

there is no need to use

import com.test.code.*

True or false?

True

False (*)
10. Which of the following files are not required to be uploaded to a web server to deploy a JWS java
application/applet?

jar files

JNLP files

html files

.java files (*)

None of the above

UnknownDecember 21, 2018 at 8:39 PM

11. The System.out is what type of stream?

A BufferedReader stream

A Reader stream
A BufferedWriter stream

An OutputStream

A PrintStream (*)

12. You can read input by character or line.

True or false?

True (*)

False

13. Which of the following static methods is not provided by the Files class to check file properties or duplication?

Files.isReadable(Path p);
Files.isArchived(Path p); (*)

Files.isHidden(Path p);

Files.isWritable(Path p);

14. The read() method of java.io.Reader class lets you read a character at a time.

True or false?

True (*)

False

15. File permissions are the same across all of the different operating systems.

True

False (*)
Reply

UnknownDecember 21, 2018 at 8:49 PM

5. The import keyword allows you to access classes of the package without package Fully Qualified Name.

True or false?

True (*)

False

10. The Files class lets you check for file properties.

True or false?

True (*)

False

11. The new Paths class lets you resolve .. (double dot) path notation.

True or false?

True (*)

False
12. Which of the following is an absolute Windows path

/home/user/username

data

C:\Users\UserName\data (*)

\Users\UserName\data

13. The Files class can perform which of the following functions?

Works with absolute paths

Navigates the file system


Works across disk volumes

Works with relative paths

Creates files (*)

14. The normalize() method removes redundant name elements from a qualified path.

True or false?

True (*)

False

15. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.

True or false?

True (*)

False
Reply

UnknownDecember 21, 2018 at 8:56 PM

5. Given the following code, assume there are rows of data in the table EMP. What is the result?

1 Connection conn - new Connection(URL);

2 Statement stmt = conn.createStatement();

3 ResultSet result - stmt.executeQuery("select count(*) from EMP");

4 if(rs.next()){

5 System.out.println(rs.getInt(1));

6}

Compiler error on line 2

Runtime error on line 3

Compiler error on line 1 (*)

13. Which JDBC interface can be used to access information such as database URL, username and table names?

Statement Interface
PreparedStatement Interface

DatabaseMetaData Interface (*)

CallableStatement Interface

Reply

UnknownDecember 21, 2018 at 9:14 PM

1. Which of the following statements can be compiled?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

List list = new ArrayList();

List list = new ArrayList(); (*)

List list = new ArrayList(); (*)

List list = new ArrayList(); (*)

[Correct] Correct
2. Which line contains an compilation error?

interface Shape {}

class Circle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls = new ArrayList(); // Line 1

List lc = new ArrayList(); // Line 2

Circle c = new Circle();

ls.add(c); // Line 3

lc.add(c); // Line 4

} Mark for Review

(1) Points

Line 4

Line 1

Line 2

Line 3 (*)
[Correct] Correct

3. Which of these could be a set? Why? Mark for Review

(1) Points

{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same type.

{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.

{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)

All of the above are sets because they are collections that can be made to fit any of the choices.

[Correct] Correct

4. Sets may contain duplicates.

True or false? Mark for Review

(1) Points

True

False (*)
[Correct] Correct

5. Which interface forms the root of the collections hierarchy? Mark for Review

(1) Points

java.util.List

java.util.Collection (*)

java.util.Collections

java.util.Map

Reply

Replies

UnknownDecember 21, 2018 at 9:15 PM

6. Stacks are identical to Queues.

True or false? Mark for Review

(1) Points

True
False (*)

[Correct] Correct

7. Which scenario best describes a queue? Mark for Review

(1) Points

A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom.

A row of books that you can take out of only the middle of the books first and work your way outward toward either
edge.

A line at the grocery store where the first person in the line is the first person to leave. (*)

All of the above describe a queue.

[Correct] Correct

8. The Comparable interface defines the compareTo method.

True or false? Mark for Review

(1) Points
True (*)

False

[Correct] Correct

9. Where you enqueue an element in the list? Mark for Review

(1) Points

removes it from the end of the list

removes it from the front of the list

adds it to the start of the list

adds it to the end of the list (*)

[Correct] Correct
10. What are maps that link a Key to a Value? Mark for Review

(1) Points

HashSets

ArrayLists

HashMaps (*)

Arrays

UnknownDecember 21, 2018 at 9:15 PM

11. Nodes are components of LinkedLists, and they identify where the next and previous nodes are.

True or false? Mark for Review

(1) Points

True (*)

False

[Correct] Correct
12. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?

The steps are shown below:

{'M', 'S', 'A', 'T', 'H'}

{'M', 'A', 'S', 'T', 'H'}

{'A', 'M', 'S', 'T', 'H'}

{'A', 'M', 'S', 'H', 'T'}

{'A', 'M', 'H', 'S', 'T'}

{'A', 'H', 'M', 'S', 'T'} Mark for Review

(1) Points

Binary Search

Merge Sort

Sequential Search

Bubble Sort (*)

Selection Sort

[Correct] Correct

13. Why might a sequential search be inefficient? Mark for Review


(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

[Correct] Correct

14. Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping
2 adjacent values if they are in the wrong order until all elements are in the correct order? Mark for Review

(1) Points

Merge Sort

Binary Search

Selection Sort
Sequential Search

Bubble Sort (*)

[Correct] Correct

15. Which of the following is the correct lexicographical order for the conents of the following int array?

{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review

(1) Points

{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}

{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}


UnknownDecember 21, 2018 at 9:15 PM

16. Which of the following best describes lexicographical order? Mark for Review

(1) Points

A simple sorting algorithm that is inefficient on large arrays.

The order of indicies after an array has been sorted.

An order based on the ASCII value of characters. (*)

A complex sorting algorithm that is efficient on large arrays.

[Correct] Correct

17. Which of the following best describes lexicographical order? Mark for Review

(1) Points

The order of indicies after an array has been sorted.

A complex sorting algorithm that is efficient on large arrays.

An order based on the ASCII value of characters. (*)


A simple sorting algorithm that is inefficient on large arrays.

[Correct] Correct

18. Why might a sequential search be inefficient? Mark for Review

(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

[Correct] Correct

19. public static void printArray(T[] array){ナ.

is an example of what? Mark for Review

(1) Points
A generic instance

A concreate method.

A generic method (*)

A generic class

[Correct] Correct

20. A generic class is a type of class that associates one or more non-specific Java types with it.

True or False? Mark for Review

(1) Points

True (*)

False

UnknownDecember 21, 2018 at 9:15 PM

21. Which of the following would initialize a generic class "Cell" using a String type?

I. Cell cell = new Cell(); .


II. Cell cell = new Cell(); .

III. Cell cell = new String;

Mark for Review

(1) Points

III only

I only

I and II (*)

II only

II and III

[Correct] Correct

22. The local petting zoo is writing a program to be able to collect group animals according to species to better keep
track of what animals they have.

Which of the following correctly defines a collection that may create these types of groupings for each species at the
zoo? Mark for Review

(1) Points

public class
animalCollection {ナ} (*)

public class

animalCollection(AnimalType T) {ナ}

public class

animalCollection {ナ}

public class

animalCollection(animalType) {ナ}

None of the these.

[Incorrect] Incorrect. Refer to Section 6 Lesson 1.

23. What is the output from the following code snippet?

public static void main(String[] args){

List li=new ArrayList();

li.add(1);

li.add(2);

print(li);

public static void print(List list) {


for (Number n : list)

System.out.print(n + " ");

} Mark for Review

(1) Points

1 2 (*)

The code will not compile.

[Correct] Correct

24. What is the result from the following code snippet?

public static void main(String[] args) {

List list1 = new ArrayList();

list1.add(new Gum());

List list2 = list1;

list2.add(new Integer(9));

System.out.println(list2.size());

} Mark for Review

(1) Points
2 (*)

an exception will be thrown at runtime

The code will not compile.

[Correct] Correct

Section 7

(Answer all questions in this section)

25. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false? Mark for Review

(1) Points

True (*)
False

UnknownDecember 21, 2018 at 9:16 PM

26. One benefit to using groups with regular expressions is that you can segment a matching string and recall the
segments (or groups) later in your program.

True or false? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

27. What is the function of the asterisk (*) in regular expressions? Mark for Review

(1) Points

Indicates that the preceding character may occur 1 or more times in a proper match.

Indicates that the preceding character may occur 0 or more times in a proper match. (*)

The asterisk has no function in regular expressions.


Indicates that the preceding character may occur 0 or 1 times in a proper match.

[Correct] Correct

28. What does the dot (.) represent in regular expressions? Mark for Review

(1) Points

An indication for one or more occurrences of the preceding character.

A match for any character. (*)

A range specified between brackets that allows variability of a character.

Nothing, it is merely a dot.

[Correct] Correct

29. Which of the following are true about parsing a String?(Choose Three) Mark for Review

(1) Points
(Choose all correct answers)

It is a way of dividing a string into a set of sub-strings. (*)

It is not possible to parse a string using regular expressions.

It is possible to use a for loop to parse a string. (*)

It is possible to use the String.split() method to parse a string. (*)

[Correct] Correct

30. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review

(1) Points

remove(String oldString, String newString)

replaceAll(String oldString, String newString) (*)

replaceAll(String newString)
substring(int start, int end, String newString)

None of the above. There is no replaceAll(String newString) method with one argument.

UnknownDecember 21, 2018 at 9:16 PM

31. Which of the following correctly initializes a StringBuilder? Mark for Review

(1) Points

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

[Correct] Correct

32. Which case handles the last recursive call? Mark for Review

(1) Points

The convergence case


The primary case

The base case (*)

The recursive case

The secondary case

[Correct] Correct

33. Which two statements can create an instance of an array? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

int[] ia = new int [5]; (*)

Object oa = new double[5]; (*)

char[] ca = "java";
int ia[][] = (1,2,3) (4,5,6);

double da = new double [5];

[Correct] Correct

34. The base case condition can work with a constant or variable.

True or false? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

35. Forward thinking helps when creating linear recursive methods.

True or false? Mark for Review

(1) Points

True
False (*)

UnknownDecember 21, 2018 at 9:16 PM

36. Which of the following are files that must be uploaded to a web server to deploy a Java application/applet?(Choose
Three) Mark for Review

(1) Points

(Choose all correct answers)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above

[Correct] Correct
37. To deploy java applications you may use Java Web Start.

True or false? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

38. Which of the following files are not required to be uploaded to a web server to deploy a JWS java
application/applet? Mark for Review

(1) Points

jar files

JNLP files

html files

.java files (*)


None of the above

[Correct] Correct

39. Which statement determine that "java" is a directory? Mark for Review

(1) Points

Boolean isDir=(new Directory("java")).exists(); (*)

Boolean isDir=Directory.exists ("java");

Boolean isDir=(new File("java")).isDir();

Boolean isDir=(new File("java")).isDirectory();

[Correct] Correct

40. You can read input by character or line.

True or false? Mark for Review

(1) Points
True (*)

False

UnknownDecember 21, 2018 at 9:16 PM

41. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

42. Which of these construct a DataInputStream instance? Mark for Review

(1) Points

New dataInputStream(new FileInputStream("java.txt")); (*)

New dataInputStream(new file("java.txt"));


New dataInputStream(new InputStream("java.txt"));

New dataInputStream("java.txt");

New dataInputStream(new writer("java.txt"));

[Correct] Correct

Section 9

(Answer all questions in this section)

43. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does
the following output?

String sql = "select first_name from Employees order by first_name desc";

Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rset= stmt.executeQuery(sql);

rset.absolute(1);

rset.next();

System.out.println(rset.getString(1));

Mark for Review

(1) Points

A
B (*)

The code does not compile.

A SQLException is thrown.

[Correct] Correct

44. Which type of Statement can execute parameterized queries? Mark for Review

(1) Points

ParameterizedStatement

CallableStatement and ParameterizedStatement

PreparedStatement (*)

All of the above


[Correct] Correct

45. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored
procedure sayHello?

class Test{

public static void main(String[] args) {

try {

Connection conn = getConnection();

//INSERT CODE

cstat.setString(1, "Hello");

cstat.registerOutParameter(2, Types.NUMERIC);

cstat.setInt(2, 10);

catch(SQLException e){}

Mark for Review

(1) Points

CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");

CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");

CallableStatement cstat = con.prepareCall("{call sayHello}");


CallableStatement cstat = con.prepareCall("sayHello(?, ?)");

CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)

UnknownDecember 21, 2018 at 9:17 PM

46. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for
Review

(1) Points

? (*)

[Correct] Correct

47. How many categories of JDBC drivers are there? Mark for Review

(1) Points
1

4 (*)

[Correct] Correct

48. What type of JDBC driver will convert the database invocation directly into network protocol? Mark for Review

(1) Points

Type 1 driver

Type 2 driver

Type 3 driver

Type 4 driver (*)


[Correct] Correct

49. Which of the following is NOT a JDBC interface used to execute SLQ statements? Mark for Review

(1) Points

Statement Interface

PreparedStatement Interface

PrePreparedStatement Interface (*)

CallableStatement Interface

[Correct] Correct

50. You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review

(1) Points

True (*)
False

Reply

agustiawanApril 14, 2019 at 12:29 PM

What is the output from the following code snippet?

boolean status=false;

int i=1;

if( (++i>1) && (status=true))

i++;

if( (++i>3) || (status=false))

i++;

System.out .println (i); Mark for Review

(1) Points

5 (*)

Reply

Replies

agustiawanApril 14, 2019 at 12:42 PM

Virtual method invocation occurs: Mark for Review

(1) Points

When the method of a superclass is used on a superclass reference.

When the method of a subclass is used on a subclass reference.

Not part of polymorphism.

When the method of a subclass is used on a superclass reference. (*)


Correct Correct

Reply

Sugantha RajaJuly 10, 2019 at 2:31 AM

This is very great thinks. It was very comprehensive post and powerful concept. Thanks for your sharing with us. Keep it
up..

Oracle Training in Chennai | Oracle Training Institutes in Chennai

Reply

Raj SharmaJuly 13, 2019 at 12:48 AM

Good Post. I like your blog. Thanks for Sharing

Oracle Training Course in Noida

Reply

unknownOctober 2, 2019 at 4:39 AM

Hiiii...Thanks for sharing Great info...Nice post...Keep move on...

Python Training in Hyderabad

Reply

gkumarsnghNovember 10, 2019 at 4:49 AM

Wow! this is Amazing! Do you know your hidden name meaning ? Click here to find your hidden name meaning

Reply

gkumarsnghNovember 13, 2019 at 4:59 AM

Wow! this is Amazing! Do you know your hidden name meaning ? Click here to find your hidden name meaning
Reply

UnknownDecember 7, 2019 at 7:23 PM

Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object?

beforeFirst() (*)

absolute()

afterFirst()

afterLast()

beforeLast()

previous() (*)

Reply

UnknownDecember 7, 2019 at 9:02 PM

What is the output from the following code snippet?

Integer[] ar = {1, 2, 1, 3};

Set set = new TreeSet(Arrays.asList(ar));

set.add(4);

for (Integer element : set) {

System.out.print(element);

11234

1213

12134

1234 (*)

Reply

UnknownDecember 7, 2019 at 9:03 PM


What is the output from the following code snippet?

TreeSett=new TreeSet();

if (t.add("one"))

if (t.add("two"))

if (t.add ("three"))

t.add("four");

for (String s : t)

System.out.print (s);

twofouronethree

The code does not compiles.

onetwothreefour

fouronethreetwo (*)

Reply

UnknownDecember 7, 2019 at 9:24 PM

Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole.
True or false?

True

False (*)

Reply
UnknownDecember 7, 2019 at 9:25 PM

What is the result from the following code snippet?

interface Shape {}

class Circle implements Shape{}

class Rectangle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls= new ArrayList();//line 1

ls.add(new Circle());

ls.add(new Rectangle());// line 2

ls.add(new Integer(1));// line 3

System.out.println(ls.size());// line 4

Compilation error at line 3

3 (*)

Compilation error at line 2

Compilation error at line 4

Compilation error at line 1

Reply

UnknownDecember 7, 2019 at 9:26 PM

Examine the code below. Which statement about this code is true?

1.class Shape { }

2.class Circle extends Shape { }

3.class Rectangle extends Shape { }

4.class Node { }
5.public class Test{

6.public static void main(String[] args){

7.Node nc = new Node<>();

8.Node ns = nc;

An error at line 7 causes compilation to fail.

An error at line 8 causes compilation to fail. (*)

The code compiles.

An error at line 4 causes compilation to fail.

Reply

UnknownDecember 7, 2019 at 9:34 PM

Which of the following is a valid JDBC URL?

oracle:thin:localhost@dfot/dfot:1521/xepdb1

jdbc::oracle-thin:dfot/dfot@oracle:1521/xepdb1

jdbc:oracle:thin:dfot/dfot@localhost:1521/xepdb1 (*)

oracle:thin:jdbc:dfot/dfot@localhost:1521/xepdb1

Reply

UnknownDecember 7, 2019 at 10:07 PM

What is the definition of a logic error?

Something that causes your computer to crash.

Computer malfunction that makes your code run incorrectly.


Bugs in code that make your program run different than expected (*)

Wrong syntax that will be caught at compile time.

Reply

satriaprJanuary 30, 2020 at 11:49 PM

terima kasih sangat membantu boss good

Reply

ASD international hacker & coders academyMay 18, 2020 at 12:41 AM

Apply Now for Distance/Regular Learning through tablet specially designed for learn ethical hacking, Android app
development,

software development, security engineer, forensic investigator,For more information visitClick Here

Reply

anishJune 19, 2020 at 4:54 AM

Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post.
Keep Blogging!

Oracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore |
Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune |
Oracle Training | Online Course | Certification in coimbatore

Reply

DeviAugust 11, 2020 at 1:51 AM

Thank you for valuable information.I am privilaged to read this post. oracle training in chennai

Reply

Keturah CarolSeptember 29, 2020 at 3:38 AM

This comment has been removed by the author.


Reply

Keturah CarolSeptember 29, 2020 at 3:40 AM

Nice Post! Thanks for sharing such an amazing article, really informative, it helps me a lot.

Oracle Java Certifications

Reply

AchmadzOctober 12, 2020 at 3:23 AM

6. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete
classes, subclasses, and enum classes.

Mark for Review

(1) Points

True (*)

False

Reply

AchmadzOctober 14, 2020 at 11:21 PM

6. The following code can be compiled, True/False?

byte b = 1 + 1;

Mark for Review

(1) Points

True (*)

False

Reply
UnknownNovember 16, 2020 at 1:20 PM

14. A base case can handle nested conditions.

True or false?

True (*)

False

Reply

UnknownNovember 16, 2020 at 1:49 PM

Wildcards in generics allows us greater control on the types that can be used.

True or False?

True (*)

False

Reply

AnonymousDecember 12, 2020 at 6:22 AM

Thanks, this is generally helpful.

Still, I followed step-by-step your method in this Java online training

Java online course

Reply

UnknownDecember 25, 2020 at 2:51 AM

When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can occur
(Choose all that apply).

Mark for Review

(1) Points

NoSuchFileException
(*)

DirectoryNotEmptyException

(*)

No exception is thrown

IOException

(*)

Reply

UnknownDecember 25, 2020 at 3:07 AM

The java.io package has problems with no support for symbolic links.

True or false?

Mark for Review

(1) Points

True (*)

False

Reply

UnknownDecember 25, 2020 at 3:08 AM

47. Which of the following statements is NOT TRUE for the Class.forName("HelloClass") method? (Choose three)

public class Foo{

public void test(){

Class.forName("HelloClass");

Mark for Review

(1) Points
The forName() method does not initialize the HelloClass.

(*)

The forName() method returns the Class object associated with the HelloClass.

The forName() method does not load the HelloClas class into the Java Runtime.

(*)

In this example, the Class.forName("HelloClass") will use the ClassLoader which loads the Foo class.

The forName method will instantiate a HelloClass object.

(*)

Reply

UnknownDecember 25, 2020 at 3:39 AM

Which is the correct way to initialize a HashSet?

Mark for Review

(1) Points

classMates = new HashSet[String]();

ClassMates = public class

HashSet();

String classMates = new

String();

HashSet classMates =

new HashSet>(); (*)

Reply

UnknownDecember 25, 2020 at 3:39 AM

Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three)

Mark for Review


(1) Points

Read the String backwards (from last element to first element).

(*)

Parse the String.

(*)

Search for a specific character or String inside of the String.

(*)

You don't use a FOR loop with Strings

Reply

UdinDecember 30, 2020 at 6:35 PM

Thanks.. Bro.

PROxyz

Reply

UnknownJanuary 20, 2021 at 2:04 AM

Which of the following is NOT TRUE about Java?

Mark for Review

(1) Points

The JVM offers a secure environment to run a Java application

Bytecode is not portable, and needs to be compiled again in order to run on a different platform. (*)

The JVM can interpret bytecode.

Once Java source code is compiled, it converts to bytecode.

Reply
ramJune 8, 2021 at 11:52 PM

Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all!
Do check them out

oracle plsql training in chennai & get to know everything you want to about software trainings.

Reply

UnknownJune 11, 2021 at 9:19 PM

Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the
first position, and repeating these steps for the remainder of the list.

True (*)

False

Reply

IDmitryJune 15, 2021 at 11:22 AM

A serialized class implements which interface?

Serializable (*)

SerializedObject

Serializer

Serializing

Serialized

Reply

IDmitryJune 15, 2021 at 11:34 AM

A serialized class implements which interface?

Serializable (*)

SerializedObject

Serializer
Serializing

Serialized

Reply

AdministradorJune 17, 2021 at 4:22 AM

38. Which of the following methods adds a Key-Value map to a HashMap?

add(Key, Value)

put(Key, Value) (*)

remove(Key, Value)

get(Key, Value)

Reply

DeviJune 24, 2021 at 7:13 AM

Did you want to set your career towards Oracle? Then Infycle is with you to make this into reality. Infycle Technologies
gives the combined and best Oracle course in Chennai, which offers various stages of Oracle such as Oracle PL/SQL,
Oracle DBA, etc., along with 100% hands-on training guided by professional tutors in the field. Along with that, the mock
interviews will be given to the candidates to face the interviews with complete confidence. Apart from all, the
candidates will be placed in the top MNC's with an excellent salary package. To get it all, call 7502633633 and make this
happen for your happy life.

Best Oracle Course in Chennai | Infycle Technologies

Reply

EsinJune 29, 2021 at 5:22 AM

adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman
escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort -
eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort -
ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya
escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu
escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort -
uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort

Reply
AdministradorJune 29, 2021 at 3:55 PM

When you import a package, subpackages will not be imported.

True or false?

True (*)

False

Reply

Section 3 - Quiz 2 L4-L6

(Answer all questions in this section)

1. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

None of them execute since you cannot have multiple catch statements.

Correct
2. When do errors occur in code? Mark for Review

(1) Points

(Choose all correct answers)

When files are not found or are unreadable. (*)

When hardware issues occur (e.g., not enough memory). (*)

When an exception is thrown (*)

When there is an error in your logic. (*)

Incorrect. Refer to Section 3 Lesson 6.

3. When is the proper time to use exceptions? Mark for Review

(1) Points

When you want to print statements to the screen.

When you want to efficiently and reliably debug your program. (*)

If you purposefully put errors in your code you wish to handle.


Every time a new method is called.

Correct

4. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.

5. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False
Correct

6. Methods can not throw exceptions.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct
8. The BufferedOutputStream is a direct subclass of what other class? Mark for Review

(1) Points

OutputStream

ObjectOutputStream

FilterOutputStream (*)

PrintStream

DigestOutputStream

Incorrect. Refer to Section 3 Lesson 5.

9. The read() method lets you read a character at a time. True or false? Mark for Review

(1) Points

True (*)

False
Incorrect. Refer to Section 3 Lesson 5.

10. A serialized class implements which interface? Mark for Review

(1) Points

Serializer

Serializing

Serializable (*)

SerializedObject

Serialized

Incorrect. Refer to Section 3 Lesson 5.

11. The Files class lets you check for file properties. True or false? Mark for Review

(1) Points

True (*)

False
Incorrect. Refer to Section 3 Lesson 5.

12. Which of the following is an absolute Windows path? Mark for Review

(1) Points

/home/user/username

data

\Users\UserName\data

C:\Users\UserName\data (*)

Incorrect. Refer to Section 3 Lesson 4.

13. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

14. Java 7 requires you create an instance of java.io.File class. True or false? Mark for Review

(1) Points

True

False (*)

Correct

15. The java.io package has problems with missing operations, like copy, move, and such.

True or false? Mark for Review

(1) Points

True (*)

False
Correct

1. The normalize() method removes extraneous elements from a qualified path. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

2. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method. True or false? Mark for
Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

3. The Files class performs which of the following? Mark for Review

(1) Points
Works with absolute paths

Navigates the file system

Creates files (*)

Works with relative paths

Works across disk volumes

Incorrect. Refer to Section 3 Lesson 4.

4. The new Paths class lets you resolve .. (double dot) path notation. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.


5. What is one step you must do to create your own exception? Mark for Review

(1) Points

Declare the primitive data type Exception.

Create a new class that implements Exception.

Create a new class that extends Exception. (*)

Exceptions cannot be created. They are only built in to Java.

Correct

6. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.


7. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct

8. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

9. What is special about including a resource in a try statement? Mark for Review

(1) Points
(Choose all correct answers)

The resources will auto-close. (*)

The program will fail if the resource does not open.

An error will be thrown if the resources does not open. (*)

Incorrect. Refer to Section 3 Lesson 6.

10. When do you use try-catch statements? Mark for Review

(1) Points

Every time you would like to assign a new value to a variable that is being asserted.

If you want to switch different values for a certain variable.

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)


Incorrect. Refer to Section 3 Lesson 6.

11. When should you not use assertions? Mark for Review

(1) Points

(Choose all correct answers)

When you want your program to execute efficiently.

When you believe you have no bugs in your code.

When you want to check the values of parameters. (*)

When you call methods that may cause side effects in your assertion check. (*)

Incorrect. Refer to Section 3 Lesson 6.

12. File permissions are the same across all of the different operating systems. Mark for Review

(1) Points

True

False (*)
Incorrect. Refer to Section 3 Lesson 5.

13. When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can
occur (Choose all that apply). Mark for Review

(1) Points

(Choose all correct answers)

NoSuchFileException (*)

DirectoryNotEmptyException (*)

No exception is thrown

IOException (*)

Incorrect. Refer to Section 3 Lesson 5.

14. The System.out is what type of stream? Mark for Review

(1) Points

A PrintStream (*)
A BufferedWriter stream

An OutputStream

A Reader stream

A BufferedReader stream

Incorrect. Refer to Section 3 Lesson 5.

15. The read() method lets you read a character at a time. True or false? Mark for Review

(1) Points

True (*)

False

Correct

1. The finally clause only executes when an exception is not caught and thrown.

True or false? Mark for Review

(1) Points
True

False (*)

Correct

2. What is one step you must do to create your own exception? Mark for Review

(1) Points

Create a new class that extends Exception. (*)

Create a new class that implements Exception.

Exceptions cannot be created. They are only built in to Java.

Declare the primitive data type Exception.

Incorrect. Refer to Section 3 Lesson 6.

3. When do errors occur in code? Mark for Review

(1) Points
(Choose all correct answers)

When there is an error in your logic. (*)

When an exception is thrown (*)

When hardware issues occur (e.g., not enough memory). (*)

When files are not found or are unreadable. (*)

Incorrect. Refer to Section 3 Lesson 6.

4. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.


5. When do you use try-catch statements? Mark for Review

(1) Points

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)

Every time you would like to assign a new value to a variable that is being asserted.

If you want to switch different values for a certain variable.

Incorrect. Refer to Section 3 Lesson 6.

6. Why should you not use assertions to check parameters? Mark for Review

(1) Points

Not all methods have parameters, therefore assertions should never be used on parameters.

Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)

Assertions do not work on parameters.

It is hard to assume expected values for parameters.


Incorrect. Refer to Section 3 Lesson 6.

7. Multiple catch statements can be used for a single try statement.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.

8. An ObjectInputStream lets you read a serialized object. True or false? Mark for Review

(1) Points

True

False (*)

Correct
9. File permissions are the same across all of the different operating systems. Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 5.

10. The Files class lets you check for file properties. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 5.

11. The System.in is what type of stream? Mark for Review

(1) Points

A Reader stream
An InputStream (*)

A PrintStream

A BufferedWriter stream

A BufferedReader stream

Incorrect. Refer to Section 3 Lesson 5.

12. The normalize() method removes extraneous elements from a qualified path. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

13. The new Paths class lets you resolve .. (double dot) path notation. True or false? Mark for Review

(1) Points
True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

14. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

15. An absolute path always starts from the drive letter or mount point. Mark for Review

(1) Points

True (*)

False
Incorrect. Refer to Section 3 Lesson 4.

What two packages are available in Java to allow you to transfer data? Mark for Review

(1) Points

(Choose all correct answers)

java.nio.file package (*)

java.output.package

java.io package (*)

java.input.package

Incorrect. Refer to Section 3 Lesson 4.

7. What is the definition of a logic error? Mark for Review

(1) Points

Bugs in code that make your program run different than expected (*)
Something that causes your computer to crash.

Wrong syntax that will be caught at compile time.

Computer malfunction that makes your code run incorrectly.

Incorrect. Refer to Section 3 Lesson 6.

12. The BufferedInputStream is a direct subclass of what other class? Mark for Review

(1) Points

FileInputStream

FilterInputStream (*)

InputStream

InputStream

PipedInputStream

Incorrect. Refer to Section 3 Lesson 5.


1. Java 7 requires you create an instance of java.io.File class. True or false? Mark for Review

(1) Points

True

False (*)

Correct

2. Which of the following is an absolute Windows path? Mark for Review

(1) Points

/home/user/username

\Users\UserName\data

data

C:\Users\UserName\data (*)
Correct

3. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

4. The way that you read from a file has changed since the introduction of Java 7. Mark for Review

(1) Points

True (*)

False

Correct

5. What is the definition of a logic error? Mark for Review

(1) Points
Computer malfunction that makes your code run incorrectly.

Wrong syntax that will be caught at compile time.

Something that causes your computer to crash.

Bugs in code that make your program run different than expected (*)

Correct

6. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. Why should you not use assertions to check parameters? Mark for Review
(1) Points

Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)

Not all methods have parameters, therefore assertions should never be used on parameters.

It is hard to assume expected values for parameters.

Assertions do not work on parameters.

Correct

8. Multiple exceptions can be caught in one catch statement.

True or false? Mark for Review

(1) Points

True (*)

False

Correct
9. When do errors occur in code? Mark for Review

(1) Points

(Choose all correct answers)

When files are not found or are unreadable. (*)

When an exception is thrown (*)

When there is an error in your logic. (*)

When hardware issues occur (e.g., not enough memory). (*)

Correct

10. When do you use try-catch statements? Mark for Review

(1) Points

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)

Every time you would like to assign a new value to a variable that is being asserted.
If you want to switch different values for a certain variable.

Correct

11. Multiple catch statements can be used for a single try statement.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

12. When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can
occur (Choose all that apply). Mark for Review

(1) Points

(Choose all correct answers)

NoSuchFileException (*)

No exception is thrown
DirectoryNotEmptyException (*)

IOException (*)

Incorrect. Refer to Section 3 Lesson 5.

13. Which of the following static methods is not provided by the Files class to check file properties or duplication?
Mark for Review

(1) Points

Files.isWritable(Path p);

Files.isArchived(Path p); (*)

Files.isReadable(Path p);

Files.isHidden(Path p);

Correct

14. A serialized class implements which interface? Mark for Review


(1) Points

Serializer

Serialized

Serializing

Serializable (*)

SerializedObject

Correct

15. The System.out is what type of stream? Mark for Review

(1) Points

An OutputStream

A BufferedReader stream

A BufferedWriter stream
A PrintStream (*)

A Reader stream

Correct

Section 3 - Quiz 2 L4-L6

(Answer all questions in this section)

1. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

None of them execute since you cannot have multiple catch statements.

Correct

2. When do errors occur in code? Mark for Review


(1) Points

(Choose all correct answers)

When files are not found or are unreadable. (*)

When hardware issues occur (e.g., not enough memory). (*)

When an exception is thrown (*)

When there is an error in your logic. (*)

Incorrect. Refer to Section 3 Lesson 6.

3. When is the proper time to use exceptions? Mark for Review

(1) Points

When you want to print statements to the screen.

When you want to efficiently and reliably debug your program. (*)

If you purposefully put errors in your code you wish to handle.


Every time a new method is called.

Correct

4. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.

5. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False
Correct

6. Methods can not throw exceptions.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct

8. The BufferedOutputStream is a direct subclass of what other class? Mark for Review
(1) Points

OutputStream

ObjectOutputStream

FilterOutputStream (*)

PrintStream

DigestOutputStream

Incorrect. Refer to Section 3 Lesson 5.

9. The read() method lets you read a character at a time. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 5.


10. A serialized class implements which interface? Mark for Review

(1) Points

Serializer

Serializing

Serializable (*)

SerializedObject

Serialized

Incorrect. Refer to Section 3 Lesson 5.

11. The Files class lets you check for file properties. True or false? Mark for Review

(1) Points

True (*)

False
Incorrect. Refer to Section 3 Lesson 5.

12. Which of the following is an absolute Windows path? Mark for Review

(1) Points

/home/user/username

data

\Users\UserName\data

C:\Users\UserName\data (*)

Incorrect. Refer to Section 3 Lesson 4.

13. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)
False

Incorrect. Refer to Section 3 Lesson 4.

14. Java 7 requires you create an instance of java.io.File class. True or false? Mark for Review

(1) Points

True

False (*)

Correct

15. The java.io package has problems with missing operations, like copy, move, and such.

True or false? Mark for Review

(1) Points

True (*)

False
Correct

1. The normalize() method removes extraneous elements from a qualified path. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

2. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method. True or false? Mark for
Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

3. The Files class performs which of the following? Mark for Review

(1) Points
Works with absolute paths

Navigates the file system

Creates files (*)

Works with relative paths

Works across disk volumes

Incorrect. Refer to Section 3 Lesson 4.

4. The new Paths class lets you resolve .. (double dot) path notation. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.


5. What is one step you must do to create your own exception? Mark for Review

(1) Points

Declare the primitive data type Exception.

Create a new class that implements Exception.

Create a new class that extends Exception. (*)

Exceptions cannot be created. They are only built in to Java.

Correct

6. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.


7. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct

8. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

9. What is special about including a resource in a try statement? Mark for Review

(1) Points
(Choose all correct answers)

The resources will auto-close. (*)

The program will fail if the resource does not open.

An error will be thrown if the resources does not open. (*)

Incorrect. Refer to Section 3 Lesson 6.

10. When do you use try-catch statements? Mark for Review

(1) Points

Every time you would like to assign a new value to a variable that is being asserted.

If you want to switch different values for a certain variable.

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)

Incorrect. Refer to Section 3 Lesson 6.


11. When should you not use assertions? Mark for Review

(1) Points

(Choose all correct answers)

When you want your program to execute efficiently.

When you believe you have no bugs in your code.

When you want to check the values of parameters. (*)

When you call methods that may cause side effects in your assertion check. (*)

Incorrect. Refer to Section 3 Lesson 6.

12. File permissions are the same across all of the different operating systems. Mark for Review

(1) Points

True

False (*)
Incorrect. Refer to Section 3 Lesson 5.

13. When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can
occur (Choose all that apply). Mark for Review

(1) Points

(Choose all correct answers)

NoSuchFileException (*)

DirectoryNotEmptyException (*)

No exception is thrown

IOException (*)

Incorrect. Refer to Section 3 Lesson 5.

14. The System.out is what type of stream? Mark for Review

(1) Points

A PrintStream (*)
A BufferedWriter stream

An OutputStream

A Reader stream

A BufferedReader stream

Incorrect. Refer to Section 3 Lesson 5.

15. The read() method lets you read a character at a time. True or false? Mark for Review

(1) Points

True (*)

False

Correct

1. The finally clause only executes when an exception is not caught and thrown.

True or false? Mark for Review

(1) Points
True

False (*)

Correct

2. What is one step you must do to create your own exception? Mark for Review

(1) Points

Create a new class that extends Exception. (*)

Create a new class that implements Exception.

Exceptions cannot be created. They are only built in to Java.

Declare the primitive data type Exception.

Incorrect. Refer to Section 3 Lesson 6.

3. When do errors occur in code? Mark for Review

(1) Points

(Choose all correct answers)


When there is an error in your logic. (*)

When an exception is thrown (*)

When hardware issues occur (e.g., not enough memory). (*)

When files are not found or are unreadable. (*)

Incorrect. Refer to Section 3 Lesson 6.

4. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.

5. When do you use try-catch statements? Mark for Review


(1) Points

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)

Every time you would like to assign a new value to a variable that is being asserted.

If you want to switch different values for a certain variable.

Incorrect. Refer to Section 3 Lesson 6.

6. Why should you not use assertions to check parameters? Mark for Review

(1) Points

Not all methods have parameters, therefore assertions should never be used on parameters.

Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)

Assertions do not work on parameters.

It is hard to assume expected values for parameters.


Incorrect. Refer to Section 3 Lesson 6.

7. Multiple catch statements can be used for a single try statement.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 6.

8. An ObjectInputStream lets you read a serialized object. True or false? Mark for Review

(1) Points

True

False (*)

Correct

9. File permissions are the same across all of the different operating systems. Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 5.

10. The Files class lets you check for file properties. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 5.

11. The System.in is what type of stream? Mark for Review

(1) Points

A Reader stream

An InputStream (*)
A PrintStream

A BufferedWriter stream

A BufferedReader stream

Incorrect. Refer to Section 3 Lesson 5.

12. The normalize() method removes extraneous elements from a qualified path. True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

13. The new Paths class lets you resolve .. (double dot) path notation. True or false? Mark for Review

(1) Points

True (*)
False

Incorrect. Refer to Section 3 Lesson 4.

14. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 4.

15. An absolute path always starts from the drive letter or mount point. Mark for Review

(1) Points

True (*)

False
Incorrect. Refer to Section 3 Lesson 4.

What two packages are available in Java to allow you to transfer data? Mark for Review

(1) Points

(Choose all correct answers)

java.nio.file package (*)

java.output.package

java.io package (*)

java.input.package

Incorrect. Refer to Section 3 Lesson 4.

7. What is the definition of a logic error? Mark for Review

(1) Points

Bugs in code that make your program run different than expected (*)

Something that causes your computer to crash.


Wrong syntax that will be caught at compile time.

Computer malfunction that makes your code run incorrectly.

Incorrect. Refer to Section 3 Lesson 6.

12. The BufferedInputStream is a direct subclass of what other class? Mark for Review

(1) Points

FileInputStream

FilterInputStream (*)

InputStream

InputStream

PipedInputStream

Incorrect. Refer to Section 3 Lesson 5.

1. Java 7 requires you create an instance of java.io.File class. True or false? Mark for Review
(1) Points

True

False (*)

Correct

2. Which of the following is an absolute Windows path? Mark for Review

(1) Points

/home/user/username

\Users\UserName\data

data

C:\Users\UserName\data (*)

Correct
3. The java.nio.file package has improved exception handling.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

4. The way that you read from a file has changed since the introduction of Java 7. Mark for Review

(1) Points

True (*)

False

Correct

5. What is the definition of a logic error? Mark for Review

(1) Points
Computer malfunction that makes your code run incorrectly.

Wrong syntax that will be caught at compile time.

Something that causes your computer to crash.

Bugs in code that make your program run different than expected (*)

Correct

6. Is this the correct syntax for catching an exception?

try(inputStream = "missingfile.txt"); catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. Why should you not use assertions to check parameters? Mark for Review

(1) Points
Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)

Not all methods have parameters, therefore assertions should never be used on parameters.

It is hard to assume expected values for parameters.

Assertions do not work on parameters.

Correct

8. Multiple exceptions can be caught in one catch statement.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

9. When do errors occur in code? Mark for Review


(1) Points

(Choose all correct answers)

When files are not found or are unreadable. (*)

When an exception is thrown (*)

When there is an error in your logic. (*)

When hardware issues occur (e.g., not enough memory). (*)

Correct

10. When do you use try-catch statements? Mark for Review

(1) Points

When you want to exit your code before an exception is caught.

When you want to handle an exception. (*)

Every time you would like to assign a new value to a variable that is being asserted.
If you want to switch different values for a certain variable.

Correct

11. Multiple catch statements can be used for a single try statement.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

12. When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can
occur (Choose all that apply). Mark for Review

(1) Points

(Choose all correct answers)

NoSuchFileException (*)

No exception is thrown
DirectoryNotEmptyException (*)

IOException (*)

Incorrect. Refer to Section 3 Lesson 5.

13. Which of the following static methods is not provided by the Files class to check file properties or duplication?
Mark for Review

(1) Points

Files.isWritable(Path p);

Files.isArchived(Path p); (*)

Files.isReadable(Path p);

Files.isHidden(Path p);

Correct

14. A serialized class implements which interface? Mark for Review

(1) Points
Serializer

Serialized

Serializing

Serializable (*)

SerializedObject

Correct

15. The System.out is what type of stream? Mark for Review

(1) Points

An OutputStream

A BufferedReader stream

A BufferedWriter stream
A PrintStream (*)

A Reader stream

Correct

 Examine the code below.  Which statement about this code is true?

1. class Shape { }
2. class Circle extends Shape { }
3. class Rectangle extends Shape { }
4. class Node <T> { }
5. public class Test{
6. public static void main(String[] args){
7. Node <Circle>nc = new Node<>();
8. Node <Shape>  ns = nc;
}
 }
Marcar para Revisión

(1) Puntos
An error at line 4 causes compilation to fail.
The code compiles.
An error at line 8 causes compilation to fail.
An error at line 7 causes compilation to fail.

What is the output from the following code snippet?

int i=0,j=0;
i=++i;
j=i++;
System.out.println("i=" + i + " " + "j=" + j);
(1/1) Puntos
The code will compile and print "i=1 j=1"
The code does not compile.
The code will compile and print "i=2 j=1" (*)
The code will compile and print "i=2 j=2"
The code will compile and print "i=1 j=2"

You might also like