Why int[] a = new int[1] instead of just int a?

defines a primitive int. defines an array that has space to hold 1 int. They are two very different things. The primitive has no methods/properites on it, but an array has properties on it (length), and methods (specifically its on clone method, and all the methods of Object). Arrays are a bit of a weird … Read more

Good way to encapsulate Integer.parseInt()

You could return an Integer instead of an int, returning null on parse failure. It’s a shame Java doesn’t provide a way of doing this without there being an exception thrown internally though – you can hide the exception (by catching it and returning null), but it could still be a performance issue if you’re parsing hundreds of thousands of … Read more

ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”

From the Java 11 BigDecimal docs: When a MathContext object is supplied with a precision setting of 0 (for example, MathContext.UNLIMITED), arithmetic operations are exact, as are the arithmetic methods which take no MathContext object. (This is the only behavior that was supported in releases prior to 5.) As a corollary of computing the exact result, the rounding mode setting of a MathContext object with … Read more

Why int[] a = new int[1] instead of just int a?

defines a primitive int. defines an array that has space to hold 1 int. They are two very different things. The primitive has no methods/properites on it, but an array has properties on it (length), and methods (specifically its on clone method, and all the methods of Object). Arrays are a bit of a weird … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)