Saturday, October 14, 2006

Use of Interface class in Java

When we write an interface class, it should be always public. We can’t write private interface classes because there will be no use or can’t accomplish the purpose of writing it. As we know Java language supports only one inheritance of its parent class. We can’t inherit more than one class. For example,

We can write,
public class Civic extends Honda {}

We cannot write,
public class Civic extends Honda, CarAudio {}

In the above line Civic type car is created inheriting Honda class. Say, we want to use a method which resides in another class called CarAudio, which contains all the methods related to audio functions. In this case we can use an interface class called ICarAudio that contains all the methods related to audio functions, and this can be used to add the audio functions to the Civic class.

public class Civic extends Honda implements ICarAudio {}

Interface classes can be used for the purpose of multiple inheritances in Java programming language. But note an interface class should be defined with static or public scope.

Let me point of some facts about interface class.

1. interface class will contain the signature of the method without the implementation.

public void maxVol() {}

2. Any given class can inherit more than one interface, we can achieve multiple inheritance through this.

3. Any given class cannot instantiate an interface class.

4. Methods should be written public or abstract in an interface class. It doesn’t allow writing private methods.

5. Variables in an interface class should be public, static or final.

6. A class should use all the methods in an interface class if it inherits an interface class.

Above can be applied for C# also.

Cheers!

Monday, October 02, 2006

Mapping icons for documents in SharePoint document library

As a sharepoint developer, I have come across this small issue which is to have an image for the 'pdf's in the document library. As default, pdf file's image icon is not mapped with a 'pdf icon' image file, but we can do this manually.

Browse to the folder,

%SystemDrive%:\Program Files\Common Files\Microsoft Shared\web server extensions\60

First Step:
under IMAGES folder, insert the pdf icon file (basically a GIF file with 16 x 16 pixels to look consistent)

Second Step:
under XML folder, open DOCICON.XML xml file.
Insert another mapping element with variables key="pdf" and Value="pdf.gif" as shown below.

<Mapping Key="pdf" Value="pdf.gif"/>

Key is the document's extension and Value is the name of the image file.

This will simply solve the icon problem and the best thing is you can have any icon for any file type.

Try and enjoy :)

Cheers!

Starting another application using .Net code

In .Net, I came across to start an external program through scripting. This is a very simple task but should make sure that the external application has rights when it is called to run. For example, had an experience to call another console application which will be called by a web part for a web page in sharepoint. Web part is installed with InstallAssemblies program, which install it in the Global Assembly Cache (GAC) and the console application will triggger some functions when it is called by the webpart. OK, enough with the bla bla stuff and the simple line of code is,

[C#.Net]
System.Diagnostics.Process.Start(string filename,string arguments);


Cheers!