Computer Science Java

  1. Encapsulation
    Enclosing data within a class and hiding the details of the its implementation.
  2. Information hiding
    Setting classes, methods, and variables to private
  3. 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.
  4. Overloading
    When 2 methods have the same name but different numbers and parameter types.
  5. Garbage collection
    When something has no references to it, Java releases its memory back to the operating system. Java does it automatically.
  6. Preconditions
    Statement of conditions that have to be true before a client executes a method.
  7. Postconditions
    Describes the value returned by a method. Void methods describe any changes made to the calling object.
  8. Readability - What is it?
    How easy a program is can be understood
  9. Readability - How can we increase it?
    • Meaningful variable names
    • Space between lines of code
    • Commenting the code
    • Indenting blocks of code
    • Using named constants
  10. Readability - Why do we care about it?
    So a programmer reading your code can understand it
  11. 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
  12. 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
  13. 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
  14. 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[]
  15. 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
  16. 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 /**
  17. 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. */
  18. 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. */
  19. 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
  20. 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
  21. 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?

    • Allows dynamically sized arrays
    • This means the arrays can grow and shrink as needed
    • Locations can be inserted or deleted as desired
  22. 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
  23. 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.
  24. Allocating memory
    • Assigning memory to a new object.
    • Instantiating a node
  25. Traversing a Linked List
    • currentNode = firstNode;
    •    while (currentNode != null)
    •       {
    •           currentNode =;
    •       }
  26. Classes
    Describes the data and behavior associated with instances of that class
  27. Methods
    Group of statements that execute an operation
  28. Variables
    Containers that store values
  29. Looping
    Executes a set of instructions when a condition is met
Card Set
Computer Science Java
Study Guide for Data Structures java