From charlesreid1

(Created page with "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...")
 
No edit summary
 
Line 12: Line 12:
** Move on to utility/protected/private classes, iterators/iterables, items, etc.
** 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.)
** Finally, include class content at bottom (it is at end, because that's the "least surprising" part of the code.)
[[Category:Java]]
[[Category:Best Practices]]
[[Category:CS]]
{{CSFlag}}

Latest revision as of 23:33, 25 June 2017

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: