adding 2 BigDecimal values
Perhaps this is what you prefer:
BigDecimal z = new BigDecimal(5).add(x);
Every operation of BigDecimal
returns a new BigDecimal
but not change the current instance.
BigDecimal is immutable. Every operation returns a new instance containing the result of the operation:
BigDecimal sum = x.add(y);
If you want x to change, you thus have to do
x = x.add(y);
Reading the javadoc really helps understanding how a class and its methods work.