JAVA TEST 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

An uncaught exception ________.

is an exception that occurs for which there are no matching catch clauses

Which of the Java strings represent the regular expression ,\s*?

",\\s*"

Which of the following is not a word character?

&

Given the following declaration: StringBuilder buf = new StringBuilder(); What is the capacity of buf?

16

Consider the Java segment: String line 1 = new String("c = 1 + 2 + 3); tokenizer makes it ("c=1+2+3") aka 7 chars StringTokenizer tok = new StringTokenizer(line1); Int count = tok.countTokens(); The value of count is ________.

7

How many String objects are instantiated by the following code segment (not including the literals)?

7

The statement s1.startsWith("art") has the same result as which of the following?

All of these

Exceptions can be thrown by ______.

All of these.

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

All of these.

The statement has the same result as which of the following?

All of these.

When an unchecked exception occurs in a method but is not caught, ________.

All of these.

Which of the following errors is synchronous?

All of these.

Which of the following statements is true?

Both "A*" and "A+" will match "AAA", but only "A*" will match an empty string.

Which of the following is true?

Both A precondition must be true when a method is invoked and A postcondition must be true when a method successfully returns to its caller.

Which of the following are types of assertions?

Both Preconditions and Postconditions.

Consider the examples below: A string 'A string' "A string" "1234" integer Which could be the value of a Java variable of type String?

C and D

Consider the statement below: StringBuilder sb1 = new StringBuilder("a toyota"); Which of the following creates a String object with the value "toy"?

Char dest[] = new char[sb1.length()]; sb1.getChars(2,5,dest,0); String res = new String(dest);

Which of the following are static Character methods?

Character.isDigit(char c);

Which of the following statements is false?

Exception handling can catch but not resolve exceptions.

Which of the following exceptions is a checked exception?

IOException

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

Instructions on handling the exception.

Which class is not a type-wrapper class?

Int

Which of the following statements regarding the throw point of an exception is false?

It specifies the point at which the exception must be handled.

Which of the following statements is true?

Like any other class, an exception class can contain fields and methods.

Consider the Java segment: For the String line1 to have 4 tokens, delimArg should be ________.

String delimArg = "+=";

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 = a. concat(b.concat(c));

Consider the String below: String r = "a toyota"; Which of the following will create the String r1 = "a TOYOTa"?

String r1 = r.replace('t','T').replace('o', '0').replace('y', 'Y');

Which of the following statements is false?

The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.

Which of the following statements is false?

The finally block and try block can appear in any order.

Which of the following statements is true?

The length of a StringBuilder cannot exceed its capacity.

In the catch block below, what is e?

The name of catch block's exception parameter.

Which of the following statements is true?

The throw statement is used to throw an exception.

What is the difference between a try block and a try statement?

The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.

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

Thrown

Which of the following statements about the try-with-resources statement is false?

You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block. (Don't have to call explicitly it auto does it)

The String method substring returns ________.

a String

The StringBuilder contents at the end of this segment will be ________.

a landrover a

In Java, after an exception is handled, control resumes ________. This is known as the ________ model of exception handling.

after the last catch block (or the finally block, if there is one), termination

Chained exceptions are useful for finding out about ________.

an original exception that was caught before the current exception was thrown

Given the following declarations: StringBuilder buf; StringBuilder buf2 = new StringBuilder(); String c = new String("test"); Which of the following is not a valid StringBuilder constructor?

buf = new StringBuilder(buf2, 32);

Given the following declarations: StringBuilder buffer = new StringBuilder("Testing Testing"); buffer.setLength(7); buffer.ensureCapacity(5); Which of the following is true?

buffer has capacity 31

String objects are immutable. This means they ________.

cannot be changed

To find the character at a certain index position within a String, use the method ________.

charAt, with the index as an argument

All exception classes inherit, either directly or indirectly, from ________.

class Throwable

After a finally block has finished executing (and there are no exceptions to be handled), ________.

control proceeds to the first statement after the finally block

Consider the java segment: String line 1 = new String("c = 1 + 2 + 3"); StringTokenizer tok = new Stringtokenizer(line1, "+="); String foo = tok.nextToken(); String bar = tok.nextToken(); The values of foo and bar are ________.

foo is "c ", bar is " 1 "

For String c = "now is the time for all"; The java statements String i = c.substring(7); String j = c.substring(4,15); will result in ________.

i = "the time for all" and j = "is the time"

For String c = "Hello. She sells sea shells"; The Java statements Int i = c.indexOf("ll"); Int j = c.lastIndexOf("ll"); will result in ________.

i = 2 and j = 24

For String c = "hello world"; The Java statements Int j = c.indexOf('o'); Int j = c.lastIndexOf('l'); will result in:

i = 4 and j = 9.

The statement Is equivalent to which of the following?

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

The throws clause of a method ________.

specifies the exceptions a method throws.

The length of a string can be determined by ________.

the String method length()

If the catch-or-declare requirement for a checked exception is not satisfied ________.

the compiler will issue an error message indicating that the exception must be caught or declared

To catch an exception, the code that might throw the exception must be enclosed in a ________.

try block

Which of the following statements is true?

All of these.

Which of the following statements is true?

None of these are true. The code in the finally block is always executed provided that the flow of control enters the corresponding try block.

Which of the following statements about try blocks is true?

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

A String constructor cannot be passed ________.

int arrays


Set pelajaran terkait

Chapter 7 The Atmosphere Key Concepts

View Set

FRCS Fifth grade science chapter 6 checkup

View Set

PEDS Practice: Chapter 11 Caring for Children in Diverse Settings

View Set

Chapter 14 Supply Chain Management

View Set

Anatomy and Physiology Final Chapter 3

View Set

Unit 3 Intro to Trig (Chap 4.1-4.4 in Book)

View Set