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