Shared Flashcard Set

Details

Java CS170 Chapter. 4 Lecture
Lecture Questions
23
Computer Science
Undergraduate 1
10/14/2011

Additional Computer Science Flashcards

 


 

Cards

Term
mixed-type expressions are
Definition
Having an int and a double in the same expression
Term
Java data is arranged in a hierarchy meaning
Definition
Types holding more info at the top, less at bottom
Term
Binary operators usually are
Definition
left-associative
Term
Assignment and unary operators are
Definition
right-associative
Term
You can tell Java to “try” to store closest value this is called
Definition
"cast" or "type cast"
(Ex: int x = 123
byte b = (byte) x;)
Term
Floating-point numbers represent
Definition
approximations. So it can't be a .1 or 1/3
Term
There are shorthand versions of all binary operators:
Definition
a += b; // same as a = a + b;
a -= b; // same as a = a - b;
a /= b; // same as a = a / b;
a *= b; // same as a = a * b;
a %= b; // same as a = a % b;
Term
Increment and decrement operators are
Definition
Unary operators (++, --) that add or subtract one. Can only be applied to a variable. You may use the operator before or after the variable. Both have exactly the same effect on variable. Variable is always incremented or decremented by 1.
(Ex: int a = 5;
++a; // a is now 6
a++; // a is now 7)
Term
The ++ and -- also have an
Definition
expression value
Term
With post-increment (after the variable)
Definition
The original value is saved temporarily

The variable is updated

The original value is returned as the expression's value
Term
System.out.printf() allows us to
Definition
control format
Term
%10.2f is an example of
Definition
Placeholders or format specifiers for each variable
Term
Specifiers start with
Definition
%, followed by variable type. You must provide a variable for each specifier
(Ex: %f for reals, %d for integers, %s for string)
Term
Specifiers are fine tuned by using
Definition
width, precision, and flags
(Ex: "%5d" – integer right-aligned in a 5 character field
"%5.2f" – real with 2 digits of precision, 5-wide
"%-20s" – string left aligned in a field 20 wide
"%,d" – integer with thousands separator
Term
In Java programming, functions:
Definition
Are named blocks of code declared inside a class
Accept (take) one or more parameters (inputs)
Return a single value of a specific type
Term
String objects are
Definition
NOT passed explicitly as parameters. These are called instance methods

S.length(); --- OK
String.length(s); ----NOT OK
Term
Don't use a semi-colon when
Definition
calling the functions
Term
Builder methods create
Definition
new String objects by transforming, (applying a rule), to existing ones
Term
Replace substrings using
Definition
s.replace("a","b"). Very useful for scrubbing user input.
Term
Each type has a class (object) type that "shadows" it. These are called
Definition
the wrapper types. Provide convenient methods for working with types
Term
Turning Strings into numbers is known as
Definition
Parsing
Term
Coordinates used for x,y represent
Definition
"Points" or infinitely small location located between pixels
(Ex: points 2,2 and 6,6)
Term
Shape-drawing methods come in two varieties
Definition
Those that draw an outline. Those that fill an area.
Supporting users have an ad free experience!