Java Lambda Expressions: Consumer, Supplier and Function

Lambdas are used to create function objects. With them, we can specify methods inside other methods—and even pass methods as arguments to other methods. A lambda has a shape, one determined by its parameters and return values (if any) and their types. Classes like Function, Supplier, Consumer, accept lambdas with specific shapes. Example expression. This…

How Java Debug works

You can just attach your IDE to a running application (which has been runned for debug as we’ll see later), or you can even debug it from command line. And the application you debug can even be be in a different machine. The magic lies in where the debug information actually resides. Apparently people normally…

java String intern

What is String Interning ? String Interning is a method of storing only one copy of each distinct String Value, which must be immutable. In Java, String class has a public method intern() that returns a canonical representation for the string object. Java’s String class privately maintains a pool of strings, where String literals are automatically interned. When the intern() method is invoked on a String object it…

get tomcat hot swap work with intellij

It usually takes a lot of time whenever you’re recompiling a Java web project. The IDE would usually recompile the entire project, package them into a war and have it redeployed on your  application server (i.e., Tomcat) then letting the server reinitialize itself. It takes a lot of time, and it just gets worse as your…

Watch out the milliseconds in java Calendar

milliseconds  problem If you run the following test multiple times, you get different results: result : Time 1369454400208 Time 1369454400185 Time 1369454400926 When getting Instance of calendar it has been initialized with current time. And when setting year,month etc. MILLISECOND were taken from current date. What’s more if you get a calendar instance and  use…

java vs c++

At the beginning of a new project, you may be faced with the question, “Should I use C++ (or some other language) for my next project, or should I use Java?” As an implementation language, Java has some advantages and some disadvantages over other languages. One of the most compelling reasons for using Java as…

ORA-00911: invalid character

ORA-00911: invalid character Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q’#…#’) cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the…

Java Thread Local

Thread Local is an interesting and useful concept, yet most of the Java developers are not aware of how to use that. In this post, I’ll explain what is Thread Local and when to use it, with an example code. Since it’ll be little tough to understand this concept at first, I’ll keep the explanation…

JAVA Output Alignment

The printf function works fine for space padding. For example: // % – insert argument value // , – insert locale-specific separators // 20 – pad out to 20 spaces // .2 – fix precision at two decimal places // s – string argument // f – float argument System.out.printf(“%20s %20s\n”, “Column 1”, “Column 2”); System.out.printf(“%,20.2f %,20.2f\n”,…

java switch compile time constant

The switch statement can only contain case statements which are compile time constants and which evaluate to an integer (Up to Java 6 and a string in Java 7). Compile time constant include: a char, byte, short, int, or, as of Java 6, an enum. Also if you define : a cannot be used in a switch statement though it is…

java class name this

The syntax “Classname.this” is for inner classes. If you want to refer to the enclosing instance of type “Outerclass” then you do it as “Outerclass.this”.