JGym.IO Live - Data Structures in Java - 9-10 November 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 November 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
- Welcome to the course and how to get the most from your learning
1: Introduction to Collections in Java
- O(1), O(n), O(n2), O(log n), O(n * log n)
- Primitive vs object arrays
- Memory usage and layout
- Multi-dimensional arrays
- Quick look at the List methods
- Optional methods
- asList() vs List.of()
- Adding four seasons
- indexOf() and contains()
- size() vs elementData.length in debugger
- Enumeration bugs
- Fail fast collection
- Safe iteration
- Node memory usage
- Accessing middle of list
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
- union with addAll()
- intersection with retainAll() or stream/filter
- Sorted by natural order
- Red-black tree
- Unbalanced tree O(n) vs O(log n)
- Counting maximum tree depth
- Thread-safe sorted set
- For very small sets
- Writing very basic hashtable
- Clashes and distribution
- % vs &
- hashCode() vs identityHashCode()
- Pixel and good hash code
- Bucket collisions
- Making keys implement Comparable
- one-to-one dictionary
- 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
- Creating maps of numbers
- computeIfAbsent() for List of values
- Always use
- Compound operations review
- hashCode(), equals() and compareTo()
- Own Comparator
- 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)
- Grows, does not shrink
7.5: LinkedBlockingQueue and LinkedBlockingDeque
- Lock splitting
- Compact array structure
7.7: Highly specialized queues
- DelayQueue, SynchronousQueue, LinkedTransferQueue, PriorityQueue and PriorityBlockingQueue
8: Collection Facades
- Course wrap-up and next steps
- 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
- Sign up to The Java Specialists’ Newsletter for lots of tips on the latest Java developments: https://www.javaspecialists.eu/archive
Get started now!
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.