First day of spring
Today is the first day of spring this year.
I heard a thousand blended notes, While in a grove I sate reclined, In that sweet mood when pleasant thoughts Bring sad thoughts to the mind. To her fair works did Nature link The human soul that through me ran; And much it grieved my heart to think What man has made of man. Through primrose tufts, in that green bower, The periwinkle trailed its wreaths; And ’tis my faith that every flower Enjoys the air it breathes. The birds around me hopped and played, Their thoughts I cannot measure:-- But the least motion which they made It seemed a thrill of pleasure. The budding twigs spread out their fan, To catch the breezy air; And I must think, do all I can, That there was pleasure there. If this belief from heaven be sent, If such be Nature’s holy plan, Have I not reason to lament What man has made of man?
Posted at 10:27AM Mar 20, 2008 by Manveen Kaur in Personal | Comments[0]
Blob vs file system storage
Images can be stored as a database blob or in the file system. How do you decide what to choose? What are the performance impacts of each one?
Well, there are several reasons why you should not store binary data in your database:
Now here are some reasons why you should:
Here's one solution that takes into account the points above:
Store a link (e.g. a file path) to the image file in the database. Whenever you need the image, use the link in whatever program you use to retrieve the file containing the image.
Or you could think of storing your images in the database to gain the benefits there (preferable for smaller images and for limited images), but also use file system caching of these to obtain the performance benefits.
Some tips for getting the best performance out of the file system:
Posted at 02:38PM Mar 19, 2008 by Manveen Kaur in General | Comments[7]
Boxing and unboxing
Every type in Java is either a reference type or a primitive type. A reference type is any class, instance, or array type. All reference types are subtypes of class Object, and any variable of reference type may be set to the value null. There are eight primitive types, and each of these has a corresponding library class of reference type. The library classes are located in the package java.lang.
Primitive : Reference Mapping byte : Byte short : Short int : Integer long : Long float : Float double : Double bool : Boolean char : Character
Conversion of a primitive type to the corresponding reference type is called boxing and conversion of the reference type to the corresponding primitive type is called unboxing.
Autoboxing / unboxing is the automated under the covers conversion between primitive types and their equivalent object types. For example, the conversion between an int primitive and an Integer object or between a boolean primitive and a Boolean object. This was introduced in Java 5.
// Assigning primitive type to wrapper type : Boxing
Integer iWrapper = 10;
// Assigning object to primitive : Unboxing
public void intMethod(Integer iWrapper){
int iPrimitive = iWrapper;
}
Posted at 11:47PM Mar 13, 2008 by Manveen Kaur in General | Comments[0]
On Generics
Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection.
When we declare c to be of type Collection
JDK 1.5
You might think that generics are similar, but the similarity is superficial. Generics do not generate a new class for each specialization, nor do they permit “template metaprogramming.”
Is the following code snippet legal?
List<String> ls = new ArrayList<String>(); //1 List<Object> lo = ls; //2
Line 1 is definitely legal. But line 2 will give a compile time error.
Well, take a look at the next few lines:
lo.add(new Object()); // 3 String s = ls.get(0); // 4: attempts to assign an Object to a String!
In general, if Foo is a subtype (subclass or subinterface) of Bar, and G is some
generic type declaration, it is not the case that G
It’s written as
Collection<?>(pronounced “collection of unknown”) , that is, a collection whose element type matches anything.
Collection> c = new ArrayListLine 2 will give a compile time error since we don't know what element type of c stands for, we cannot add arbitrary data to it.(); //1 c.add(new Object()); //2
Posted at 12:40AM Mar 09, 2008 by Manveen Kaur in General | Comments[0]
Java Serialization
The process of saving an object's state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time.
To persist an object in Java, we must have a persistent object. An object is marked serializable by implementing the java.io.Serializable interface, which signifies to the underlying API that the object can be flattened into bytes (and subsequently inflated in the future).
public class PersistedClass implements Serializable
On the other hand, certain system-level classes such as Thread, OutputStream and its subclasses, and Socket are not serializable. These should be marked transient since it doesn't make sense to serialize them.
transient private Thread notserialthread;
Imagine you have a serialized flattened object sitting in your file system for sometime. Meanwhile, you update the class file, perhaps adding a new field. What happens when you try to read in the flattened object?
An java.io.InvalidClassException will be thrown! -- because all persistent-capable classes are automatically given a unique identifier. If the identifier of the class does not equal the identifier of the flattened object, the exception will be thrown.
If you wish to control versioning, you simply have to provide the serialVersionUID field manually and ensure it is always the same, no matter what changes you make to the classfile.
How? JDK distribution comes with a utility called serialver which returns the generated serialVersionUID. (it is just the hash code of the object by default).
Simply copy the returned line with the version ID and paste it into your code.
The version control works great as long as the changes are compatible. Compatible changes include adding or removing a method or a field. Incompatible changes include changing an object's hierarchy or removing the implementation of the Serializable interface.
Posted at 11:51AM Mar 04, 2008 by Manveen Kaur in General | Comments[0]