Pages

Sunday, June 29, 2008

I found another Sun Java Creator 2 example for using a custom validator. This may have also been an example from Creator, but I updated its project files to work with Netbeans 6.1. I updated the project so that the original visual JSF files can still be manipulated visually.

Saturday, June 28, 2008

I came across an old Sun Java Studio Creator 2 custom message example. This may have originally been an example project on the IDE. I am not sure so I can not make claim to doing the original coding. I did however bring it up to speed on Netbeans 6.1. I transferred the code and updated the project so that it will build and it works very nicely. The result is a page which prompts you for a value and should you submit it without one, it will pop up an error message.

Here is another example of how to use a common file handling mechanism in Java. RandomAccessFile is very powerful tool to open a file and find specific items in it. It also allows you to update, delete, or append data to the file. Developers become accustomed to using File for a number of operations, but I contend that using RandomAccessFile is more powerful and flexible.

In the code example and Netbeans project that follow, I create a file and append data to it. I print the data out, and then add the class name to the beginning of the file, append the existing data, and print it back out again.

I originally came across my work on it when I was learning Java many years ago. I re-examined it, tweaked it, and converted it to a Netbeans project.

Friday, June 27, 2008

Someone from our users group posed a good question. Should you put the current directory in the CLASSPATH? Does it represent any security issues like on UNIX?

Here is the answer...depends, but it is generally a bad idea. Here is an example. I created a class called TestCase. It calls another class called ClassA in a jar file called ExampleJar.jar. I put another class called ClassA in the current directory and set the CLASSPATH as a passed parameter

The Classloader finds the first instance of the class which matches the appropriate signature and loads it. Subsequent classes of the same name and signature are not loaded.

Why does it matter?

The inclusion of the current directory into the CLASSPATH represents a potential security risk, also it may produce unexpected results from similarly named classes. The second item may be a bit more contrived in general terms, i.e. com.abc.ClassA and com.cba.ClassA are called ClassA, but are in different packages. This will not represent a problem.

The security issue can be real. A lot of programs that do installs on Windows specifically, add the CLASSPATH variable to the Windows environment and put the . (period) first. I checked my installation and found it to be the case. I would not knowingly put it there myself. Also I checked a couple of tutorials which suggest that you should do it for convenience. That piece is quickly forgotten 200 pages ago.

ADDENDUM:

Java 6 SE (J6SE) has added some additional enhancements around classpath. You can use the * (asterisk) wildcard to include all files in the classpath:

Tuesday, June 24, 2008

I was cleaning up my system and looking at code samples from over the years. I came across an example Job using the Quartz Scheduler to connect to an HSQLDB database and reading the information about the session. I thought I would update it a little and post it.

Requirements:

You must have an HSQLDB database running in server mode.

package com.bluelotussoftware.quartz.example;

/* * HSQLJob.java * */

/* * Copyright (C) 2008 Blue Lotus Software. All Rights Reserved. * * THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT A WARRANTY OF ANY KIND. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. * BLUE LOTUS SOFTWARE, LLC AND ITS LICENSORS SHALL NOT BE LIABLE * FOR ANY DAMAGES OR LIABILITIES * SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE, MODIFICATION * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL * BLUE LOTUS SOFTWARE, LLC OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED * AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE * OF OR INABILITY TO USE SOFTWARE, EVEN IF BLUE LOTUS SOFTWARE, LLC * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. */

/* * Copyright 2008 John Yeary * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.sql.SQLException;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;

/* * Copyright (C) 2008 Blue Lotus Software. All Rights Reserved. * * THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT A WARRANTY OF ANY KIND. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. * BLUE LOTUS SOFTWARE, LLC AND ITS LICENSORS SHALL NOT BE LIABLE * FOR ANY DAMAGES OR LIABILITIES * SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE, MODIFICATION * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL * BLUE LOTUS SOFTWARE, LLC OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED * AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE * OF OR INABILITY TO USE SOFTWARE, EVEN IF BLUE LOTUS SOFTWARE, LLC * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. */

/* * Copyright 2008 John Yeary * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.text.ParseException;import org.quartz.CronTrigger;import org.quartz.JobDetail;import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.quartz.SchedulerFactory;import org.quartz.impl.StdSchedulerFactory;

I really liked the book because it assembled a number of political and social theories into a readable and digestible items. The Broken Windows Theory, which makes hypothesized that if a vacant building gets a broken window, you should fix it as soon as possible. The consequences of not-fixing it result in people assuming that no one really cares. The result is the rest of the windows getting broken. If you fix the window, then it is likely that no further damage will be done. This policy was implemented in New York in the 1990s. The result was a dramatic reduction in crime, and vandalism. This is the case of making a small change which results in further downstream effects. The explanation in the book is insightful and makes these theories easy to understand.

How does it relate to software and technology? It covers a methodology for making trends and social behaviors "stick". The ideas covered in the book speak in terms of epidemics. Those who understand viral expansion loops (viral marketing) will be able to understand the book and its underlying premises. If you are looking for some material on viral expansion loops (Viral Marketing), there is a really good one on Fast Company which is very well done. Fast Company had a cover article for May 2008 on CEO Gina Bianchini of Ning. They mention the use of viral expansion to attempt to grow Ning into a social powerhouse.

The book details items on how to make things stick, and how to spread the word about something. My stickiness factor is how to make social networks stick. For example, why is Facebook becoming more popular than MySpace. Why do people use LinkedIn? What benefits are there to blogging. This book can provide a wealth of information into social and environmental factors which make software and technologies popular.

The book is a real quick read, and I would recommend it with 4/5 stars.

Wednesday, June 18, 2008

If you are trying to insert values into a table which has an identity column, the documentation is not very clear. If I create a table in an Apache Derby (JavaDB) database which has a primary key which is generated always, the syntax for doing a query based insert is a little different.

After setting <scripting-invalid>true</scripting-invalid> The page willthrow an exception is there are any JSP scripting elements on the page.

I went back and set the value back to false and set the <el-ignored>false</el-ignored>This causes the container to treat the EL syntax as literal text.The result is what you would expect. The only values diaplayed are JSP script.

The question is why would you want to go through the effort... If you were doing work on JSP pagesprior to JSP 2.0, you may have used some syntax similar to EL which you may not wantto have translated.

Turning off scripting forces the developer to use Java Standard Tag Libraries (JSTL)and Expression Language (EL). This ensures a cleaner separation of code frompresentation in the MVC paradigm.

At the Greenville Java Users Group (GreenJUG) meeting the other night, the topic of auto comments for Javadocs was brought up. In Netbeans 6.1, if you enter a method and then starting typing /** / on the method it will create Javadoc comments for you. For example,

private String fx(String x) {return x;}

Next add a Javadoc comment /** */ and you will end up with something like this:

/**** @param x* @return*/private String fx(String x) {return x;}

This is a great start to your comments.

There is a plugin in the Netbeans Development Center called Javadoc Analyzer. Download and install this plugin. It will provide you with some cool additional functionality.

In this screenshot I have created a servlet using the Netbean defaults which include some default Javadoc comments. I then ran the Analyze Javadoc menu item under Source. You can see it found a number missing tags including some on the visible text.

Saturday, June 07, 2008

I decided to change the look and feel of my blog. I went with a more minimalist design. I wanted to make sure that I could add content more easily, and that the constraints of the template would not interfere with the content.

I am hoping to add more content and links to the site. I have a couple of tutorials, and book reviews I am working on right now.