Monday, August 19, 2013

JAVA EE SERVERS

JAVA EE SERVERS

I recently notice that Jboss changed the name of its community server version from JBoss AS to Wildfly. It took me some time to understand what was all the fuzz about, first I thought it was a new server but then I finally get it, Red hat was just making a bigger distinction between the JBoss supported (Jboss EAP) and community (now Wildfly) version nothing else, just like red hat and fedora.
You can find more information about it in the following link:

With this I realized that there are plenty versions of JEE servers in the market and is hard to understand for a non expert or a newbie which one does what and what is the difference between all of them, so I decided to write a post about the JEE Servers that are available, just to list some of its features and not a benchmark because that would require expertise in each server and I don't have that.

Before getting into serves here is a list of the specifications that a full Java EE 7 server should have, I will refer to it in a future as figure 1.







































Apache Tomcat 


Apache tomcat is an open source web server, it has many years in the market and is very common to find implementations using it.
Tomcat is a web server because it supports the Java Servlet and JavaServer Pages and others related to them, the table below shows the specification version supported by the tomcat version.

Tomcat home page: http://tomcat.apache.org/



Jetty


Jetty is a open source web container, it an Eclipse project and is hosted entirely at the Eclipse Foundation. It is known for be a lightweight server and be easily embedded in devices, tools, frameworks, application servers, and clusters. It has support for SPDY, WebSocket, OSGi, JMX, JNDI, JAAS and many other integrations.

The specifications that jetty has support are:
















More information about jetty can be found in the following link:


Apache TomEE




Apache TomEE is an open source Java EE 6 Web Profile server, it is based on Tomcat with EE features, that's the reason of its name “TomEE” pronounced as "Tommy”. It is practically new its first release came out in April of 2012, but it is gaining popularity and it has the support of the apache community.

TomEE server supports more JEE specifications than tomcat such as Enterprise JavaBeans, Java Persistence API (JPA), and others. It comes in different packages each with different specifications, the following table shows a comparison of the different packages.



















TomEE uses other project to provide the specifications:
  • CDI - Apache OpenWebBeans
  • EJB - Apache OpenEJB
  • JPA - Apache OpenJPA
  • JSF - Apache MyFaces
  • JSP - Apache Tomcat
  • JSTL - Apache Tomcat
  • JTA - Apache Geronimo Transaction
  • Servlet - Apache Tomcat
  • Javamail - Apache Geronimo JavaMail
  • Bean Validation - Apache BVal
  • JAX-RS - Apache CXF
  • JAX-WS - Apache CXF
  • JMS - Apache ActiveMQ
  • Connector - Apache Geronimo Connector


Use the following link for more information:


Glassfish


Glassfish is an open source Java EE application server sponsored by Oracle, it works as a reference implementation of the latest Java EE specifications. Its latest version Glassfish 4 supports the Java EE 7 specifications, so it should support all the specifications shown in figure 1.

 It makes use of some others opens source projects to implement the specifications:












Also Oracle provides a commercial version of this server which offers support. The following links will provide more information.



Geronimo



Apache Geronimo is an open source server, it is Java EE 6 certified and it is based in OSGI offering a more modular design.

Geronimo also uses other source projects to implement the specifications:
  • OpenEJB
  • OpenJPA
  • ActiveMQ
  • Tomcat
  • Jetty
  • TranQL


In the following link you can find a list of all the components or projects used in geronimo:

Geronimo home page:





JBoss Wildfly and Jboss AS



Wildfly formerly JBoss AS is an open source Java EE server now sponsored by Red Hat. Wildfly is still in alpha version but it would've be the Jboss AS 8 version. It supports the Java EE 7 specifications shown in “figure 1”, and it is based in OSGI offering a more modular design.

It makes use of some others opens source projects to implement the specifications, such as:


Red hat also offers a commercial version of Wildfly named JBoss EAP and it has all the benefits of a commercial product such as support, extra tools and many others. Its fees are not cheap it will probably cost tens of thousand of dollar, so be careful at the time of choosing a commercial server, the following link is a calculator from RED HAT so you can get an idea about the fees http://www.redhat.com/promo/eap_calculator/

Some of the links where you can find more information about Jboss are:



Weblogic



Oracle WebLogic Server is a commercial Java EE application server, its latest version is weblogic 12 is a Java EE 6 Full Profile, so the Java EE 6 specifications are supported. The following image shows the platforms supported by Weblogic.


















As it is commercial counterpart from redhat, oracle provides support and many tools for maintain the server, but is not a cheap server it will probably cost tens of thousand of dollar also. The following link is a pdf about the costs so you can get an idea about the fees:

Some of the links where you can find more information about Weblogic are:


Websphere 


IBM WebSphere Application Server is a commercial Java EE application server, its latest version is WebSphere 8, it is JEE6 certiļ¬ed based in OSGI offering a more modular design, some of the features they include are:

● Enterprise JavaBeans (EJB) 3.1
● Java Servlet 3.0
● Contexts and Dependency Injection for Java (CDI) 1.0
● Bean Validation 1.0
● Java Architecture for XML Binding (JAXB) 2.2
● Enterprise Web Services 1.3
● Java API for XML-Based Web Services (JAX-WS) 2.2

The Operative Systems supported are:




















As it is commercial as Weblogic and JBoss EAP, it comes with all the benefits from a commercial product but also its fees, the following image shows how much could it cost to have Webshpere:








In the following link more information about websphere can be found:

FUJITSU

FUJITSU Software Interstage Application Server is a commercial server and support standards such as Java EE, Web Service, and CORBA. Interstage Application Server component technologies and development frameworks.

It has support for the following features:
























The OS supported are:
  • Microsoft Windows Server 2008 R2
  • Microsoft Windows Server 2008
  • Microsoft Windows Server 2003 R2
  • Microsoft Windows Server 2003
  • Windows Azure Guest OS 1.18~(4)
  • Windows Azure Guest OS 2.6~(4)
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 5
  • Solaris 11
  • Solaris 10

For more information about fujitsu server go to the following links:

JEUS

TmaxSoft's JEUS is a commercial Java EE certified application server. It supports the following specifications:



















JEUS offer support for clustering, load balancing and has tools for the development and administration process.

For more information about JEUS go to the following link:




JONAS


OW2 Jonas is an open source Java EE application server, it is Java EE 5 certified and has a Java EE 6 preview version, is based in OSGI offering a more modular design.

Jonas use other opens source projects to implement the specifications, and since it is based on osgi different options and you can choose what project to use:















OW2 do not offer a commercial version of Jonas server but it offers a support subscription for professional support and training, it has tools for managing and clustering but they are for free.

In the following link more information about JONAS can be found:



Resin 


Resin is a commercial Java application server by Caucho, it supports the Java EE 6 Web Profile. It supports Servlet, JSP, JSTL, EJB, Candi (Java CDI), JSF, JPA, and more. It is a lightweight server designed with CDI.It has Java monitoring and OS monitoring facilities available via built-in console or third party applications via JMX and REST



















It has support for clustering and tools for application deployment, distributed caching, load balancing and messaging, and so on.

Resin can be used with Amazon Web Services for cloud deployment. More information about resin and amazon can be found in the following link:

The prices of the licenses of resin can be found in the following link:

Resin has an open source version http://resin.caucho.com/ , the differences between the open source and the commercial version, is the amount of tools offered by the commercial version, in the following link a comparison between the two versions can be found:

For more information about resin go to the following link:

Well these are the most known options that can be found for a JEE server, I try to list some of its features and useful links. As I said before this is not a benchmark, but for choosing one server first you have to check if you want a commercial option or open source option, then check what options are among between your budget and then evaluate these options, its features, the support, if it is open source the community support, the documentation and so on.

And finally here is a link where you can find which servers are compatible with each JEE profile:


Sunday, August 4, 2013

Java Collections Framework Part 7 - Collections Utility

Collections Utility class
The java.util.Collections class is an utility class, an utility class defines a set of static methods that perform common operations, all the methods of Collections are public and static.

The java API says about the Collection class “This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends”.

The Collections class has methods for changing the order of lists:

void reverse(List<?> list): Reverses the order of the elements
void rotate(List<?> list, int distance): Rotates the elements in the specified list by the specified distance.
void shuffle(List<?> list): Randomly permutes the list elements
void shuffle(List<?> list, Random rnd): Randomly permutes the list using the randomness source rnd
<T extends Comparable<? super T>> void sort(List<T> list): Sorts the supplied list using natural ordering
<T> void sort(List<T> list, Comparator<? super T> c): Sorts the supplied list using the supplied ordering
void swap(List<?> list, int i, int j): Swaps the elements at the specified positions

It has methods for changing the contents of a list, the copy() transfers elements from the source list into an initial a the destination list, the fill() replaces every element of a list with a specified object and replaceAll() replaces every occurrence of one value in a list with another.

<T> void copy(List<? super T> dest, List<? extends T> src): Copies all of the elements from one list into another
<T> void fill(List<? super T> list, T obj): Replaces every element of list with obj
<T> boolean replaceAll(List<T> list, T old, T new): Replaces all occurrences of old in list with new.

It has methods for finding elements in ordered collections:

<T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll): Returns the maximum element using natural ordering.
<T> T max(Collection<? extends T> coll, Comparator<? super T> comp): Returns the maximum element using the supplied comparator
<T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll): Returns the minimum element using natural ordering
<T> T min(Collection<? extends T> coll, Comparator<? super T> comp): Returns the minimum element using the supplied comparator
<T> int binarySearch(List<? extends Comparable<? super T>> list, T key): Searches for key using binary search
<T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c): Searches for key using binary search
int indexOfSubList(List<?> source, List<?> target): Finds the first sublist of source which matches target
int lastIndexOfSubList(List<?> source, List<?> target): Finds the last sublist of source which matches target

Some methods require that the collection should be ordered before using them otherwise their outcome will make no sense, this is the case of the binarySearch(), if the list is not ordered then the binarySearch() will return a wrong value, Example:


In the example you can see how the collection is ordered before using the binarySearch() method.

Some methods are overloaded with a version that takes a Comparator, in this case the type of the Collection doesn't have to implement the Comparable interface, Example:


In the example you can see that the List is of type Person and it doesn't implements the Comparable interface but at the time to order the collection and search it, a Comparator instance is used it.

The Collections class has methods for creating collections:

<T> List<T> emptyList(): Returns the empty list (immutable)
<K,V> Map<K,V> emptyMap(): Returns the empty map (immutable)
<T> Set<T> emptySet(): Returns the empty set (immutable)

These methods can be used to indicate there are no values, the collections returned by this methods are immutable, this means no elements can be added to them.

Example:

The previous example will throw a java.lang.UnsupportedOperationException at the time the new element was added.

There are also methods for creating collections containing only a single element.

<T> Set<T> singleton(T o): Returns an immutable set containing only the specified object.
<T> List<T> singletonList(T o): Returns an immutable list containing only the specified object.
<K,V> Map<K,V> singletonMap(K key, V value): Returns an immutable map, mapping only the key K to the value V

The collections returned by this methods are also immutable and no elements can be added to them.

Example:


The previous example will throw a java.lang.UnsupportedOperationException at the time the new element was added.

There is a method that creates a list containing a number of copies of a given object.

<T> List<T> nCopies(int n, T o): Returns an immutable list containing n references to the object o

Sometimes a collection implementation is not synchronized, in order to make a collection thread safe the Collections class provides methods for this purpose:

<T> Collection<T> synchronizedCollection(Collection<T> c);
<T> Set<T> synchronizedSet(Set<T> s);
<T> List<T> synchronizedList(List<T> list);
<K, V> Map<K, V> synchronizedMap(Map<K, V> m);
<T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s);
<K, V> SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> m);

Basically this last post is a summary of the java.util.Collections class, but if I was doing a tutorial about collections I had to add it. So with this I finish the tutorial and I hope you can find a quick reference to the collections API and learn something new.