background preloader

Java

Facebook Twitter

Monocaffe (dead): Java Template Engines, fight! One of the greatest features Java provides for enterprise applications, are the many frameworks, libraries and tools provided by many third-party developers.

monocaffe (dead): Java Template Engines, fight!

In the web development front, we find many useful resources and today I'm gonna compare the most popular template systems a Java developer will find. Basically, instead of using several HTML pages, you produce some templates which allows you to easily maintain most of the static content of a site without having to touch 40 different files. This way, if we want to modify the header of any site, simply by editing our header template, all the headers on our site will change. A template system is comprimised of three main components: Template EngineContent ResourceTemplate Resource You can find more information about the theory behind template systems in the Wikipedia Entry. J2EE Templates Our candidates are:FreemarkerVelocityStringTemplateMVEL Freemarker License: BSD-style Tested Version: Dependencies: None Advantages: Disadvantages: Apache.

Groking Enum (aka Enum<E extends Enum<E>>) Groking Enum (aka Enum 09 Feb 2004 ← →

Groking Enum (aka Enum<E extends Enum<E>>)

La sérialisation binaire en Java. La sérialisation en Java s'appuie sur les flux (voir ce tutoriel sur le package java.io), c'est pourquoi une certaine connaissance de ceux-ci est souhaitable pour aborder ce tutoriel en toute sérénité.

La sérialisation binaire en Java

L'API Java nous fournit les outils nécessaires à la sérialisation suivants : l'interface Serializable la classe ObjectOutputStream la classe ObjectInputStream L'interface Serializable permet d'identifier les classes sérialisables, les classes ObjectOutputStream et ObjectInputStream implémentent, quand à elle, les mécanismes de sérialisation et de désérialisation afin de nous les abstraire. Nous avons aussi à notre disposition l'interface Externalizable qui nous permet d'implémenter notre propre mécanisme de sérialisation. II-A. Afin de pouvoir sérialiser un objet d'une classe donnée, celle-ci doit implémenter l'interface Serializable ou hériter d'une classe elle-même sérialisable.

II-B. Déclaration du serialVersionUID Sélectionnez private static final long serialVersionUID = 42L; Java - How to serialize an object into a string. Le Singleton en environnement Multithread. Le design pattern singleton fait partie des plus utilisés en programmation.

Le Singleton en environnement Multithread

Il permet de s'assurer qu'il n'y a qu'une seule instance d'une classe dans un environnement d'exécution et pour une durée d'exécution : Pour plus de détails. Toutefois, dans un environnement multithread, l'utilisation de ce pattern nécessite quelques précautions pour limiter les problèmes d'accès concurrents. Dans cet article, nous allons évoquer le problème du singleton en environnement multithread. 2.1. Description▲ Le principe du singleton repose sur un constructeur déclaré privé, un attribut permettant de stocker l'instance de la classe et une méthode statique qui vérifie qu'une instance de la classe a été créée et la renvoie. Import java.util.* ; class Singleton{ private static Singleton instance; private List maList; private boolean etat; private Singleton(){ maList= new ArrayList(); etat = true; } public static Singleton getInstance(){ if (instance==null) instance=new Singleton(); return instance; }}

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded. More with Java enums: simulating inheritance. Java Tip 98: Reflect on the Visitor design pattern. Collections are commonly used in object-oriented programming and often raise code-related questions.

Java Tip 98: Reflect on the Visitor design pattern

For example, "How do you perform an operation across a collection of different objects? " One approach is to iterate through each element in the collection and then do something specific to each element, based on its class. That can get pretty tricky, especially if you don't know what type of objects are in the collection.

If you wanted to print out the elements in the collection, you could write a method like this: public void messyPrintCollection(Collection collection) { Iterator iterator = collection.iterator() while (iterator.hasNext()) System.out.println(iterator.next().toString())} That seems simple enough. Public void messyPrintCollection(Collection collection) { Iterator iterator = collection.iterator() while (iterator.hasNext()) { Object o = iterator.next(); if (o instanceof Collection) messyPrintCollection((Collection)o); else System.out.println(o.toString()); }} Conclusion.