029: All about the infamous 65,536 dex method count

If you’ve been an Android developer in the last 2 years, you must have seen this dreaded exception: dex: method ID not in [0, 0xffff]: 65536

Quick googling would immediately bring up the phrase “65K method count” and the recommended solution “multi-dexing”. But if you want to really understand this mysterious number and the reason behind its existence, listen on!

Download

Show Notes

Contact

025: Effective Java for Android developers : Item 7

In this mini Fragment, we introduce Joshua’s seventh Item and a momentous end to the first chapter: Avoid finalizers

Stay tuned for more items from our “Effective Java for Android developers” Fragment series.

Download

Show Notes

Avoid finalizers

  • If you don’t know what they are, ignorance is bliss. If you know what they are, avoid them!
  • Finalizers in Java != destructors in C++ (C++ counterparts to constructors).
  • In C++ destructors
    • you reclaim resources here (Java has GC)
    • you also reclaim non-memory resources (use the try-finally block in Java)
  • (unpredicatable amt of time between object becoming unreachable and finalizer being executed) Never do anything time critical in finalizer!
    • System.gc + System.runFinalization increase chances – no guarantee
    • System.runFinalizersOnExit + Runtime.runFinalizersOnExit are the ones that do – but they are fatally flawed
  • Java 7 has try with resources, which is also interesting and auto-closeables. [Android] devs can only dream of these.
  • If an uncaught exception is thrown in a finalizer, it is ignored, and the finalization abruptly terminates.
  • Severe performance penalty for using finalizers – (one e.g.) time to create and destroy simple object goes from 5.6ns -> 2400ns
  • Only valid use: as a safety net or to terminate noncritical native resources.
  • [Android] you’re probably better off using Android’s lifecycle methods.

Contact

024: Effective Java for Android developers : Item 6

Joshua’s sixth Item: Eliminate obsolete object references, in a distinctively croaky voice.

Stay tuned for more items from our “Effective Java for Android developers” Fragment series.

Download

Show Notes

Eliminate obsolete object references

Supplemental reading (for the diligent ones that follow shownotes)

Contact

022: Effective Java for Android developers : Item 5

In this mini Fragment, we introduce Joshua’s fifth Item: Avoid creating unnecessary objects.

Stay tuned for more items from our “Effective Java for Android developers” Fragment series.

Download

Show Notes

Avoid creating unnecessary objects

Snippet to demonstrate AutoBoxing problems

// sum of all positive values
Long sum = 0L;
for (long i=0; i< Integer.MAX_VALUE; i++) {
  sum+=i;
}

Contact

019: Effective Java for Android developers : Item 4

Singer and Android developer Donn Felker explores Joshua Bloch’s fourth Item: Enforce noninstantiability with a private constructor.

Stay tuned, cause we got more of these quick ones coming.

Download

Show Notes:

Enforce noninstantiability with a private constructor.

Examples where you don’t want class to be instantiated

  1. class that groups static methods and static fields (Util like classes think java.lang.Math/java.util.Arrays)
  2. class that groups static methods (including factory methods) for objects implementing specific interfaces (think java.util.Collections)
  3. class that group methods on a final class (vs. extending the class)

Considerations

  • Makes no sense to instantiate such “Util” classes
  • Private constructors prevent instantiation
  • Important side effect: prevents subclassing

Contact us: