theory Flashcards

(72 cards)

1
Q

What do you call the program that runs Java byte-code instructions

A

interpreter

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

scanner take input from text file

A

Scanner fileIn = new Scanner(new FileInputStream(“data.txt”)

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

Programmers of robots need to ensure?

A

the robot does not harm humans
the robot obeys orders
the robot protects itself

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

moral agency

A

Moral agency requires that all three criteria of causality, knowledge and
choice apply to the agent/person involved

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

Categorical Imperative

A

fundamental principle behin deontology

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

static variable

A

variable that belongs to the class as a whole, and not just to one object
▪ There is only one copy of a static variable per class, unlike instance variables where each object has its own copy
▪ All objects of the class can read and change a static variable
▪ Although a static method (discussed shortly) cannot access an instance variable, a static method can access a static variable
▪ A static variable is declared like an instance variable, with the addition of the modifier static
static variable should always be defined private, unless it is also a
defined constant
value cannot be altered
In addition to static, the declaration for a static defined constant must include modifier final, which indicates that its value cannot be changed
▪ When referring to such a defined constant outside its class, use the name of its class in place of a calling object
Static variables in base class are inherited by any of its derived classes

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

data type default values

A

boolean static variables are initialized to false
Other primitive types static variables are initialized to the zero of their type
▪ Class type static variables are initialized to null

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

static methods

A

one that can be used without a calling object
▪ A static method still belongs to a class, and its definition is given inside the class definition
Static methods are invoked using the class name in place of a calling
object
static method cannot refer to an instance variable of the
class, and it cannot invoke a nonstatic method of the class
has no this, so it cannot use an instance variable or
method that has an implicit or explicit this for a calling object

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

wrapper classes

A

provide a class type corresponding to each of the primitive types
▪ This makes it possible to have class types that behave somewhat like
primitive types
▪ The wrapper classes for the primitive types byte, short, long,
float, double, and char are (in order) Byte, Short, Long, Float, Double, and Character
▪ Wrapper classes also contain a number of useful predefined
constants and static methods

have static methods to convert: eg Integer.parseInt , Double.toString, Character.toUpperCase(char)

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

boxing

A

process of going from a value of a primitive type to an object of its wrapper class
▪ To convert a primitive value to an “equivalent” class type value, create
an object of the corresponding wrapper class using the primitive value as an argument
▪ The new object will contain an instance variable that stores a copy of the primitive value
▪ Unlike most other classes, a wrapper class does not have a no-
argument constructor

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

unboxing

A

process of going from an object of a wrapper class to the corresponding value of a primitive type
▪ The methods for converting an object from the wrapper classes Byte, Short, Integer, Long, Float, Double, and Character to their
corresponding primitive type are (in order) byteValue, shortValue,
intValue, longValue, floatValue, doubleValue, and charValue
▪ None of these methods take an argument
int i = integerObject.intValue()

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

secondary vs main memory

A

2nd: hold files for permanent storage
main: used by computer program when it is running a program, keeps values stored in program’s variables

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

bytes

A

long list of numbers for location
contains 8 bits
data item can be stored in byes
identified by a number called its address, used to find the data when its needed

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

memory location

A

entire chunk of memory that holds data
address of the first byte of this memory location is used as the
address for the data item

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

storing primative variables

A

When the variable is a primitive type, the value of the variable
is stored in the memory location assigned to the variable
Each primitive type always require the same amount of memory to
store its values

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

storing class type variables

A

When the variable is a class type, only the memory address (or
reference) where its object is located is stored in the memory location
assigned to the variable
The object named by the variable is stored in some other location in memory
value of class variable is a fixed size
the value of a class variable is a memory address or reference
object can be any size

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

references

A

Two reference variables can contain the same reference, and
therefore name the same object
The assignment operator sets the reference (memory address) of one
class type variable equal to that of another
Any change to the object named by one of theses variables will
produce a change to the object named by the other variable, since
they are the same object
variable2 = variable1;

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

paramters gen

A

call-by-value parameters
▪ A parameter is a local variable that is set equal to the value of its
argument
▪ Therefore, any change to the value of the parameter cannot change
the value of its argument

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

class parameters

A

value plugged into a class type parameter is a reference
(memory address)
▪ Therefore, the parameter becomes another name for the argument
▪ Any change made to the object named by the parameter (i.e.,
changes made to the values of its instance variables) will be made
to the object named by the argument, because they are the same
object
▪ Note that, because it still is a call-by-value parameter, any change
made to the class type parameter itself (i.e., its address) will not
change its argument (the reference or memory address)

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

primitive vs class type parameters

A

A method cannot change the value of a variable of a primitive type that is an argument to the method
▪ In contrast, a method can change the values of the instance variables of a class type that is an argument to the method

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

== vs equals

A

== checks that two class type variables have the same memory addres
Two objects in two different locations whose instance variables have exactly the same values
would still test as being “not equal”

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

defensive copying

A

The private modifier only prevents direct field access—it doesn’t prevent indirect modification through shared object references

this.birthDate = new Date(birthDate.getTime());

use copy rather then actual reference which can create data leaks

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

copy constructor

A

constructor with a single argument of the same type as the class

should create an object that is a
separate, independent object, but with the instance variables
set so that it is an exact copy of the argument object
creates completely new and independent copy

check null then if not assign variables from parameter to this

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

immutable class

A

A class that contains no methods (other than constructors) that
change any of the data in an object of the class is called an
immutable class

Objects of such a class are called immutable objects

safe to return a reference to an immutable object

object cannot be changed in any way
the contents of an immutable object cannot be modified.
immutable object contains no mutator methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
mutable class
A class that contains public mutator methods or other public methods that can change the data in its objects is called a mutable class, and its objects are called mutable objects Never write a method that returns a mutable object ▪ Instead, use a copy constructor to return a reference to a completely independent copy of the mutable object
26
deep vs shallow copy
A deep copy of an object is a copy that, with one exception, has no references in common with the original : References to immutable objects are allowed to be share Any copy that is not a deep copy is called a shallow copy ▪ This type of copy can cause dangerous privacy leaks in a program
27
array
data structure used to process a collection of data that is all of the same type ▪ An array behaves like a numbered list of variables with a uniform naming mechanism ▪ It has a part that does not change: the name of the array ▪ It has a part that can change: an integer in square bracket
28
classes
Every program is a class All helping software consists of classes All programmer-defined types are classe
29
new
new operator must be used to create the object and associate it with its variable name
30
array - call by reference
any changes you make to array are permanent changes The parameter becomes another name for the argument ▪ Any change made to the object named by the parameter (i.e., changes made to the values of its instance variables) will be made to the object named by the argument, because they are the same object any change made to the class type parameter itself (i.e., its address) will not change its argument (the reference or memory address
31
infornation hiding
practice of separating how to use a class from the details of its implementation
32
abstraction
another term used to express the concept of discarding details in order to avoid information overloa
33
@Override
ensures method is an override and not an overload
34
encapsulation
data and methods of a class are combined into a single unit (i.e., a class object), which hides the implementation details ▪ Knowing the details is unnecessary because interaction with the object occurs via a well-defined and simple interface In Java, hiding details is done by marking them private
35
overloading & overriding
overriding- subclass provides a specific implementation for a method that is already defined in the superclass. inheritance . exact same number and types of parameters as in base class overloading: multiple methods in the same class with the same name but have different numbers of parameters. It allows to perform operations with different inputs. two or more methods in the same class can be derived, diff signature from method in base class
36
is a
inheritance derived class not aggregation or composition
37
has a
composition occurs when a class contains an instance variable of a class type does not denote polymorphism
38
driver program
A program whose only purpose is to test a method
39
bottom up testing
One method often invokes other methods, so one way to do this is to first test all the methods invoked by that method, and then test the method itself
40
a stub
Sometimes it is necessary to test a method before another method it depends on is finished or tested. In this case, use a simplified version of the method, called a stub, to return a value for testing
41
The Fundamental Rule for Testing Methods
Every method should be tested in a program in which every other method in the testing program has already been fully tested and debugged
42
method signature
signature consists of the name of a method together with its parameter list does not include the type returned
43
class definition
specifies the data items (properties) and methods (actions) that all of its objects will have Data items and methods are sometimes called members of the object Data items are called fields or instance variables
44
local variable
variable declared within a method definition All variables declared in the main method are local All method parameters are local variable
45
call by value mechanism
the value of each argument (not the variable name) is plugged into the corresponding method parameter' plugging in arguments for formal parameters any change to the value of the parameter cannot change the value of its argument
46
boolean default
false
47
primitive default
0
48
equals
== :checks for reference equality, meaning it only returns true if both references point to the same memory location. .equals() check for value equality appropriate for comparing content of objects
49
memory in computer
Secondary memory is used to hold files for "permanent" storage Main memory is used by a computer when it is running a program
50
main memory
consists of a long list of numbered locations called bytes Each byte contains eight bits: eight 0 or 1 digits the entire chunk of memory (several adjacent bytes) that holds the data is called its memory location The address of the first byte of this memory location is used as the address for the data item
51
address
number that identifies a byte A data item can be stored in one (or more) of these bytes ▪ The address of the byte is used to find the data item when needed
52
primitive references
When the variable is a primitive type, the value of the variable is stored in the memory location assigned to the variable Each primitive type always require the same amount of memory to store its value
53
class references
When the variable is a class type, only the memory address (or reference) where its object is located is stored in the memory location assigned to the variable ▪ The object named by the variable is stored in some other location in memory The value of a class variable is a fixed size The value of a class variable is a memory address or reference ▪ The object, whose address is stored in the variable, can be of any size
54
Differences Between Primitive and Class-Type Parameters
A method cannot change the value of a variable of a primitive type that is an argument to the method ▪ In contrast, a method can change the values of the instance variables of a class type that is an argument to the method
55
final
method may not be redefined in derived class class may not be used as a base class to derive other classes
56
types of derived object
An object of a derived class has type of the derived class, and it also has type of the base class has the type of every one of its ancestor classes object of derived class can be assigned to variable of any ancestor type can be used anyplace that an object of any of ancestor types can be used (NOT vice versa)
57
Object
every class is a descendent of the class Object equals toString
58
overriden equals
The parameter otherObject of type Object must be type cast to the given class (e.g., Employee) However, the new method should only do this if otherObject really is an object of that class, and if otherObject is not equal to null Finally, it should compare each of the instance variables of both objects
59
getClass vs instancof
The instanceof operator simply tests the class of an object true if object is an instance of class or any subclass The getClass() method used in a test with == or != tests if two objects were created with the same class getClass more restrictive, doesnt care abt inheritance
60
Circle x = new Circle(),
x contains a reference to a Circle object.
61
privacy leak
A condition that allows a programmer to circumvent the private modifier and change the private instance variable
62
default value of uninitialized boolean
false
63
Java features that ensure platform independence or security
bytecode no direct memory access java virtual machine (JVm)
64
overriden methods in subclass
When a method is overridden in a subclass, it can be made MORE visible and its return type can be made more SPECIALISED (meaning its return type can be a DESCENDANT of the type in the parent's method)
65
visibility of modifers in order
private, default (if no modifier is used), protected, and public
66
which is ideal for a use case where several classes share functionality and have partial overlap in implementations?
abstract classes
67
static methods
Static variable- belongs to class Only one copy per class - all objects of that class refer to that static variable Static method : - cannot access instance variable - can access static variable - cannot invoke a non-static method of the class - can invoke another static method It is always preferable to explicitly initialize static variables rather than rely on the default initialization static variable should always be defined private, unless it is also a defined constant Static methods are invoked using the class name in place of a calling object
68
non static inner class
A non-static inner class cannot be created without an instance of the outer class
69
int a =7; int b =2; double c = a/b; System.out.println(c); output?
3.0 does integer division
70
User experience design is an important part of user interface design.
False
71
User interface design is an important part of user experience design.
True
72