Wednesday, June 24, 2009

JCaptcha

JCAPTCHA stands for Java Completely Automated Public Test to tell Computers and Humans Apart.

The open source java framework for captcha definition and integration.

I have done a sample program and the program code snippet is shown below :








































The output of the program as follows :


Tuesday, June 23, 2009

Java SE 7 & Java EE 6

Java 7 is expected to be released Feb 2010. Based on last year's conference notes and milestones released this year already, many thought (including myself) that Java 7 would be released sooner. The last feature-complete milestone is scheduled for Oct 2009. I attended a few sessions that discussed what will be in Java 7. Everyone was careful to say that the final decisions hadn't been made yet, indicating there is still work being done on Java 7. Some of the things likely to be in Java 7...
1. modules (allowing you to customize the features of Java you need for your app and finally killing the classpath)
2. null check operator/conditional - "?:"
3. Strings in switches
4. multiple exception catches in the catch block (using "")
5. diamond operator to allow the generics to be more easily used.
//For example...
HashMap> map = new HashMap>();
//becomes
HashMap> map = new HashMap<>();

Things not likely to make Java 7 but at one time rumored to have a chance...
1. closures
2. SQL expression checking

Java EE 6 will actually come out sooner. Java EE 6 is due on in final form in Sept 2009. In this release, the big new features are:
1. JAX-RS (support for RESTful web services)
2. JSF 2.0
3. Asynch servlets
4. Bean validation (adding validation to JavaBeans that can be used to validate property data anytime they are used).
5. Web.xml is gone (at least it can be gone) with the use of annotations and/or web.xml fragments.
6. Web beans - essentially session beans in the WAR file.

A few other notes from the conference...

Eclipse Galileo is the next train release of Eclipse (following the previous year releases of Calisto, Europa, and Ganymede) and it will come out on June 24th. This release now includes 33-48 Eclipse projects (Ganymede included 24 projects). On Jun 26, there will be a live Webinar to learn about new features. From the talk, I wouldn't say there is any real big thing in this release that most of us would use on a regular basis.

Spring has a new project called Spring Roo (yes for kangaroo). Essentially, this is Rails or Grails but all in Java and Spring. Meta programming is here to stay folks. I hope to have more on that in a later blog posting.

Wednesday, June 17, 2009

JDBCAppender

The JDBCAppender provides for sending log events
to a database.

To Configure this feature with Log4J, you need to
include the jdbcappnder.jar.

A sample log4j configuration is attached with the database
log facility for your further reference.
I have used this in our KF project.














Similarly, if you need to send an email using Log4j
you can do it as follows.



When to call isDebugEnabled() before writing debug messages

When using a logging framework like log4j most developers never check whether debug is enabled before writing a debug message or always makes the check. The theory behind it is to prevent unnecessary string concatenations if debug messages are disabled, which is the case most of the times on production environments.

logger.debug("Saved order successfully. Order ID : " + order.getId() +
" items in order " + order.getItems().size())
;

In the above case there is a new string object created by concatenating all the parameters before making the call to debug method. This is done regardless of debug is enabled or not which will be a unnecessary performance overhead if debug is disabled.

if( logger.isDebugEnabled()){
logger.debug("Before saving the order");
}

In the above code section the if condition is not necessary as there is no String concatenations involved and ends up adding two redundant lines of code.

Therefore the rule would be to do a isDebugEnabled check only if there is any String concatenation involved in the call to debug. This seems to be obvious but developers somehow keep getting this wrong.

Chart generation library: JFreeChart

JFreeChart is a free Java class library for generating charts, including:
  • Pie charts (2D and 3D);
  • Bar charts (regular and stacked, with an optional 3D effect);
  • Line and area charts;
  • Scatter plots and bubble charts;
  • Time series, high/low/open/close charts and candle stick charts;
  • Combination charts;
  • Pareto charts;
  • Gantt charts;
  • Wind plots, meter charts and symbol charts;
  • Wafer map charts;

PDF file creation: iText

iText is a free Java class library to create PDF files.

Features:
  • Barcode generation with or without fonts (Code 39, Code 128, EAN13, EAN8, UPCA, UPCE, and EAN with supplemental 5, EAN with supplemental 5, EAN with supplemental 2, Interleaved 2 of 5, Postnet and Planet)
  • PDF encryption
  • Headers and footers
  • Absolute positioning of graphics (PNG, GIF, JPEG, WMF) and text
  • Table support (see also the more advanced PDFTable class)
  • Metadata manipulation
  • HTML output
  • RTF output
  • Local and remote goto, destinations and outlines
  • Includes tools to concat, split, create a handout and encrypt PDF files

Tuesday, June 16, 2009

Measuring execution times: SpeedTimer