Chapter 3 Fundamentals of Java

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the relationship between methods, messages, and objects?

-Classes implement methods -if class implements the corresponding method, objects respond to the message -to correspond, methods have to have the same name as the message

What symbol marks the beginning of a multiline comment?

/*

In java, the expression (double) (11/10) yields what?

1.0

The Java programming language has a total of ______ numeric data types.

2 (int & double)

In Java, the expression (int) 2.5 * 4.0 yields what?

8.0

T or F: a value of type double can be assigned to a variable of type int?

False

T or F: All methods for Java objects are required to return some type of value to the calling routine.

False (ex. print)

T or F: Unlike other programming languages, Java does not allow the use of parentheses to override the order of evaluation in an expression.

False--does allow parentheses to override order of evaluation

What are some examples of operands?

Literals: 32.0, 5.0 Variables: fahrenheit, celsius Parenthesized expressions: (fahrenheit - 32.0)

What is the difference between programming and natural languages?

Size-programming is much smaller, easier to learn Rigidity-syntax in programming must be exactly correct; cannot be understood without correct syntax Literalness-computers follow instructions literally>have to be exactly correct

T or F: a Java program can be written and compiled on one type of computer and then run on an entirely different type of computer.

True

True or False: Syntax errors are easier to detect than logic errors.

True

What must we know to run a method successfully?

Type, what it returns, the name, and parameters

What is a screen coordinate system?

a coordinate system used by most programming languages in which the origin is in the upper-left corner of the screen, window, or panel, and the y values increase toward the bottom of the drawing area

What is a coordinate system?

a grid that allows a programmer to specify positions of points in a plane or of pixels on a computer screen

What is a signature?

a method's name, the types and number of its parameters, and what type of value it returns

What is a float-pointing number?

a number written in scientific notation to accommodate numbers that may have very large or very small values

What is a virus?

a program that can enter a computer and perhaps destroy information

What is a bug?

a program that contains a logic error

What is pseudocode?

a stylized half-English, half-code language written in English but suggesting Java code

What is casting?

a technique allowing one data type to be converted to another

what is a constant?

a variable declared that does not change in value (ex. final int AGE = 20)

Write the answers to the following: a. 5/4 b. 5.0/4 c. 5/4.0 d. 5.0/4.0

a. 1 b. 1.25 c. 1.25 d. 1.25

Assume int variable x is 5 and y is 10. a. x + y times 2 b. x - y + 2 c. (x + y) times 2

a. 25 b. -3 c. 30

What is an exception?

an abnormal state or error that occurs during runtime and is signaled by the operating system

What is a run-time error, and when is it found?

an error detected when, after compilation is completed, an error message results instead of the correct output (found during execution)

What is a syntax error, and when is it found?

an error in spelling, punctuation, or placement of certain key symbols in a program (found during compilation)

What is a logic error, and when is it found?

an error such that a program runs, but unexpected results are produced (found in the terminal window)

What are graphics context?

an object associated with a component where the images for that component are drawn

Which of the following is NOT a Java error type? a. Run-time error b. Type-cast error c. Syntax error d. Logic error e. none of these

b. Type-cast error

Which of the following user-defined variables is valid? a. double thee.cheers; b. double three_cheers; c. double 3cheers; d. double int; e. all of the above

b. double three_cheers;

How is a logic error caught?

by the programmer or user

How are packages copied into a new program?

by using an import statement

What String results from the expression "1 + 2 = "+ 1 + 2 a. "1 + 2 = 3" b. "3 = 1 + 2" c. "1 + 2 = 12" d. "3 = 3" e. "1 + 2 = " + 1 + 2

c. "1 + 2 = 12"

What is the maximum positive value that can be stored in a Java variable of type int? a. 32,755 b. 1,073,741,824 c. 2,147,483,647 d. 4,294,967,294

c. 2,147,483,647

A variable of one data type can be temporarily converted to a different data type to perform a calculation by using which method?

casting

What is a package?

codes written by other programmers that make it easy for programmers to share code

Two string variables can be combined into one string variable by _______.

concatenating the strings

What are semantics?

define the rules for interpreting the meaning of statements

What are the different types of run-time errors?

division by integer zero, division by floating-point zero, null pointer exception, no such method error

What is the correct syntax for declaring a variable named alpha, of data type double?

double alpha;

What are the methods in a Scanner class?

double nextDouble(); [returns the first double in the input line--leading and trailing spaces are ignored] int nextInt(); [returns the first integer in the input line--leading and trailing spaces are ignored] String nextLine(); [returns the input line, including leading and trailing spaces--a leading newline is returned as an empty string]

Which of the following is not a typical use for a comment? a. Begin a program with a statement of its purpose b. Explain the purpose of a variable declaration c. Explain the purpose of a major segment of code d. Explain the workings of complex or tricky sections of code e. Al of the above are typical uses for comments

e. All of the above are typical uses for comments

What is a variable declaration statement?

ex. int age; double celsius; String name;

What keyword is used to declare a variable as a constant in a Java program?

final

A ______ object recognizes messages to draw text and shapes.

graphics

What does this statement mean? int i double d i = (int) 3.14 d = (double) 5/4

i = 3 (truncation toward 0) d = 1.25

The ______ data type represents whole numbers in Java.

int

What does a program do when it encounters an input statement, such as reader.nextInt(); or reader.nextDouble();?

it pauses and waits for the user to press Enter, at which point the reader object processes the user's input

What are literals?

items in a program whose values do not change (restricted to primitive data types and strings--ex. 4.0, 2)

The ______ method can be used to determine the current size of a String object.

length

What are comments?

lines of code that clearly explain the purpose and function of a program

Which error type listed below cannot be automatically detected by a programming environment? a. syntax b. run-time c. logic d. none of the above

logic (found by user)

What Scanner method ignores leading blank spaces?

nextInt

The Scanner method for reading lines of text is called ______.

nextLine

What types of data are stored in primitive data types?

numbers (integer and floating-point), characters (a, b, c), and Booleans (true/false)

An arithmetic _______ in Java consists of operands and a operators combined in a manner similar to algebra.

operator

What are the two categories of data types?

primitive data types, reference data types

What does a program do when it encounters an input statement like reader.nextLine();?

prints the string and moves the cursor to the next blank line once the user presses "Enter"

Java's modulus operator returns the value of the _______ in a divide operation.

remainder

What is syntax?

rules for combining words into statements

What are escape sequences?

sequences involving the backslash character \t indicates a tab character \n indicates a newline character

What is vocabulary?

set of all words and symbols in the language

What are the different types of comments?

single line comments (//) multi-line comments (/* start, */ end)

What is a variable?

something that has a place in memory whose value can change throughout the course of a program

Java's ________ consists of the rules for combining words and symbols into a program statement.

syntax

What are the three types of programming errors?

syntax, run-time, and logical errors

What does instantiation mean?

the creation of a new item (object, variable)

What is the length method?

the length method calls to the length message so that when executed, the String object returns the number of characters (the length) of the string

What is the concatenation operator?

the operator that joins two strings together

How can someone modify code so that the cause of a logic error can be discovered?

the person can add lines of code that print the value of selected variables in the terminal window, so that it may define the variable to see if that is the issue in the original source code--the lines precede or follow the places in the program where we think the bug is likely located

What is the origin?

the point (0,0) in the coordinate system

What should a debugging output statement display?

the variable's value that is near the possible error in the code to see if its value is not correct and that is the problem

What is the escape character?

used to indicate that a quotation mark within a string is to be taken literally symbol: \"word\"

What is an arithmetic expression?

using operands and operators combined in a manner familiar from algebra

An item in a program whose value can change during a program execution is called a(n) ________.

variable

When defining a variable in Java, you must always declare the ________.

variable's data type

What are reserved words?

words that have special meaning in java that cannot be employed as user-defined symbols


संबंधित स्टडी सेट्स

General Psychology: Ch. 6 Memory (Quiz)

View Set

Maternity & Newborn Chapter 18: Nursing Management of the Newborn

View Set

Encyclopedia of Counseling Chapter 10

View Set