My 100th blog post: my Java StringArray class
Learning a new programming language can be very frustrating at first. However, I have a very clear idea where I want to go: make a web development framework on IBM Lotus Notes/Domino using Java on the server side. So I have to adapt the core things I've programmed in LotusScript to fit them into the Java world. The first thing I did however is adding the Java language to my Syntax highlight tool.
Installing Eclipse
This was really simple: I went to Eclipse.org and installed the Eclipse Classic 3.3.1.1 edition for Windows. Very cool features: Eclipse does not change or add any Windows registry settings. It does not require setting up the classpath. You just unzip Eclipse to a directory and it works. You can have many versions of Eclipse working with different Java versions.
Hello World
My first Java class. I used it to test my syntax highlighting as well:
package dworks.test;
public class HelloWorld {
public static void main() {
String myString="Hello World!";
System.out.println(myString);
}
}
Remember my StringBuffer class in LotusScript?
In fact, it is nothing at all like the Java StringBuffer class. The ArrayList class comes more near. However, it does not have a "join" method. So I decided to make my own class StringArray based on the ArrayList class:
package dworks.web.util;
import java.util.ArrayList;
public class StringArray extends ArrayList<String> {
private static final long serialVersionUID = 1L;
public String join(String delim){
StringBuffer sb = new StringBuffer();
Object[] tmp=this.toArray();
for( int x = 0; x < ( tmp.length - 1 ); x++ ){
sb.append(tmp[x] );
sb.append(delim );
}
sb.append( tmp[ tmp.length - 1 ] );
return sb.toString();
}
}
And voila: I have a class that has the same behaviour as my LotusScript StringBuffer class. I'm not sure if I have done the right thing here: maybe there was a class in Java that did exactly what I wanted. If so, I'll be glad to hear.
Comments
07.12.2007 13:30:16, Karsten Lehmann
Please take a look at java.lang.StringBuffer. It's not necessary to reinvent the wheel :-) The JDK class library is much more powerful than the stuff you know from Lotusscript.
12/07/2007 01:32:15 PM, Theo Heselmans
Congrats with your 100th blog post !
07.12.2007 13:42:51, Karsten Lehmann
Ok, I should have read your code more thoroughly. ;-) The code is ok. I would use getSize() and get(int) on the ArrayList instead of toArray(), which generates a copy of the internal ArrayList's string array.
07/12/2007 18:41:46, Michel Van der Meiren
@Karsten: thanks for te tip. I am not very familiar with Java yet I'm afraid. @Theo: thanks. We still have to go on that drink together, remember ;-)
07.12.2007 23:16:09, Tommy Valand
Congrats!
It will be interesting to see how your quest to "no more LS" goes. I've wanted to do the same myself, but I always end up giving up. My biggest obstacle is that I work mainly on developing one application. Moving all code to java would be impossible if you compare cost-vs-value.
Another "obstacle" is that Java is not a scripting language. Simple tasks in LS is sometimes a hassle in Java.
Example, the lack of multiline String literals and the lack of Strtoken (Java has StringTokenizer).
Then again, Java has a lot better array datatypes. Example Map, somewhat similar to Lists in LS, and ArrayList, which is superior to LS' arrays.
A little tip, if you're not already aware of it. Java's equivalent to Evaluate is .evaluate( ). Returns a Vector object.
To add a comment, log in or register as new user. It's free and safe.