Ruby Soup

Thursday, November 20th, 2008 12:06 am
flwyd: (java logo)
I had a thought at work the other day. Java has a strict one-parent-class rule. Philosophically, this is a good match in domains like taxonomic biology (a phylum is in one kingdom, a genus is in one family). But it's a terrible match in domains like cooking. A soup inherits flavors from many sources. You can add meat to what was originally a vegetable stew. Ruby is a much better language for programming a curry.
flwyd: (java logo)
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files.

Chaos Game Applet

Sunday, April 22nd, 2007 01:52 pm
flwyd: (java logo)
[Chaos Game] I spent most of yesterday and the first part of today writing a Java applet implementation of the Chaos Game. I find that the color schemes help significantly to understand why configurations lead to the patterns they do. The original description (which explains verbally better than I have) just featured monochrome images.

While I write Java code every day at work, most of it is data-focused. Data-focused GUIs (put this field over here, put these buttons in this panel over here) are important and often tricky to get right, but it's been years since I did anything with public void paint(Graphics g). Playing with code which requires no database, no metadata configuration, and no client-server communication was also refreshing.

You'll need at least Java 1.4 to view the applet. I compiled from Eclipse running under Java 1.5 and while I don't think I used any new API methods I didn't have a 1.4 JVM convenient for testing. Let me know if you can't get it to work.
flwyd: (java logo)
If a poor and despised Indian tried to get a job at a company testing Java software they would throw him out with a ClassCasteException.

throw null

Thursday, January 18th, 2007 03:45 pm
flwyd: (java logo)

I saw some typo Java code in my CVS update today which called throw null. I wondered just what that would do. null can be cast to any object, so I thought it might get caught by the first catch clause. Alternatively, I thought it might escape all catch clauses (dangerous!). The answer?

	try {
	    throw null;
	} catch (IllegalArgumentException e) {
	    System.err.println("Caught IllegalArgumentException " + e);
	} catch (NullPointerException e) {
	    System.err.println("Caught NullPointerException " + e);
	} catch (Throwable t) {
	    System.err.println("Caught Throwable " + t);

Caught NullPointerException java.lang.NullPointerException
	at TestStuff.main(

Java (even pre-1.5) automatically creates a NullPointerException if you throw null. It's like very specialized autoboxing.

flwyd: (java logo)
Save me Edsgar! I just wished I could use a goto statement in Java. My code's primary purpose is to take a bunch of fixed-width data and save it to another file in a tab-delimited format. I decided to add the ability to save the layout. If the layout file already exists, I prompt the user with a Yes/No/Cancel dialog to overwrite. If they cancel, I don't want to write anything (layout or data) and just return from the function. If they say no, I won't write the layout file, but I still need to write the data. If they say yes, or if the file didn't already exist, I write the layout file and then write the data. With a goto, I could break out of my if conditions and just write the data. But without the goto, my options are to set a status flag, write a function to prompt and write the layout, returning a boolean if it was canceled so I can refrain from writing data (probably the best solution), or the following solution: write a one-iteration for loop and break to a label, like so:
Read more... )
flwyd: (Trevor shadow self portrait)
At work we use iText, a free library for manipulating PDFs. The library's author makes his money by giving away cool software that's complicated enough that developers are motivated to buy the book so they can use it well. We just bought said book, and I want royalties:

Trevor armed and ready to do battle with code

Fun Java Facts

Thursday, April 27th, 2006 06:12 pm
flwyd: (dogcow moof!)
Running JVM 1.4.2_08:
System.out.println("1 + --0 = " + new BigDecimal("1").add(new BigDecimal("--0")));
1 + --0 = 1
System.out.println("Int " + new BigDecimal("--00").intValue());
Int -1
System.out.println("Double " + new BigDecimal("--0").doubleValue());
ArrayIndexOutOfBoundsException: -1
System.out.println("BigDecimal " + new BigDecimal("--0").toString());
ArrayIndexOutOfBoundsException: -1
System.out.println("BigDecimal --42 = " + new BigDecimal("--42").toString());
NumberFormatException: Illegal digit
April 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 2017

Most Popular Tags

Expand Cut Tags

No cut tags


RSS Atom
Page generated Monday, May 1st, 2017 06:11 am
Powered by Dreamwidth Studios