<< March 2004 | Home | May 2004 >>

Meta-Meta-Meta

Attended an MDA talk yesterday evening. It was very informative. However I've got this song stuck in my head afterwards:

Meta, Meta, Meta,
Meta, Meta, Meta,
Meta, Meta, Meta,
Meta------

Generating HTML From Code With Enscript

I've been talking about enscript a lot lately.

It just so happens that it can also generate HTML from source code, converting the <, & signs, etc., with syntax highlighting, in color if you want. Very handy for putting code snippets into blogs or other Web documents:

[weiqi@gao] $ enscript --color --language=html --output=Main.html Main.java

Thread Synchronization Puzzle

Take a look at the code below. Should Main finish immediately? Under Sun J2SE SDK 1.4.2_04 on Fedora Core 1 Linux it does. Under gij 3.3.2 (the JVM in GCC 3.3.2) it doesn't. Intuitively, the worker thread waits on lock, which is never notified, so worker should be waiting indefinitely. Right?

public class Main {
    public static void main(String[] args) {
        final Thread lock = new Thread();
        Thread worker = new Thread() {
            public void run() {
                synchronized (lock) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        worker.start();
        lock.start();
    }
}

Enscript, Cygwin, Lpr, ...

I posted an elaborate script for pretty-printing code listings 19 days ago:

On Linux systems, enscript is hooked up directly to the default printer, so a simple command like:

[weiqi@gao] $ enscript Foo.java

will do.

On Windows, I use Cygwin to accomplish what I want. Things are not as automatic as on Linux, ...

I have learned since then that, in Cygwin too, enscript is properly hooked up to the default printer, just like on Linux. So I have thrown away that script, and use the enscript command directly.

Tags :

IDEA Educational License, $99

Mike Shoemaker: Jetbrains ended up sending me an overstuffed URL that allowed me to purchase their product for the educational price $99. I was floored ...

It pays to call JetBrains up.

Write JavaBeans, Then Piece Them Together with XML

I'm the kind who's sort of slow. You know, when everyone was talking about Web Services, I'm still not done learning CORBA.

So it's no surprise that I went through Don Box's blog entry on 2003-11-04T09:14:15Z about XAML (to ship some time in the future) without too big an reaction:

XAML is just an XML-based way to wire up CLR types - no more no less.

Then at the March NFJS St. Louis Symposium, I heard Bruce Tate talking about the Spring Framework, the core of which is XMLBeanFactory:

Convenience extension of DefaultListableBeanFactory that reads bean definitions from an XML document.

Since:
15 April 2001

Finally this week, while reading some old code, I noticed the use of the java.beans.XMLEncoder and java.beans.XMLDecoder, part of JSR 57: Long-Term Persistence for JavaBeans. They can be used to serialize an already configured set of interrelated JavaBeans into an XML file and reconstitute the JavaBeans from the XML file.

According to this article on Sun's Swing Connection, this technology was demoed at JavaOne '99---in the last millennium!

Now, I'm just wondering, are these three technologies manifestations of the same idea?

Edit Style

I spotted this bit advice through JavaBlogs:

Eugene Kuleshov: However with Mozilla/Firefox there are easier and more practical way. You can use EditCSS or Web Developer extensions to change styles for any elements on the fly.

As reported on the EditCSS home page (in message 8), it works for good old Mozilla too. After installation, "Edit CSS" appears in the context menu. I also dragged the bookmarklet onto my toolbar to have easier access to it.

Thanks, Eugene. It works.

Using "Black-On-White" Fonts in "White-On-Black" Web Pages

Quite a few websites choose to use a darker background with lighter text. These web pages are impossible to read. Highlight a passage usually helps, but not always. "View Source" is another alternative that's not much better:

However, if I save the page as an image and use The Gimp to revert the colors (Image -> Colors -> Invert), the result is much more pleasant to read:

The trick is in the fonts. Most of the modern fonts are designed for use as black texts on a white background. Since the human brain has a tendency of letting the darker letters "bleed" into the lighter background, these fonts compensate by making the letters just a tiny bit on the "thin" side so that after the post-processing by our brains, things would look "just right."

When used in a "reverse-video" situation, our brain's compensation goes against the page: the darker background would bleed into the already thin letters, making them even thinner and that much harder to read.

So web designers please be considerate. When using a dark background, use one of those "White-On-Black" fonts. Or better yet, use a lighter background altogether.

Thank you!

Page 23

Sam told me to:

  1. Grab the nearest book.
  2. Open the book to page 23.
  3. Find the fifth sentence.
  4. Post the text of the sentence in your journal along with these instructions.

From The Analects of Confucius, the Great Learning, Doctrine of the Mean by James Legge:

Amid the changes of dynasties, the slabs both of Han and Wei had perished, or nearly so, before the rise of the Tang dynasty, A.D. 624; but under one of its emperors, in the year 836, a copy of the Classics was again cut on stone, though only in one form of the character.

NetBeans 3.6: Still Annoying

I downloaded NetBeans 3.6 and installed it yesterday.

Today I tried to write some Java code with it. I mounted my src directory in ten clicks after reading a 1.3KB document.

Then I created a class with the CreaetAClassWizard. And here is the class:

/*
 * Foo.java
 *
 * Created on April 15, 2004, 2:23 AM
 */

/**
 *
 * @author  weiqi
 */
public class Foo {
    
    /** Creates a new instance of Foo */
    public Foo() {
    }
    
}

In case anybody is listening at NetBeans, it is the public no-arg constructor that is annoying. I did not ask for it. It is not obvious to me while I'm in the Wizard that I'm going to get a public no-arg constructor before I clicked Finish. I applaud the Wizards attempt at guessing what I want.

But I'm sorry. You guessed wrong. And I'm uninstalling the thing.

I'm not saying NetBeans isn't any good. I'm sure people who've been using it all along will find it the most pleasing thing in the world. It's just not for me.

Downloading Day

Both NetBeans and IntelliJ released new versions yesterday or today. So I've been downloading.

They say this version of NetBeans should be a big improvement over the previous version. I'll see.

For both IDEs, I have to download a Linux version and a Windows version. It strikes me as odd that I have to do that. They spent all their time and energy to make the Linux version and the Windows version identical, and at the last step throw away that benefit for their users.

Whatever happened to executable jars?

Or is it time for the Cross Platform Installer API JSR?

$249 IntelliJ IDEA Personal License

JetBrains is offering the $249 IntelliJ IDEA Personal License again. The sale runs through April 22, 2004.

I bought IDEA on a similar deal last Christmas. I believe it's worth the money.

Boolean.getBoolean()

Quickly, what is printed by the following line of Java code?

    System.out.println(Boolean.getBoolean("true"));

Pretty Printed Code Listings in Cygwin

Been doing a lot of code reviews lately. Aside from turning into a mean person ("Too many 'return's!", "Indentation is wrong!"), I also experienced the non-uniformness of the code printouts various developers bring to the table. While IntelliJ IDEA, Eclipse, Together, JBuilder and NetBeans all have their own pretty print facilities, they all left something to be desired.

In my opinion, the GNU Enscript program generates the best quality code printouts when used with appropriate switches. The magic switch I use is "-G2rE -C -M Letter", which I set as the ENSCRIPT environment variable so that enscript picks it up automatically.

On Linux systems, enscript is hooked up directly to the default printer, so a simple command like:

[weiqi@gao] $ enscript Foo.java

will do.

On Windows, I use Cygwin to accomplish what I want. Things are not as automatic as on Linux, but all the ingredients are there. I can use GNU Enscript to turn source files into PostScript files, use GhostScript to turn PostScript files into the format for my printer (which happens to be an HP LaserJet 8150 PCL), and then use Lpr to send the PCL to the printer. Here's the script I use to print code in Cygwin (enscript, gs, and lpr are all distributed with the Net version of Cygwin):

#!/bin/bash
#
# print-code
#
# Generate a filename based on the current date/time
FILENAME=`date +%Y%m%d%H%M`
#
# Generate PostScript
enscript $1 -o $FILENAME.ps
#
# Generate PCL
gs -sDEVICE=ljet4 \
   -sOutputFile=$FILENAME.pcl \
   -dNOPAUSE \
   -dBATCH \
   -q $FILENAME.ps
#
# Send PCL to printer
lpr -l $FILENAME.pcl
#
# Remove temporary files
\rm $FILENAME.ps $FILENAME.pcl

Now I can do things like:

[weiqi@gao] $ print-code Foo.java

and

[weiqi@gao] $ for x in *.java; do print-code $x; done

to have my Java files printed.

Tags :

Sun Settled With Microsoft, Shouldn't You?

I'm not talking about the other companies who still have a case against Microsoft pending.

I'm talking about you. Yes, you! You who vowed not to use a PC when MSDOS came out. You who vowed not to upgrade to Windows when Windows came out. You who vowed to never to upgrade to Windows 95 when it came out. You who vowed to never use IE when it came out. You who never learned COM. You who vowed to never use .NET or C# when they came out. You who is against everything and anything that Microsoft produces---because they are evil.

The anti-Microsoft cause lost its last battle when Sun settled with Microsoft.

It's time to recognize the cause is lost. And move on.

Friday Thoughts

If you can't do it in five years, you can't do it in five years and a day. So don't bother coming in on Saturday.


Control-Shift-F1 on a Java GUI window dumps the GUI hierarchy to the terminal.


public boolean getFlag() {
    return this.flag;
}
public void setFlag(boolean flag) {
    this.flag = flag;
}
private boolean flag;

is not thread-safe. Synchronization on both getter and setter are required, all because of the Java Memory Model.


Bloglines.com is pretty cool. (BTW, I wrote this on this, which prompted this. :) )


How many Java developers turn on the assert keyword when they compile? Is it on by default?


Prefer

    jframe.show();

to

    jframe.setVisible(true);

The former works on more JDK platforms than the latter, and is shorter. Contrary to popular belief, JFrame.show(), which is inherited from java.awt.Window, is not deprecated.

Save $500, Use Open Office

Eric Burke blogged his positive experience using Open Office as a replacement for Microsoft Office.

Eric is not an open source zealot like I sometimes am. He has no patience for inferior software. Yet Open Office works fine for what he's doing.


The other day I was having a cross-cubicle conversation about how cheap computers are:

I can buy a white box computer at a local store for $600. 2.4GHz CPU, 80GB hard drive, and 1GB memory.

How come every time I buy a computer it costs me $1700 at Dell.

You don't have to buy from Dell. And you probably are paying for software.

Yeah. I always buy Windows and Office.

I stopped buying Windows a long time ago. Linux works just fine for me for what I do. And I use Open Office.

The reason I buy Microsoft Office is that I sometimes have to collaborate with other people who send me Word documents and Excel spreadsheets.

Open Office will handle most of those fine. You can even save in Microsoft format. I've been using Open Office for a couple of years now, just to open other people's Word documents. I have never come across one that Open Office can't handle. Excel spreadsheets too.

How much is Open Office.

It's free.

Free?

Just go to http://www.openoffice.org and download it.

I'll take a look at it. You may have just saved me $500.


In case you are thinking Open Office is some sort of inferior knock off written by hyper-active college kids, read the Tim Bray post I linked to yesterday again:

... (Sun is paying several floors in a big building full of people to work on it, and there are tons of other contributors) ...