JavaChapter_2 – Flashcards
98 test answers
Unlock all answers in this set
Unlock answers 98question
The ____ method is similar to the println method, except that it does not advance to the next line
answer
print
Unlock the answer
question
Therefore anything printed after a print statement will appear on the?
answer
same line
Unlock the answer
question
operator (+) is used to append one string to the end of another
answer
string concatenation
Unlock the answer
question
It can also be used to append a number to a string A string literal cannot be broken across two lines in a program
answer
String Concatenation
Unlock the answer
question
operator is also used for arithmetic addition
answer
+
Unlock the answer
question
+++ If both operands are strings, or if one is a string and one is a number, it performs
answer
string concatenation
Unlock the answer
question
+ operator If both operands are numeric?
answer
it adds them
Unlock the answer
question
The + operator is evaluated left to right, but _____can be used to force the order
answer
parentheses
Unlock the answer
question
is a series of characters that represents a special character
answer
escape sequence
Unlock the answer
question
sequence begins with a backslash character ()
answer
escape
Unlock the answer
question
is a name for a location in memory that holds a value
answer
variable
Unlock the answer
question
specifies the variable's name and the type of information that it will hold
answer
variable declaration
Unlock the answer
question
changes the value of a variable
answer
assignment statement
Unlock the answer
question
is an identifier that is similar to a variable except that it holds the same value during its entire existence
answer
constant
Unlock the answer
question
As the name implies, it is constant, not?
answer
variable
Unlock the answer
question
The compiler will issue an ____if you try to change the value of a constant
answer
error
Unlock the answer
question
In Java, we use the___ modifier to declare a constant
answer
final
Unlock the answer
question
First, they give meaning to otherwise unclear literal values Example: MAX_LOAD means more than the literal 250 Second, they facilitate program maintenance If a constant is used in multiple places, its value need only be set in one place Third, they formally establish that a value should not change, avoiding inadvertent errors by other programmers
answer
Constants
Unlock the answer
question
There are eight primitive data types in Java
answer
Four of them represent integers: byte, short, int, long Two of them represent floating point numbers: float, double One of them represents characters: char And one of them represents boolean values: boolean
Unlock the answer
question
The difference between the numeric primitive types is their ?
answer
size and the values they can store:
Unlock the answer
question
A ____variable stores a single character
answer
char
Unlock the answer
question
Note the difference between a primitive character variable, which holds only one character, and a ____ object, which can hold multiple characters
answer
String
Unlock the answer
question
is an ordered list of characters, with each character corresponding to a unique number
answer
character set
Unlock the answer
question
variable in Java can store any character from the Unicode character set
answer
char
Unlock the answer
question
set uses sixteen bits per character, allowing for 65,536 unique characters
answer
Unicode character
Unlock the answer
question
It is an international character set, containing symbols and characters from many world languages
answer
Unicode character
Unlock the answer
question
character set is older and smaller than Unicode, but is still quite popular
answer
ASCII character set
Unlock the answer
question
are a subset of the Unicode character set, including:
answer
ASCII characters
Unlock the answer
question
value represents a true or false condition
answer
boolean
Unlock the answer
question
true and false are the only valid values for a boolean type
answer
reserved words
Unlock the answer
question
variable can also be used to represent any two states, such as a light bulb being on or off
answer
boolean
Unlock the answer
question
is a combination of one or more operators and operands
answer
expression
Unlock the answer
question
compute numeric results and make use of the arithmetic operators:
answer
Arithmetic expressions
Unlock the answer
question
If either or both operands are floating point values, then the result is a
answer
floating point value
Unlock the answer
question
If both operands to the division operator (/) are integers, the result is an
answer
integer (the fractional part is discarded)
Unlock the answer
question
returns the remainder after dividing the first operand by the second
answer
The remainder operator (%)
Unlock the answer
question
Operators
answer
can be combined into larger expressions result = total + count / max - offset
Unlock the answer
question
precedence
answer
Operators have a well-defined _____ which determines the order in which they are evaluated
Unlock the answer
question
Multiplication, division, and remainder
answer
_____, _____, and_____ are evaluated before addition, subtraction, and string concatenation
Unlock the answer
question
parentheses
answer
Arithmetic operators with the same precedence are evaluated from left to right, but can be ____used to force the evaluation order
Unlock the answer
question
expression tree
answer
The evaluation of a particular expression can be shown using an ____ ____
Unlock the answer
question
assignment operator
answer
has a lower precedence than the arithmetic operators
Unlock the answer
question
The increment (++) and decrement (--)
answer
operators use only one operand
Unlock the answer
question
The statement count++ is functionally equivalent to
answer
count = count + 1
Unlock the answer
question
postfix or prefix
answer
The increment and decrement operators can be applied in ____form: count++ or ____ form: ++count
Unlock the answer
question
The entire right-hand expression is evaluated first, then the result is combined with the original variable •Therefore result /= (total-MIN) % num
answer
result = result / ((total-MIN) % num) is equivalent to?
Unlock the answer
question
If the operands to the += operator are strings, the assignment operator performs ______ _____
answer
string concatenation
Unlock the answer
question
The behavior of an assignment operator (+=) is always consistent with the behavior of the corresponding operator ;
answer
(+)
Unlock the answer
question
Widening conversions
answer
are safest because they tend to go from a small data type to a larger one (such as a short to an int);
Unlock the answer
question
Narrowing conversions
answer
can lose information because they tend to go from a large data type to a smaller one (such as an int to a short);
Unlock the answer
question
In Java, data conversions can occur in three ways
answer
assignment conversion, promotion,casting;
Unlock the answer
question
Promotion
answer
happens automatically when operators in expressions convert their operands;
Unlock the answer
question
Casting
answer
is the most powerful, and dangerous, technique for conversion
Unlock the answer
question
widening and narrowing conversions
answer
can be accomplished by explicitly casting a value
Unlock the answer
question
cast
answer
To ______, the type is put in parentheses in front of the value being converted;
Unlock the answer
question
input
answer
Programs generally need _____on which to operate
Unlock the answer
question
Scanner class
answer
provides convenient methods for reading input values of various types
Unlock the answer
question
Scanner object
answer
can be set up to read input from various sources, including the user typing values on the keyboard
Unlock the answer
question
System.in object
answer
Keyboard input is represented by the?
Unlock the answer
question
Scanner scan = new Scanner(System.in)
answer
The following line creates a Scanner object that reads from the keyboard
Unlock the answer
question
new operator
answer
creates the Scanner object
Unlock the answer
question
Scanner object
answer
can be used to invoke various input methods, such as: answer = scan.nextLine()
Unlock the answer
question
java.util class
answer
The Scanner class is part of the ______ library, and must be imported into a program to be used
Unlock the answer
question
nextLine method
answer
reads all of the input until the end of the line is found
Unlock the answer
question
white space
answer
is used to separate the elements (called tokens) of the input
Unlock the answer
question
White space
answer
includes space characters, tabs, new line characters
Unlock the answer
question
string
answer
The next method of the Scanner class reads the next input token and returns it as a ______
Unlock the answer
question
Methods
answer
such as nextInt and nextDouble read data of particular types
Unlock the answer
question
picture or drawing
answer
must be digitized for storage on a computer
Unlock the answer
question
A picture
answer
is made up of pixels (picture elements), and each pixel is stored separately
Unlock the answer
question
picture resolution
answer
The number of pixels used to represent a picture is called the ?
Unlock the answer
question
monitor resolution
answer
The number of pixels that can be displayed by a monitor is called the
Unlock the answer
question
pixel
answer
Each _____ can be identified using a two-dimensional coordinate system
Unlock the answer
question
coordinate system
answer
When referring to a pixel in a Java program, we use a _____with the origin in the top-left corner Y X (0, 0) (112, 40) 112 40
Unlock the answer
question
Red, Green, and Blue
answer
Every color can be represented as a mixture of the three additive primary colors?
Unlock the answer
question
RGB value
answer
Each color is represented by three numbers between 0 and 255 that collectively are called an ?
Unlock the answer
question
color
answer
in a Java program is represented as an object created from the Color class
Unlock the answer
question
A Java application
answer
is a stand-alone program with a main method (like the ones we've seen so far)
Unlock the answer
question
A Java applet
answer
is a program that is intended to be transported over the Web and executed using a web browser
Unlock the answer
question
An applet also
answer
can be executed using the appletviewer tool of the Java SDK
Unlock the answer
question
main method
answer
An applet doesn't have a_____?
Unlock the answer
question
paint method
answer
is executed automatically whenever the applet's contents are drawn
Unlock the answer
question
paint method
answer
accepts a parameter that is an object of the Graphics class
Unlock the answer
question
Graphics object
answer
defines a graphics context on which we can draw shapes and text
Unlock the answer
question
Graphics class
answer
has several methods for drawing shapes
Unlock the answer
question
An applet
answer
is embedded into an HTML file using a tag that references the bytecode file of the applet
Unlock the answer
question
The bytecode
answer
version of the program is transported across the web and executed by a Java interpreter that is part of the browser
Unlock the answer
question
A shape
answer
can be filled or unfilled, depending on which method is invoke
Unlock the answer
question
The method parameters
answer
specify coordinates and sizes
Unlock the answer
question
Shapes with curves
answer
, like an oval, are usually drawn by specifying the shape's bounding rectangle
Unlock the answer
question
An arc
answer
can be thought of as a section of an oval
Unlock the answer
question
An arc
answer
is defined by an oval, a start angle, and an arc angle:
Unlock the answer
question
Every drawing surface
answer
has a background color
Unlock the answer
question
Every graphics context
answer
has a current foreground color
Unlock the answer