Programming

The Re-inventing of Java

At one time, Java seemed unbeatable. It was the language which would replace C++ in many areas and it would be the premiere language for web development. This, however, did not happen due to poor marketing by Sun and aggressive marketing by Microsoft with their own development tools.

Yesterday at the JavaOne Conference, Sun announced OpenJDK. This is an open source version of Java which will be distributed under the GPL license. There are some parts of the code which came from sources outside of Sun and cannot be distributed under the open source license. Sun chose to include the binaries with OpenJDK, but Richard Stallman of the Free Software Foundation would like to liberate Java from this proprietary code:

“Only one last obstacle remains in liberating JDK and disarming the Java trap completely: some nonfree, legally encumbered code. The free-software community and Sun must work together to replace that code with free software.”

What’s included in OpenJDK? You get the compiler, virtual machines, and class libraries. Eventually the entire development tool will be open source when the proprietary code is re-written.

An open source Java may regain the market share that Sun has lost over the years. They currently hold a dominant position in cell phones, but even this is threatened by Windows CE and Symbian OS. Sun’s new initiative may bring to reality it’s original vision of the wide spread use of Java.

Deprecating Functions in Visual C++ 2005

I was recently trying to modify an open source FTP client in Visual C++ 2005. The software was written for an earlier version of VC++ so it had to be imported into the 2005 version. The import process generated hundreds of warnings of deprecated functions. This is not really something you want to see when compiling a program.

The warnings were the result of Microsoft deprecating many standard C functions. The complete list can be found on MSDN. These functions are being removed due to security concerns that Microsoft has. The new function has “_s” appended to it’s name, for example, printf becomes printf_s.

One might think that all you have to do is a global search and replace throughout your project to change the function names, but this won’t work. The updated functions have different parameter lists and return types.

So you can spend hours or days manually updating all of your code, or you can tell the compiler to use the deprecated functions instead. This can be done by placing the following at the start of your program:

#define _CRT_SECURE_NO_DEPRECATE

Keep in mind that this is a temporary solution. There may come a time when Microsoft removes these deprecated functions completely but at least you have time to gradually update the functions to their more secure counterparts.

Hiding Affiliate Links

There may be certain situations when you need to hide a URL on your web site. This is useful, for example, in changing the display URL for affiliate links. While there are several good techniques for accomplishing this, I prefer using the refresh metatag to redirect users entering that page to another location.

This is how it works. When you open a URL, such as www.cyprich.com, it will automatically look for a page called index.htm, index.html, or index.php (if you have PHP installed on your web server). An ASP.NET server will try to open a page called index.asp, index.aspx, or Default.aspx. These default pages can be defined by the web server settings for that URL.

The defaults also work for subfolders. For example, if you open www.cyprich.com/richmond/ and there is a file called index.php in that folder, it would be opened just as if you would had entered www.cyprich.com/richmond/index.php.

You can redirect a user that opens a web page with the refresh metatag as the following example shows.

====[ index.php ]===============

<html>

<head>
<meta http-equiv=”refresh” content=”0; url=http://www.advertiser.com/id=57912″>
</head>

<body>
</body>

</html>

=============================

So now when someone moves the mouse over the linked ad, they will see http://www.cyprich.com/richmond/ and when they click on it, they will be directed to www.advertiser.com/id=57912.

This technique for hiding affiliate links is very easy to do because all you have to do is define the url in the refresh tag. However, in order to hide links this way you need to be able to log into your web site by FTP or SSH and create these subfolders. I’m not sure if you can do this sort of thing in Blogger or similar sites.

Douglas Crockford: The JavaScript Programming Language

This video is an outstanding presentation on the history, the language itself, advanced features, available platforms, the state of the standards, and programming styles of JavaScript. It’s presented by the Douglas Crockford. He is the Yahoo! JavaScript Architect.

The video is good for people learning JavaScript and also for experienced developers who would like a greater insight in this language.

What’s interesting here is that Crawford claims that JavaScript is one of the most misunderstood languages and that all books on it are bad, except for one that he recommends that is the “least bad” of the JavaScript books.

The presentation is in 4 parts and lasts about 2 hours.

Part 1 (30:58)

Part 2 (29:08)

Part 3 (19:47)

Part 4 (31:08)

Displaying a Web Site in an IFrame

In an earlier post, I demonstrated a simple technique to create a scrollable region on a web page using CSS. While this is a good way to display static text, it doesn’t work for displaying another web page. The inline frame (IFrame) element in HTML will allow you to do this.

IFrames are typically used for displaying content from another page, such as an advertising banner. You can use frames to accomplish this, but frames are not good for use in cross-browser applications.

The following is an example of the code and output using the IFrame element. You need to specify the size of the window and the web page that will be displayed. The text in between iframe tags is what will appear on web browsers that can’t display the iframe contents.