Posted by Dario Santamaria
Sun, 17 Oct 2010 11:54:00 GMT
Questo tutorial ha lo scopo di guidarvi passo passo nella creazione e installazione di un’applicazione (Hello Android) all’interno di un dispositivo Android disponendo di un PC con distribuzione Debian Testing.
Di che cosa abbiamo bisogno:
- Un IDE per sviluppare la nostra app – Eclipse
- Android SDK – presso Google
- Un plugin per l’IDE (ADT) per poter creare il nostro package .apk
- Uno smartphone Android – Motorola Flipout
Intanto segnalo il fatto che si potrebbe utilizzare come IDE Netbeans (ne sono un utilizzatore convinto), ma il problema è che nei repositories Debian siamo attualmente fermi alla versione 6.0.1 che non supporta l’attuale plugin nbandroid :-(
Iniziamo a configurare la nostra distro per ottenere il risultato desiderato: creare un package .apk da inviare al nostro smartphone.
Read more...
Posted in Tips & Tricks, Programmazione | Tags android, debian, Eclipse, tutorial | 34 comments
Posted by Lucio Benfante
Wed, 20 Feb 2008 10:30:00 GMT
Occasionally I experienced some problems in debugging test classes using NetBeans with Maven projects. Simply, the debugger started but didn’t attach to the running tests.
Eventually I discovered the reason!
I used to configure the surefire plugin with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<useFile>true</useFile>
<forkMode>once</forkMode>
<argLine>-Xmx512M</argLine>
</configuration>
</plugin>
The problem is the argLine
parameter. It will override the parameters the Mevenide plugin will pass for debugging tests. So, I commented it in my configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<useFile>true</useFile>
<forkMode>once</forkMode>
</configuration>
</plugin>
...and now I can debug my tests!
Posted in Tips & Tricks, Programmazione | Tags debug, maven, netbeans, test | 46 comments
Posted by Lucio Benfante
Fri, 27 Jul 2007 04:42:00 GMT
(You’ll find all the code of this post in Benfante’s Utilities mini-library)
One of the futures I ‘m reappraising is the JDK 5 enhanced for statement.
I still consider it too limited, but it’s very comfortable in the simplest (and maybe common) cases.
But…what if the elements on which you want to iterate are not managed by an Iterable class?
For example, this happens with the XOM library, where the Element.getChildElements returns an instance of the Elements class, wich is neither a Collection, or an Iterable class. So, for iterating on children elements, you have to use the basic for statement:
for (int i=0; i < elements.size(); i++) {
Element element = elements.get(i);
// etc...
}
I would like to write simply:
for (Element element: elements) {
// etc...
}
So I wrote an Iterabletor
class that builds a proxy around a class, enhancing it with the Iterable interface.
Now You can write:
Iterable<Element> iterable =
new Iterabletor<Element>(elements).getIterable();
for (Element element: iterable) {
// etc...
}
Read more...
Posted in Tips & Tricks, Software | Tags for, Iterable, Iterator, proxy, reflection | 38 comments
Posted by Enrico Giurin
Wed, 11 Apr 2007 18:07:00 GMT
If you have to connect to oracle
RAC (Real Application Cluster) using
JDBC with thin driver, the classic url:
jdbc:oracle:thin:@<HOST>:1521:<SID>
doesn’t work and you get the error
ORA – 12505.
Instead, you must use this url:
jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)
(ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service)))
If you have an oracle client, like
toad, check the tsnames.ora for the correct values of
SERVICE_NAME and host.
Posted in Tips & Tricks | Tags jdbc, oracle | 105 comments | no trackbacks
Posted by Lucio Benfante
Tue, 13 Mar 2007 06:40:00 GMT
You’ll find an article in italian on the same topic in my personal blog.
In Tomcat you can define a JNDI Resource for a JavaMail session putting the following code in you Context definition:
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"
mail.smtp.host="localhost"/>
Read more...
Posted in Tips & Tricks, Programmazione | Tags bug, JavaMail, JNDI, Tomcat | 39 comments | no trackbacks
Posted by Paolo Dona'
Wed, 06 Dec 2006 07:45:00 GMT
Ciao, in un progetto su cui sto lavorando sto provando un approccio che non avevo mai usato in passato per le liste di oggetti java, immaginate che di avere una lista tipo:
List<SomeObject> list = new ArrayList<SomeObject>();
Se volessi estrarre dalla lista tutti gli elementi aventi un certo campo valorizzato ad un dato valore, ovvero fare un filtro, farei:
class SomeObject {
public static List<SomeObject> filterByField(List<SomeObject> input, String value) {
// ciclo la lista input e restituisco una lista nuova con gli oggetti che hanno field=value
}
}
usato così:
List<SomeObject> all = new ArrayList<SomeObject>();
List<SomeObject> filtered = SomeObject.filterByField(all, "someValue");
Il fatto però di avere metodi statici ‘helper’ dentro SomeObject
per aggiungere funzionalità ad una lista non mi piace molto… ho provato invece a wrappare List
e a spostare il metodo filerByValue
da SomeObject
alla nuova classe SomeObjects
:
class SomeObjects extends ArrayList<SomeObject> {
public SomeObjects filterByField(String value){
// filtro ciclando gli elementi in this e restituisco una nuova istanza di SomeObjects
}
}
Il codice di utilizzo quindi diventa:
SomeObjects all = new SomeObjects();
SomeObjects filtered = all.filterByField("someValue");
Che mi pare molto più pulito e leggible, che ve ne pare?
So che non è un gran cambiamento, ma ho un parametro in meno per ogni filterByXXX
che desidero aggiungere e ogni metodo è nel posto che gli compete, ovvero i medoti per filtrare una lista stanno nella lista e non come metodi helper dell’oggetto contenuto.
Un’altro punto dove questo approccio è utile è nei Dao che wrappano funzionalità di IBatis o Hibernate, dove si trova spesso codice di questo tipo per prevenire il ritorno di liste nulle:
List<SomeObject> result = new ArrayList<SomeObject>();
result.addAll( ...queryForList("your query", param));
return result;
Con i wrapper possiamo scrivere un costruttore ad hoc, che prende una lista in input e fa addAll(...)
solo se è diversa da null
:
public class SomeObjects extends ArrayList<SomeObject> {
public SomeObjects () {}
public SomeObjects (Collection<SomeObject> c) {
if (c!=null) addAll(c);
}
}
E il codice di utilizzo diventa magicamente:
return new SomeObjects(...queryForList("your query", param));
Fatemi sapere che ne pensate, io mi sto trovando bene con questo approccio.
_ Paolo Donà si occupa di sviluppo web in Java e Ruby, sviluppo progetti su commessa e formazione/training. Potete contattarlo via mail o leggere il suo blog aziendale o personale. _
Posted in Tips & Tricks | Tags list | 8 comments | no trackbacks
Posted by Lucio Benfante
Fri, 03 Nov 2006 16:00:00 GMT
“La vera saggezza sta in colui che sa di non sapere! Perchè io so di sapere più di te, che pensi di sapere.” (Socrate) Allora i programmatori Java dovrebbero essere molto saggi, perchè dovrebbero essere convinti di (non) conoscere null
molto bene. Ma siamo così sicuri?
Domanda 1: Di che tipo è il litteral null
?
qui prossimamente la risposta
Domanda 2: Assegnando il litteral null
ad una variabile, devo fare un cast esplicito?
qui prossimamente la risposta
Domanda 3: C’è qualche caso in cui ha senso fare un cast esplicito di un litteral null
?
qui prossimamente la risposta
Domanda 4: Assegnando il litteral null
ad una variabile, posso aspettarmi una ClassCastException?
qui prossimamente la risposta
Domanda 5: Può accadere una NullPointerException assegnando un valore ad una variabile di un tipo primitivo?
qui prossimamente la risposta
…altre? Se conoscete qualche stranezza riguardante il null
(a)…scrivete…scrivete…
Hey! Ma che razza di post è questo? L’idea è di dare degli argomenti di discussione legati principalmente alla conoscenza delle basi del linguaggio Java.
Da tali discussioni deriverà sicuramente una migliore conoscenza di alcuni aspetti di base del linguaggio, necessari, ad esempio, per superare le certificazioni Programmer e Developer, ma anche, magari, per programmare un po’ meglio.
Quindi, commentate…commentate…Chi darà la risposta megliore se la vedrà riportata sopra (o eventualmente un mix delle risposte migliori), con ovviamente il riconoscimento della paternità, o maternità, nel caso delle gentili signore che vorranno cimentarsi.
Posted in Tips & Tricks | Tags certification, java, quiz | 9 comments
Posted by Lucio Benfante
Wed, 11 Oct 2006 14:06:00 GMT
A proposito della classe java.lang.Math…
Domanda 1: E’ possibile estenderla, creando una nuova classe che deriva da essa?
Lost: No, la classe java.lang.Math è stata definita final e quindi non è possibile estenderla.
Domanda 2: Ha senso crearne un’istanza?
Lost: No, la classe java.lang.Math non ha costruttore pubblico.
…altre?
Hey! Ma che razza di post è questo? L’idea è di dare degli argomenti di discussione legati principalmente alla conoscenza delle basi del linguaggio Java.
Da tali discussioni deriverà sicuramente una migliore conoscenza di alcuni aspetti di base del linguaggio, necessari, ad esempio, per superare le certificazioni Programmer e Developer, ma anche, magari, per programmare un po’ meglio.
Quindi, commentate…commentate…Chi darà la risposta megliore se la vedrà riportata sopra (o eventualmente un mix delle risposte migliori), con ovviamente il riconoscimento della paternità, o maternità, nel caso delle gentili signore che vorranno cimentarsi.
Posted in Tips & Tricks | Tags certification, java, quiz | 9 comments | no trackbacks
Posted by Lucio Benfante
Sat, 01 Apr 2006 07:45:00 GMT
Mustang will be the next release of the Java Standard Edition (Java SE 6). At present Mustang is in beta, it will be delivered in Autumn 2006.
One of the new desktop features
of Mustang is the capability of showing a splash screen even before the starting of the Java Virtual Machine.
You can configure the splash screen by command line:
java -splash:mysplash.gif MyApplication
…or, if your application is packaged in a JAR file, using the SplashScreen-Image option in the manifest file:
Manifest-Version: 1.0
Main-Class: MyApplication
SplashScreen-Image: mysplash.gif
For testing this new cool feature of Mustang, I wrote a small example, with some supporting classes. For trying it you can download the Splasher.jar file from here. Execute it using:
…of course you have to download and install Mustang.
Read more...
Posted in Tips & Tricks | Tags desktop, Mustang, splash screen | 40 comments