In this Spring framework tutorial, we will learn how to write hello world example. This should be the first tutorial to start learning Spring framework, as it gets ball rolling and while coding and running this example, you learn a lot about Spring framework, Spring XSD files, required JAR file and more importantly how spring works.This Helloworld program in Spring framework is an example of classical Java hello world program, written using dependency Injection design pattern by using Spring Framework's IOC container. Spring is so far one of the most popular Java application framework, which promotes some best practices while writing Java application e.g. dependency Injection. Spring provides an IOC container to manage life-cycle of Spring beans and provides support to get beans any time from IOC container. Apart from Spring's IOC container, it also provide rich API to simply many of Java task e.g. JdbcTemplate help you to write JDBC code without taking care of boiler plate things like closing connection, statement, result-set etc. Similarly Spring framework also provides JmsTemplate to simply JMS related task e.g. sending and receiving messages in Java. I first learned about usefulness of Spring framework, while reading Expert Spring MVC and Web Flow, it first few chapters, which explains about how dependency injection provides improved testing, loose coupling and help in clean code. Those two chapters are so far my best read on Spring, and I also suggest to take a look. By the way in this Spring tutorial, we will see one of the most simple example of Dependency Injection e.g. Hello Example. Message to Hello class is provided by Spring framework using Dependency Injection.
Thursday, June 13, 2013
Tuesday, June 11, 2013
MD5 checksums are good to verify integrity of files and It's easy to generate MD5 checksum in Java. Java provides couple of ways to generate MD5 checksum for any file, you can either use java.security.MessageDigest or any open source library like Apache commons codec or Spring. All 3 ways we have seen in our earlier article about generating MD5 hash for String is also applicable to generate MD5 checksum for any file. Since most of md5() or md5Hex() method takes byte, you can simply read bytes from InputStream or pass to these md5 methods. Apache commons codec from version 1.4 also provides an overloaded method to accept InputStream, which makes generating checksum very easy in Java. For those who are not familiar with checksum, it's a fixed size datum generated from a block of data to detect any accidental change in data. Which means once you create checksum for a file, which is based on contents of file, any change on file e.g. adding white space, deleting a character will result in different checksum. By comparing stored checksum with current checksum, you can detect any change on File. It's good practice to provide checksum of WAR or JAR files to support teams for production release. In this Java tutorial we will learn how to create MD5 checksum for any file in Java.
Thursday, June 6, 2013