Bidvertiser

Tuesday, April 30, 2013

How to add a Git submodule from eclipse EGit

Adding a submodule using eclipse

You can add a new submodule to a repository by selecting a repository in the Git Repositories view and selecting the Add Submodule context menu option.

The wizard will prompt for the path and URL of the submodule being added. The path entered will be relative to the parent repository's working directory and the URL will be used to clone the repository locally.

Once the wizard is completed the submodule will be cloned, added to the index, and the submodule will be registered in the .gitmodules file as well as in the parent repository's .git/config file.

Credit: http://wiki.eclipse.org/EGit/User_Guide

Tuesday, April 23, 2013

Mac - How to fix disappearing scroll bar

Are you getting frustrated that you are not able to get your scroll bars in your macbook? You are not the only one. J

How to fix your scroll bar?

Here are the steps,
  1. Click on the Apple logo on the left corner.
  2. Click on System preferences
  3. Under personal select General
  4. Click on Always radio button under Show scroll bars. 
Now you can see your scroll bars not disappearing.


Friday, April 5, 2013

Comparison of primitive type vs Wrapper object

After coming across this question in several interviews, came up with a small piece of code to compare primitive type and wrapper object.  Auto boxing after Java 5 has shadowed the behind seen happenings to fellow developers. :-)

There will be n number of pages in google to give the differences, I am just giving a small program to compare the performance of int and Integer.


import java.util.Date;

/**
 * PerformanceTester.java
 *
 * @author cananth
 */
public class PerformanceTester {
   public void processWithWrapper() {
      long startTime = new Date().getTime();
      Integer ctr = 0;
      for (int i = 0; i < Integer.MAX_VALUE; i++) {
         ctr += i;
      }
      long endtime = new Date().getTime();
      System.out.println("---------------------------------------------------");
      System.out.println("Time using Integer: " + (endtime - startTime) + " ms");
      System.out.println("---------------------------------------------------");
   }

   public void processWithPrimitive() {
       long startTime = new Date().getTime();
       int i = 0;
       int ctr = 0;
       for (i = 0; i < Integer.MAX_VALUE; i++) {
           ctr += i;
       }
       long endtime = new Date().getTime();
       System.out.println("Time using int: " + (endtime - startTime) + " ms");
       System.out.println("---------------------------------------------------");
   }

   public static void main(String[] args) {
       System.out.println("Same Object");
       System.out.println("---------------------------------------------------");
       PerformanceTester test = new PerformanceTester();
       test.processWithWrapper();
       test.processWithPrimitive();
       test.processWithWrapper();
       test.processWithPrimitive();
             
       System.out.println();
       System.out.println("New Object");
       System.out.println("---------------------------------------------------");
       new PerformanceTester().processWithWrapper();
       new PerformanceTester().processWithPrimitive();
       new PerformanceTester().processWithWrapper();
       new PerformanceTester().processWithPrimitive();
   }
}

Output:
Same Object
---------------------------------------------------
Time using Integer: 7835 ms
---------------------------------------------------
Time using int: 1505 ms
---------------------------------------------------
Time using Integer: 7685 ms
---------------------------------------------------
Time using int: 1489 ms
---------------------------------------------------

New Object
---------------------------------------------------
Time using Integer: 7369 ms
---------------------------------------------------
Time using int: 1 ms
---------------------------------------------------
Time using Integer: 7356 ms
---------------------------------------------------
Time using int: 1 ms
---------------------------------------------------

The difference in execution is huge.  In few of my trials I have got 0ms too for the int.

Verdict: Never use wrapper class for computations.

submit to reddit