[Java Application Performance and Memory Management] Chapter 21 – Other Coding Choices

Published by

on

Primitive type vs Reference type

BigDecimal vs Double

  • BigDecimal requires more precision which consumes more resources

StringBuilder vs String literal

  • StringBuilder always shows better performance
  • If the String literals concatenation is in one line, JVM automatically optimizes it which results in the same performance as StringBuilder
    • ex) "Hello" + str1 + "World" + str2
      almost equals to
      StringBuilder sb = new StringBuilder();
      sb.append("Hello");
      sb.append(str1);
      sb.append("World");
      sb.append(str2);

Reference

Leave a comment