When/why to call System.out.flush() in Java

System.out is based around a PrintStream which by default flushes whenever a newline is written. From the javadoc: autoFlush – A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte (‘\n’) is written So the println … Read more

Android Framework?

Soon there will be! I am working on DroidFu, an Android shared library which will give you: tons of utility functions available directly in Activities (and Services), such as spawning list and error dialogs, checking for Intent availability, and other workarounds/replacements for cases where Android lacks desired functionality easy handling of asynchronous tasks (takes care … Read more

Checking for a not null, not blank String in Java

Is there a string that will make the isEmpty and isBlank behave differently in a test case? Note that Character.isWhitespace can recognize Unicode characters and return true for Unicode whitespace characters. Determines if the specified character is white space according to Java. A character is a Java whitespace character if and only if it satisfies … Read more

What are the differences between a Java enum and a class with private constructor? [duplicate]

Differences: Enums extend java.lang.Enum and gain all of its nice features: Automatic singleton behaviour through correct serialization Automatic human-readable .toString method on enum values without the need to duplicate your enum names .name and .ordinal special-purpose methods Usable in high-performance bitset-based EnumSet and EnumMap classes Enums are treated by the language specially: Enums use a … Read more

Spring MVC: please explain difference between @RequestParam and @ModelAttribute

@RequestParam just populates stand-alone variables (which may of course be fields in a @ModelAttribute class). These variables will be thrown away when the Controller is done, unless they have been fed into the model. Don’t confuse the word “model” with session. The http conversation is generally: HTTP.GET, server response, then HTTP.POST. When you have the … Read more

8 branches for try with resources – jacoco coverage possible?

Well I can’t tell you what the exact problem with Jacoco is, but I can show you how Try With Resources is compiled. Basically, there are a lot of compiler generated switches to handle exceptions thrown at various points. If we take the following code and compile it public static void main(String[] args){ String a … Read more