-
Encapsulation
Enclosing data within a class and hiding the details of the its implementation.
-
Information hiding
Setting classes, methods, and variables to private
-
Private vs. public classes, methods, variables
- Private classes, methods, and variables cannot be accessed and changed outside of the class.
- Public classes, methods, and variables can be accessed and changed as long as they are not final.
-
Overloading
When 2 methods have the same name but different numbers and parameter types.
-
Garbage collection
When something has no references to it, Java releases its memory back to the operating system. Java does it automatically.
-
Preconditions
Statement of conditions that have to be true before a client executes a method.
-
Postconditions
Describes the value returned by a method. Void methods describe any changes made to the calling object.
-
Readability - What is it?
How easy a program is can be understood
-
Readability - How can we increase it?
- Meaningful variable names
- Space between lines of code
- Commenting the code
- Indenting blocks of code
- Using named constants
-
Readability - Why do we care about it?
So a programmer reading your code can understand it
-
Generic classes (as they occur in Java)
You can use the same syntax and similar operations for different data types
Creating one uses the diamond notation <>
You put the type into the diamond
Primitive types are not allowed; the data types have to be wrapper classes
-
Interfaces
An interface is a shell that contains the public methods for a class
It contains only the method headers; it does not contain any actual code
An interface can be reused by simply writing a new implementation
-
Data Structures and ADTs - What is the difference?
An ADT is a specific set of data and what the data does while a data structure is the programming or implementation of that data.
An array and a linked list are examples of data structures
A bag is an example of an ADT
-
Common Operations on a Data Structure
- Add an item
- +add(newEntry: T): boolean
- Remove an item
- +remove(): T
- +remove(anEntry: T): Boolean or +remove(anEntry: T): T
Test if there is room to add a new item (Test if the data structure is full)
- Test if the data structure is empty
- +isEmpty(): boolean
- Count how many items are in the data structure
- +getCurrentSize(): integer
- Test if a particular item is in the data structure
- +contains(anEntry: T): boolean
- Determine how many of a particular item are in the data structure
- +getfrequencyOf(anEntry: T): integer
Print a list of all the items in the data structure
- Convert the data structure to an array
- +toArray(): T[]
-
Unified Modeling Language (UML)
It’s a way to pictorially describe the attributes and the methods of a class
It’s a box with three parts, the name, the attributes, and the methods of the class
It uses + for public items, - for private items
-
Javadoc
Javadoc is a standard way of documenting Java programs
It creates an HTML document containing a summary of the methods
All Javadoc items are comments
All Javadoc descriptions starts with /**
-
Javadoc Tags
- /** Adds a new entry to this bag.
- @param newEntry The object to be added as a new entry.
- @return True if the addition is successful, or false if not. */
-
Javadoc Comments
- /** Adds a new entry to this bag.
- @param newEntry The object to be added as a new entry.
- @return True if the addition is successful, or false if not. */
-
Parallel Arrays
Data structure that uses multiple arrays to represent an array of records
They are easy to create and use
The danger is that they are connected only in the programmer’s mind
-
Arrays
A group of data items that are all the same type
An array is an easy-to-use data structure
It has a fixed size and cannot grow or shrink. For this reason, it is usually very wasteful of memory
-
Can you insert new positions into an array?
Can you delete positions from an array?
If the answer to a question above is yes, that’s great!
Otherwise, how do you get around the problem?
ArrayLists
- Allows dynamically sized arrays
- This means the arrays can grow and shrink as needed
- Locations can be inserted or deleted as desired
-
Data Structures
- It is easy to add and remove items form the data structure
- Order of putting items into the data structure doesn't matter
- You wont take them out in the order you put them in
- You can put two of the same thing into the data structure
- You can check if an item is in the data structure
-
Linked Lists
- A collection of items that are linked together
- The items in the list are called nodes
- Each node points to the next node
- There is a pointer to the first node in the list
- There is no such (physical) thing as a linked list in a program. It’s only in memory.
-
Allocating memory
- Assigning memory to a new object.
- Instantiating a node
-
Traversing a Linked List
- currentNode = firstNode;
- while (currentNode != null)
- {
- currentNode = currentNode.next;
- }
-
Classes
Describes the data and behavior associated with instances of that class
-
Methods
Group of statements that execute an operation
-
Variables
Containers that store values
-
Looping
Executes a set of instructions when a condition is met
|
|