Sunday, February 27, 2005
vi copy and past
mq = mark the location with key q
move the cursor to the desired location.
'yq = copy the lines into buffer from mark q
now go to a different location, type p
All the lines get pasted into the new location
mq = mark the location with key q
move the cursor to the desired location.
"a = create a register named a
y`q = copy the lines into buffer from mark q
now go to a different file
:e file.new
"ap - paste from register a.
All the lines get pasted into the new location
mq = mark the location with key q
move the cursor to the desired location.
'yq = copy the lines into buffer from mark q
now go to a different location, type p
All the lines get pasted into the new location
mq = mark the location with key q
move the cursor to the desired location.
"a = create a register named a
y`q = copy the lines into buffer from mark q
now go to a different file
:e file.new
"ap - paste from register a.
All the lines get pasted into the new location
Tuesday, February 22, 2005
Saturday, February 12, 2005
Friday, February 04, 2005
Java Coding Practices
Encapsulation:
- Aim to make all of your instance variables private and provide accessor methods where necessary.
- Make accessor methods for instance variables "final".
- Only use protected instance variables or protected constructors in well-defined packages
Packages :
- use packages constantly to manage complexity.
- if a class is only used within a package, make it package local (default visibility) to reduce system-level coupling.
- prefer the use of packages over static inner classes.
- An inner class only makes sense, and should only be used, if it is going to associate and be visible only to the class that contains it.
inheritance:
- constructors are not inherited.
- keep inheritance hierarchies small.
- prefer delegation or utility classes over inheritance for reuse.
- inheritance is a class-based, "is a type of" relationship.
- inheritance and delegation are 2 types of generalization. sometimes it is better to delegation over inheritance. ( performance is one of them. )
- all classes implicitly extend the class "Object".
- avoid unnecessary casting.
abstract classes :
- if a class is designed to be inheriated, but it does not make sense to have an instance of the class, it should be defined as abstract.
- abstract classes that contain only method signatures and static final fields should be declared as interfaces.
interfaces :
- interfaces can define method signatures and static final fields only.
- interfaces cannot define constructors.
- program to an interface, not to an implementation.
polymorphism
- the JVM will always search up the inheritance hierarchy from the real class of the target object, in order to find the first match for the signature of the target method, no matter what the apparent type of the object is at the time of the call.
- the field access such as "public static" is based on the apparent type and not the real type of the object.
- migrate common instance varibles and concrete accessor methods to an abstract class that can lie between the interface and concrete classes in a hierarchy.