Posts

Installing Font in Fedora

Recently I needed to print a receipt with Barcode. But the particular webpage was not showing the Barcode. I googled and found a very helpful page and I followed the steps and then I was able to achieve my goal. The link I am talking about is http://www.cb1.com/~john/notes/fedora-font-install.html . I followed the first option. First I donwloaded the font library and then installed using kfontview. type kfontview from the command line. if kfontview is not available then install it by typing yum install kdebase  from the command line. From the kfontview window, open the font you have downloaded. Click on the "Install". Thats all , now close all your browse instances and again open the page with Barcode . You should be able to view it properly

When to User Interface and When Abstract Class

This discussion is very common , when to use interface and when to use Abstract Class. Before deciding we should know properties of Abstract Class and Interface in details ::Abstract Class:: It contains both abstract methods and non abstract methods Classes Extend Abstract Class Abstract Classes cannot be instantiated. Abstract can't be declared with Final Synchronised Native. It can have static and instance initialise block. Abstract Class has constructor. Abstract Class may not contain any method(any abstract method) ::Interfaces:: Interface contains all abstract methods. Classes implements Interface. all methods compulsory implemented by particular class which implement interface. Interface variables are implicitly public static and final. Interface variables are constants that cannot be overridden. They are inherited by any class that implements an interface. Interface may not contain any method(Marker Interface). Interface does not contain Constructor. I...

How To Get country name, city name,Location from IP address

hostip.info provides Api's where if we pass the IP Address, it returns the Location details like Country Name, City Name , Lon and Lat etc. We can use PHP to process the response from the api call and get the required data. Some of the API provided by hostip.info are as follows, http://api.hostip.info/country.php US http://api.hostip.info/get_html.php?ip=12.215.42.19 Country: UNITED STATES (US) City: Sugar Grove, IL http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true Country: UNITED STATES (US) City: Sugar Grove, IL Latitude: 41.7696 Longitude: -88.4588 Now I will show you how to use PHP to call and process similar Api's http://api.hostip.info/?ip=12.215.42.19 [use the URL above for an example - XML too long to paste below] Following is the PHP function, function countryCityFromIP($ipAddr) { //get the XML result from hostip.info $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr); //get the city name inside the node and preg_mat...

Setting User Name in Eclipse For Comments Generation

Recently I have noticed that eclipse IDE on Fedora inserts the default system user name "root" in the @author attribute for java comments. I have found two ways to change the Default System User name to what ever you like, The First way is to The other one is just by  changing the associated templates in Window -> Preferences -> Java -> Editor -> Templates -> @author , and hard coding the author's name. The Other way is by editing the eclipse.ini file, For example , the following eclipse.ini file shows what I have done to set my name -showsplash org.eclipse.platform -framework plugins/org.eclipse.osgi_3.4.2.R34x_v20080826-1230.jar -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -XX:MaxPermSize=256m -Duser.name="Siddhartha(Sidd)" Notice the  attribute Duser.name , that I have set to Siddhartha(Sidd),  after changing eclipse.ini we should restart eclipse so that changes can take effect. Now, when ever I want to a...

Hibernate 3 with Annotation Hands on with Example

I have worked with Hibernate2 where we had to define all configuration as well as Class to Table mapping though XML files. Hibernate 3 goes one step ahead and provides new ways to work Where we can use annotation to define Class-Table mapping. Hibernate3 supports annotation and requires Java 5 or above to function properly. While trying to work with Hibernate you will notice it has several dependencies to other third party jars, like apache commons collections , apache commons logging. I have tried to put all the required file in a zip file  and named it   "hibernate3AllJars" . Since while playing around with codes which require some data base I prefer MySQL   since it is very easy to use and it is free. I have also putted the  MySQL JDBC Driver  mysql-connector-java-5.0.5-bin in the zip file. If needed you can email me regarding the zip file. For the Hands on I have created a Table in MySQL Database "sidd"  by executing the following command, CREATE TABLE `hone...

What is Design By Contract

Design by Contract is a trademarked term of BertrandMeyer and implemented in his EiffelLanguage as assertions. Design By Contract (DbC) is a software correctness methodology. It uses preconditions and postconditions (Contracts) to programmatically assert the change in state caused by a piece of a program. The Preconditions and Postconditions that are in demand in DbC could summarized by the "three questions" that the designer must repeatedly ask:     * What does it expect?     * What does it guarantee?     * What does it maintain? Some attributes of Design By Contract... Classes should specify their invariants: what is true before and after executing any public method. Methods should specify their pre- and post-conditions: what must be true before and what must be true after their execution, respectively. Pre-conditions may be weakened by subclasses and post-conditions may be strengthened. The explicit definition of these "assertions" forces the designer to th...

Static Import In Java 5

Constant Interface Anti pattern is a real hot topic of discussion in java, after browsing the web for hours I am not sure whether to use it or avoid it. Constant Interface is a interface which defines some public static final constants. And when we need those constants we can implement the Interface and uses the defined constants or we can access the static constants as InterFaceName.ConstantName. The book Effective Java by Joshua Bloch discusses this problem he calls it "Constant Interface Anti pattern." Poor use of interfaces and  Exposes Implementation Detail are some of the issues why author advocates to avoid it. public interface Constants {       public static final double PI = 3.14159;       public static final double PLANCK_CONSTANT = 6.62606896e-34;   }     public class Calculations implements Constants {       public double getReducedPlanckConstant() {         return PLANCK_CONSTANT / (2 * PI);     }   } Java 5 comes with a Static Import concept. We can solve the...