YONG KianOn

Sunday, January 15, 2012

Struts2 vs SpringMVC

Struts2 vs SpringMVC

Struts framework is one of the initial web application frameworks for developing Java EE web applications. Spring is an open source application framework. Some time after the introduction of Spring framework, the developers added an MVC framework to the Spring framework, hoping to address some of the limitations they perceived in Struts. But few years later, Struts2 (or Struts version 2) arrived, and it was completely different and highly improved web application framework. Now, both Struts and SpringMVC are being used very heavily for developing Java EE applications in the world.

What is Struts?
Struts (also known as Apache Struts) is a cross-platform open source framework written in Java, which is intended for developing Java EE web applications. Struts encourage the usage of MVC (Model-View-Controller) architecture. It is an extension of Java Servlet API. Craig McClanahan is the original creator of Struts. Initially it was known as Jakaratha Struts, and was maintained under Jakarta Project of Apache Software Foundation. Its current stable release is version 2.2.3, which was released in May, 2011. It is released under Apache License 2.0. Struts framework is called a request-based framework, and it is made up of three main components: a request handler, a response handler, and a tag library. Standard URI (Uniform Resource Identifier) is mapped to a request handler. Response handler is responsible for transferring control. To create interactive applications with forms, the features offered by the tag library can be utilized. Struts support REST applications and various technologies like SOAP, AJAX, etc.

What is SpringMVC?
Spring is an open source application framework. It was developed by Rod Johnson,, and the first version was released in 2004. Spring 3.0.5 is the current version of the Spring framework. It is licensed under Apache 2.0 license. Any Java application can use the core features of the Spring framework. There are several modules in Spring framework, and MVC is one of them. The SpringMVC framework was not a part of their original plan. In fact, the reason that Spring developers came up with their own MVC framework was to provide solutions to what they showed as deficiencies in the Struts (version 1) and other similar frameworks. In particular, they said that they wanted to address the lack of separation between the presentation layer, request handling layer, and the model. SpringMVC is also a request-based web application framework.

What is the difference between Struts and SpringMVC?
Although SpringMVC and Struts are two popular web application frameworks used for developing Java EE web applications, they have their differences. In fact, SpringMVC was developed in order to address few limitations in Struts (version 1). But Struts2 is a highly improved framework than version 1 (they don’t even share the same code base), and therefore, the SpringMVC and Struts2 are highly comparable.

One of the main advantages of SpringMVC is that it is possible to have seamless integration with many view options such as JSP/JSTL, Tiles, FreeMaker, Excel, PDF and JSON. But, unlike Struts, SpringMVC does not provide built-in AJAX support (need to use third-party AJAX library).

Ultimately, both of them are considered highly mature frameworks, and choosing between the two comes down to the personal preference. It is important to note here that if there are any negative feelings towards struts, they are only due to the deficiencies that were found in Struts version 1 (which is now considered obsolete).


http://www.differencebetween.com/difference-between-struts-and-vs-spring-mvc/


Friday, March 11, 2011

Touring the bottom of ocean (NOAA)


http://www.FunToWatch.TV The ocean -- it is the most prominent feature on Earth, and of immeasurable importance to life on the planet. But what would it look like if all of the water was drained out of it? Mountains and valleys that dwarf Everest; shifting plates and undersea volcanoes; seams, ripples, and plains. Though ships have mapped only a small portion of the ocean floor, satellites are used to generate incredibly details maps of the bottom of the ocean. By sensing the minute gravitational changes that pull, push, and bulge the ocean surface, the bottom's shape can be inferred from space. These bathymetric maps reveal the incredibly dynamic terrain of the ocean. Where available, ship-based measurements are included to provide even higher detail.

This visualization tours the ocean floor from the gentle continental slopes to the deepest trenches using data analyzed and archived by NOAA. Does it look familiar? It is actually the same data that Google has incorporated into Google Earth and Ocean.



Friday, September 10, 2010

Enhancements in JAVA 5

Please refer to http://download.oracle.com/javase/1.5.0/docs/guide/language/


JAVA Variable Arguments


Variable Arguments (Varargs)

Varargs can be used only in the final argument position.

So when should you use varargs? As a client, you should take advantage of them whenever the API offers them. Important uses in core APIs include reflection, message formatting, and the new printf facility. As an API designer, you should use them sparingly, only when the benefit is truly compelling. Generally speaking, you should not overload a varargs method, or it will be difficult for programmers to figure out which overloading gets called.


(*^__^*)

Wednesday, September 8, 2010

String, StringBuffer, StringBuilder



String is immutable whereas StringBuffer and StringBuilder can change their values.

What is the difference between StringBuffer and StringBuilder?

The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.

Criteria to choose among String, StringBuffer and StringBuilder

1. If your text is not going to change use a String Class because a String object is immutable.
2. If your text can change and will only be accessed from a single thread, use a StringBuilder because StringBuilder is unsynchronized.
3. If your text can changes, and will be accessed from multiple threads, use a StringBuffer because StringBuffer is synchronous.

StringBuilder was introduced in JDK 1.5. According to javadoc, StringBuilder is designed as a replacement for StringBuffer in single-threaded usage. Their key differences in simple term:

* StringBuffer is designed to be thread-safe and all public methods in StringBuffer are synchronized. StringBuilder does not handle thread-safety issue and none of its methods is synchronized.

* StringBuilder has better performance than StringBuffer under most circumstances.

* Use the new StringBuilder wherever possible.

Other than that, the two classes are remarkably similar with compatible API.


(^_ end _^)

Tuesday, August 31, 2010

Java Collections Framework


List<E>
Implementations: LinkedList<E>, ArrayList<E>, Vector<E>, Stack<E>

A List<E> is a collection which can contain duplicate elements, and the elements are ordered (like an array, you can add an element at a specific position, and the elements are accessed using their index).

[Stack<E> has come up in the examination in the past, so here is some information on it.

Stack<E> is a subset of Vector<E>, which contains some extra methods. The idea of a stack is like its name, it acts like a piled up stack of items: When you add an element, it goes to the top of the stack, and when you extract an element, it is taken off the top. In other words, this is a last-in, first-out system. The methods are:

push(object) - Add an element onto the top of the stack.
pop() - Removes the object at the top of this stack and returns that object as the value of this function.
peek() - Looks at (i.e. returns) the object at the top of this stack without removing it from the stack.. ]



Set<E>
Implementations: Hashset<E>

A Set<E> is a collection which cannot contain any duplicate elements and has no explicit order to its elements (unlike array, where every element exists at a particular index i.e. MyArray[15]).

SortedSet<E>
Implementations: TreeSet<E>

A SortedSet<E> is a Set<E> which maintains its elements in ascending order.



Map<K, V>
Implementations: HashMap<K, V>, Hashtable<K, V>, WeakHashMap<K, V>

Maps keys to values. In other words, for every key, there is a corresponding value, and you look up the values using the keys. Maps cannot have duplicate keys, and each key maps to at most one value.

Note: A Map<K, V> does not implement the Collection interface.

SortedMap<K, V>
Implementations: TreeMap<K, V>

A SortedMap<K, V> is a Map<K, V> which maintains its mapping in ascending key order.



add() method is available for any type of Collection classes only
TreeMap<K, V> is a java.util.Map<K, V>, use put() method with 2 arguments. This is due to Map<K, V> does not implement the Collection interface.




Thread-safe and slowest iteration speed
Hashtable, Vector

NON thread-safe
ArrayList, HashSet, HashMap, LinkedList, TreeSet, LinkedHashSet, TreeMap





Object Ordering

Implementations of the SortedSet and SortedMap interfaces sort their elements. To determine what criterion is used to sort the elements you can use either the Comparable or Comparator interfaces. Using Comparable means that the classes that you put in your SortedSet or SortedMap implement the Comparable interface, which just means that they contain a method compareTo() which determines whether the object is "greater" or "less than" another object. To use the Comparator interface, you pass an object which implements Comparator to your SortedSet or Sorted map, and it will use the Comparator for ordering.




Distinguish between correct and incorrect implementations of hashCode() methods.

The hashCode() value of an object gives a number which can be used to in effect to 'index' objects in a collection. A collection class can group its objects by their hashcodes, and if you called e.g. contains() (or get() in case of a Map), it can first find the group based on the hashcode, then search that group. This avoids the need to check every object in the collection.

The requirements of a hashCode() implementation are that if two objects are equal as determined by the equals() method, their hashcodes should be the same. This is why wherever you override the equals() method, you should override hashCode() as well.

The reverse is not required i.e. it is permitted for two objects that are not equal to have the same hashcode. This makes sense, as it is not always possible to ensure unique hashcodes. The method returns an integer and there are only an finite number of integer values to use. However, where possible, it is desirable to have the hashcodes be distinct as this can improve performance. If the hashcodes can be well distributed (i.e. scattered throughtout the integer range) as well, all the better.




BitSet

For completeness, here is some information on BitSet, which isn't part of the Collections Framework, but may be examinable:
A BitSet contains elements which are bits, i.e. of the boolean primitive type. Like, for example, a Vector, and unlike an array, a BitSet does not have a fixed size, and grows as needed when you add elements to it.






(^_^)





Monday, August 30, 2010

JAVA strictFP


A new keyword in Java2 is strictfp. strictfp is not in versions of Java prior to Java2.

strictfp is a keyword and can be used to modify a class or a method, but never a variable. Marking a class as strictfp means that any method code in the class will conform to the IEEE 754 standard rules for floating points.

It is included here for completeness, however, I cannot say whether it is examinable and you will have to look elsewhere for information on its syntax. This modifier tells the compiler to use a strict form of floating point calculations, which ensures an identical result on every platform. In Java 1.1, this strict form is always used, but in Java2, when you do not specify strictfp, the Java virtual machine can do a fast calculation, which makes the most of the performance of the native processor without the overhead of converting to a consistent cross-platform format.

[Technical aside, for those interested in microprocessors:
I believe part of the reason for its introduction is that the X86 CPUs have an 80bit FPU, versus 64bits used in the Java standard and on Suns processors. Intel complained that this gave their CPUs a disadvantage in Java]

Reference



(*_*)

About

My photo
Petaling Jaya, Selangor, Malaysia