Ch.1 Flashcards

1
Q

Section1.1 “We begin our Java primer with a program that prints “Hello Universe!” on the screen, which is shown in a dissected form in Figure 1.1. In Java, executable statements are placed in functions, known as methods, that belong to ….” A high level program language, Java uses a class system , with brackets, to contain a class, the main body in a Java program. From the class, methods (or functions) are used to contain actual code that runs from the Java [class]. There are names that can be used which are called an [id…r], and can be combined with letters, numbers, or underscores but with no [sp…s]. There are also reserved words, shown in a table, where any [Un…e cha…r set] are usable. Show section number and page to [blank] answer.

A

[identifier] [spaces] [Unicode character…]1.1 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Section 1.1 
"For the most commonly used data types, Java provides the following base types (also called primitive types): boolean : a boolean value true or false
char: ...." There are several base types in the Java language, and these include:
[bo...n], char, [b...e], [sh...t], [i...t],[lo...g], [f...t], [d...e]. 
These values are given as types, and a variable may be initialized as such type. If they are uninitialized, they may have default values given, when in a class structure.
A

[boolean], [byte], [short], [int], [long], [float], [double] 1.1 4&;5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In more complex Java programs, the primary
“actors” are [ob..s]. Every object is an [i..e] of a
class, which serves as the [t..e] of … and …modifying that
data. The critical [m..s] of a class in Java are….

[I..e va..s], which are also called [f..s],
represent the data associated
with an object of a class. Instance variables
must have a [t..e], which can
either be a base type (such as [i..t], [f..t], or
[d..e]) or any class type (also
known as a [r..e t..e] for reasons we soon
explain).
• [M..s] in Java are blocks of code that can
be called to perform actions
(similar to functions and procedures in other
high-level languages)… A method that returns information to the caller without changing … [a..r
m..d], while an [u..e ][ m..d]
is one that may change one or more instance
variables when called.

A

[objects][instance][type][members][Instance variables][fields][type][int][float][double][reference type][Methods][accessor method][update method] 5&6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

This establishes the identifier, c,as a variable of
type Counter, but it does not create
a Counter instance. Classes are known as
[r..e t..s] in Java, and a variable of
that type (such as c in our example) is known as
a [r..e v..e]. A reference
variable is capable of storing the location (i.e.,
[m..y a..s]) of an object from
the declared class. So we might assign it to
reference … [n..l].

A

[reference types][reference variable][memory address][null] 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In Java, a [n..w] object is created by using the
new operator followed by a call to
a constructor for the desired class; a constructor
is a method that always shares the
same name as its class. The [n..w] operator returns
a [r..e] to the newly created
instance; the returned reference… .

A

[new][new][reference] 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(Such a zero-parameter constructor
is known as a [d..t c..r].) At line 9 we
construct another counter using a
one-parameter form that allows us to specify a
nonzero initial value for the counter.
www.it-ebooks.info
1.2.Classes andObjects
7
Three events occur as part of the creation of a new
instance of aclass:
• A new object is dynamically allocated in memory,
and all instance variables
are initialized to standard default values. The
default values are [n..l] for reference variables and 0 for all base types except [b..n] variables (which
are [f..se] by default).

A

[default constructor][null][boolean][false] 6&7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

…so the object variable [r..rs] to this newly created

object.

A

[refers] 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A method’s name combined with the
number and types of its parameters is called a
method’s [s..re], for it takes all of these parts… to
…method call.

A

[signature] 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Immediately before the definition of a class, instance
variable, or method in Java, keywords known as
[m..rs] can be placed to convey additional
stipulations about that definition.
Access Control Modifiers
The first set of modifiers …

A

[modifiers] 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

[a..s c..l m..s], as they control the level of
access (also known as [v..y]) that the defining
class grants to other classes inthe context of a larger
Java program. The ability to limit access among
classes supports a key principle of object-orientation
known as encapsulation (see Section 2.1)…[p..c] … of Code
Fragment 1.2 designates
[p..c c..s] … instances of the Counter class, as
well as to declare variables and
parameters of type Counter. In Java, each
public class must…

A

[access control modifier][visibility][public][public class] 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
For example, line 5 of Code
Fragment 1.2 designates
[p..c i..t] getCount() {[r..n] count; }
which is why the CounterDemo class may call
c.getCount().
If an instance variable is declared as public,
dot notation can be used to directly
access the variable by code in any other
class that possesses a reference
to an instance of this class.
A

[public int][return] 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
The [p..d] class modifier designates that
access to the defined aspect is only granted to the
following groups of other classes:
◦ Classes that are designated as [s..s] of
the given class through
inheritance... (We will discuss inheritance as
the focus of Section 2.2.)... that belong to the same [p..e] as
the given class...
• The [p..e] class modifier designates that access
to a defined member of a class be granted only to
code within that class. Neither subclasses nor...
A

[protected][subclasses][package][private] 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Finally, we note that if no explicit access control
modifier is given, the de-fined aspect has what is
known as [p..e-p..e a..s] level. This allows
other classes inthe same package (see Section 1.8)
to have access …

The static Modifier
The [s..c] modifier in Java can be declared for any
variable or method of a class (or for a nested class, as
we will introduce in Section 2.6).
When a variable of a class is declared as [s..c],
its value is associated with the class as a whole...
When a method of a class is declared as [s..c],
it too is associated with the class itself...
A

[package-private access][static][static][static] 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

An array can be initialized by a String[]… A [m..x] for an Array is formatting, that allows [i..n] to be entered for code entry, data, etc. The matrix format …
1.2.Classes andObjects
11
The abstract Modifier
A method of a class may be declared as [a..t], in
which case its signature is provided but without an
implementation of the method body. Abstract
methods are an advanced feature…
A class with one or more abstract methods must
also be formally declared as [a..t], because it is
essentially incomplete. (It is also permissible to
declare aclass as abstract even if it does not contain
any abstract methods.) As a result…
The final Modifier
A variable that is declared with the [f..l] modifier
can be initialized as part of that declaration, but can
never… again be assigned a new value. If it is a base
type, then it is a constant. If a reference variable is
[f..l], then it will always refer to the same…

A

[matrix][information][abstract][abstract][final][final] nts & 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
If a member variable of a class is declared as [f..l], it will typically be declared as [s..c] as well, because it would be unnecessarily wasteful to have every instance store
the identical value ...
A

[final][static] 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
The vector class inputs data as a matrix for an [a..y], and then uses a variety of [a..s] to calculate the [v..r] directions...
The project that is discussed in class...[o..t] an array as a message. The [i..t] is to...
A

[array][arrays][vector][output][intent] nts

17
Q

We have already discussed the
significance of modifiers such as [p..c], [p..e],
and [s..c]. The returnType designation defines the
type of value returned by the method. The
methodName can be any valid Java identifier. The list
of parameters and their types declares the local
variables … Each type
declaration typei can be any Java type name …

A

[public][private][static] 12

18
Q
Return Types
A method definition must specify the type of value
the method will return. If the method does not return
a value (as with the increment method of the Counter
class), then the keyword [v..d] must be used. To
return a value in Java, the body of the method must
use the [r..n] keyword, followed by a value of the
appropriate return type. Here is an example of a
method (from the Counter class) with a nonvoid
return type:
public [i..t] getCount() {
A

[void][return][int] 12

19
Q

Parameters
A method’s parameters are defined in a
comma-separated list enclosed in parentheses after the
name of the method. A parameter consists of two
parts, the parameter type and the parameter name …

All parameters in Java are passed [b..e], that is,
any time we pass a parameter to a method, a copy of that parameter is made for use within the method
body. So if we pass an int variable to a method, then
that variable’s integer value is copied.

A

[by value] 13

20
Q

A [c..r] is a special kind of method that is used
to initialize a newly created instance of the class so
that it will be in a consistent and stable initial state.
This is typically achieved by initializing each
instance variable of the object (unless the default
value will suffice), …

A

[constructor] 14

21
Q
A class can have many constructors, but each
must have a different [s..e], that is,each must be
distinguished by the type and number of the
parameters it takes. If no constructors are explicitly
defined, Java provides an implicit [d..t
c..r] for the class, having zero arguments and
leaving all instance variables initialized to their default
values. However, if a class defines one or more...
A

[signature][default constructor] 14

22
Q

The StringBuilder Class
An important trait of Java’s String class is that its instances are i..e; once an instance is created
and initialized, the value of that instance cannot be
changed … allows
for great efficiencies and optimizations within the
Java Virtual Machine.

A

[immutable] 18

23
Q

To get around this obstacle, Java defines a [w..r
c..s] for each base type. An instance of each wrapper
type stores a single value of the corresponding base…

A

[wrapper class] 19

24
Q

A common programming task is to keep track of an
ordered sequence of related values or objects. For
example, we may want a video game to keep track… Again, we would rather not
have to introduce 200 variables inour program just
because…
In such cases, we can save programming effort
by using an a..y, which is a sequenced collection of
variables all of the same type. Each variable, or c..l,
in an array has an i..x, which uniquely refers to the
value stored in that cell. The cells of an array a are
numbered 0,1,2,and so on. We illustrate an array…

A

[array][cell][index] 20

25
Q

Each value stored in an array is called an [e..t] of
that array. Since the length of an array determines the
maximum number of things that can be stored in the
array, we …refer to the length of an array
as its [c..y]. In Java, the length …the syntax a.length.

A

[element][capacity] 20

26
Q

It is a dangerous mistake to attempt to index into an
array a using a number outside the range from 0 to
a.length−1. Such a reference is said to be [o.t
of b..s]. Out of bounds references have been
exploited numerous times by hackers using a method
called the [b..r o..w a..k] to compromise the
security of computer systems written in languages
other than Java. As a safety feature, array indices are
always checked in Java to … If an array index is out of bounds, the runtime Java environment signals an error condition.

A

[out of bounds][buffer overflow attack] 20

27
Q

Like C and C++, Java provides increment and decrement operators. Specifically, it provides the
plus-one increment [(+..] and decrement [(− ..]
operators. If such an operator is used in front of a
variable reference, then 1 is added to (or subtracted
from) the variable …

A

[(++)][(–)] 25

28
Q

Java supports the standard comparisons operators
between numbers:
< [l..s t..n]
<= [l..s t..n or e..l to]
== [e..l to]
!= not equal to
>= greater [t..n or e..l to]
> greater than
The type of the result of any of these comparison is a
[b..n]. Comparisons may also be performed on
[c..r] values, with inequalities determined according
to the underlying character codes…

A

[less than][less than or equal to][equal to][than or equal to][boolean][char] 25

29
Q

For reference types, it is important to know that
the operators ==and !=are defined so that
expression a==b is true if a and b both refer to
the identical object (or are both [n..l]). Most object
types support anequals method,… such that
a.equals(b) is true if a and b refer to what are deemed
as “equivalent” instances for that class…
Operators defined for boolean values are the
following:
! not (prefix)
&& conditional and…
The boolean operators && and || will not evaluate the
second operand (to the right) in their expression if it is
not needed to determine the value of the expression.
This [“s..t c..g”] feature is useful for
constructing boolean expressions where we first test
that a certain condition holds (such as an array index
being valid)…

A

[null][short circuiting] 25

30
Q

The second constructor (beginning at
line 16) accepts only four parameters; it relies on use
of the special [t..s] keyword to invoke the
five-parameter version, with an explicit initial
balance of zero (a reasonable default for most new
accounts)…

A

[this] 41

31
Q
[p..e] String account;
6 [p..e] int limit;
7 [p..d d..e] balance;
8 // Constructors:
9 [p..c] CreditCard(String cust,,
10 customer =cust;
11 bank=bk;
12 account =acnt;
13 limit=lim;
A

[private][private][protected double][public] 42

32
Q

C- 1.18 The [p..m] of a vector v = (v1,v2 ,…,vn )
in n-dimensional space is defined as For the special case of p=2, this results in the traditional Euclidean norm,
which represents the length of the vector. For
example, the [E..n n..m] …of a two-dimensional

A

[p-norm][Euclidean norm] 56