CSCI 431 — Java 8 stuff

A long example

  1. Download a Java project.
  2. Add a compareTo method to the SectionInfo so that it implements the Comparable interface. In the sort, give priority to department, number, and section in that order. Also, invoke Collections.sort to sort the courses before printing them.
  3. Add a third class SectionInfoCompareLimit that implements Comparator<SectionInfo>. This time sort by limit, department, number, and section. Also, use the two-argument version of Collections.sort to sort the courses by limit this time.
  4. Make your SectionInfoCompareLimit class a nested class of SectionInfoRun. (I think it must be a static class.) This should eliminate a Java file.
  5. Make your SectionInfoCompareLimit class a local class of the main method of SectionInfoRun. This is a JDK 8 thing.
  6. Make your SectionInfoCompareLimit class an anonymous class of the main method of SectionInfoRun.
  7. Finally, use a lambda expression as your second argument to Collections.sort. My starts with something like:
    (si1, si2) ->

How did they do it?

How do you add functions to a programming language without functions? Download and read Introducing Java 8 from O’Reilly.

Download the following Java classes and run MethodReferencesTest. The to do some interesting changes. By the way, doesn’t Oracle also do something with databases?

References to ponder