Wednesday, February 28, 2007

Java Case or Switch Example

How do you use the CASE function in Java?

The Switch or Case function in Java is useful for branching off to different actions based on a conditional expression. For example if you have a series of categories that can be selected and depending on which category was selected, you want the program to do a different action, the Case function is the best way to do this.

Here is the syntax

    switch( expression ) {
case value1:
case value2:
case value3:
case valuen:
statement n;

A real example of this from the Sun website:

int month = 8;
switch (month) {
case 1: System.out.println("January"); break;
case 2: System.out.println("February"); break;
case 3: System.out.println("March"); break;
case 4: System.out.println("April"); break;
case 5: System.out.println("May"); break;
case 6: System.out.println("June"); break;
case 7: System.out.println("July"); break;
case 8: System.out.println("August"); break;
case 9: System.out.println("September"); break;
case 10: System.out.println("October"); break;
case 11: System.out.println("November"); break;
case 12: System.out.println("December"); break;
default: System.out.println("Invalid month.");break;

Tuesday, February 27, 2007

String Parsing in Java

In Awk you can easily find the position of a delimiter and then take all characters up to that point by using the index() and substr() functions. But how does that work in Java? Is there an easy way to parse a String and carry out these type of routine actions?

Here you go:

subtring method:

int start = 1;
int end = 4;
String substr = "aString".substring(start, end); // Str
index method:
String string = "madam, i am Adam";
// First occurrence of a c
int index = string.indexOf('a'); // 1
Here is a live example I am working with where I need to parse the String into two variables as my webpage is passing me a parameter that is pipe-delimited:

String str = "YES|12345";

int pipe = str.indexOf('|'); //4

String firstPart = str.substring(1,pipe-1);
String lastPart = str.substring(pipe+1);


The DECODE function in Oracle SQL is used for if-then-else statements. A very handy tool for powerful queries.

The syntax for the DECODE function is as follows:

DECODE(value, if1, then1, if2, then2, if3, then3, etc., else)

Here is a good example of this from the website:

Consider the following example in which the Viewable column can have values of 1, 2, and 3:

SELECT FirstName, Viewable
FROM employee;


John 1
Tim 2
Julie 2
Stacy 1
Rahul 3
Leena 4
Amy 1
Bill 3
Teri 3

Now, we can use Decode to display different things in a report based on the values in Viewable.

SELECT Firstname,
Decode(Viewable, 1,'VISIBLE', 2,'INVISIBLE',
FROM employee;



Decode checks the column values and interprets the provided values in pairs. This is how it works:

Switch viewable:

Case 1:
Result = VISIBLE
Case 2:
Case 3:
Result = UNKNOWN
Result = OTHER
End Case


If Viewable = 1 Then
Result = VISIBLE
Elsif Viewable = 2 Then
Elsif Viewable = 3 Then
Result = UNKNOWN
Result = OTHER
End If

One can use Decode in Updates as well. For example, instead of writing 50 different updates to change state names, we can do it in one Update using Decode as follows:

Update employee
set homestate = decode(homestate,
'AL', 'Alabama',
'AK', 'Alaska',
'AS', 'American Samoa',
'AZ', 'Arizona',
. . . . . . . .
. . . . . . . .
'WA', 'Washington',
'WV', 'West Virginia',
'WI', 'Wisconsin',
'WY', 'Wyoming' , homestate)
where homecountry = 'UNITED STATES'

This will replace state abbreviations with state names. And it leaves the abbreviations alone in case it doesn't match any of the values, such as AL, AK, etc.

Most Oracle SQL users do not realize the power of this function. Hopefully this post will enlighten some on it.

Sunday, February 25, 2007

Scientology Edinburgh

A new website was just put up for the Church of Scientology in Scotland. The Volunteer Ministers are really needed there right now with the recent train wreck.

Tuesday, February 20, 2007

Google Directory - Computers > Data Formats > Markup Languages > HTML > Tutorials

I figured its about time I learned HTML. Here is a great starting point with a plethora of tutorials, examples, etc.

Google Directory - Computers > Data Formats > Markup Languages > HTML > Tutorials

Submit Links Directory

Wednesday, February 14, 2007

Moving Data around HTML pages with JSP

Ok, I admit I never programmed a web site before. But I've recently realized the potential in using an internal website to handle administrative tasks such as tracking jobs, etc. Previously I tried doing such with a Swing based approach as this is what I was familiar with, but after consulting with a fellow programmer I chose to set up a webpage with hibernate on top of a MySql db. So far so good, however, I am looking for a crash course in HTML and JSP to get me going.

An excellent guide for this is on IBMs site under JSP Best practices. I am going through this and hopefully it will answer all my questions...

Event Viewer not showing up

What to do if the alerts in your Event Viewer do not show up? Try the refresh button in the Event Viewer. Usually this means there are too many events logged and your Event Viewer is jammed.

This happened to me after installing some new software that bunged up my machine.
Events were being logged like every minute or so and it shortly was overstuffed. I searched the net and found this suggestion in a TechRepublic forum and it worked. After refreshing I could see the events, delete the log if needed and carry on.

Friday, February 09, 2007

Java isDate Date Checker

Here is an earlier post, showing what what proposed as one solution to the Java isDate() problem:

Below is a method that simulates the Visual Basic isDate() method and is configurable so you can set what you consider are the valid date formats.
I modifed this and added the "Jan|Feb|Mar|Apr..." and "JAN|FEB|MAR|APR|..." to the regex so that the method now validates the formats I needed to check.
I am now implementing this in my application.
See this code in my earlier blog post.

However, since that time, I worked out the below which has worked wonders and I am posting it here for any others who may need such a simple tool as to convert a text string to a Date object or check if a string is a valid Date, etc. Let me know if anyone found this useful:

First load the different type of date formats that you consider valid formats:
public static ArrayList loadFormats() {

ArrayList dateFormats = new ArrayList();
dateFormats.add(new SimpleDateFormat("yyyy-MM-dd"));
dateFormats.add(new SimpleDateFormat("yyyy MM dd"));
dateFormats.add(new SimpleDateFormat("yyyy.MM.dd"));
dateFormats.add(new SimpleDateFormat("yyyy-MMM-dd"));
dateFormats.add(new SimpleDateFormat("yyyy MMM dd"));
dateFormats.add(new SimpleDateFormat("yyyy.MMM.dd"));
dateFormats.add(new SimpleDateFormat("dd-MM-yyyy"));
dateFormats.add(new SimpleDateFormat("dd MM yyyy"));
dateFormats.add(new SimpleDateFormat("dd.MM.yyyy"));
dateFormats.add(new SimpleDateFormat("dd/MM/yyyy"));
dateFormats.add(new SimpleDateFormat("dd-MM-yy"));
dateFormats.add(new SimpleDateFormat("dd MM yy"));
dateFormats.add(new SimpleDateFormat("dd.MM.yy"));
dateFormats.add(new SimpleDateFormat("dd/MM/yy"));
dateFormats.add(new SimpleDateFormat("dd-MMM-yy"));
dateFormats.add(new SimpleDateFormat("dd MMM yy"));
dateFormats.add(new SimpleDateFormat("dd.MMM.yy"));
dateFormats.add(new SimpleDateFormat("dd/MMM/yy"));
dateFormats.add(new SimpleDateFormat("dd-MMM-yyyy"));
dateFormats.add(new SimpleDateFormat("dd MMM yyyy"));
dateFormats.add(new SimpleDateFormat("dd.MMM.yyyy"));
dateFormats.add(new SimpleDateFormat("dd/MMM/yyyy"));
dateFormats.add(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy MM dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy-MMM-dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy MMM dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy.MMM.dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("yyyy/MMM/dd hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd MM yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd MMM yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd.MMM.yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss"));

return dateFormats;

Next create your isDate method:
public static boolean isDate(String date) {

// Load formats
ArrayList dateFormats = loadFormats();

boolean validDate = false;
Date myDate = null;

Object[] myDateFormats = dateFormats.toArray();
for (int i = 0; i
SimpleDateFormat myFormat = (SimpleDateFormat) myDateFormats[i];
try {
myDate = myFormat.parse(date);
validDate = true;
catch (Exception e) {
validDate = false;
return validDate;
Here is a converter from String to Date to ensures it is a valid format:
public static Date convertStringToDate(String date) {

// Load formats
ArrayList dateFormats = loadFormats();

boolean validDate = false;
Date myDate = null;

Object[] myDateFormats = dateFormats.toArray();
for (int i = 0; i < myformat =" (SimpleDateFormat)" mydate =" myFormat.parse(date);" validdate =" true;" validdate =" false;">
There you go!

Java isDate() Function Anyone?

From my earlier "pre-category" blog, this post was written when deep into the lack of a Java isDate() function:

New to Java, but learning fast and definitely experiencing the "Paradigm Shift", however I find it odd that there is no isDate() function like there is in Visual Basic.

As mentioned in an earlier post, I ran into a Java Date Conversion issue where the date format that I was expecting and turned out in the live data tests, to be a different format. This was after building over 500 test cases that test each of the business rules programmed into a Drools Rules (now Jboss) processor.

So obviously, I want to have all possible date formats accounted for so the solution is to have a function that loops through each of the possible date formats and check if the string parses into a valid Date object using that particular SimpleDateFormat.

I know this can be done using try-catch blocks, but I want to create a more elegant approach calling my custom isDate() function.

Checking aroung Javalobby and other places to see if anyone has already solved this, or if I need to create from scratch.

Jigloo Eclipse Windows Builder?

Building GUIs for rich client apps in Eclipse is not the easiest thing in the world. I'm looking for windows builders comparable to the Net Beans Matisse GUI builder.

I've downloaded the Jigloo GUI builder which sounds pretty good but that is coming from company who made it.

What about WindowsBuilderPro? Both Jigloo and WindowsBuilder are commercial products that offer free trial editions. I've generally heard that WindowsBuilderPro is the better product.

I'll try both and see for myself...

On the install, Jigloo is very simple and is just like any other Eclipse plugins. Just copy to the features and plugins directories and your done. WindowBuilder on the other hand has you walk through a install wizard which took only a couple minutes to run through. (Make sure you don't have Eclipse running during the install).

WindowsBuilder has several example apps you can try. In 5 minutes of testing this builder I found it very user friendly. I liked the "quick view" feature where without even compiling you can get a feel for how your app will look during runtime. Now on to Jigloo.

After the few minutes I found it easy to create a basic app. Nothing difficult. I liked the two screen (code/app) view that shows the two-way changes so if you edit the GUI the code changes or you edit the code and the GUI changes.

So far they are both comparable products and I'll spend a bit more time using each on an actual application to see which is the better product. ...

After spending several hours using Jigloo and writing over 1,000 lines of Java using GUI parts from Jigloo I've come to the conclusion that the best use of a GUI builder is for the initial creation of your form and widgets. The size, arrangement of widgets and placement of your GUI can be very much sped up using Jigloo.

However, once you understand what a GUI builder is doing and have your basic form created, continued use of any GUI builder is more annoying than anything. I'd recommend using one to get started, get your basic form created and then drop kick it for any later modifications or additions.

Star UML Design Tool

Ok, I downloaded the Star UML Design tool. Looks like an open source UML tool. Sounds promising. I'll give it a review in a bit.

As far as basic modeling tools go, this is the most easy to work with, simple to understand and fastest startup time. I've used this to generate a myriad of Use Case Diagrams, Activity Diagrams and Sequence Diagrams. Not reviewed yet is Star UML's Code Generation capabilities which look pretty straightforward.

One thing a bit confusing to a UML/MDA beginner is the "New Project By Approach" window where you have to select which UML approach you want to use. This basically means how the different types of diagrams will be organized. You have the option of selecting the 4+1 View Model, the Rational Approach, the UML Components Approach or the Default Approach.

I recommend just using the Default Approach unless you are familiar other standard UML approaches.

Eclipse Visual Editor vs. Jigloo

Ok, I've been using the Eclipse Visual Editor for all of 15 minutes and I am sold. Up until now, I've been using Cloudgarden's Jigloo free version, yet after getting constantly annoyed by Jigloo's constant modifications to my code, prevention of using builders and the incessant warnings about how you are using the free version and that this can not be used for commercial use, I had it.

It is much easier to build with the Model View Control (MVC) architecture using the VE tool as opposed to the Jigloo builder.

Here are some comparisons and reviews of these GUI builder tools:

Jigloo Review
Comparison of Java GUI Builders
Comparison with Matisse
IBM Giving Away VE Source Code to Eclipse

Refresh a JTable from a JDBC connection

I have a Swing application that uses a JTable and JScrollPane to display data from an Access database via a JDBC connection.

Even though I had properly coded the SQL INSERT statement and the data was loading into my database, the JTable was not refreshing with the new record. I tried the .revalidate() and the .repaint() methods to no avail.

Finally, after reading Ben Hendry's Mastering JTable I was able to sort this out.

In my JButton ActionListener I added the TableModel.addRow method and inserted the newly inserted records into the JTable as well. Followed by a .revalidate() and the data properly displayed without even a flicker in my application.

Moral of the story - always use Model-View-Control (MVC) architecture and separate your view from your data and controls.

Tom Cruise, Baby Suri, Photos Released

As you can see, Suri is absolutely a beautiful child. Vanity Fair has a major feature on Tom Cruise, Katie Holmes and Suri Cruise. This article dispels the rumors that have been generated by the media over the last several months.

Marilyn Monroe - Death By Psychiatry?

On the CCHR website there is a section devoted to artists. As I am an artist this was struck home to me. Artists and successful people are often found surrounded by "professionals" in the field of mental health.

I've heard many stories about what happened to Marilyn Monroe but this, from CCHR's website makes the most sense. Here is an excerpt:

"In 1960, Monroe saw psychiatrist Ralph Greenson, whose control over her was swift, severing all her close relationships. By 1962, she realized—too late—that she must "disconnect from Greenson." After spending six hours with him, she was found dead of a drug overdose. In the seven years prior to psychiatry’s influence, Monroe had made 23 movies. In the seven years of her psychiatric "care," she only made six films."
Check out the Citizen's Commission on Human Rights for more information on other famous artists whose lives have been destroyed by Psychiatry in the name of help.

Wednesday, February 07, 2007

Probabilistic Matching

Probabilistic matching uses likelihood ratio theory to assign comparison outcomes to the correct, or more likely decision.

Probabilistic matching enables one to use match scores and percentages on a field by field comparison to determine a match. There are three categories output from probabilistic matching and are set by the user based on the overall probability percentage:

1) Match - that can be automatically merged
2) Candidate Match - requiring manual review
3) Non Match

Artificial Intelligence and Machine Learning utilize probabilistic matching.

Tuesday, February 06, 2007

Service Oriented Architecture (SOA)

A service-oriented architecture is a collection of services that communicate with each other. The services are self-contained and do not depend on the context or state of the other service. They work within a distributed systems architecture.

Record Linkage

Record linkage is the act of detecting and linking duplicate records within a database. It is also called match/merge, deduplication, match/consolidate, etc.

Some record linkage software tools include:
Febrl (Freely Extensible Biomedical Record Linkage) - Open Source
MatchIT - Commercial
Business Objects - Commercial
Group1 - Commercial

Fuzzy Matching Logic

A method of matching where algorithms are used to compare character strings and detect recurring patterns within these strings. Common algorithms are Soundex, Levenshtein Distance and Double Metaphone which find similarities based on patterns and similarities. It is called a "fuzzy match" because the match is not exact, like if you were looking at the two records out of focus, they would look the same, but would be a bit fuzzy.

Enterprise Resource Planning (ERP)

Software that integrates departments and functions across a company into one computer system. ERP runs off a single database, enabling various departments to share information and communicate with each other. It helps a manufacturer or other business manage the important parts of its business, including product planning, parts purchasing, maintaining inventories, interacting with suppliers, providing customer service, and tracking orders.

Customer Data Integration (CDI)

Customer Data Integration (CDI) is the consolidation and management of customer data from all available sources. This customer data typically includes contact details, value data, and other information collected across multiple channels and through various interactions. The purpose of CDI is to keep source data systems and the central database in synch with each other to provide an accurate central view of each customer

Customer Relationship Management (CRM)

The functions and programs a company uses to connect with its customers - typically divided into Operational CRM (call centers, sales force automation, supply chain management) and Analytic CRM (customer analysis, database marketing). It allows an individual approach to marketing to and servicing customers.

Sunday, February 04, 2007

CDI - Glossary of Terms

As I've mentioned before, a primary barrier to studying any subject is the misunderstood word. Per Hubbard's study technology site:

"To clear a word, one looks it up in a good dictionary.

"The first step is to look rapidly over the definitions to find the one which applies to the context in which the word was misunderstood. One reads the definition and uses it in sentences until one has a clear concept of that meaning of the word. This could require ten or more sentences.

"Then one clears each of the other definitions of that word, using each in sentences until one has a conceptual understanding of each definition.

"The next thing to do is to clear the derivation – which is the explanation of where the word came from originally. This will help gain a basic understanding of the word." ...
- L. Ron Hubbard
Therefore I've started putting together simple to understand definitions for the most common terms in the field of Customer Data Integration.
Customer Relationship Management (CRM)

Customer Data Integration (CDI)
Enterprise Resource Planning (ERP)
Fuzzy Matching Logic
Probabilistic Matching Logic
Record Linkage

Service Oriented Architecture (SOA)