Archive

Archive for the ‘Beginners’ Category

Faster Java – Strings

January 29th, 2009

If you’re building a long String in Java, don’t stick String objects together using ‘+’, for example:

String str = "Hello";
str = str + world;
str = str + "!";

Why not?

It’s really slow when you do it a lot!

What should you do instead?

Use the append(String) method in StringBuffer (Java 1.4.2 on), or StringBuilder (Java 5 on). StringBuilder is slightly faster than StringBuffer, but is not thread safe. Both are much faster than concatenating String objects – by orders of magnitude. For example:

StringBuffer str = new StringBuffer("Hello");
str.append(world);
str.append("!");

Read more…

Paul Brabban Beginners, Development, Java , , , , , , , ,

My Website’s Pictures Won’t Load!

September 20th, 2008

So you’ve got a website with some pictures that you’ve saved somewhere. The pictures work on some pages, maybe only one, put not on others. Your problem is all to do with relative links in your HTML. Read more…

Paul Brabban Beginners, Development