We extend, and finalize, our memory model for Java programs, and discuss garbage collection. We use our memory model to introduce Java programs that use mutation and circular data structures. We discuss the effects of mutation and circular data structure to our programs covering stack overflow exceptions and equality between objects.
We introduce class invariants and use pre-conditions and post-conditions along with invariants to reason about Java programs that use mutation.
- Write the names of the two types of memory used by the JVM.
- Given a Java class with a main method, draw a diagram to show the state of the JVM's memory.
- Write a Java program that can cause a stack overflow exception.
- Given a diagram that shows the memory state of the JVM, mark the elements that will be removed by a garbage collection cycle.
- Given a specification for cyclic data, write a Java class that implements the specification.
- Given a set of Java classes, verify object state by writing JUnit tests.
- Given a Java class with mutable state, write pre-conditions for each method.
- Given a Java class with mutable state, write post-conditions for each method.
- Given a Java class with mutable state, write a class invariant.
- Given two Java classes, show if one class is a behavioral subtype of the other.
- DUE DATE: 27th February @ 11:59pm
Submission Criteria
Repository Contents
Your repositories must contain only the following
- pom.xml file and
- src folder with appropriate sub-folders with your code and test code only.
Code Criteria
-
Your solution for each problem should
be in its own package. The package names
should follow this naming convention
edu.neu.ccs.cs5004.assignmentN.problemM
where you replaceN
with the assignment number andM
with the problem number, e.g., all your code for problem 1 for this assignment must be in a package namededu.neu.ccs.cs5004.assignment6.problem1
. - Your project should successfully build using maven generating all the default reports.
- Your Javadoc generation should complete with no errors or warnings.
- Your Checkstyle report must have no violations.
- Your JaCoCo report must indicate 75% code coverage per package for "Branches" and "Instructions" or more.
- Your FindBugs report must have no violations (except for violations categorized as PERFORMANCE or SECURITY, you can ignore those).
- Your PMD report should have no violations.
Binary Search Trees with mutation
You asked to design a program in Java to implement the following Binary Search Tree (BST) data type.
-
create() : BST
- creates an empty BST -
add(Integer n) : void
- adds the elementn
into the BST. If the element we are trying to add is already in the BST, the BST remains unchanged. -
remove(Integer n) : void
- removes the elementn
from the BST. If the element is not present in the BST then the BST remains unchanged. -
contains(Integer n) : Boolean
- returns true if the elementn
is in the BST and false otherwise. -
size() : Integer
- returns the total number of elements in the BST
Queue with mutation
You are asked to design a program in Java to implement the following first in, first out (FIFO) Queue data type.
-
create() : Queue
- creates an empty Queue -
isEmpty() : Boolean
- returns true of the Queue is the empty one and false otherwise -
enqueue(String n) : void
- adds the elementn
into the Queue. -
dequeue() : String
- removes the oldest element from the Queue and returns it to the caller. -
remove(String n) : void
- removes the elementn
from the Queue. If the element is not in the Queue the Queue remains unchanged. After the removal of an element, the remaining elements should maintain their order, e.g., given a queue("a","b","c","d")
after removing"c"
the Queue's behavior should be identical to the Queue("a","b","d")
-
size() : Integer
- returns the total number of elements in the Queue