Chapter 4: Classes & Objects, Object Oriented Data Structures Java: Chapter 2, Java Methods Chapter 1
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.
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
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.
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.
What conditions do Java interfaces have?
- Variables must be constant - Methods must be abstract - A Java interface cannot be instantiated
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.
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.
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
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
1024
1 terabyte= __ gigabytes
What methods give outsiders access to public and private methods?
Accessors and getters
What is the creation of an object called?
An Instantiation (of its class)
What is an object?
An entity that models something from the real world.
Preconditions
Assumptions that must be true on entry into a method for it to work correctly.
Give an example and a diagram of a HAS-A relationship.
Balloon <>------------Color (Balloon has a color)
central processing unit
CPU (acronym)
millions of semiconductor devices (transistors) etched into a silicon chip; speed measured in Hz
CPU (def)
What does CRC stand for?
Class, Responsibilities, and Collaborators (classes that are used by this class - Balloon class uses Canvas class)
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.
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.
What are two attributes that a field always has?
Data type (int, double, String, Color) & name (usually lowercase by convention)
Input/ Output
I/O devices (acronym)
monitor and video adapter, keyboard, mouse, touchpad, internet adapter, modem, D/A and A/D convertors, scanners, digital cameras, printers
I/O devices (ex)
What does the .* (java.awt.*) wildcard symbol mean?
Imports all the classes from that package
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
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.
What does "jar" stand for?
Java archive
What does final mean?
Means the field is constant (values cannot be changed)
What does void indicate?
Method does not return any value.
What is java.util?
Miscellaneous utility classes
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.
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.
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.
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.
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?
random access memory
RAM (acronym)
CPU can read directly from and write to any memory location; holds data and CPU instructions
RAM (def)
read only memory
ROM (acronym)
initialization and hardware diagnostic programs; can never be deleted or edited
ROM (def)
Instance variable String name;
Recall that every StringLog must have a name. We call the needed variable name.
String name;
Recall that every StringLog must have a name. We call the needed variable name.
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
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).
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
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)
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.
What class extends what other class?
Subclass extends Superclass
Postconditions or Effects
The results expected at the exit of a method, assuming that the preconditions are true.
Data abstraction
The separation of a data type's logical properties from its implementation
Functional domain
The set of valid input data for a program or method
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.
What is a StringLog used for?
To record strings and later check to see if a particular string has been recorded
Deskchecking
Tracing an execution of a design or program on paper
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.
What is java.awt?
Windowing and graphics toolkit
What purpose do test cases serve?
allow us to assert that a program works correctly
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
program with simple text user interface
console application (def)
combination of transistors into logical devices
gates (def)
An object is an ________ of its class.
instance
program that maintains file system, dispatches applications, other system-level services
operating system (def)
secondary storage, input/ output
peripheral devices (ex)
hard disk, CD-ROM, optical (ZIP) disk, memory stick/ flash drive
secondary storage (ex)
applications -> operating system -> device drivers -> BIOS, firmware
software layers order
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.
What does and doesn't a subclass inherit?
A subclass inherits all the methods and fields of its superclass, but not the constructors.
What is the paradox of subclass inheritance?
A subclass inherits the private fields of its superclass but does not have access to them.
Walk-through
A verification method in which a team performs a manual simulation of the program or design
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
Software verification
The process of determining the degree to which a software product fulfills its specifications
Software validation
The process of determining the degree to which software fulfills its intended purpose.
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.
How are Java interfaces similar to Java classes?
- Can include variable declarations - Can include methods
1024^3
1GB= __ bytes
1024
1KB= __ bytes
1024^2
1MB= __ bytes
What must a StringLog have?
A "Name"
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);
What is a class?
A class (class definition) is a blueprint for making an object.
Self-referential class
A class that includes an instance variable or variables that can hold a reference to an object of the same class
Abstract data type (ADT)
A data type whose properties (domain and operations) are specified independently of any particular implementation
Test plan
A document showing the test cases planned for a program or module, their purposes, inputs, expected outputs, and criteria for success
Abstraction
A model of a system that includes only the details essential to the perspective of the viewer of the system
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.
Test driver
A program that calls operations exported from a class, allowing us to test the results of the operations
Graphical User Interface
GUI (acronym)
graphics, menus, buttons, icons
GUI (def)
What three things can an object represent?
GUI components ( title bar, buttons), software entities ( events, files), abstract concepts ( location on grid, game rules)
What is javax.swing?
GUI development package
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.
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.
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.
Instance variable String[] log;
The elements of a StringLog are stored in an array of String objects named log.
What does static mean?
The field belongs to all objects of the class, not to a particular class. (static applies to methods too)
Where does the object's memory go when it is no longer being used?
The garbage collection (free-memory pool)
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)
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)
What is called upon to create an object?
The new operator calls the constructor
What is the main method?
The place where control is passed when the Java program starts. There can only be one public main method
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