Bottom Up vs Top Down Web Services
Top-down means you start with a WSDL and then create all the necessary scaffolding in Java all the way down.
Bottom-up means you start with a Java method, and generate the WSDL from it.
How To Override toString
@Override public String toString()
{
return this.get(Field you want to return); // e.g: getName();
}
Why to use this kind override?
Sometimes we need to add for example a collection to a combo box so instead of looping
over the object list you override the toString in that object to return one of the object variables
public class SingletonClass { private static SingletonClass instance; private SingletonClass() {} public static SingletonClass getInstance() {
if(instance == null) {
instance = new SingletonClass();
return instance;
} else { return instance; } }
public void foo(){
int intVar = 5;
String strVar = intVar+"";
}
public void foo();
Code:
0: iconst_5
1: istore_1
2: new #2; //class java/lang/StringBuilder
5: dup
6: invokespecial #3; //Method java/lang/StringBuilder."<init>":()V
9: iload_1
10: invokevirtual #4; //Method java/lang/StringBuilder.append:(I)Ljava/lan
g/StringBuilder;
13: ldc #5; //String
15: invokevirtual #6; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
18: invokevirtual #7; //Method java/lang/StringBuilder.toString:()Ljava/la
ng/String;
21: astore_2
22: return
public void bar(){
int intVar = 5;
String strVar = String.valueOf(intVar);
}
String
to get the String version of intpublic void bar();
Code:
0: iconst_5
1: istore_1
2: iload_1
3: invokestatic #8; //Method java/lang/String.valueOf:(I)Ljava/lang/Stri
ng;
6: astore_2
7: return
Advantages
|
Inside Constructor
|
Outside Constructor
|
One initialization even if you have
multiple constructors
|
X
|
|
Can add exception handling to the
initialization
|
X
|
|
More Readable
|
X
|
|
Faster Class Load
|
-
|
-
|
StringBuffer
is synchronized, StringBuilder
is not, So off course string builder is faster.