Archive for the ‘Java’ Category

What is the difference between “overloading” and “overridding”?

December 10, 2009

Function Overloading is the implementation of static polymorphism where same function name having different defenitions for different uses.

Function overriding is applicable for dynamic polymorphism where where the function name and the definition are same but the function call is decided at the run time according to the type of object reference.

ABC to Convert Integers to Strings in C++

June 23, 2009

I was solving a problem in TopCoder. It required a conversion of  integer to a string. This is simple in Java but a little complicated in C++. So, I am jotting down here some of the link that helped me. I will also try to make a mention of the problem associated with them.

The first one – itoa. Well, itoa considered unsafe to use this in C++. You may get an error like ” itoa was not declared in the scope “. I got stuck with the same error. It was then I started searching for solutions. The link following is about itoa. Note that, itoa doesn’t work in TopCoder.

The next link use boost and a string stream. Again, the header file “boost/lexical_cast.hpp” is not detected by TopCoder.

So, I feel, more or less the best way is to have you own customized code.

string convertInt(int number)
    if (number == 0)
        return "0";
    string temp="";
    string returnvalue="";
    while (number>0)
    for (int i=0;i<temp.length();i++)
    return returnvalue;

The following link has more information about it.

If you have any doubt, post in them as comments.

In Java, you can go about with some code like the following. Note, ‘s’ is a String and ‘a’,’ b’ and ‘c’ are Integers.

s = a + ” ” + b + ” ” + c;

Though something like above is possible in C++, it requires ‘a’,’ b’ and ‘c’ to be Strings.

Happy coding ! 🙂


ABC to Import a jar file in Netbeans 6.5

June 17, 2009

If you want to import a jar file in NetBeans, I guess I can help you out. Using the following procedure, you can import folders as well as other projects to the project you desire. I wanted to use the log4j for using logger in my application. So I had to import a jar file (log4j-1.2.15.jar) to the project. One of my friends helped me out, infact both of us just discovered how to import. Here we go…

I always feel that a picture can convey 1000 words, so the snaps. The following is what I did:

Right click on the project to which you which to import files. Note that the project need not be set as a Main project to import packages into it.

.Right Click on the Project Name !

Right Click on the Project Name !

In the window that opens, Choose Libraries in the left panel as shown below. On the right hand side of the window, I hope,  you can see an option called ‘Add JAR/Folder‘, click on that.

Select Libraries from the Left Panel !

Select Libraries from the Left Panel !

The new window that opens in familiar, I guess. Well, then Browse to the place where you have the jar file, select it and press ‘Open

Select the jar file you want to import

Select the jar file you want to import

As shown below, in a tab called ‘Compile‘, you can see the files that you have added (This is the default chosen tab, so after you have pressed ‘Open‘ in the previous step you will land here). Repeat the process if you want to add more files and then press ‘OK‘.

Click on Ok after you have imported

Click on Ok after you have imported

Another windows opens and you can see that the things you have added get saved (This is what the window shows :), it is just to see, nothing needs to be done).

The filed you have imported are saved

The filed you have imported are saved

As said earlier, the same procedure can be applied to add folders and other projects. If you had noticed, those where the other option in the image 2 shown above. Problems are Welcome  ! 😀

Types of Log Appenders in log4j

June 3, 2009

Types of log appender

An appender specifies where your log messages are written to. There is a wide choice of appenders available. All appenders are direct or indirect subclasses of the AppenderSkeleton. Therefore we can find all options on the following API page:

The console and the file appender are a subclass of WriterAppender.

Later on, we are going to choose examples for the following appenders.

ConsoleAppender Logs to console
FileAppender Logs to a file
SMTPAppender Logs by email
RollingFileAppender Logs to a file, starts a new file once the max size is reached. (An alternative is the DailyRollingFileAppender which creates on file per day)

But there are as well:

AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, DailyRollingFileAppender, RollingFileAppender.

Custom appenders can be created as well. The log4j download comes with a whole bunch of samples in the examples directory.

For more information on log4j, visit the source below.

Source :

Download and Install JDK !

May 23, 2009

Is it necessay to install JDK in Suse 11.1 ?

I was trying to install NetBeans 6.5 in Suse 11.1. Unfortunately, the JDK was not installed when I installed the OS. I had to search a lot before I found the JDK. The following site has the jdk-6u14 for Linux, Windows and Solaris along with the installation instructions. (Note – Always download and install the jdk from the java sites and ensure that you install the correct version)

I am briefing out the procedure anyways. Choose the appropriate version of JDK depending on the type of your OS. For Suse 11.1, I used the Linux Self Extracting File


You can download and install the rpm as well. Then you need to copy this file to appropriate folder. Usually people install java in /usr/java or /usr/local/java. Give executable permission to the binary file. This is done by

chmod +x filename

Then execute the file. It can be done as follows


Read the instruction and the accept it by typing yes“. You have successfully done. I did the same and went ahead installing NetBeans. 😀

Download and Install log4j / Log for Java

May 1, 2009

Log for java aka log4j is a library. Its a small software that need to be downloaded an installed. The installation which I am going to illustrate if for Linux and a similar procedure can be followed for windows. It can be downloaded from the following link –

Download the tar file and extract it using the following command

tar -xvvzf apache-log4j-1.2.15.tar.gz

Move the for apache-log4j-1.2.15 to the a location of your choice. But I recommend you to put it in a folder where you have installed java (say you have moved the extracted the folder to /usr/java/). Now, the jar file log4j is inside the folder. The path should be


After this there are two ways to make it recogniseable by you java program. One is you need to set the CLASSPATH. The second and the best alternative is, you could import that jar file. I guess most of you use NetBeans or Eclipse for java programming. So all you need to do is to imort this jar file and it will be recognised by you package. If you want to know how to use logger function, read the following manual

%d bloggers like this: