• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/134

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

134 Cards in this Set

  • Front
  • Back

Which of the following is not one of the three general types of computer languages?

Spoken languages.

Which of the following is not a Java primitive type?

real

________ models software in terms similar to those that people use to describe real-world objects.

Object-oriented design

All import declarations must be placed

before the class declaration.

Which class provides prebuilt dialog boxes that enable programs to display windows containing messages (such windows are called message dialogs)?

JOptionPane

What is the result value of c at the end of the following code segment?




int c = 8;


c++;


++c;


c %= 5;

0

How many times is the body of the loop below executed?




int counter = 1;


while ( counter > 20 ) {


// body of loop


counter = counter - 1;


} // end while

0

End-of-line comments that should be ignored by the compiler are denoted using

Two forward slashes ( // )

Which of the following is a Scanner method?

nextLine.

Which of the following is not one of the six logical units of a computer?

Printer.

(True / False) Compilers translate high-level language programs into machine language programs.

True

(True / False) The following segment is a proper way to call the method readData four times?




int i = 0;


while ( i < 4 ) {


readData();


i = i + 1; } // end while

True


(True / False) The following does not contain a syntax error?




System.out.println( "Hello world!" );

True

What is the difference between a float and a double?

Double variables store numbers with larger magnitude and finer detail.

What does the expression x %= 10 do?

Divides x by 10 and stores the remainder in x.

Which command compiles the Java source code file Welcome.java?

javac Welcome.java

What is output by the following Java code segment?




int temp = 180;


if ( temp > 90 ) {


System.out.println( "This porridge is too hot.");


// cool down


temp = temp – ( temp > 150 ? 100 : 20 );


} // end if


else {


if ( temp < 70 ) {


System.out.println("This porridge is too cold.");


// warm up


temp = temp + (temp < 50 ? 30 : 20);


} // end if


} // end else


if ( temp == 80 )


System.out.println( "This porridge is just right!");

None of the above

What is output by the following Java code segment?




int temp = 180;


while ( temp != 80 ) {


if ( temp > 90 ) {


System.out.print( "This porridge is too hot! " ); // cool down


temp = temp – ( temp > 150 ? 100 : 20 );


} // end if


else {


if ( temp < 70 ) {


System.out.print("This porridge is too cold! "); // warm up


temp = temp + (temp < 50 ? 30 : 20);


} // end if


} // end else


} // end while


if ( temp == 80 )


System.out.println( "This porridge is just right!" );

This porridge is too hot! This porridge is just right!

(True / False) Information in the memory unit is persistent—it is retained when the computer's power is turned off.

False

(True / False) Declaration structure is NOT a control structure

True

(True / False) The following will count down from 10 to 1 correctly?

for ( int j = 10; j >= 1; j-- )

True

(True / False) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do…while statement

True

What is another way to write the code segment below:




if ( gender == 1 ) {


if ( age >= 65 )


++seniorFemales;


} // end if

if ( gender == 1 && age >= 65 )


++seniorFemales;

The control variable of a counter-controlled loop should be declared as ________to prevent errors.

int

For the code segment below:




switch( q ) {


case 1:


System.out.println( "apple" );


break;


case 2:


System.out.println( "orange" );


break;


case 3:


System.out.println( "banana" );


break;


case 4:


System.out.println( "pear" );


case 5:


System.out.println( "grapes" );


default:


System.out.println( "kiwi" );


} // end switch




Which of the following values for q will result in kiwi being included in the output?

Anything greater than or equal to 4.

(True / False) The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

False

Suppose variable gender is MALE and age equals 60, how is the following expression evaluated?




( gender == FEMALE ) && ( age >= 65 )

The condition ( gender == FEMALE ) is evaluated first and the evaluation stops immediately.

(True / False) The body of a do…while loop is always executed at least once.

True

To exit out of a loop completely, and resume the flow of control at the next line in the method, use _______.

A break statement.

Attempting to access an array element out of the bounds of an array, causes a(n)

ArrayIndexOutOfBoundsException.

Arrays are:

fixed-length entities

The preferred way to traverse a two-dimensional array is to use

two nested for statements.

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

Which statement correctly passes the array items to method takeArray? Array items contains 10 elements

takeArray( items )

A programmer must do the following before using an array:

declare then create the array.

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 );


} // end main


} // end class Test




The output of this program will be:

Result is: 65.

Which method call converts the value in variable stringVariable to an integer?

Integer.parseInt( stringVariable )

What do the following statements do?




double[] array;


array = new double[ 14 ];

Create a double array containing 14 elements.

In this question, assume a class, Book, has been defined. What is a set of statements that creates an array of Book objects?

Book[] books;books = new Book[ numberElements ];

Static class variables:

are shared by all objects of a class.

(True / False) Variables (or fields) should usually be private

True

Instance variables declared final do not or cannot:

Be modified.

Having a this reference allows

all of the above

When should a program explicitly use the this reference?

Accessing a field that is shadowed by a local variable.

(True / False)




Objects are marked for garbage collection by method finalize.

False

A package is:

all of the above

The import declaration import *; ________.

causes a compilation error

A class within a package must be declared public if

It will be used by classes that are not in the same package

When no access modifier is specified for a method or variable, the method or variable:

Has package access

Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass’s method causes ________.

infinite recursion

Superclass methods with this level of access cannot be called from subclasses.

private

The default implementation of method clone of Object performs a ________.

shallow copy

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

super

Every class in Java, except ________, extends an existing class.

Object

Which superclass members are inherited by all subclasses of that superclass?

protected instance variables and methods

Using the protected keyword gives a member:

package access

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

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

Overriding a method differs from overloading a method because:

Overridden methods have the same signature.

An advantage of inheritance is that:

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

Declaring a method final means

it cannot be overridden

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

Polymorphism allows for specifics to be dealt with during:

execution

Non-abstract classes are called:

concrete classes

(True / False) Methods in an abstract class are implicitly final

False

Polymorphism enables you to:

program in the general

(True / False - about abstract superclasses)




Abstract superclasses may contain data

True

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;


} // end Foo constructor


public abstract int calculate(); }


// end class Foo




Any concrete subclass that extends class Foo:

Both (a) and (b)

A(n) __________ class cannot be instantiated.

abstract

Which keyword is used to specify that a class will define the methods of an interface?

implements

(True / False)




The try block should contain statements that may throw an exception

True

When a __________ method or block is running on an object, the object is locked so no other such method can run on that object at the same time

synchronized

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.

Runnable

A new thread begins its life cycle by transitioning to the __________ state

new

(True / False) ExecutorService is an object that can be run in a separate thread

False

All exception classes inherit, either directly or indirectly, from

class Throwable

The main method executes in the ________ thread of execution.

main

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

try block

In the catch block below, what is arithmeticException?




catch (ArithmeticException arithmeticException)


{ System.err.printf( arithmeticException ); }


// end catch

The name of catch block’s exception parameter

An uncaught exception

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

One generic Stack class could be the basis for creating many Stack classes, e.g., Stack, Stack and Stack. These classes are known as __________


parameterized classes

The classes and interfaces which comprise the collections framework are members of package ________

java.util

(True / False)




A non-generic class cannot be derived from a generic class

False

When a generic class is instantiated without specifying a type argument, it is said to have a __________

raw type

__________ enable programmers to specify, with a single method declaration, a set of related methods

Generic methods

The collections framework algorithms are __________, i.e., each of these algorithms can operate on objects that offer given interfaces without concern to the underlying implementations

polymorphic

When the compiler translates a generic method into Java bytecodes, it uses __________ to replace the type parameters with actual types

erasure

Collections method sort that accepts a List as an argument sorts the elements of a List, which must implement the __________ interface.

Comparable

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

Iterator

(True / False)




A List cannot contain duplicate elements

False

A JEditorPane generates HyperlinkEvents only if it is __________

uneditable

A(n) _________ is thrown when a String that is not in proper URL format is passed to a URL constructor

MalformedURLException

If an ObjectInputStream is used to read information from the server, an __________ is generated when the client attempts to read a value from a stream on which end-of-stream is detected

EOFException

__________ sockets and the __________ protocol are more desirable for the vast majority of Java programmers.

Stream, TCP

(True / False)




Normally, an applet can read files on any server that can be reached over the network

False

A(n) __________ is thrown when a server address indicated by a client cannot be resolved

UnknownHostException

Using a URL as an argument to the __________ method of interface AppletContext causes the browser in which an applet is executing to display the URL

showDocument

(True / False)




UDP is a connection-oriented protocol

False

(True / False)




With datagram sockets a process establishes a connection to another process

False

Once the ServerSocket is created, the server can listen indefinitely (or block) for an attempt by a client to connect. This is accomplished with a call to the ServerSocketmethod __________

accept

Which of the following can be an argument to a method?




a. Constants.


b. Variables.


c. Expressions.


d. All of the above.

All of the above

(True / False)




\ is an escape character

True

Overloaded methods always have the same _________.




a. method name.


b. return type.


c. number of parameters.


d. order of the parameters.

method name.

An overloaded method is one that




a. has a different name than another method, but the same parameters.


b. has the same name as another method, but different parameters (by number, types or order of the types).


c. has the same name and parameters as a method defined in another class.


d. has the same name and parameters, but a different return type as another method.

b. has the same name as another method, but different parameters (by number, types or order of the types).

Which command below runs TestProgram, and passes in the values files.txt and 3?




a. java TestProgram files.txt 3.


b. java TestProgram files.txt, 3.


c. java TestProgram "files.txt", "3".


d. java TestProgram (the arguments files.txt and 3 were passed in when the application was compiled).

a. java TestProgram files.txt 3.

A default constructor has how many parameters?

0

Which of the following is a valid fully qualified name?


a. Scanner.


b. java.Scanner.


c. util.Scanner.


d. java.util.Scanner.

d. java.util.Scanner.

Consider the classes below, declared in the same file:




class A {


int a;


public A() {


a = 7;


}


}


class B extends A {


int b;


public B() {


b = 8;


}


}




Which of the statements below is false?




a. Both variables a and b are instance variables.


b. After the constructor for class B executes, the variable a will have the value 7.


c. After the constructor for class B executes, the variable b will have the value 8.


d. A reference of type A can be treated as a reference of type B.

d. A reference of type A can be treated as a reference of type B.

Declaring main as ________ allows the JVM to invoke main without creating an instance of the class.


a. public.


b. void.


c. static.


d. final.

c. static

Which command executes the Java class file Welcome.class?

java Welcome

The throws clause of a method:

specifies the exceptions a method throws.

A constructor cannot

specify a return type

Which of the following is a double selection control statement?

if..then..else

A well-designed method


a. performs multiple unrelated tasks.


b. repeats code found in other methods.


c. contains thousands of lines of code.


d. performs a single, well-defined task.

d. performs a single, well-defined task.

A(n) ________ enables a program to read data from the user.

Scanner

What type of methods allow a client of a class to assign values to a private instance variable?


a. Get methods.


b. Replace methods.


c. Assign methods.


d. Set methods.

d. Set methods

Composition is sometimes referred to as a(n) ________.


a. is-a relationship.


b. has-a relationship.


c. many-in-one relationship.


d. one-to-many relationship.

b. has-a relationship.

Information is passed to a method in:


a. the method name.


b. that method's return.


c. the method body.


d. the arguments to the method.

d. the arguments to the method.

Suppose method1 is declared as


void method1 ( int a, float b )




Which of the following methods correctly overloads method1?

void method1 ( float a, int b ).

Which is a correct static method call of Math class method sqrt?


a. sqrt( 900 );.


b. math.sqrt( 900 );.


c. Math.sqrt( 900 );.


d. Math math = new Math(); math.sqrt( 900 );.

c. Math.sqrt( 900 );.

What is the name of the values the method call passes to the method for the parameters?




a. Arguments.


b. References.


c. Objects.


d. Values.

a. Arguments

Which of the following is NOT a control structure:




a. Declaration structure.


b. Repetition structure.


c. Sequence structure.


d. Selection structure.

a. Declaration structure

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




a. public constructors.


b. public instance variables.


c. public methods.


d. All of the above.

c. public methods

Every Java application is composed of at least one:


a. local variable


b. instance variable


c. public class declaration


d. imported class

c. public class declaration

Calling a method of another object requires which item?


a. The dot separator.


b. Open and close braces.


c. The new keyword.


d. None of the above.

a. The dot separator

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


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


b. array n[ int ] = { 1, 2, 3, 4, 5 };


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


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

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

Counter-controlled repetition requires




a. A control variable and initial value.


b. A control variable increment (or decrement).


c. A condition that tests for the final value of the control variable.


d. All of the above.

d. All of the above

Which expression adds 1 to the element of array arrayName at index i?




a. ++arrayName[ i ]


b. arrayName++[ i ]


c. arrayName[ i++ ]


d. None of the above

a. ++arrayName[ i ]

When an exception occurs it is said to have been

thrown

Which primitive type can hold the largest value?


a.int


b.long


c.float


d.double

d. double

What is the size in bits of an int?


a.8


b.16


c.32


d.64

c. 32

Stacks are known as ________ data structures.




a. FIFO.


b. FILO.


c. LIFO.


d. LILO

c. LIFO

Which statement is false?


a.A generic class can be derived from a non-generic class


b.A generic class can be derived from another generic class


c.A non-generic class cannot be derived from a generic class


d.A generic method in a subclass can override a generic method in a superclass if both methods have the same signatures

c. A non-generic class cannot be derived from a generic class

Which of the following statements is true?


a.Interpreted programs run faster than compiled programs.


b.Compilers translate high-level language programs into machine language programs.


c.Interpreter programs typically use machine language as input.


d.None of the above.

b.Compilers translate high-level language programs into machine language programs.

What is the default value of a reference?


a.0


b.""


c.null


d.default

c. null