Advanced Java Exam 1

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/56

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

57 Terms

1
New cards

A well-designed method ________.


A) performs a single, well-defined task

B) contains thousands of lines of code

C) performs multiple unrelated tasks

D) repeats code found in other methods

A

2
New cards

Stacks are known as ________ data structures.

A)FILO.

B) FIFO.

C) LIFO.

D) LILO.

C

3
New cards

To declare a method as static, place the keyword static before ________ in the method’s declaration.

A) the return type

B) the method modifier

C) the method name

D) the argument list

A

4
New cards

Declaring main as static allows the JVM to invoke main ________.


A) without knowing the name of the class in which main is declared.

B) without creating an instance of the class in which main is declared.

C) by creating an object of the class in which main is declared.

B

5
New cards

Which of the following promotions of primitive types is not allowed to occur?

A) char to int.

B) double to float.

C) short to long.

D) int to double.

B

6
New cards

Information is passed to a method in ________.

A) the argument's to the method

B) the method name

C) the method's body

D) the method's return

A

7
New cards

Arrays are ________.

A) fixed-length entities

B) used to draw a sequence of lines, or “rays”

C) data structures that contain up to 10 related data items

D) variable-length entities

A

8
New cards

Which of the following statements about arrays are true?

A. An array is a group of variables containing values that all have the same type.

B. Elements are located by index.

C. The length of an array c is determined by the expression c.length();.

D. The zeroth element of array c is specified by c[0].

A,B,D

9
New cards

Consider the array:

s[0] = 7
s[1] = 0
s[2] = -12
s[3] = 9
s[4] = 10
s[5] = 3
s[6] = 6

The value of s[s[6] - s[5]] is:

9

10
New cards

Which of the following initializer lists would correctly set the elements of array n?

A) array n[int] = {1, 2, 3, 4, 5};

B) int[] n = {1, 2, 3, 4, 5};.

C) int n[5] = {1; 2; 3; 4; 5};.

D) int n = new int(1, 2, 3, 4, 5);.

B

11
New cards

 Consider the program below:

public class Test {
   public static void main(String[] args) {
      int[] a;
      a = new int[10];

      for (int i = 0; i < a.length; i++) {
         a[i] = i + 2;
      }

      int result = 0;
      for (int i = 0; i < a.length; i++) {
         result += a[i];

      }

      System.out.printf("Result is: %d%n", result);
   }
}

The output of this program will be:

65

12
New cards

Which set of statements totals the values in two-dimensional int array items?

int total = 0;
for (int[] subItems : items) {
   for (int item : items) {
      total += item;
   }
}

A

13
New cards

When must a program explicitly use the this reference?

A) Accessing a public variable.

B) Accessing a private variable.

C) Accessing a local variable.

D) Accessing an instance variable that is shadowed by a local variable.

D

14
New cards

An advantage of inheritance is that:

A) Objects of a subclass can be treated like objects of their superclass.

B) None of the above.

C) All instance variables can be uniformly accessed by subclasses and superclasses.

D) All methods can be inherited

A

15
New cards

The static method ________ of class String returns a formatted String.

A) formatString.

B) format.

C) printf.

D) toFormatedString.

B

16
New cards

Which of the following statements is false?

A) If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly.

B) A class's instance variables are normally declared private to enforce good software engineering.

C) A class can directly inherit from class Object.

D) It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.

A

17
New cards

Can a reference of type A can be treated as a reference of type B. T or F

F

18
New cards

Using the protected keyword also gives a member:

A) package access

B) public access

C) private access

D) block scope

A

19
New cards

Which of the following is not a superclass/subclass relationship?

A) Sailboat/Tugboat.

B) Vehicle/Car.

C) None of the above.

D) Employee/Hourly Employee.

A

20
New cards

The _________ of a class are also called the public services or the public interface that the class provides to its clients.

A) public instance variables.

B) All of the above.

C) public constructors.

D) public methods.

D

21
New cards

Constructors: Initialize instance variables and When overloaded, are selected by number, types and order of types of parameters. T or F

T

22
New cards

Which of the following statements is true?

A) Information hiding is achieved by restricting access to class members via keyword public.

B) Methods and instance variables can both be either public or private.

C) The private members of a class are directly accessible to the clients of a class.

D) None of the above is true.

B

23
New cards

When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable?

A) The program compiles and runs because the instance variables are initialized to their default values.

B) A run-time error occurs.

C) A compile-time error occurs.

D) A syntax error occurs.

A

24
New cards

Which of the following class members should usually be private?

A) Constructors.

B) Methods.

C) Variables (or fields).

D) All of the above.

C

25
New cards

Consider the abstract superclass below:

public abstract class Foo {
   private int a;
   public int b;

   public Foo(int aVal, int bVal) {
      a = aVal;
      b = bVal;
   }

   public abstract int calculate();
}

Any concrete subclass that extends class Foo:

Will not be able to access the instance variable a.

Neither (a) nor (b).

Both (a) and (b). THIS

Must implement a method called calculate.

26
New cards

For which of the following would polymorphism not provide a clean solution?

A) A maintenance log program where data for a variety of types of machines is collected and maintenance schedules are produced for each machine based on the data collected.

B) A billing program where there is a variety of client types that are billed with different fee structures.

C) A program to compute a 5% savings account interest for a variety of clients.

D) An IRS program that maintains information on a variety of taxpayers and determines who to audit based on criteria for classes of taxpayers.

C

27
New cards

 A(n)  ______  class cannot be instantiated.

abstract

28
New cards

Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?

public int nonfinal method1();

public int abstract method1();

public int method1();

public abstract int method1();

public abstract int method1();

29
New cards

Which statement best describes the relationship between superclass and subclass types?

A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

30
New cards

Polymorphism allows for specifics to be dealt with during:

execution

31
New cards

Which of the following is not included in an exception’s stack trace?

A) A descriptive message for the exception.

B) Instructions on handling the exception.

C) The method-call stack at the time the exception occurred.

D) he name of the exception.

B

32
New cards

Which of the following statements about try blocks is true?

The try block should contain statements that may process an exception.

The try block must be followed by a finally block.

The try block must be followed by at least one catch block.

The try block should contain statements that may throw an exception.

D

33
New cards

In the catch block below, what is e?

   catch (ArithmeticException e)   {

      System.err.printf(e);

   }

The name of catch block’s exception parameter.

The type of the exception being caught.

An exception handler.

A finally block.

A

34
New cards

Which of the following statements is false?

Exception handling can catch but not resolve exceptions.

All of the above are true.

Exception handling can resolve exceptions.

Exception handling enables programmers to write robust and fault-tolerant programs.

A

35
New cards

When an exception occurs it is said to have been ________.

thrown

handled

declared

caught

A

36
New cards

Consider the statements below:

String a = "JAVA: ";

String b = "How to ";

String c = "Program";

Which of the statements below will create the String r1 = "JAVA: How to Program"?


String r1 = b.concat(c.concat(a));

String r1 = a.concat(b.concat(c));

String r1 = c.concat(b.concat(a));

String r1 = c.concat(c.concat(b));

B

37
New cards

StringBuilder objects can be used in place of String objects if ________.

All of the above.

the string data is not constant

the programs frequently perform string concatenation

the string data size may grow

A

38
New cards

Consider the examples below:

  1. A. a string.

  2. B. 'a string'.

  3. C. "a string".

  4. D. "1234".

  5. E. integer.

Which could be the value of a Java variable of type String?

C AND D

39
New cards

The statement

s1.equalsIgnoreCase(s4)

is equivalent to which of the following?

s1.regionMatches(0, s4, 0, s4.length);

s1.regionMatches(0, s4, 0, s4.length());

s1.regionMatches(true, s4, 0, s4.length);

s1.regionMatches(true, 0, s4, 0, s4.length());

D

40
New cards

For

String c = "hello world";

The Java statements

int i = c.indexOf('o');

int j = c.lastIndexOf('l');

will result in:

i = 4 and j = 9.

i = 5 and j = 8.

 i = 4 and j = 8.

i = 5 and j = 9.

A

41
New cards

The length of a string can be determined by ________.

the String instance variable length

the String method length()

the String method strlen()

All of the above.

B

42
New cards

 Which of the following classes is not used for file input?

Formatter

FileReader

FileInputStream

ObjectInputStream

A

43
New cards

Which of the following statements is false?

Storage of data variables and arrays is temporary.

Files are used for long-term retention of large amounts of data.

Data is lost when a local variable “goes out of scope.”

Data maintained in files is often called transient data.

D

44
New cards

Which of the following is false?

Marshaling is the process of deserializing an object.

dXML (eXtensible Markup Language) is a widely used language for describing data.

A serialized object is represented by XML that includes the object’s data.

JAXB (Java Architecture for XML Binding)  enables you to perform XML serialization.

A

45
New cards

Streams that input bytes from and output bytes to files are known as ________.

Unicode-based streams

character-based streams

byte-based streams

bit-based streams

C

46
New cards

Java supports type inferencing with the <> notation in statements that declare and create generic type variables and objects. For example, the following line:

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

can be written as:

List<String> list = new ArrayList();

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

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

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

B

47
New cards

Which statement is false?

A synchronization wrapper class receives method calls, adds some functionality for thread safety and then delegates the calls to the wrapped class.

All built-in collections are synchronized.

Concurrent access to a Collection by multiple threads could cause indeterminate results or fatal errors.

To prevent potential threading problems, synchronization wrappers are used around collection classes that might be accessed by multiple threads.

B

48
New cards

 Which of these is not an example of a "real-life" collection?

Your favorite songs stored in your computer.

The number of pages in a book.

The players on a soccer team.

The cards you hold in a card game.

B

49
New cards

Which statement is false?

A collection is an object that can hold references to other objects.

The collection interfaces declare the operations that can be performed on each type of collection.

 Collections are carefully constructed for rapid execution and efficient use of memory.

Collections discourage software reuse because they are non-portable.

D

50
New cards

A(n) __________ allows a program to walk through the collection and remove elements from the collection.

Iterator

Queue

List

Set.

A

51
New cards

Which statement is false?

A List is a Collection.

Lists use zero-based indices.

A List is sometimes called a sequence.

A List cannot contain duplicate elements.

D

52
New cards

Two tasks that are operating ________ are executing simultaneously.

in parallel

concurrently

sequentially

iteratively

A

53
New cards

Which of the following statements is false?

Java programs can have multiple threads of execution, where each thread has its own method-call stack and program counter, allowing it to execute concurrently with other threads. This capability is called multithreading.

Today’s multi-core computers have multiple processors that can perform tasks in parallel.

Concurrency is a subset of parallelism.

Java makes concurrency available to you through the language and APIs.

C

54
New cards

Which of the following statements is false?

The concurrent collections have been enhanced to support lambdas.

The collections from thejava.util.concurrent package are specifically designed and optimized for sharing collections among multiple threads.

ConcurrentHashMap and ConcurrentLinkedQueue are by far the most frequently used concurrent collections.

Rather than providing methods to support streams, the concurrent collections provide their own implementations of various stream-like operations—e.g., ConcurrentHashMap has methods forEach, reduce and search—that are designed and optimized for concurrent collections that are shared among threads.

A

55
New cards

 Synchronized versions of the collections in the Java Collections API allow ________ at a time to access a collection that might be shared among several threads.

a maximum of two threads

only one thread

None of the above.

any number of threads

B

56
New cards

The preferred means of creating multithreaded Java applications is by implementing the ________ interface. An object of a class that implements this interface represents a task to perform.

None of the above.

Runnable

Runner

Thread

B

57
New cards

Two tasks that are operating ________ are both making progress at once.

recursively

concurrently

iteratively

sequentially

B