Java 8 Date Time API Usage

Introduction Every effort we put in to showcase the extent of Java 8 Date Time API usage leaves us only scratching the surface of it. This post walks through a couple of examples and some standard methods that can be helpful in daily use. Timezone aspects are not covered in this post. Refer to this post to for an introduction to Java 8 Date Time API. Old And The New Let us see how date formatting code changes with the new Java 8 Date Time API. If you landed directly on this post, we recommend reading this introductory post first. [crayon-5905dec93b7f4454532748/] Goodbye ThreadLocals and c...
Read More

Java 8 Date Time API

What ailed Date and Time handling in Java? The existing java.util.Date and SimpleDateFormat are mutable and not thread-safe, more often than not, leading to concurrency issues for users. Having to deal with this overhead is not welcoming for novice developers. Inconsistent API (months starting at 1 while days start at 0), no ability to handle Time alone, no utilities like plus/minus dates lead to popularity of libraries like joda-time. Many enterprise products use joda-time, when date/time usage and manipulation should have been provided by the language which was in it's 7th iteration (person...
Read More

Try With Resources in Java 7 and Above

Introduction Try with Resources in Java 7 and above allows for automatic closing of resources that implement java.lang.AutoCloseable or the more familiar java.io.Closeable (which extends AutoCloseable) Anyone through a basic Java course will be familiar with this block of code. Open a text file to write data and close it when done. [crayon-5905dec93d6bc278017434/] The method attempts to write to a file and throws any exception that hinders in achieving this. The finally block ensures that no file handle is left open by this method. But close() can throw an exception if closing the file f...
Read More

Injecting Prototype Beans in Singletons

Introduction This is a series and it would make a lot of sense if read in a sequence. You can find all the posts under the heading "Spring Beginners to Professionals". In the previous posts,we talked about scopes of Spring beans. Now as there are many different scopes, the basic problem which arises is injecting prototype beans in singletons. We can also define this problem in a more general way, say collaboration between beans of different scopes. Injecting Prototype Beans in Singletons By now we have learnt that the dependency injection happens when the container starts. All the singleton...
Read More

Understanding the Bean Scopes in Spring

Introduction This is a series and it would make a lot of sense if read in a sequence. You can find all the posts under the heading "Spring Beginners to Professionals". In one of the previous posts, I introduced the concept of scopes for beans. This post is completely focused on explaining the bean scopes in Spring and their usages. Bean Scopes in Spring A scope can be considered as a logical boundary within which a bean is deployed and known to the application. There are handful of scopes in Spring. Before moving on to the scopes defined by Spring, let us  understand how a scope in gener...
Read More

Spring Environment and Spring Profiles

Introduction This is a series and it would make a lot of sense if read in a sequence. You can find all the posts under the heading “Spring Beginners to Professionals“. In real enterprise scenario you run your application in different environments. For e.g.: dev, testing, stage, production etc. And it is logical to have different set of properties for each of these environment. For e.g. a developer might want to use an in memory database configuration for his unit testing, whereas a QA might want to test it against a test database. Business users may want to test it against a stage database...
Read More

Properties and PropertySources in Spring

Introduction This is a series and it would make a lot of sense if read in a sequence. You can find all the posts under the heading “Spring Beginners to Professionals“. All the modern enterprise level applications require external properties files and it is important to have a clean mechanism of using these properties in the application. Spring provides an abstraction for achieving the same in form of Properties and PropertySources. This post is a continuation to the ApplicationContext chapter. Remember, this is one of the important features imparted by the ApplicationContext? How are Prop...
Read More