Older blog entries for derupe (starting at number 30)

Ended the year with a new release of Kaprekar - version 3.0.

There are two main changes in this release - a) Parameterized the classes based on Java 5 Generics and b) Added a pause and resume option.

The pause and resume option holds only for the current run of Kaprekar. I plan to allow a "save state" feature in a future version where the user can save the current state of the Kaprekar run in a file and exit the application. Later, the user may "load the state" and resume the Kaprekar run.

For more info on the Kaprekar Series Generater, check its web site at http://kaprekar.sourceforge.net

Eclipse Bug - Encapsulate Field

Found this bug in Eclipse today while using the Encapsulate field functionality.

Eclipse Version: Version: 3.1.0 Build id: 200412162000

Create this simple class in eclipse -

public class TestEncapsulate {

String a, b; }

1) Select the Field a.
2) Right-click and select Refactor -> Encapsulate Field.
3) Click Ok.
4) The following code is generated -

public class TestEncapsulate {

String b; private int a;

/** * @param a The a to set. */ void setA(String a) { this.a = a; }

/** * @return Returns the a. */ String getA() { return a; } }

Problems
a) The field was changed to a private field even though it was package-private earlier.
This is ok by me, since I typically keep the fields as private.

b) The data type was changed from String to int!!!
This is crazy!

The encapsulate field works fine when there is only one package-private field delared in one line (String a;)
It breaks in the above code for both fields 'a' & 'b'.

I have reported this Encapsulate field bug.

Java 5.0 Crash

I was using the Eclipse Profiler Plugin to launch my application when the 5.0 JVM crashed.

Here's the information -

java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

Eclipse Version: 3.1.0 Build id: 200412162000

Plugin: Eclipse Profiler http://eclipsecolorer.sourceforge.net/index_profiler.html Plugin Version: 0.5.33

And here's the crash message - # # An unexpected error has been detected by HotSpot Virtual Machine: # # Internal Error (455843455054494F4E530E43505000FF), pid=2116, tid=2268 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode) # An error report file with more information is saved as hs_err_pid2116.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp #

It created the log file in the project workspace folder. It contained Thread, Stack, Native frames, Heap, Dynamic Libraries, VM, Environment and System information.

Java Code: Boolean Fun

Over time I've encountered Java code that I feel could have been written better. I'll list out a few example that I encountered recently.

If you do code review you'll want to check PMD, JLint, FindBugs and some such tools [I've mentioned these before while talking of Eclipse Plugins.]

Boolean Fun

Cosider this code

if(str.length() > len) {
      return true;
} else {
      return false;
}
The Boolean Expression need not be kept in an if-else block, the output of the boolean expression could have easily been returned as

return (str.length() > len);

A more advanced form of this problem was using a ternary operator -

return (str.length() > len ? true : false);

Yes, the ternary operator is absolutely unnecessary here.

This one was really funny!

if(!(x == y))

I wonder why the developer thought of such a convoluted way to write x != y.

Another common problem I have come across when Boolean objects are used. Invariably you'll see

Boolean b = new Boolean(true);

There is no need to create a new instance here, you could just write -

Boolean b = Boolean.TRUE;
14 Dec 2004 (updated 14 Dec 2004 at 21:03 UTC) »
Eclipse QuickFix problem

Encountered a strange problem while working on Eclipse [In the latest integration build - Version: 3.1.0 Build id: 200412081200]

I wrote a small snippet of code -

    if(getContentSpec().equals("Test"))
        return true;
The method getContentSpec was not implemented in the class; so it gave a compilation error. I took the QuickFix route and asked Eclipse to generate the stub for me. To my surprise, it generated the following code -
/**
* @return
*/
private AbstractList getContentSpec() {
    // TODO Auto-generated method stub
    return null;
}
I didn't really expect the method to return a String - but I at least expected it to return an Object. But it ended by returning an AbstractList!!!!! This was s t r a n g e!

To recreate the problem, before I submit the bug, I created a simple class -

public class QuickFixEquals {

public boolean hasChildren() { return(getContentSpec().equals("Test")); } }

Applied QuickFix ... and the code generated was
    private Object getContentSpec() {
        // TODO Auto-generated method stub
        return null;
    }
Well, thats what I wanted in the original code ... why did it behave differently here?

I finally tracked it down to ... guess what? ... an import statement.

Try QuickFix on the following code

import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() { return(getContentSpec().equals("Test")); } }

It will generate
	private List getContentSpec() {
		// TODO Auto-generated method stub
		return null;
	}
Better yet, try this code
import java.util.ArrayList;
import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() { return (getContentSpec().equals("Test")); }

public List<String> getList() { return new ArrayList<String>(); } }

Apply QuickFix, and lo, you get -
    private AbstractList<E> getContentSpec() {
        // TODO Auto-generated method stub
        return null;
    }
Here's the link to the QuickFix Bug.
3 Dec 2004 (updated 3 Dec 2004 at 18:57 UTC) »
Languages based on the Java VM

I read the article "GJ: Extending the JavaTM programming language with type parameters" [by Gilad Bracha, Martin Odersky, David Stoutamire, Philip Wadler, March 1998; revised August 1998]. It introduces the GJ compiler that is an extension of Java (during the time of JDK 1.2) which provided generics support. The current generics support in Java 5 is based on GJ.

GJ, per the article, is based on Pizza. "GJ is based closely on the handling of parametric types in Pizza".

This led me to search around for Pizza and other languages based on the Java programming language.

The Pizza compiler is hosted on sourceforge. Its current version is 1.1 [released 03-Jan-2002].

The Pizza language is an extension to Java with three new features:

  • Generics (aka Parametric polymorphism)
  • Function pointers (aka First-class functions)
  • Class cases and pattern matching (aka Algebraic types)

The Pizza Tutorial explains the three new features listed above.

GJ - A Generic Java Language Extension - is currently on version 0.6m. It is a superset of the Java programming language and is compatible with existing libraries.

Bistro is a new programming language that integrates the best features of Smalltalk and Java. It is currently on version 3.5 [21-Apr-2002?]. You can read about Bistro in the language neutrality article.

Kiev is another language derived from Java. It was initially written in (and tries to be source compatible with) Pizza language. It is currently on version 0.09a.

You can check many more languages at the list of languages based on the Java VM.

19 Nov 2004 (updated 19 Nov 2004 at 16:57 UTC) »
pipeman asked: What does the numbers next to the names in the Advogato recentlog mean?

Could it be what others have rated your dairy?

Everyone's home page has a question similar to this -

How interesting is pipeman's diary, on a 1 to 10 scale?

It could be the average of all the ratings - hence the fraction against some dairy entries ...

Released version 2.2b of Kaprekar Series Generator.

This is more of a code refactoring release. The code was changed to be more modular. The serialization, SVG generation and statistics code had crept into the Kaprekar Engine. I extracted those into separate classes - this also fixed some cut-and-paste code.

The only bug-fix in this code is for the progress bar in the GUI - the progress bar would not show the progress while searching for Kaprekar Series with more than 19 digits. This is fixed now. Well I had written the code, but for some reason I didn't invoke it. Ok, I thought it was an expensive call so didn't invoke it. Now I'm keeping track of the heartbeat and invoking it initially every 50 heartbeats and then every 500 heartbeats. It didn't seem to have too much of an overhead.

This change was in preparation of moving Kaprekar Series Generator to Java 1.5 to use the new language features.

Found this article on Functional programming in the Java language at IBM DeveloperWorks. A good read ... now need to explore about the Apache Commons Functor.

This is fun - never knew that something like Elephant Polo existed! ;-)

8 Jul 2004 (updated 8 Jul 2004 at 20:43 UTC) »

So, Advogato is back up finally!!! I had nearly given up checking on it!

My last post was on May 27th and a lot has happened since then. I've talked about it in my blog on blogspot and the project blogs for kaprekar and matra. Also started a photo blog and a blog for my genealogy interests.

Well I got Gmail and am comfortably using it. Got a set of invites and distributed it too. Meanwhile my email accounts at yahoo and hotmail stand neglected (though they have increased the capacity). Gave a lot of feedback to Gmail - looks like they have been overwhelmed by the suggestions. :)

Matra

Added a lot of dtdtrees on the Matra site -

1. Bioinformatic Sequence Markup Language dtdtree.

2. WAP Wireless Markup Language dtdtree.

3. Speech Synthesis Markup Language dtdtree.

4. RSS 0.91 dtdtree

5. XHTML strict dtdtree.

6. GEDCOM.

7. GedML.

Kaprekar

Two releases were made for the Kaprekar application -

Released version 2.0b. The main changes in this release includes addition of a Gui interface to the application and processing of hexadecimal numbers. Other changes include a few minor bug-fixes and changes to the algorithm.

Released Version 2.1b. The main changes include removing dependency on the Ganita package (Huge and Number classes). So now the Demonstrate process uses BigInteger - and consequently can handle numbers with any number of digits! Changed the algorithm a little bit to improve the performance while seaching for Kaprekar Series.

Lots of changes to the Kaprekar project web site. The site now uses valid XHTML and CSS. Added an introduction to the UML SVG documents.

Kaprekar Site: Making it XHTML Valid.

Here are my observations while making the site xhtml valid.

1. The biggest culprit was the <p> tag. Out of years of habit, I hadn't closed any of them. Removing this problem reduced the number of validation errors to the minimum.

2. Another one was the use of the < sign in the proofs without escaping it to <

3. XHTML does not have a "target" attribute. I have used the target attribute in the navbar - this invalidates all my pages. I could not find a non-javascript alrenative for this one, so just had to delete that attribute.

4. The second problem - only on one page (release: changes) - is the use of the font tag. This one was somehow missed when I changed my site to use css. This was an easy fix for me, but many sites who use font tags will have a tough time on this one.

5. The last problem was the missing alt attribute in the img tag - again only in one page (playing with numbers). The alt tag seems to be mandatory!

Other changes to the site

Made some changes across both the Kaprekar and Matra sites.

Changed the background color of the site to floral white to make it more pleasant to the eyes. And changed the links style so that they are underlined - so that its apparent that they are links.

Added Google search and ads on the site.

Added a separate CSS for the print media. Now the navbar and ads won't print - when you fire a printout - so only the content will be printed.

21 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!