My Tech Notes - Java Coding Practices

Java Coding Practices : Simple rules to Optimise your code and make it work faster

http://www.capitalware.com/dl/docs/WhitePaperJavaCodingPractices.pdf


  1. Garbage collection 
  2. Loop optimisation 
  3. Data Structures
  4. Synchronization
  5. Exception Handling - A simple performance improvement can be achieved by placing the try-catch block outside any loops.
  • Set -  no particular order, sets are slower than most other collection objects. No duplicates
    •  HashSet -  HashSet stores the object in random order.There is no guarantee that the element we  inserted first in the HashSet  will be printed first in the output
    • TreeSet - Elements are sorted according to the natural ordering of its elements in TreeSet
  • List -  A list has the characteristics that objects are stored in a linear manner
    • ArrayList  - Ordered list the order in which elements are entered is maintained
    • Vector - Dynamic array. Synchronised 
    • Stack  - LIFO last in first out 
    • LinkedList - Internally uses doubly linked list faster than array list 
  • Hash - Maps involve pairs of objects, a key and the object itself.
    • Hash Map - no order in key value pair stored. 
    • Tree Map - ordered by key
    • Linked Hash Map - insertion order maintained. 
    • Hash table - synchronised hash table  


Others Notes: 
Thread synchronization is defined as a mechanism which ensures that two or more concurrent processes or threads do not simultaneously execute some particular program segment known as mutual exclusion.

Some useful links : 

http://tutorials.jenkov.com/java-collections/stack.html

Comments