Computer Programming Midterm Guide

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

In Java (not arithmetic) 7 / 2 is what?

3

Given String city = "Saratoga"; what is the value of city.length( )?

8

If there are two or more constructors for a class, the constructor is said to be what?

overloaded

In Java, ______ are used to indicate the order in which mathematical expressions should be computed.

parenthesis

What declares an integer instance variable?

private int variableName;

Write a short Java program named MyProgram that will contain a main function and just one line in this function that will print your name to the console window.

public class MyProgram { public static void main(String[] args) { System.out.println(" name") } }

What is the correct definition of a class called Teacher?

public class Teacher

In Java, Strings are enclosed in ______ marks, which are not themselves part of the string.

quotation

The contents of a String must be enclosed inside _______.

quotations

What is RAM?

random access memory

Number variables hold values. Object variables hold ______.

references

Given the statement: Rectangle deskTop = new Rectangle( ); the deskTop variable...

refers to a rectangle

Use the _____ statement to specify the value that a method returns to its caller.

return

Another name for logic error

run-time error

Another term for a logic error is what?

runtime error

All Java statements must end with a(n)_______

semicolon

The Java expression Math.pow(side,2) is the same as what?

side*side

What is what we type...ex println, class...?

source code

A ___ method does not operate on an object.

static

A ________ error is a violation of the rules of the programming language

syntax

Local variables die when . . .?

the method exits

What does Rectangle myRec = new Rectangle mean?

the new rectangle is assigned to myRec

No capitals, no spaces, no numbers, no special characters (like &) No numbers No spaces No & No reserved words Yes lower case letters! Can be made up of letters, digits, and underscore characters Can't use & or ? Case sensitive Spaces not permitted within name Can't use reserved words like public What do these rules apply to?

valid variable names

Given the code shown, what is the value stored in tomsSavings ? SavingsAcct tomsSavings = new SavingsAcct(250); SavingsAcct jerrysSavings = tomsSavings; jerrysSavings.deposit(50);

300

What executes a sequence of stored instructions called a program?

CPU

The class Car must be contained in a file named with what?

Car.java

What does the computer acronym "CPU" stand for?

Central Processing Unit

What executes a series of simple tasks in rapid succession and stores data and executes programs?

Computer

In the statement new Rectangle(10, 20, 30, 40); the values in the parentheses are called . . .

Construction Parameters

True/False: Given the following class definition: public class Greeter { public String sayHello( ) { String message = "Hello, Class"; return message; } } If there are no other files in this project, then this file is executable.

False

True/False: In order to use the out object in the System class you must place this line at the top of your program: import java.lang.System;

False

True/False: To use a computer, you need to know how to write a computer program.

False

True/False: You should declare all instance fields as public so that the programmer who uses the class can access them directly.

False

What translates source code (the code you give) into bytecode (code the computer understands)?

Java compiler

What executes bytecode instructions?

Java interpreter

What is a valid constructor for a class called Car?

Public car() { }

The memory or primary storage of a computer is called?

RAM

Given String message = "Java Rules"; the statement String sub = message.substring(5); sets the variable sub equal to what?

Rules

What would you use to access the constant NUMBER_OF_SIDES in a method in a class SquareTest?

SquareTest.NUMBER_OF_SIDES;

What statement will prompt the user for an input string?

String input = JOptionPane.showInputDialog("give a string");

With all programs using the JOptionPane dialog box, which statement must you use to exit the application?

System.exit();

Write the Java statement to display the line on your terminal screen: 12 / 6 = 2

System.out.println("12 / 6 = 2");

What Java statements will display the string "3 + 4 = 5" to standard output (a console window).

System.out.println("3 + 4 = 5");

Given the code segment to the right, what will be printed? String message = "The answer is "; int answer = 42; System.out.println(message + answer);

The answer is 42

True/False: Objects are entities in your program that you manipulate by invoking methods.

True

True/False: The Java Virtual Machine is a CPU (Central Processing Unit) developed by Sun Micro systems.

True

True/False: The component of a computer that contains the CPU, RAM, and the card slots is called the motherboard.

True

True/False: The default constructor usually has no parameters.

True

True/False: The name of the public class and the name of the file that contains it must match.

True

The statement System.out.println( )denotes a call of the println __a__ of the out __b__ inside the System __c__ .

a. method b. object c. class

What is a system in the computer that allows data to transfer between components of the computer?

bus

Source code is translated into what?

bytecode

The keyword ___ causes a variable to become a constant.

final

Multiplying an integer (such as 10) by a floating point number (such as 0.5) yields what?

floating-point number

What is a type of removable data storage/media?

floppy disk

-an access specifier (like public or private) -the return type of the method (String, double, int) -name of method(like getGrades) -body of the method(braces) -a list of parameters of the method enclosed in parentheses (for the input ex: double height or int volume) What does this specify?

method definition/heading

Given the declaration String name = " "; . Which method will compute the length of the string object name:

name.length();

You construct an object of a class with the ____ operator.

new

How do you create a new Rectangle object?

new Rectangle(x, y, width, height)

If you do not explicitly set a string instance field, the instance field equals...?

null

Character constants are delimited by ______ marks.

' '

The output of the Java compiler is a file with a _____ extension

.class

The Java compiler requires that Java file names end with ____

.java

Given the code segment to the right, what is the value of value1? double value1 = 2000; double value2 = value1; value2 = value2 + 500;

2000

If you do not explicitly set a numeric instance field, the instance field equals ...?

0

In Java, 7 % 2 is what?

1

True/False: Constructors have the same name as their class.

True

Given the code segment to the right, when it executes, ch will be set to what? String name = "MacBeth"; char ch = name.charAt(3);

B

True/False: A computer program executes a sequence of very basic operations in rapid succession.

True

Strings are composed of characters. Characters are values of the ______ type.

char

In the Java expression Math.round(x) , Math is a(n) ...

class

Another name for syntax error

compile-time error

Rectangle rec1 = new Rectangle(10,20,30,40); Rectangle rec2 = rec1; Given this code segment above, what is the result when you try to compile and execute the code?

compiler error

In Java, the statement days++; has the same effect as what?

days = days + 1

Given int interest; . What could not be assigned to interest?

double or long

The expression used to convert a double type to an int type is what?

double x = 12.0 (int)x = 12

What are valid representations of numbers in Java?

double, long, int

The main purpose of a constructor is to do what?

initialize instance variables

-an access specifier (like private or public) -the type of variable (like String) -The name of the variable (such as name) -They don't have parameters What does this specify?

instance fields

Given the code segment to the right, which statement will set the integer value 42 into the variable answer?

int answer = 42;

import a Rectangle.

java.awt.Rectangle[x=..., y=..., width=..., height=...]

Given String name = "Wilkinson"; what is name.substring(3,6)?

kin

A ______ contains a collection of programming instructions that describe how to perform a particular task.

library

What belongs to an individual method?

local variables

What is the starting point for the execution of the source code in the application?

main method


Set pelajaran terkait

Chapter #8: Thinking and Intelligence

View Set

Mercantilism and Its Impact on American Colonists

View Set

Christian Faith and Living Unit 7

View Set

BDCS - K-Plan - Questions & Answers

View Set

Sociology 201 Final (UD: Prof. Best)

View Set

Physics Practice Questions- Ch. 13

View Set

Leadership and Management exam 5

View Set

Ch. 15: Adolescence: Cognitive Development

View Set