This is an old revision of the document!
Table of Contents
Apuntes de Java
Varias notas sobre java.
<WRAP column 30%> Application servers
Frameworks and Tools
Standards
- http://wiki.metawerx.net/wiki/Web.xml - toda la documentación sobre “web.xml”
Recipes
Projects
Miscellaneous
</WRAP>
About software tools to synchronize with subversion
2013/03/22 update: I've tried subversion in a Windows machine and I found out that it doesn't work because it requires a connector and the instructions to download the connector are not easily found. I recognize that I gave up at first difficulty, but talking about plugins, I don't give them many opportunities. Moreover, I found that the subclipse plugin has more popularity.
I have a 64 bit laptop –Intel–. I usually develop java in there. I found that the subclipse plugin for subversion crashes frequently, but the Subversive doesn't. For anyone that may be interested.
And by the way, if you are planning to download something from sourceforge, choose SVN Kit 1.3.2 connector compatible with version 1.6.x of subversion. See this: http://sourceforge.net/scm/?type=svn&group_id=80882.
Configure a C3P0 datasource in spring
Launching a java batch file from a visual basic script
' ' sisyphus.vbs ' dim osh dim classpath classpath="./;./CopyTables.jar;./lib/*" set osh = createobject("wScript.shell") ' get the variables of the "process" environment set objEnv = osh.Environment("Process") objEnv("CLASSPATH") = classpath osh.run "java App -Dorg.apache.commons.logging.Log=log4j.properties >> console.log 2>>error.log",1
¿Qué tarda más???
Con frecuencia veo construcciones como ésta:
if(logger.isInfoEnabled()){ logger.info("Prueba de log"); }
En el código Java de otros. “Es para que vaya más rápido” me dicen. Muy bien. Vamos a comprobarlo: he hecho un programa de prueba (ver abajo) a ver qué construcción tarda más: si con el isInfo or isDebug o lo que sea, o sin él.
Me he llevado la sorpresa de que es más rápido sin el if
… justo lo que yo pensaba.
Otra mas: para el ejemplo del programa (1.000.000 de ejecuciones) la diferencia es de un segundo. Es decir, la comprobación tarda un microsegundo en hacerse.
No merecería la pena, aunque el resultado fuera al revés: la legibilidad del código es mejor cuanto más simple.
import java.io.File; import java.util.Date; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class App { public static final int ERROR_CODE = -1; public static final int OPERATION_OK = 0; /** * @param args */ public static void main(String[] args) { String log4jFile = "c:/workspace/LogTester/src/log4j.properties"; // deletes the log file prior to do the test File deleter = new File("c:/temp/logtester.log"); deleter.delete(); // start the logger tester Logger logger = Logger.getLogger("tester"); PropertyConfigurator.configure(log4jFile); Date start1 = new Date(); for( long count1 = 0; count1 < 1000000; count1++ ) { if(logger.isInfoEnabled()){ logger.info("Prueba de log"); } } Date end1 = new Date(); Date start2 = new Date(); for( long count2 = 0; count2 < 1000000; count2++ ) { logger.info("Prueba de log"); } Date end2 = new Date(); System.out.println( "con comprobacion tardó: " + (end1.getTime() - start1.getTime())/1000 + " segundos " ); System.out.println( "SIN comprobacion tardó: " + (end2.getTime() - start2.getTime())/1000 + " segundos " ); } }
Formatear fechas y números
Un ejemplo de tres formateadores: uno para fechas, otro para horas, y otro para números. Estos formateadores van a usar los formatos “a capón” en lugar de usar los que provee por defecto Locale, que debería ser la forma correcta de usarlos para que la aplicación fuese internacionalizable.
import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.Locale; SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat formatDateFecharea = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm"); DecimalFormat formatNumber = new DecimalFormat("#,###.##"); DecimalFormatSymbols symbols2 = new DecimalFormatSymbols(Locale.US); DecimalFormat formatNumberUS = new DecimalFormat("#,###.##", symbols2 );
Parsing a Date in Java
try { // Some examples DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); Date date = (Date)formatter.parse("01/29/02"); formatter = new SimpleDateFormat("dd-MMM-yy"); date = (Date)formatter.parse("29-Jan-02"); // Parse a date and time; see also // Parsing the Time Using a Custom Format formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); date = (Date)formatter.parse("2002.01.29.08.36.33"); formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); date = (Date)formatter.parse("Tue, 29 Jan 2002 22:14:02 -0500"); } catch (ParseException e) { }
Example taken from http://exampledepot.com/egs/java.text/ParseDate.html.
Recursos Java
Java básico
Manejo de propiedades (properties) en java
El formato de los ficheros de propiedades (properties) en java
J2EE
API's de Java
Hay dos: una es la de la “Standard Edition”, que contiene lo más básico:
http://java.sun.com/javase/6/docs/api/
Y la otra es la “Enterprise Edition” que contiene paquetes y clases para el desarrollo de aplicaciones web, servicios y programación con xml: