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
How to Generate MD5 checksum for Files in Java
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.
Labels:
coding,
core java,
programming
Thursday, June 6, 2013
How to get current URL, parameters and Hash tag using JQuery and JavaScript
While dealing with current URL, many time you want to know what is the
current URL path, What are the parameters, and what is the hash tag on URL.
Hash tag is pretty important, if you are implementing tab structure using HTML
and JQuery. To avoid confusion, let's take an example of URL: http://javarevisited.blogspot.com/2013/01/top-5-java-programming-books-best-good.html#ixzz2PGmDFlPd
, in this example ixzz2PGmDFlPd is hash tag. Now, both JavaScript
and JQuery provides convenient way to retrieve current URL in form of window.location object.
You can use various properties of window.location JavaScript
object e.g. window.location.href to get complete URL, window.location.pathname to get
current path, and window.location.hash to get hash tag from
current URL. If you like to use JQuery then you can get window.location as JQuery
object and retrieve relevant properties using attr() function.
If you are absolutely new in JQuery, and unaware of power of one of the most
popular JavaScript framework, Head First JQuery is a good
starting point. Being a fan of head first book, I always approach a new technology
by an Head first title, it helped to learn a lot in short time, without
spending time in trivial examples. By the way, In this web tutorial, we are
going to retrieve current URL and hash tag using JavaScript and JQuery.
Labels:
HTML and JavaScript,
JQuery,
programming
Subscribe to:
Posts (Atom)
