Wednesday, December 16, 2015

My Infinite Playlist - '15

'15 you are truly insane. There were times when I hated you most for your stubbornness. Those waking up in the early morning, those late night struggles with sleep and slides, those schedules - almost all of your traits were crazy enough to drive me insane with your excuses. I sometimes hated you for your bullying gut. You almost dragged me to some amazing places where you wanted us to go but I was shy to explore. You inspired me to be good, to do something good with life, gave me a purpose. You are more than a friend to me.

I guess there were times too when you hated me too for my lazy ass. But believe me, I sincerely worked everyday to prove you that I was worth of your love and affection. My dearest, I grew with you every passing single moment. I despised you and the same time loved you. I truly loved messing with you, I know sometimes it made you annoyed but you patiently bore with a broad smile on your face. I fell in love with our awkward beautiful bonding.

Now as the time to say Goodbye is under the horizon, I want to say something to you even though I can't find anything that can properly express my feeling and our relationship but there is something I want to dedicate to you that says something about us - "The relation of growing together".


Most probably this is my last post directed towards bidding adieu to passing years.

Tuesday, December 2, 2014

Life As I Know It - Cheerio '14

As this year is almost over, I want to share some thoughts with you Jedis. Don't take failures as a stumbling block in your life. It's ok if you got things messed up, it's ok if you were rejected like hell, it's ok if you made yourself ashamed and ridiculed of yourself, it's ok if a low point came in your life and it's ok to allow yourself some time to heal before you take that next step. But remember that life is not a staircase, it's a maze. You can modify and alter your journey along the way. Be flexible and open to alternative pathways. It may lead you down some wonderful roads. Keep up the fighting spirit and know that it's not over until it's over!

And now to my '14: 
My sweetheart '14 before we say Goodbye, I want you to know something, even though you know it already my brave Lady. You will always stay loved and remembered. Here something dedicated to you.

                                                                 Happy new year!!

Thursday, November 20, 2014

Inheritance – “A type of” relation NOT “contains” relation

Many times people confuse inheritance with “contains” relationship, which is not correct at all. Inheritance is “A type of” relationship not “contains” relationship. So a child is a superset of Parent’s abilities.

Example: Each fox is an Animal. But the other way is not always true (Not every Animal is Fox). Hence, Fox is a type of Animal.

class  Animal{

                                    1.   Ability of walking

}

class Fox extends Animal{

                         1.   Inherited abilities: Ability of Animal (walking)

                         2.    It’s own abilities (like hunting)

}

Now let's try to digest few concepts here.
When I write this :  Animal  a = new Fox(). What does it mean?
It means Fox is also an Animal or  every Fox is a type of Animal which makes sense too.

What about :   Fox  f = new Animal() 
It means Animal is a type of Fox or every Animal is a Fox, which is absolutely incorrect.

So "Fox is an Animal" is fine but the reverse doesn't make sense. For example, Apple is a Fruit, Car is a Vehicle etc. Remember inheritance is uni-directional. For example, House is a Building. But Building is not a House.

Let's formulate our finding in terms of coding: A reference to child class object can't refer to the parent class object. Whereas a reference to parent class object can refer to child class object.

Example 1: 
       Animal a =  new Fox();     //True
       Fox  f = new Animal();      //False (Compilation error)

Example 2:
       Animal a = new Animal();
       Fox f = new Fox();
       a = f;               //True
       f = a;               //False (Compilation error)

So we learned few things here: 
A child class object is inherently a parent class object. In simple terms, objects/reference of parent class can hold objects of child class but the reverse is not true.

Example 3:
public class TestMain {

       public static void main(String[] args) {

              Animal a = new Fox();

              a.walk();

              ((Fox)a).hunt(); //need to typecast because reference "a" doesn't hold "hunt" method

       }

}



class Animal{

       void walk(){

              System.out.println("Animal can walk");

       }

}



class Fox extends Animal{

       void hunt(){

              System.out.println("Fox can hunt");

       }
} 

Output:
Animal can walk
Fox can hunt


Few points to mention here:
1.  A subclass can't inherit private members of Superclass obviously.
2. Try to keep all variables private or protected and use public accessor(set/get) methods to access them.
3. On a light note: Initially don't try to learn this concept with "child" and "parent" example as you might get confused. Playing with a dog or a cat is safe and easier. :)

Tuesday, November 18, 2014

Difference between method overloading and method overriding

Method overloading in Java occurs when two or more methods in the same class have the exact same name but different parameters.  Overloading is a compile time (static) phenomenon because the compiler is aware of exactly which method you are calling based on the number/type of parameters.
 
class Animal{
       void test(){
              System.out.println("Inside Animal class with no aruguments");
       }
      
       void test(int a){
              System.out.println("Inside Animal class with int aruguments");
       }
}

public class TestMain {
       public static void main(String[] args) {
              Animal a = new Animal();
              a.test();
              a.test(5);
       }

Output:
Inside Animal class with no aruguments
Inside Animal class with int aruguments

In this case, the compiler knows exactly which “test” method we are calling, based on the number/type of parameters.

Overriding methods is completely different from overloading methods. If a derived class requires a different definition for an inherited method, then that method can be redefined in the derived class. This would be considered overriding. An overridden method would have the exact same method name, return type, number of parameters, and types of parameters as the method in the parent class, and the only difference would be the definition of the method. Overriding is an example of dynamic (run-time) polymorphism. This is due to the fact that the compiler doesn't necessarily know what type of object is being passed in at compile-time.

class Animal{
       void test(){
              System.out.println("Inside Animal class with no aruguments");
       }
      
       void test(int a){
              System.out.println("Inside Animal class with int aruguments");
       }
}

class Dog extends Animal{
       void test(){
              System.out.println("Inside Dog class with no arguments");
       }
}

public class TestMain {
       public static void main(String[] args) {
              Animal a = new Dog();
              a.test();
              a.test(5);
       }

}

Output:
Inside Dog class with no aruguments
Inside Animal class with int aruguments

Here, method dispatching is performed in two steps:
  • The first one is done at compile time with the static information available, the compiler will emit a call for the signature that matches best your current method parameters among the list of overloaded methods in the declared type of the object the method is invoked upon.
  • The second step is performed at run time, given the method signature that should be called (previous step), the JVM will dispatch it to the most concrete overridden version in the actual type of receiver object.

Friday, June 20, 2014

Built-in VNC in MAC

I recently noticed there is a built in VNC in mac with name “Screen Sharing” app. (tasted with MAC 10.9.3)

Location of the app: “/System/Library/CoreServices” [Open Finder > Choose “GO” > "Go to Folder"]

Find the “Screen Sharing” app and drag it to dock bar or Desktop for easy access.
Features of this app: 
  • Multiple VNCs can be opened. 
  • Recent VNC info and password saving. This feature is missing in RealVNC application available in App Store.
  • Simple and less crashes.
  • Free!
While connecting to any VNC we have to give absolute port number, which starts with 59 always. 
For ex: bgl-mitp-013:01 vnc can be accessed with bgl-mitp-013:5901

Other option to launch this application is to use the “Connect to Server” keyboard shortcut that is available in the OS X Finder (just hit Command + K) or in web browser, type “vnc://” in the URL bar. Hit Return and the Screen Sharing app will be launched immediately.

Sunday, June 1, 2014

Some Basic How Mathematics

• Why does zero factorial (0!) equal 1 ?
   Because there is exactly one way to do nothing.

• How (a+b)2 = a2  + 2ab + b2 ?
   We can prove it geometrically.

Step 1: Draw a line of length (a + b)
             a              b
           –––|––––––––––

Step 2: Let's draw a square having sides of length (a + b). Area of this square will calculate the value of
(a+b)2




This is a square consisting two rectangular and two square parts.








Area of square part 1 = a2
Area of rectangular part 2 = ab
Area of rectangular part 3 = ab
Area of square part 4 = b2
So, Area of square of length (a+b) = (a+b)2 = a2 + 2ab + b2
i.e. (a+b)2 = a2 + 2ab + b2
Hence Proved.

Thursday, April 3, 2014

A note on iPython

In iPython, there is an Input/output caching system that offers numbered prompts (In/Out). All input is saved and can be retrieved as variables (besides the usual arrow key recall).

  The following GLOBAL variables always exist (so don't overwrite them!):
  _i: stores previous input.
  _ii: next previous.
  _iii: next-next previous.
  _ih : a list of all input _ih[n] is the input from line n.

Anywhere in code, don't use these variables, otherwise it would make very messy situation while debugging the code.