Java SimpleDateFormat Date and time formats are specified by date and time pattern strings. Within format strings, unquoted letters from ‘A’ to ‘Z’ and from ‘a’ to ‘z’ are treated as format letters representing the components of a date or time string.
@Component – generic stereotype for any Spring-managed component (auto scan component)
@Repository – stereotype for persistence layer (DAO component)
@Service – stereotype for business layer (service component)
@Controller – stereotype for presentation layer (spring-mvc)
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
DateFormat df = new SimpleDateFormat("EEE yyyy-MM-dd HH:mm:ss");
System.out.println("The date and time in the specific timezone: " + cal.getTimeZone().getID());
System.out.println("\nThe date and time in the system time zone: " + Calendar.getInstance().getTimeZone().getID());
OS: CentOS 6.5
One use case in the project: due to the remote client server system upgrade, HTTPClient runs into such exception like javax.net.ssl.SSLException: java.security.ProviderException: java.security.KeyException:
Download latest 64 bit Java SE Development Kit 8 release
# mkdir /opt/shared
# cd /opt/shared
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz"
# tar xzf jdk-8u66-linux-x64.tar.gz
In Java, HashSet uses HashMap to finish: add, get, iterator etc. The HashMap also can help an element inside HashSet is unique.
HashMap works on the principle of Hashing. There are several terms: key, hash code, hash function, bucket, entry in HashMap
Java provides us Queue interface, where we can keep and handle elements before processing. Except the methods that Collection provides, it also supports some basic operations in order to simulate the classic queue structure. Each of these operations exists in two forms:
1. if a method fails, an exception is thrown. This form includes add(), remove() and element() methods.
2. if a method fails, a special value is returned (null or false). This form contains offer(), poll() and peek() operations.
In the previous post (Synchronized vs ReentrantLock in Java) , we have discussed the difference between synchronized and ReentrantLock. The keyword synchronized can be widely used in many multi-threaded environments. However, there are some drawbacks when using synchronized. The use of keyword synchronized provides access to the implicit monitor lock associated with every object, but forces all lock acquisition and release to occur in a block-structured way: when multiple locks are acquired they must be released in the opposite order, and all locks must be released in the same lexical scope in which they were acquired. In short, when the keyword synchronized locks a block, and a thread is in the block, other threads have to wait and will be blocked until that thread exits the block. It will slow down the performance. In some situations, it may leads to a deadlock. Continue reading
Since Spring 3.0, annotation support for both task scheduling and asynchronous method execution has been added. The post will give a demo of @Async annotation and its uses. Continue reading