Mar
17
2006
Last Saturday I gladly volunteered as a web design judge for MESA day in San Jose State University. MESA stands for Math Engineering Science Achievement and is a program run throughout California to try to promote the sciences in socioeconomic disadvantaged communities.
For the web design contest, student where given a topic and 45 minutes to complete design a website with a minimum of three linked pages. Points were given for creativity, functionality, and content but most points were racked up by the different tags the students used. Points were handed out for using headers, relative links, absolute links, anchored links, style sheets, etc. After judging some of the web designs I could clearly see the influence of MySpace in some of the students work.
3 comments | posted in Rant, TechKnow
Mar
15
2006
Here is an interview questions that I have been asked. Given an employee table with a salary column, what SQL statement would give you the top five earning employees?
But before you select the SQL statement you have to select the database implementation. Here is how you might do it in Oracle:
SELECT name FROM employees WHERE ROWNUM < = 5;
In Microsoft SQL Server:
SELECT TOP 10 name FROM employees;
In MySQL:
SELECT name FROM employees LIMIT 10;
This is almost a trick question especially when the person asking the question might only know one of the many possible answers. Now, if the interviewer is reading the answer written along with the questions they might not understand that there is more than one way to do it. If they are asking questions where they don’t know the answer you might not want to work there, unless you are seriously strapped for cash. So remember, when you are looking for employment you should be looking for the top work environment.
no comments | posted in SQL, TechKnow
Mar
13
2006
I recently had to look into the image scaling code that we employ in our application because of a known bug with the JDK. Here is the original code we used to resize image icons:
int hint = Image.SCALE_AREA_AVERAGING;
icon = new ImageIcon(original.getScaledInstance(w,h, hint));
As stated, the above code occasionally will throw a ClassCastException because of a bug with the JDK. The exception is thrown because of the use of the AreaAveragingScaleFilter class which is instantiated when you use the SCALE_AREA_AVERAGING hint. A work around for this problem is to use the Image.SCALE_REPLICATE hint but which produces images with jaggies.
You can use a different approach to creating image thumb nails as in the following code:
BufferedImage bi = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
bi.getGraphics().drawImage(original, 0, 0, w, h, null);
icon = new ImageIcon(bi);
You can also scale, rotate, and shear an image using affine transformations. The following code resizes an image using the AffineTransform class.
AffineTransform tx = new AffineTransform();
tx.scale(scalew, scaleh);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_BILINEAR);
BufferedImage bi = op.filter(ogininal, null);
icon = new ImageIcon(bi);
no comments | posted in Java, Programming, TechKnow
Mar
8
2006
Some time back I wrote about how OptimizeIt was useful in profiling our application. If you can’t afford OptimizeIt Java provides you an alternative poor man’s profiling tool in the Runtime class. The Runtime class allows you get the total heap size and the amount of available memory. Using these methods you can estimate how much memory you application is consuming with some simple math:
Runtime rt = Runtime.getRuntime();
long using = (rt.totalMemory() - rt.freeMemory()) / 1024;
no comments | posted in Java, Programming, TechKnow
Mar
7
2006
I’ve had the Agile Web Development with Rails book authored by Dave Thomas and David Heinemeier Hansson for some time. Looking through Amazon I found out that there are several Rails book coming in the next few months. Dave Thomas is a good author, I also have his PickAxe book Programming Ruby: The Pragmatic Programmer’s Guide. In this post I want to quote some insights from Dave Thomas found in Agile Web Development with Rails.
The needs of the developer are very different when writing code, testing, code, and running that code in production. When writing code, you want lots of logging, convenient reloading of changed source files, in-your-face notification errors, and so on. In testing, you want a system that exists in isolation so you can have repeatable results. In production, your system should be tuned for performance, and users should be kept away from errors.
Why use an artificial primary key such as id?
The reason is largely a practical one – the format of external data may change over time. For example, you might think that the ISBM of a book would make a good primary key in a table of books. After all, ISBNs are unique. But as this particular books i being written, the publishing industry in the US is gearing up for a major change as additional digits are added to all ISBNs.
There are few absolutes when it comes to performance, and everyone’s context is different. Your hardware, network latencies, database choices, and possibly even the weather will impact how all the components of session storage interact. Our best advice is to start with the simplest workable solution and then monitor it. If it starts to slow you down, find out why before jumping out of the frying pan.
Use GET requests to retrieve information from the server, and use POST requests to request a change of state on the server.
no comments | posted in Books, Programming, Ruby, TechKnow
Mar
6
2006
Java’s WebStart was to solve some deployment problems, but recently I’ve had two deployment issues with it. The first issue is as follows; using Internet Explorer I would get the following error when trying to open a WebStart JNLP file:
An error occurred while launching/running the application.
Category: Invalid Argument Error
Could not load file/URL specified:
C:\...\Content.IE5\...\webstart[1].jnlp
The Wrapped Exception states that this is basically a FileNotFoundException on the client side. What happened was that IE didn’t cache the JNLP file on the client side and WebStart can’t find the JNLP file when it tries to launch the application. I found some advice on forums after googling for ‘WebStart Content.IE5’ and other search terms. Some forums stated that I needed to clear IE’s cache. Others suggested that I had to move the IE cache to a different directory. What worked for me was that I had to explicitly tell IE to cache the JNLP file using some JSP code.
// Set IE HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control",
"post-check=900, pre-check=3600");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "cache");
The other problem with WebStart that I have had in the past is in the way you auto-detect if WebStart is installed. To auto-detect Sun’s documentation provides you with some nasty client side JavaScript and Vbscript code. It is nasty because it is doesn’t even works properly, a bug is filed for this. I have two machines, both of which have Java 1.4.2_08 installed. But for some reason only one machine can create a JavaWebStart.isInstalled.1.4.2.0 object using the Visual Basic script on IE. This must be a Java plugin problem. A way around this is to use IE object tag. The following bit of code is what Sun provides you to auto-detect if your client has WebStart installed.
<script type="text/javascript" language="javascript">
var javawsInstalled = 0;
var javaws12Installed = 0;
var javaws142Installed = 0;
isIE = "false";
if (navigator.mimeTypes && navigator.mimeTypes.length) {
x = navigator.mimeTypes['application/x-java-jnlp-file'];
if (x) {
javawsInstalled = 1;
javaws12Installed = 1;
javaws142Installed = 1;
}
}else {
isIE = "true";
}
</script>
<script LANGUAGE="VBScript">
on error resume next
set jws = "JavaWebStart.isInstalled"
set jws12 = "JavaWebStart.isInstalled.2"
set jws142 = "JavaWebStart.isInstalled.1.4.2.0"
If isIE = "true" Then
If Not(IsObject(CreateObject(jws))) Then
javawsInstalled = 0
Else
javawsInstalled = 1
End If
If Not(IsObject(CreateObject(jws12))) Then
javaws12Installed = 0
Else
javaws12Installed = 1
End If
If Not(IsObject(CreateObject(jws142))) Then
javaws142Installed = 0
Else
javaws142Installed = 1
End If
End If
</script>
1 comment | posted in Java, JavaScript, TechKnow