JGym.IO Live - Data Structures in Java - 9-10 February 2021

Java has an overwhelming number of interfaces and classes in the java.util.** packages. It comes equipped with Collection, Map, List, Queue, Deque, BlockingQueue, Iterator and Iterable. And those are just some of the interfaces. We have a bunch of abstract classes, plus the implementations that we all know and love: HashMap and ArrayList. Java programmers typically use only a small number of these collection classes. Often they choose inappropriate ones.

In this course, we explore all the interfaces and classes that Java offers in the latest JDK collection framework. We will look at what each collection costs in terms of memory and performance. At the end, you will have a much better idea of what collections to use and when. You will also know how to write your own collections. This course is also available for self-study or as a booked in-house course.

Some of the questions we will answer include: Which is the best Collection to use in Java? When do you need to employ ConcurrentSkipListSet? What is the computational time complexity of WeakHashMap?

This course includes two live sessions of 4 hours each on the 9th and 10th of February 2021 with Dr Heinz M. Kabutz. Each data structure has exercises to solve. Heinz shows model solutions and is always happy to answer your questions.

What you'll learn - and how you can apply it

  • Is ArrayList better than LinkedList? What is the difference in space complexity between the two classes?
  • When should we use LinkedList vs ArrayList vs CopyOnWriteArrayList?
  • The memory footprint of various collections.
  • By looking at hashing closely, we can learn how to spot bad hashes.
  • We speed up hashing by 3x by using a good hash for HashMap and ConcurrentHashMap.
  • We learn when to use which concurrent classes and which to avoid.
  • Good techniques for measuring costs of collections.
  • Computational time complexity of lookups and other operations.
  • How biased locking affects our collection choices from Java 15 onwards.
  • Why do we have UnsupportedOperationException.
  • How ConcurrentModificationException came about and what to do about it.
  • Choosing the correct collection can make our code more succinct. For example, the new List.of() syntax in Java 9 is better at creating immutable lists.
  • Converting Maps to Sets.
  • Compound operations on Maps.
  • WeakHashMap, LinkedHashMap, LinkedHashSet, IdentityHashSet, ConcurrentSkipListSet and other collections we hardly use.

How do these LIVE classes work?

Our LIVE classes consist of two 4-hour sessions. They are highly interactive, with exercises, discussions, and walkthroughs of the solutions. Sessions are not recorded. We welcome questions at any time during the live session.

Each 4-hour session runs from 7am to 11am Los Angeles Time.

Once you enrol in this course, we will sign you up for the webinar. Our system will send you login details. These are personal to you so please do not share them (otherwise you might lose access to the course).

LIVE Class Calendar

 

Course Outline

0: Welcome

  • Welcome to the course and how to get the most from your learning

1: Introduction to Collections in Java

1.1: Lists

  • O(1), O(n), O(n2), O(log n), O(n * log n)

1.2: Arrays

  • Primitive vs object arrays
  • Memory usage and layout
  • Multi-dimensional arrays

2: Lists

2.1: Lists

  • Arrays.asList()
  • Quick look at the List methods
  • Optional methods
  • asList() vs List.of()
  • RandomAccess

2.2: ArrayList

  • Adding four seasons
  • indexOf() and contains()
  • size() vs elementData.length in debugger
  • removeIf()

2.3: Iteration

  • Enumeration bugs
  • Fail fast collection
  • forEach()

2.4: CopyOnWriteArrayList

  • Safe iteration

2.5: LinkedList

  • Node memory usage
  • Accessing middle of list

3: Sorting

3.1: Sorting list of Strings

3.2: Sorting custom classes like Student

  • Comparing ints and longs
  • Writing Comparators as anonymous classes

3.3: Comparators with extractor functions

  • Type witnesses
  • Declared lambda parameters
  • Method references

3.4: Sorting performance ArrayList vs LinkedList

  • Parallel sorting of ArrayList

4: Sets

4.1: Sets

  • Set.of()
  • union with addAll()
  • intersection with retainAll() or stream/filter

4.2: TreeSet

  • Sorted by natural order
  • Red-black tree
  • Unbalanced tree O(n) vs O(log n)
  • Counting maximum tree depth

4.3: ConcurrentSkipListSet

  • Thread-safe sorted set

4.4: CopyOnWriteArraySet

  • For very small sets

5: Hashing

5.1: Hashing

  • Writing very basic hashtable
  • Clashes and distribution
  • % vs &

5.2: HashSet

  • hashCode() vs identityHashCode()
  • Pixel and good hash code
  • Bucket collisions
  • Making keys implement Comparable

5.3: ConcurrentHashMap.newKeySet()

6: Maps

6.1: Maps

  • one-to-one dictionary

6.2: HashMap

  • History of hashing 1.2, 1.4, 1.8+
  • Building a hash code with bit shifting Person(name,day,month,year)
  • Cached hash code in Strings
  • MapClashInspector
  • Creating maps of numbers
  • computeIfAbsent() for List of values

6.3: ConcurrentHashMap

  • Always use
  • Compound operations review

6.4: TreeMap

  • hashCode(), equals() and compareTo()
  • Own Comparator

6.5: ConcurrentSkipListMap

  • Parallel put into TreeMap vs ConcurrentSkipListMap

6.6: LinkedHashMap and LinkedHashSet

6.7: Highly Specialized Collections

  • EnumSet, EnumMap, IdentityHashMap, Properties, WeakHashMap

7: Queues and Deques

7.1: Queues and Deques

  • Not always FIFO

7.2: ConcurrentLinkedQueue and ConcurrentLinkedDeque

  • General purpose MPMC queues
  • size() is O(n)

7.3: ArrayDeque

  • Grows, does not shrink

7.4: BlockingQueues

7.5: LinkedBlockingQueue and LinkedBlockingDeque

  • Lock splitting

7.6: ArrayBlockingQueue

  • Compact array structure

7.7: Highly specialized queues

  • DelayQueue, SynchronousQueue, LinkedTransferQueue, PriorityQueue and PriorityBlockingQueue

8: Collection Facades

  • java.util.Collections
  • java.util.Arrays

9: Wrap-Up

  • Course wrap-up and next steps

Preparation

  • This training is aimed at junior to intermediate Java programmers wanting to learn what Java data structures are available and how to best use them.
  • Students should download and install the exercises found in the Resources chapter of the course material

Recommended Reading

Get started now!



Your Instructor


Dr Heinz M. Kabutz
Dr Heinz M. Kabutz

Heinz Kabutz is the author of The Java Specialists’ Newsletter, a publication enjoyed by tens of thousands of Java experts in over 145 countries. His book “Dynamic Proxies (in German)” was #1 Bestseller on Amazon.de in Fachbücher für Informatik for about five minutes until Amazon fixed their algorithm. Thanks to a supportive mother, he has now sold 5 copies.

Heinz’s Java Specialists’ newsletter is filled with amusing anecdotes of life on the Island of Crete. He is a popular speaker at all the best Java conferences around the world, and also at some of the worst. He teaches Java courses in classrooms around the world, where his prime objective is to make absolutely sure that none of his students fall asleep. He is not always successful.


Frequently Asked Questions


How long do I have access to a fully paid course?
How does lifetime access sound? After enrolling, you have unlimited access to this course for as long as you like - across any and all devices you own. Furthermore, if we move to another platform, we will offer you a free transfer of your account for all the courses that you have purchased.
How many times can I cancel and rejoin a subscription course?
To prevent abuse, we limit the number of times that you can cancel and rejoin our subscription based courses to three times.
What is the difference between a subscription, paying in installments and an outright purchase?
With a subscription, you never own the rights to the material. If your card is declined or you cancel your subscription, you lose access to the course. The money you have paid so far is lost. Paying in installments is a bit better. You pay for 5 or 10 months and then once you have completed your installments you have lifetime access to the course. The safest is an outright purchase, where you pay the entire course in one amount. There is no risk of losing access.
Can I pay via PayPal?
Yes, you can for outright purchases, but not for recurring payments such as paying by installments or subscriptions.
Can I get an EU VAT Invoice?
Absolutely. First off, be sure to enter the VAT number in the appropriate field during the payment process. Then contact us for an EU VAT Invoice. Please tell us the receipt number for which you need the invoice.
May I share my login details with my colleagues?
Unfortunately not. The terms of usage are for a single license. Teachable tracks your progress through the curriculum, so you won't know how much you have watched. We offer a 30% discount on 50 licenses or more by one company. Please contact us for bulk licensing.
May we use the course for running in-house courses?
You may, as long as each of the students in the class has a valid license for that course. For example, some companies run lunch time Design Patterns study groups using our material. This is an effective way to learn. Please contact us for bulk licensing.
What if I am unhappy with the course?
We would never want you to be unhappy! If you are unsatisfied with your purchase, contact us in the first 30 days and we will give you a full refund and deregister you from the course.
When does the course start and finish?
The course starts now and never ends! It is a completely self-paced online course - you decide when you start and when you finish. We do recommend putting time aside and setting goals to complete the course.
Can I watch the course offline during my commute?
Teachable have an iOS app that lets you watch offline. Android is not supported unfortunately.