Chapter 4: Classes & Objects, Object Oriented Data Structures Java: Chapter 2, Java Methods Chapter 1

0.0(0)
studied byStudied by 2 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/115

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:23 AM on 10/6/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

116 Terms

1
New cards

What is an object?

An entity that models something from the real world.

2
New cards

What three things can an object represent?

GUI components ( title bar, buttons), software entities ( events, files), abstract concepts ( location on grid, game rules)

3
New cards

An object is an ________ of its class.

instance

4
New cards

What is the creation of an object called?

An Instantiation (of its class)

5
New cards

Where does the object's memory go when it is no longer being used?

The garbage collection (free-memory pool)

6
New cards

What is called upon to create an object?

The new operator calls the constructor

7
New cards

What must the name of the constructor be?

The name of the constructor must be the same name of its class:

public balloon ( int x, int y)

8
New cards

What are the restrictions for constructors and its parameters?

Constructors can have args or many args. However, constructors with the same number and type of parameters cannot coexist.

9
New cards

What does void indicate?

Method does not return any value.

10
New cards

What is the difference between public and private methods?

Private methods can only be called from constructors or methods of the same class while public methods can be called from other classes as well.

11
New cards

What methods give outsiders access to public and private methods?

Accessors and getters

12
New cards

What type of relationship exists between a RoundBalloon and a Balloon?

A RoundBalloon IS-A Balloon.

Balloon b1 = new RoundBalloon();

RoundBalloon b2 = new RoundBalloon(10, 20, color.RED);

13
New cards

What does "jar" stand for?

Java archive

14
New cards

What does a jar file allow you to do?

allows you to run a Java program with a simple click, w/o creating any projects in an IDE (no need for NetBeans!); same as .zip file

15
New cards

What are two advantages of encapsulation/information hiding?

-Change the structure of fields and rest of project won't be affected;

-easier to maintain, document, and reuse encapsulated class;

-other classes do not need to know the implementation details to use the class effectively

16
New cards

What is a class?

A class (class definition) is a blueprint for making an object.

17
New cards

Where is the source code for a class usually stored?

In a separate file with the same name as the class with extension ".java" (Balloon class in Balloon.java); capitalized by convention

18
New cards

What is a wrapper class?

These classes (Integer, Long, Byte) "wrap" primitive data types (int, long, byte) into an object. Numbers and characters are not objects.

19
New cards

What three things will a class always describe of an object?

The instance variables/fields (attributes), the procedures for creating the object (constructors), and the behaviors of the object (methods)

20
New cards

What does CRC stand for?

Class, Responsibilities, and Collaborators (classes that are used by this class - Balloon class uses Canvas class)

21
New cards

What is the main method?

The place where control is passed when the Java program starts. There can only be one public main method

22
New cards

What class extends what other class?

Subclass extends Superclass

23
New cards

How many classes can can extend the same superclass? How many superclasses can a single subclass extend?

Several classes can extend the same superclass, but a subclass can extend only one superclass (no multiple inheritance).

24
New cards

What does and doesn't a subclass inherit?

A subclass inherits all the methods and fields of its superclass, but not the constructors.

25
New cards

What is the paradox of subclass inheritance?

A subclass inherits the private fields of its superclass but does not have access to them.

26
New cards

What are two attributes that a field always has?

Data type (int, double, String, Color) & name (usually lowercase by convention)

27
New cards

Why are fields usually private?

So that a programmer can change the number, names, and types of fields without affecting other classes of the same project

28
New cards

Give an example and a diagram of a HAS-A relationship.

Balloon <>------------Color

(Balloon has a color)

29
New cards

What does static mean?

The field belongs to all objects of the class, not to a particular class. (static applies to methods too)

30
New cards

What does final mean?

Means the field is constant (values cannot be changed)

31
New cards

What is java.util?

Miscellaneous utility classes

32
New cards

What is java.awt?

Windowing and graphics toolkit

33
New cards

What is javax.swing?

GUI development package

34
New cards

What is an import statement?

Statements that allow us to use short names for library classes instead of fully-qualified names (Ex: Whenever you see JButton, treat it as javax.swing.JButton)

35
New cards

What does the . (java.awt.) wildcard symbol mean?

Imports all the classes from that package

36
New cards

Abstraction

A model of a system that includes only the details essential to the perspective of the viewer of the system

37
New cards

Information hiding

The practice of hiding details within a module with the goal of controlling access to the details from the rest of the system

38
New cards

Data abstraction

The separation of a data type's logical properties from its implementation

39
New cards

Abstract data type (ADT)

A data type whose properties (domain and operations) are specified independently of any particular implementation

40
New cards

Application (or user or client) level

We use the ADT to solve a problem. When working at this level we only need to know how to create instances of the ADT and invoke its operations.

41
New cards

Logical (or abstract) level

Provides an abstract view of the data values (the domain) and the set of operations to manipulate them. At this level, we deal with the "what" questions. What is the ADT? What does it model? What are its responsibilities? What is its interface?

42
New cards

Implementation (or concrete) level

Provides a specific representation of the structure to hold the data and the implementation of the operations. Here we deal with the "how" questions.

43
New cards

Preconditions

Assumptions that must be true on entry into a method for it to work correctly.

44
New cards

Postconditions or Effects

The results expected at the exit of a method, assuming that the preconditions are true.

45
New cards

Abstract Method Rules

Only includes a Description of its parameters

No method bodies or implementations are allowed

Only the interface of the method is included.

46
New cards

How are Java interfaces similar to Java classes?

- Can include variable declarations

- Can include methods

47
New cards

What conditions do Java interfaces have?

- Variables must be constant

- Methods must be abstract

- A Java interface cannot be instantiated

48
New cards

Why would we use an interface to formally specify the logical level of an ADT?

- It provides a template for classes to fill

- A separate class then "implements" it

49
New cards

What are some benefits to using an interface

- We can check if our syntax meets our specifications

- We can check if the interface "contract is met", IE: method names, return types, and parameters are correct.

- We can provide a consistent interface to applications from among alternate implementations of the ADT.

50
New cards

What are the responsibilities of StringLog ADT

Remember the strings that have been inserted into it and to verify if their are any matching strings

51
New cards

What is a StringLog used for?

To record strings and later check to see if a particular string has been recorded

52
New cards

What must a StringLog have?

A "Name"

53
New cards

Constructors

Crates a new instance of the ADT. It's up to the implementer of the StringLog to decide how many and what kind of constructor to provide.

54
New cards

Types of Transformers & definitions

- Insert(String Element): Assumes the StringLog is not full and adds elements to the log of strings

- Clear: resets the StringLog to the empty state; the StringLog retains its name.

55
New cards

Types of Observers

- contains(String element): returns true if element is in the StringLog, false otherwise; We ignore case when comparing the strings.

- size: returns the number of elements currently held in the StringLog.

- isFull: returns whether or not the StringLog is full.

- getName: returns the name attribute of the StringLog.

- toString: returns a nicely formatted string that represents the entire contents of the StringLog.

56
New cards

Application (or user or client) level

The UseStringLog program is the application. It declares a variable log of type StringLogInterface. It uses the ArrayStringLog implementation of the StringLogInterface to perform some simple tasks.

57
New cards

Logical (or abstract) level

StringLogInterface provides an abstract view of the StringLog ADT. It is used by the UseStringLog application and implemented by the ArrayStringLog class.

58
New cards

Implementation (or concrete) level

The ArrayStringLog class developed in Section 2.3 provides a specific implementation of the StringLog ADT, fulfilling the contract presented by the StringLogInterface. It is used by applications such as UseStringLog. Likewise, the LinkedStringLog class (see Section 2.6) also provides an implementation.

59
New cards

Instance variable

String[] log;

The elements of a StringLog are stored in an array of String objects named log.

60
New cards

Instance variable

int lastIndex = -1;

Originally the array is empty. Each time the insert command is invoked another string is added to the array. We use this variable to track the index of the "last" string inserted into the array.

61
New cards

Instance variable

String name;

Recall that every StringLog must have a name. We call the needed variable name.

62
New cards

Stepwise Refinement

- Approach a problem in stages.

- Similar steps are followed during each stage, with the only difference being the level of detail involved.

-The completion of each stage brings us closer to solving our problem.

63
New cards

What are the Two Standard variations of stepwise refinement

- Top-Down: the problem is broken down into several parts and each part is divided and then those parts are subdivided. Used to design non-trivial methods

- Bottom-up: Details come first. They are brought together into increasingly higher-level components. A useful approach if you can identify previously created program components to reuse in creating your system.

64
New cards

What are the two ways to define software testing?

- The process of executing a program with data sets designed to discover errors.

- Software testing is one facet of software verification.

65
New cards

Software validation

The process of determining the degree to which software fulfills its intended purpose.

66
New cards

Software verification

The process of determining the degree to which a software product fulfills its specifications

67
New cards

Deskchecking

Tracing an execution of a design or program on paper

68
New cards

Walk-through

A verification method in which a team performs a manual simulation of the program or design

69
New cards

Inspection

A verification method in which one member of a team reads the program or design line by line and the others point out errors

70
New cards

What purpose do test cases serve?

allow us to assert that a program works correctly

71
New cards

What must we do for each test case?

-determine inputs that represent the test case

-determine the expected behavior of the program for the given input

-run the program and observe the resulting behavior

-compare the expected behavior and the actual behavior of the program

72
New cards

Functional domain

The set of valid input data for a program or method

73
New cards

In limited test cases, where the functional domain is small, what can someone do to verify the program is working?

Test the program against every possible input element.

74
New cards

How to identify text cases?

- Covers general dimensions of data

- Within each dimension identify categories of inputs and expected results

- Test at least one instance of each combination of categories across dimensions.

- Testing like this is called black-box testing and the tester must know the external interface to the module.

75
New cards

Test plan

A document showing the test cases planned for a program or module, their purposes, inputs, expected outputs, and criteria for success

76
New cards

Test driver

A program that calls operations exported from a class, allowing us to test the results of the operations

77
New cards

What is a node?

A node in a linked list is an object that holds some important information, such as a string, plus a link to the exact same type of object, i.e. to an object of the same class.

78
New cards

Self-referential class

A class that includes an instance variable or variables that can hold a reference to an object of the same class

79
New cards

LLStringNode log

In this implementation, the elements of a StringLog are stored in a linked list of LLStringNode objects. We call the instance variable that we use to access the strings log. It will reference the first node on the linked list, so it is a reference to an object of the class LLStringNode.

80
New cards

String name;

Recall that every StringLog must have a name. We call the needed variable name.

81
New cards

central processing unit

CPU (acronym)

82
New cards

millions of semiconductor devices (transistors) etched into a silicon chip; speed measured in Hz

CPU (def)

83
New cards

combination of transistors into logical devices

gates (def)

84
New cards

random access memory

RAM (acronym)

85
New cards

CPU can read directly from and write to any memory location; holds data and CPU instructions

RAM (def)

86
New cards

read only memory

ROM (acronym)

87
New cards

initialization and hardware diagnostic programs; can never be deleted or edited

ROM (def)

88
New cards

secondary storage, input/ output

peripheral devices (ex)

89
New cards

1024

1KB= __ bytes

90
New cards

1024^2

1MB= __ bytes

91
New cards

1024^3

1GB= __ bytes

92
New cards

1024

1 terabyte= __ gigabytes

93
New cards

hard disk, CD-ROM, optical (ZIP) disk, memory stick/ flash drive

secondary storage (ex)

94
New cards

Input/ Output

I/O devices (acronym)

95
New cards

monitor and video adapter, keyboard, mouse, touchpad, internet adapter, modem, D/A and A/D convertors, scanners, digital cameras, printers

I/O devices (ex)

96
New cards

applications -> operating system -> device drivers -> BIOS, firmware

software layers order

97
New cards

program that maintains file system, dispatches applications, other system-level services

operating system (def)

98
New cards

program with simple text user interface

console application (def)

99
New cards

Graphical User Interface

GUI (acronym)

100
New cards

graphics, menus, buttons, icons

GUI (def)

Explore top flashcards

Onc lec 3
Updated 435d ago
flashcards Flashcards (112)
SAT Vocab Lesson 7-8
Updated 321d ago
flashcards Flashcards (30)
Uni
Updated 450d ago
flashcards Flashcards (42)
POS lesson 15
Updated 1074d ago
flashcards Flashcards (29)
Festival Neck Pain
Updated 1099d ago
flashcards Flashcards (81)
Unit 5: Hereditary
Updated 1044d ago
flashcards Flashcards (62)
Onc lec 3
Updated 435d ago
flashcards Flashcards (112)
SAT Vocab Lesson 7-8
Updated 321d ago
flashcards Flashcards (30)
Uni
Updated 450d ago
flashcards Flashcards (42)
POS lesson 15
Updated 1074d ago
flashcards Flashcards (29)
Festival Neck Pain
Updated 1099d ago
flashcards Flashcards (81)
Unit 5: Hereditary
Updated 1044d ago
flashcards Flashcards (62)