Ch.1 Flashcards
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.
[identifier] [spaces] [Unicode character…]1.1 3.
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.
[boolean], [byte], [short], [int], [long], [float], [double] 1.1 4&;5
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.
[objects][instance][type][members][Instance variables][fields][type][int][float][double][reference type][Methods][accessor method][update method] 5&6
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].
[reference types][reference variable][memory address][null] 6
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… .
[new][new][reference] 6
(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).
[default constructor][null][boolean][false] 6&7
…so the object variable [r..rs] to this newly created
object.
[refers] 7
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.
[signature] 7
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 …
[modifiers] 9
[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…
[access control modifier][visibility][public][public class] 9
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.
[public int][return] 9
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...
[protected][subclasses][package][private] 10
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...
[package-private access][static][static][static] 11
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…
[matrix][information][abstract][abstract][final][final] nts & 11
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 ...
[final][static] 11