Java optional parameters

There are several ways to simulate optional parameters in Java: Method overloading.void foo(String a, Integer b) { //… }void foo(String a) { foo(a, 0); // here, 0 is a default value for b }foo(“a”, 2); foo(“a”); One of the limitations of this approach is that it doesn’t work if you have two optional parameters of … Read more

How to round up to the next integer?

No, Math.ceil() won’t work on its own because the problem occurs earlier. a and b are both integers, so dividing them evaluates to an integer which is the floor of the actual result of the division. For a = 3 and b = 2, the result is 1. The ceiling of one is also one – hence you won’t get the desired result. You must … Read more

What is a serialVersionUID and why should I use it?

The docs for java.io.Serializable are probably about as good an explanation as you’ll get: The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If … Read more

How to remove single character from a String

You can also use the StringBuilder class which is mutable. It has the method deleteCharAt(), along with many other mutator methods. Just delete the characters that you need to delete and then get the result as follows: This avoids creation of unnecessary string objects.

What does Java option -Xmx stand for?

-XmxnSpecify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 … Read more

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