From charlesreid1

Java best practices:

  • When to use what type of container - trees are O(log N), sorted. hashes are O(1), not sorted.
  • Comparators vs comparable - how to maximize utility of comparators (e.g., PriorityQueue)
  • Iterator vs iterable - how and when to roll your own, how and when to be lazy.
  • Class import statements:
    • Rigorously, we do "import java.util.LinkedList;" BUT
    • Informally we do "import java.util.*; import java.io.*"
  • Why/when/how is this dangerous in Java.
  • Organization of classes:
    • Start with main method
    • Move on to utility/protected/private classes, iterators/iterables, items, etc.
    • Finally, include class content at bottom (it is at end, because that's the "least surprising" part of the code.)





See also: