SWEN501 Teaching Schedule

Week 1 (8–11 July)

  • Course & programme introduction
  • Object-oriented programming: inheritance, overloading, overriding, encapsulation, polymorphism, generic parameters
  • Version control with Git (we are going to do all this together first)
    • We will store our code in our GitLab instance using your ECS username and password
    • Generating SSH key: Window->Preferences->General->Network Connections->SSH2->Key Management->Generate RSA key
      • Don't forget to save it! The default name and location are fine
      • Copy it into Gitlab: Top-right menu->Settings->SSH Keys (sidebar) - copy and paste the entire text box contents from Eclipse and click "Add key"
    • Connecting a project in Eclipse: right click->Team->Share Project... and choose "Create", then give a directory name \YourProjectName after the default text
    • Everything else hangs off the same Team menu. Add to index, Commit, and Push... are the most important entries for the moment
  • Refresher: casting and statics

Using Git

  • Reset: wind the version, and maybe the code itself, back to another version.
    • A hard reset: throws away any changes you've made, whether you committed them or not
    • A soft reset: throws away any unrelated commits you've made
  • Merge: combining the changes from two different commits
    • Often git can do this for you, but if the same code has changed on both sides it will ask you to resolve the conflict
    • Conflict markers: <<<<< HEAD to = is your code, = to >>>> is their code.
    • Edit until it makes sense and has both sets of changes, and then add the file(s) to the index and commit the merge
  • Pull: take the latest remote code and bring your local code up to date. Will merge automatically where possible.
  • Push: send all your local commits to the server to share
    • This only sends commits, not uncommitted changes.
  • Commit: save a version of your code so it can be shared and referred to
    • Only files you add to the index will be included
    • Each time you change a file, you need to add it again to have the change included in the next commit.
      • You can drag the file from "Unstaged changes" to "Staged changes" in the commit window to add them on the spot
  • Add to index: tell git to care about this file, and to know about changes you make to it
    • The "index" is also known as the "staging area" or "staged files" (more or less)

Generics

  • Generic types are the parts in <>: in ArrayList<String>, String is a generic type argument
  • In class Box<T>, T is a generic type parameter
    • Inside Box, can use T anywhere a type appears, and it will be replaced with the type used with "new Box<...>"
  • Slides
  • Exercise: implementing and using a generic interface
    • The Comparator<T> interface is built in to Java, and is used for defining how two objects of a type compare: which is bigger/smaller/closer/greener/more important/...
      • The compare method returns -1/0/1 according to whether the first argument is less than/equal to/greater than the second
      • The sort() method on Lists and ArrayLists is given a Comparator to decide which values come before or after each other
    • Extend your BugWorld with:
      • A Comparator<Plant>, which can be used to find the biggest Plant
      • A Comparator<Bug>, which compares two Bugs' energy fields
      • Another Comparator<Bug>, which compares the bugs by species and then by name
    • Use these comparators to output the bugs in different orders
    • Make your bugs implement Comparable<Bug> with a sensible semantics

Week 2 (15–18 July)

  • Recursion: methods that call themselves
    • For example:
      • void printTree(Tree t, String prefix) {
             System.out.println(prefix + t);
                 for (Tree x : t.getChildren()) {
                     printTree(prefix + " ", x);
             }
         }
      • int fib(int n) { if (n <= 1) { return 1; } else { return fib(n - 1) + fib(n - 2); } }
      •     public static int factorial(int n) {
                if (n <= 1)
                    return 1;
                else
                    return n * factorial(n - 1);
            }
      • <T extends Comparable<T>> int indexInSortedList(T needle, List<T> haystack, int start, int end) {
             if (start =<span class='WYSIWYG_TT'>= end) return -1;
             int mid = start + (end - start) / 2;
             T val = haystack.get(mid);
             if (needle.compareTo(val) =</span> 0) { return mid; }
             if (needle.compareTo(val) < 0) { return indexInSortedList(needle, haystack, start, mid); }
             return indexInSortedList(needle, haystack, mid + 1, end);
        }
    • Want to make sure that:
      • There is a base case that doesn't recurse, so that the process stops - maybe this comes from an if-then-else, maybe an empty list that's looped over, maybe something else
      • Each time the method calls itself it gets closer to that base case: a smaller number, nearer to the bottom of the tree, a narrower window of items left to examine
  • Trains and Wagons exercise (generics, recursion, object structures)
  • Project 1: Object oriented program design (classes, interfaces, objects): The Island
  • Recursion
  • Collections: Set<E>, List<E>, and Map<K, V>
  • Object graphs

Week 3 (22–25 July)

Week 4(29 July–1 August)

Week 5 (5–8 August)

  • Project 3 (demonstration)
    The demonstration will be in the small room given the following schedule.

Demonstration Schedule

# Name Time
1 Bollineni, Dharani 10:00am
2 Burns, Jarrod M. 10:10am
3 Hasegawa, Natsuki 10:20am
4 Hilal, Mohammad 10:30am
5 Kurnanto, Abram 10:40am
6 Lertruedeeporn, Maleerat 10:50am
7 Lock, Samuel J. 11:00am
8 Macdonald, Chrissy M. 11:10am
9 Nobes, Peggy A. 11:20am
10 Pason, Jillian B. 11:30am
11 Shi, Zong 11:40am
12 Sudhakaran, Sanjay 11:50am
13 Wright, Elle 12:00pm
  • JavaDoc links:
    https://en.wikipedia.org/wiki/Javadoc

    https://www.tutorialspoint.com/java/java_documentation.htm

    http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html

    Documentation.pptx

  • Simple Application Deployment:

    1. Understand eclipse project folder hierarchy - src

- bin
    1. How to run java classes without eClipse
      example:
      1. java MyClass
      2. java mypackage.MyClass
      3. Simple batch file to run your Java application (https://www.geeksforgeeks.org/writing-windows-batch-script/)
        Create a new file in Notepad and type the following commands:
        1. java mypackage.MyClass (change mypackage with your package name if any and MyClass with your Main class (i.e. the one containing the main method).
        2. Pause (This pauses the console to see the output of your program)
        3. How to package your project into one file in eClipse and run it (i.e. Java Jar files)
          1. How to create the Jar file in eClipse: https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm
          2. How to run it: i. Use the command prompt/batch script to run the jar file using the following command: java –jar myJarFile.jar

ii. Try to double click on the Jar file in MS Windows (if you encountered a problem, please have a look at this https://windowsreport.com/jar-file-windows/)

Exercise:
Create a new project and implement the following functions:

i. Double getAverage (int value 1, int value2)

ii. Double factorial (int value)
      1. Document your project using Javadoc
      2. Create a jar file of that project.
      3. Pass the jar file and the documentation to your colleague(s) and receive his/her jar file.
      4. Create a new project with one class containing just the main method
      5. Import the jar file you received from your colleague.
      6. Read the documentation
      7. In your project, call those methods in the jar file J.
      8. [Optional] Package the new project into a new jar file and run it from console/windows file browser (i.e. don’t forget to link the other jar file to yours)

Week 6 (12–15 August)

  • Project 4: Conway's Game of Life, in groups (all week)