5 motivi per passare alla piattaforma J2SE 5 (Tiger)

Comments Off

Interessante articolo di Calvin Austin, in cui vengono presentati e discussi cinque motivi che dovrebbero invogliare il passaggio alla nuova versione J2SE 5.0, eccoli riassunti:

Five Reasons to Move to the J2SE 5 Platform:

  1. your application already works on 5.0
  2. it is faster
  3. reduced development time
  4. ready for Mission-Critical Systems
  5. you Are in Good Company

Java 2 Platform Standard Edition (J2SE) 5.0 (”Tiger”)

No Comments »

La versione della nuova release Java 1.5, conosciuta come Tiger, ha introdotto molte interessanti e utili features.

Le ho provato ad utilizzare all’interno dell’IDE Eclipse, versione 3.1 M3 che dichiara di supportare la J2SE 5, seppur ancora non completamente.
Bisogna, ovviamente aver installata la J2SE 5 e impostare correttamente Eclipse, andando in Window | Preferences, selezioanere Java | Compiler | Compliance and Classfiles e impostare i valori come mostrato in figura:

eclipse setting

Vediamo le nuove features:

Generic Types

Permetti di evitare in molte circostanze l’utilizzo del casting, evitando cos’ che si verifichino delle eccezioni ClassCastException in fase di esecuzione. E’ possibile utilizzare i generic type nelle Collections: LinkedLists, ArrayLists, HashMaps …
List<Integer> myList = new ArrayList<Integer>();
myList.add(new Integer(10));

Autoboxing and Auto-Unboxing of Primitive Types

Permette la conversione automatica fra i tipi primitivi (int, boolean) e l’equivalente oggetto java (Integre, Boolean). Questa nuova feature non è ancora supportata da Eclipse.
//old style
Integer classInteger = new Integer(10);
int primInt = classInteger.intValue();
//new 1.5 style
Integer newInteger = 10;
int newPrimInteger = newInteger;

Enhanced for Loop

Possibilità di scorrere sequenzialmente le collections in maniera più semplice.
//old style
List theList = new ArrayList();
theList.add(new Integer(10));
for(Iterator it = theList.iterator(); it.hasNext(); ) {
Integer currObject = (Integer) it.next();
System.out.println("old -> "+currObject.toString());
}
//new 1.5 style
List<Integer> myList = new ArrayList<Integer>();
myList.add(new Integer(10));
//Autoboxin not supported bye Eclipse 3.1M3
//myList.add(100);
for (Integer currObject : myList) {
System.out.println("new -> "+currObject.toString());
}

Enumerated Types

Gli Enumerations è un insieme di valori che possono essere assegnati ad un varabile. Evita la necessità di dichiarare una variabili static final per ogni valore.
public enum Month {
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
};



Month theMonth = Month.DECEMBER;

Formatted Output

Possibilità di formattare l’output in maniera molto simile al C.
// %n: cross-platform support of newlines the Java (\n)
System.out.printf("name count%n");
String user="luke";
Integer total=new Integer(12);
System.out.printf("%20s %5d%n", user,total);

Varargs

Permette di dichiarare funzioni con un numero arbitrario di parametri.
public static int min(int... values) {
if (values.length == 0) {
throw new IllegalArgumentException("No values supplied.");
}
int min = Integer.MAX_VALUE;
for (int i : values) {
if (i < min)
min = i;
}
return min;
}



System.out.println(”min(2,4) -> ” + min(2,4));
System.out.println(”min(20,6,8,1) -> ” + min(20, 6, 8, 1));

Concurrency Utilities

Il nuovo package java.util.concurrent contiene alcune comodi oggetti per gestire la concorrenza in un processo multithread.
int balance = 0;
// for non-blocking version use s.acquire()
System.out.println("lock");
s.acquireUninterruptibly();
try {
// protected value
balance = balance + 10;
} finally {
// return semaphore token
System.out.println("unlock");
s.release();
}
System.out.println("balance="+balance);

Metadata (Annotations)

Un’altra nuova funzionalità molto utile introdotta in Java 5 è quella relativa ai Metadata (Annotations) che permette di marcare ed associare particolari valori alle classi, alle interfacce e ai metodi.
Questi dati possono essere utilizzati dal compilatore o da altri tools, oppure memorizzati nella classe e recuperati runtime attraverso la Java Reflection.
@Test public static void myTest() {
...
}

FreeTTS: a speech synthesizer written in Java

Comments Off

FreeTTS permette di far “parlare” (in inglese) i proprio programmi Java!

FreeTTS è basato su Flite: un leggero run-time speech synthesis engine sviluppato dalla Carnegie Mellon University. Flite deriva da Festival (Speech Synthesis System della University of Edinburgh) e da FestVox (Carnegie Mellon University).

Provare per credere …

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in