APACHE COMMONS / NOTES</>↗Apache Commons07 Jul 2013
You need to calculate the timing or elapsed time of your code execution, so you know how long a particular method or some block of code take to finish its execution. You can do this by capturing the start-time and the end-time using System.currentTimeMillis() and find their differences. Another way is to use the StopWatch […]
APACHE COMMONS / NOTES</>↗Apache Commons05 Jul 2013
You have an array variable, and you want to make a clone of this array into a new array variable. To do this, you can use Apache Commons Lang ArrayUtils.clone() method. The code snippet below demonstrates the cloning of a primitive array that contains some integer elements in it. package org.kodejava.commons.lang; import org.apache.commons.lang3.ArrayUtils; public class […]
APACHE COMMONS / NOTES</>↗Apache Commons05 Jul 2013
You need to print the contents of an array variable. The long way to it is to user a loop to print each element of the array. To simplify this, you can use the Apache Commons Lang ArrayUtils.toString() method. This method can take any array as a parameter and print out the contents separated by […]
APACHE COMMONS / NOTES</>↗Apache Commons20 Jun 2013
package org.kodejava.commons.lang; public class ObjectHashCodeDemo { public static void main(String[] args) { Book book1 = new Book(1L, "Spring Boot in Action", "Craig Walls"); Book book2 = new Book(2L, "Docker in Action", "Jeff Nickoloff"); Book book3 = book1; System.out.println("book1.hashCode() = " + book1.hashCode()); System.out.println("book2.hashCode() = " + book2.hashCode()); System.out.println("book3.hashCode() = " + book3.hashCode()); } } package […]
JDBC / NOTES</>↗JDBC11 Jun 2013
In the following code snippet, you will see how to pass some connection arguments when connecting to a database. To do this, we can use the java.util.Properties class. We can put some key value pairs as a connection arguments to the Properties object before we pass this information into the DriverManager class. Let’s see the […]
REGEX / NOTES</>↗Regex10 Apr 2013
package org.kodejava.regex; public class GetNumberOfWordsFromString { public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog."; String one = truncateAfterWords(1, text); System.out.println("1 = " + one); String two = truncateAfterWords(2, text); System.out.println("2 = " + two); String four = truncateAfterWords(4, text); System.out.println("4 = " + four); String […]