CSC201 midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

4

24 % 5 is _____

braces

A block is enclosed inside __________.

an object represented as a sequence of bytes used to store the object's data in a file.

A serialized object is:

Elevate the importance of data. Are only approximations or models of real-world concepts and behaviors. Capture two notions, data representation and operations.

Abstract Data Types:

interface classes

Abstract methods are used when defining

a static variable

An attribute that is shared by all objects of the class is coded using _________.

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

An uncaught exception:

All three are correct, but Code 1 is preferred.

Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if (number % 2 == 0) even = true; else even = false; Code 2: even = (number % 2 == 0) ? true: false; Code 3: even = number % 2 == 0;

The program cannot compile because the compiler cannot determine which max method should be invoked.

Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(max(1, 2)); } public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked"); if (num1 > num2) return num1; else return num2; } public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked"); if (num1 > num2) return num1; else return num2; } }

Both I and II can compile and run and display Welcome to Java, but the code in I has a better style than II.

Analyze the following code. I: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

The program displays int, long followed by 5.

Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long l) { System.out.println("int, long"); return n; } public static long xMethod(long n, long l) { System.out.println("long, long"); return n; } }

permit access to the protected item by any class defined in the same package

Aside from permitting inheritance, the visibility modifier protected is also used to

has-a relationship.

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

machine language

Computer can execute the code in ____________.

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

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

The code has a runtime error indicating that the array is out of bound.

Consider the following code fragment - which of the following statements is true? int[] list = new int[10]; for (int i = 0; i <= list.length; i++) { list[i] = (int)(Math.random() * 10); }

2.0

If you enter 1 2 3, when you run this program, what will be the output? import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); } }

a compilation error

If you forget to put a closing quotation mark on a string, what kind error will be raised?

compareTo

In order to implement Comparable in a class, what method(s) must be defined in that class?

trimToSize()

In the SringBuilder class, the _____________ method will reduce the storage size used for the string builder.

SetLength()

In the SringBuilder class, the _____________ method will set the length of the builder.

The name of catch block's exception parameter.

In the catch block below, what is arithmeticException? catch ( ArithmeticException arithmeticException ) { System.err.printf( arithmeticException ); } // end catch

0 1 2

In the following code, what is the printout for list2? class Test { public static void main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list2.length; i++) System.out.print(list2[i] + " "); } }

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

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

transient

Instance variables that are not to be output with a Serializable object are declared using which keyword?

can degrade a program's performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.

Intermixing program and error-handling logic:

applets

Java ___________ can run from a Web browser.

Java bytecode

Java compiler translates Java source code into _________.

implementing interfaces

Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by

Sun Microsystems

Java was developed by ____________.

8

One byte has ________ bits.

overriding

Polymorphism is achieved by

good programming style makes a program more readable good programming style helps reduce programming errors

Programming style is important, because ______________.

the entire file is usually rewritten.

Records in a sequential file are not usually updated in place. Instead:

mutator, accessor.

Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.

The string data is not constant. The string data size may grow. The programs frequently perform string concatenation.

StringBuilder objects can be used in place of String objects if:

input.nextInt();

Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read an int value?

Test.java

Suppose you define a Java class as follows: public class Test { } In order to compile this program, the source code should be stored in a file named

javac Test.java

The JDK command to compile a class in the file Test.java is

Correct Component classes, Container classes, and Helper classes.

The Java GUI API contains classes that can be classified into three groups.

.class

The extension name of a Java bytecode file is

.java

The extension name of a Java source code file is

just right

The following code displays ___________. double temperature = 50; if (temperature >= 100) System.out.println("too hot"); else if (temperature <= 40) System.out.println("too cold"); else System.out.println("just right");

skip

The following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble();

calls the constructor as defined in the current class' parent class

The instruction super( ); does which of the following?

public static void main(String[] args)

The main method header is written as:

megahertz and gigahertz

The speed of the CPU may be measured in __________.

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

The statement s1.equalsIgnoreCase( s4 ) is equivalent to which of the following?

Hiding implementation details from clients of a class.

The term "information hiding" refers to:

specifies the exceptions a method throws.

The throws clause of a method:

try block.

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

charAt, with the index as an argument.

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

NORTH, EAST, WEST, SOUTH, CENTER

What are the areas that the BorderLayout manager divides?

encapsulation, inheritance, polymorphism

What are the main programming mechanisms that constitute object-oriented programming?

ActionEvent and ItemEvent

What event(s) would a JComboBox fire upon selecting a new item?

An EOFException is thrown.

What happens when an end-of-file marker is reached (and the program is using an ObjectInputStream to read data from a file)?

Serializable.

What interface must a class implement to indicate that objects of the class can be output and input as a stream of bytes?

An object that must be registered with an event source object and it must be an instance of an appropriate event-handling interface

What is a listener?

The component that creates an event and fires.

What is an event source object?

undefined

What is i after the following for loop? int y = 0; for (int i = 0; i<10; ++i) { y += i; }

area3.5

What is the exact output of the following code? double area = 3.5; System.out.print("area"); System.out.print(area);

12

What is the length of the following array? double[ ] values = new double[12];

11

What is the maximum index value for the following array? double[ ] values = new double[12];

0

What is the minimum index value for the following array? double[ ] values = new double[12];

the address where the array elements are stored.

What is the output of the following code? double[ ] values = {3.2,4.8,7.5}; System.out.println(values);

4

What is the output of the following code? double[] myList = {1, 5, 5, 5, 5, 1}; double max = myList[0]; int indexOfMax = 0; for (int i = 1; i < myList.length; i++) { if (myList[i] >= max) { max = myList[i]; indexOfMax = i; } } System.out.println(indexOfMax);

Event object

What is the root class of event classes?

10

What is the value in count after the following loop is executed? int count = 0; do { System.out.println("Welcome to Java"); } while (count++ < 9); System.out.println(count);

memory to hold the reference to the array elements when they are created

What memory has been allocated when the following line of code has been executed? double[ ] values;

Set frame location to center

What would the following statement do? Frame.setLoationRelateTo(null)

thrown

When an exception occurs it is said to have been:

Accessing a local variable.

When should a program explicitly use the "this" reference?

java ByteCode

Which JDK command is correct to run a Java application in ByteCode.class?

floppy disk hard disk flash stick CD-ROM

Which of the following are storage devices?

public static void class

Which of the following are the reserved words?

ObjectInputStream

Which of the following classes enable input of entire objects from a file?

ObjectOutputStream

Which of the following classes enable output of entire objects to a file?

SerializedOutputStream

Which of the following classes enable output of entire objects to a file?

All are equivalently efficient. String s; for ( int i = 1; i <= 1000; i++ ) s += i; StringBuilder sb = new StringBuilder( 10 ); for ( int i = 1; i <= 1000; i++ ) sb.append( i ); String s = new String( sb ); Correct StringBuilder sb = new StringBuilder( 3000 ); for ( int i = 1; i <= 1000; i++ ) sb.append( i ); String s = new String( sb );

Which of the following creates the string of the numbers from 1 to 1000 most efficiently?

$343

Which of the following is a valid identifier?

A laptop is both a PC and a portable device

Which of the following is an example of multiple inheritance?

compareTo

Which of the following is not a method of the Object class?

Open or edit a file.

Which of the following is not an application of a File object?

-- comments ** comments **

Which of the following lines is not a Java comment?

Integer x = 7;

Which of the following performs a boxing conversion?

int y = x;

Which of the following performs an unboxing conversion? Assume x refers to an Integer object.

System.out.println("Welcome to Java");

Which of the following statements is correct to display Welcome to Java on the console?

Exception handling can catch but not resolve exceptions.

Which of the following statements is false?

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

Which of the following statements is false?

The length of a StringBuilder cannot exceed its capacity.

Which of the following statements is true?

The throw statement is used to throw an exception.

Which of the following statements is true?

The program compiles and runs fine.

Which of the statements listed below is true for the Java code shown here? public class Test { private int t; public static void main(String[] args) { Test test = new Test(); System.out.println(test.t); } }

because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

Why do computers use zeros and ones?

To ensure that the listener has the correct method for processing the event.

Why must a listener be an instance of an appropriate listener interface?

Pseudocode

_______ is the code with natural language mixed with Java code.

Java JDK

________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.

Java API

________ contains predefined classes and interfaces for developing Java programs.

Java

________ is Architecture-Neutral.

Java language specification

________ is a technical definition of the language that includes the syntax and semantics of the Java programming language.

Java C++ C# Python

________ is an object-oriented programming language.

Java

________ is interpreted.

Hardware

________ is the physical aspect of the computer that can be seen.

Java IDE

________ provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.

Java virtual machine

_________ is a software that interprets Java bytecode.

CPU

__________ is the brain of a computer.

Top-down approach

__________ is to implement one method in the structure chart at a time from the top to the bottom.

A compiler

___________ translates high-level language program into machine language program.

Software Programs

____________ are instructions to the computer.

NIC

____________ is a device to connect a computer to a local area network (LAN).

Windows XP

____________ is an operating system.

Operating system

_____________ is a program that runs on a computer to manage and control a computer's activities.

In Java, the word true is ________.

a Boolean literal

A3 is a subclass of A2 and A2 is a subclass of A1

public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following is true with respect to A1, A2 and A3?

x, z, a, q

public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... }Which of the following lists of instance data are accessible in A3?

x, z, a, b

public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... }Which of the following lists of instance data are accessible in class A2?

double

If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value.

abstract class Aggregate extends Stone {

"class Aggregate" is incorrect. Choose the correct line so that this program prints Granite: weight=25.0 value=4 numKind=7 public class Inherit { abstract class Stone { protected float weight = 13; protected int value = 4; abstract public String toString( ); } class Aggregate { protected int numKind; } class Granite extends Aggregate { Granite( ) { weight = 25; numKind = 7; } public String toString( ) { return "Granite: weight=" + weight + " value=" + value + " numKind=" + numKind; } } Inherit( ) { Granite g = new Granite( ); System.out.println(g); } void main(String[ ] args) { new Inherit( ); } }

true

Every letter in a Java keyword is in lowercase?

a semicolon (;)

Every statement in Java ends with ________.

a reference to the array elements in row1

For the following multi-dimensional array what value will be stored in values[1] when the array is actually created? int[ ][ ] values;

public int compareTo(Object cp)

For the question below, consider a class called ChessPiece. This class has two instance data, String type and int player. The variable type will store "King", "Queen", "Bishop", etc and the int player will store 0 or 1 depending on whose piece it is. We wish to implement Comparable for the ChessPiece class. Assume that, the current ChessPiece is compared to a ChessPiece passed as a parameter. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."

16

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

buf = new StringBuilder( buf2, 32 );

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?

buffer has capacity 31.

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

10

Given the following statement - what value does list.length have? int[ ] list = new int[10];

a method to refer explicitly to the instance variables and other methods of the object on which the method was called. a method to refer implicitly to the instance variables and other methods of the object on which the method was called. an object to reference itself.

Having a "this" reference allows:

The FontMetrics class

How do you find leading, ascent, descent, and height of a font?

stringWidth(String str)

How do you find the width in pixels of a string in a Graphics object?

8

How many columns in each row of the following array? char[ ][ ] studentGrades = new char[3][8];

3

How many dimensions are included in the following array? char[ ][ ][ ] studentGrades;

class, block.

Identifiers in Java have ________ and ________ scopes?

public Student()

If a class named Student has no constructors defined explicitly, the following constructor is implicitly provided.

a logic error

If a program compiles fine, but it produces incorrect result, then the program suffers __________.


Kaugnay na mga set ng pag-aaral

chapter 4 (and questions on paper)

View Set

23.5 The Long-Run Industry Situation: Exit and Entry

View Set

Chapter 3: Evaluating Moral Arguments

View Set