Thursday, July 10, 2014

literal

  • In computer science, a literal is a notation for representing a fixed value in source code.
In contrast to literals, variables or constants are symbols that can take on one of a class of fixed values, the constant being constrained not to change.
Literals are often used to initialize variables, for example, in the following, 1 is an integer literal and the three letter string in "cat" is a string literal:
 int a = 1;
 String s = "cat";

 http://en.wikipedia.org/wiki/Literal_%28computer_programming%29

Static Import in Java


  • import static java.lang.Math.PI;
double r = cos(PI * theta);

http://viralpatel.net/blogs/static-import-java-example-tutorial/

  • Static import can reduce code size and allow you to freely use static field of external class without prefixing class name on that
http://javarevisited.blogspot.com/2012/10/what-is-static-import-in-java-5-example-tutorial.html#ixzz370mlCrPP

BigDecimal

  • How to Use Java BigDecimal
Ability to specify a scale, which represents the number of digits after the decimal place
Ability to specify a rounding method
The java.math.BigDecimal class handles both of these considerations.

suppose we have a product which costs 10.00 in a given currency and the local sales tax is 0.0825, or 8.25%. If we work it out on paper, the tax amount is,
10.00 * 0.0825 = 0.825
Because our precision for the currency is two digits after the decimal, we need to round the 0.825 figure. Also, because this is a tax, it is good practice to always round up to the next highest cent. That way when the accounts are balanced at the end of the day, we never find ourselves underpaying taxes.
0.825 -> 0.83
so the total we charge to the customer is 10.83 in the local currency and pay 0.83 to the tax collector. Note that if we sold 1000 of these, we would have overpaid the collector by this much,
1000 * (0.83 - 0.825) = 5.00

http://www.opentaps.org/docs/index.php/How_to_Use_Java_BigDecimal:_A_Tutorial


  • The java.math.BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.
Two types of operations are provided for manipulating the scale of a BigDecimal:

    scaling/rounding operations
    decimal point motion operations.
http://www.tutorialspoint.com/java/math/java_math_bigdecimal.htm

CamelCase Java Naming Convention

CamelCase Java Naming Convention
CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter (e.g., CamelCase, CustomerAccount, PlayingCard).
http://java.about.com/od/javasyntax/a/nameconventions.htm