First of all, it doesn't make sense to initialize test to a new String() there, since the initialization block immediately assigns it to something else. Anyways...
One alternative is initializing at the declaration:
public class BlockTest {
String test = "testString";
}
Another is in the constructor:
public class BlockTest {
String test;
public BlockTest () {
test = "testString";
}
}
Those are the two main, common options.
There are two main uses for an initialization block. The first is for anonymous classes that have to perform some logic during initialization:
new BaseClass () {
List<String> strings = new ArrayList<String>();
{
strings.add("first");
strings.add("second");
}
}
The second is for common initialization that must happen before every constructor:
public class MediocreExample {
List<String> strings = new ArrayList<String>();
{
strings.add("first");
strings.add("second");
}
public MediocreExample () {
...
}
public MediocreExample (int parameter) {
...
}
}
However, in both cases there are alternatives that do not use the initialization block:
new BaseClass () {
List<String> strings = createInitialList();
private List<String> createInitialList () {
List<String> a = new ArrayList<String>();
a.add("first");
a.add("second");
return a;
}
}
And:
public class MediocreExample {
List<String> strings;
private void initialize () {
strings = new List<String>();
strings.add("first");
strings.add("second");
}
public MediocreExample () {
initialize();
...
}
public MediocreExample (int parameter) {
initialize();
...
}
}
There are many ways to do these things, use the way that is most appropriate and provides the clearest and most easily maintainable code.