Main BLOGGER
Saturday, December 31, 2005
Thinking in Java
1. Pass by value all the time
2. For Object, the value is the reference to Object.
3. Use clone to avoid the change to alias object
Clonable is a tagging interface (RandomAccess for Collections)
Thursday, December 29, 2005
3D obj file format
http://www.csit.fsu.edu/~burkardt/data/obj/obj.html
http://www.csit.fsu.edu/~burkardt/data/obj/obj_format.txt
Run the samples in j3d-examples
Remember to set
classpath=c:\sun\AppServer\jdk\lib\ext\j3dcore.jar;
c:\sun\AppServer\jdk\lib\ext\j3dutils.jar;
c:\sun\AppServer\jdk\lib\ext\vecmath.jar;.
java PrintCanvas3D ..\geometry\p51_mustang.obj
Java 3D
cvs -d :pserver:pliu@cvs.dev.java.net:/cvs login
cvs -d :pserver:pliu@cvs.dev.java.net:/cvs checkout java3d
cvs -d :pserver:pliu@cvs.dev.java.net:/cvs checkout j3d-examples
passwd is the same as unix account
Home
http://www.java3d.org/
Tutorial
http://www.java3d.org/tutorial.html
Wednesday, December 28, 2005
Design patterns
Design patterns
1. Iterator (high)
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
2. Decorator (medium)
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
3. Facade (high)
Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.
Tuesday, December 27, 2005
Java Tutorials
Java online Tutorial
Java Collection Tutorial
Legacy Implementation: (Synchronized)
1. Vector
2. Hashtable (does not allow null keys and values)
Collection Interfaces:
1. Collection: Set-->SortedSet, List, Queue,
2. Map-->SortedMap,
General-Purpose Implementations: (non-synchronized, dynamic sized)
- HashXXX: Hash table implementation, the best all-around implementation
- TreeXXX: red-black tree implementation, it can search, insert, and delete in O(logn) time
- LinkedXXX: doubly-linked list implementation, good for frequently insertion and deletion
- MapXXX allows null keys and values while Hashtable will not.
- Use static factory wrapper to provide synchronization.
1. Set: HashSet, LinkedHashSet; SortedSet: TreeSet
2. List: ArrayList, LinkedList
3. Queue: PriorityQueue
4. Map: HashMap, TreeMap, LinkedHashMap
Convenience for compability
1. Arrays.asList(): allows an array to be viewed as a list
2. Collection.toArray()
*WeahHashMap
An implementation of the Map interface that stores only weak references to its keys. Storing only weak references allows key-value pairs to be garbage-collected when the key is no longer referenced outside of the WeakHashMap. This class provides the easiest way to harness the power of weak references. It is useful for implementing "registry-like" data structure, where the utility of an entry vanished when its key is no longer reachable by any thread. It is can be used to implement cache data structure as well.
Java Memory Control
1. Weak Object References
Manage memory effectively with Java reference objects
///MemoryBlock.java
public class MemoryBlock {
int id;
int size;
byte[] block;
public MemoryBlock( int id, int size ) {
this.id = id;
this.size = size;
block = new byte[size];
System.out.println( "MemoryBlock created: "+this );
}
public String toString() {
return "{id="+id+",size="+size+"}";
}
protected void finalize() {
System.out.println( "MemoryBlock finalized: "+this );
}
}
//MyReference.java
import java.lang.ref.*;
public class MyReference extends SoftReference<MemoryBlock> {
public MyReference( MemoryBlock referent ) {
super( referent );
}
public MyReference( MemoryBlock referent, ReferenceQueue<MemoryBlock>q ) {
super( referent, q );
}
public String toString() {
return String.valueOf(get());
}
}
///MemoryTest1.java
import java.util.*;
public class MemoryTest1 {
public static void main( String[] args ) {
ArrayList<MemoryBlock> blocks = new ArrayList<MemoryBlock>();
int size = 65536;
for ( int id=0; true; id++ ) {
blocks.add( new MemoryBlock(id,size) );
System.out.println( "blocks: "+blocks );
size *= 2;
}
}
}
///MemoryTest2.java
import java.lang.ref.*;
import java.util.*;
public class MemoryTest2 {
public static void main( String[] args ) {
ArrayList<MyReference> blocks = new ArrayList<MyReference>();
int size = 65536;
for ( int id=0; true; id++ ) {
blocks.add( new MyReference(new MemoryBlock(id,size)) );
System.out.println( "blocks: "+blocks );
size *= 2;
}
}
}
2.
Java reference objects make caching easy
Friday, December 09, 2005
WSDL Design: style=Document/Rpc Use=Literal/Encoded
quoted from "Which Style of WSDL shoud I use?" and "SOAP Fight: RPC vs. Document"
1. Structure of WSDL
a. Root element "definition"
b. PortTypes: include a set of operations
c. Messages in the operations
d. Types used in the message: schema
e. Bindings to "portType": actual implementation protocol e.g. SOAP
f. Services
2. Where to specify "style" and "use"?
3. STYLE difference
RPC style: soap body contains an element with the name of the Web method being invoked. This element in turn contains an entry for each parameter and the return value of this method.
Document style: The message parts appear directly under the soap body element.