Skip to content

Difference of constructor in PHP and Java

I know it’s lampzone, but I would like to talk about a little bit Java here.
In php , child’s constructor never calls parent’s constructor unless you call it intentionally. Like the code below, unless you uncomment out parent::__constuct() , it only prints out “I am B”.
<?php

// testab.php
class A {
public function __construct()
{
echo " I am A\n";
}
}
class B extends A {
public function __construct()
{
echo " I am B\n";
//parent::__construct();
}
}
$b = new B();
However, java does the contrary. If a child’s constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. By the way, you also HAVE TO call superclass constructor at the beginning of subclass constructor.
public class ConstructorTest {
    public static void main( String[] args )
    {
        //System.out.println("Hello world");
        //Parent p = new Parent();
        Child c = new Child();
    }
}

class Parent {

    public Parent( int n )
    {
        System.out.println("I'm a parent" + n);
    }
}

class Child extends Parent
{
    public Child()
    {
        super(10);
        System.out.println("I'm a child");
    }
}
Advertisements

Git : failed to push some refs

I got some problem today when I tried to git push origin master , here is the error message

jqyao@jqyao-x61t:~/dev/git-yaominator/makefile$ git push origin master
To git@github.com:yaominator/yaominator.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to ‘git@github.com:yaominator/yaominator.git’

I searched on Internet and found out that you only need to run git pull again, then you are fine from then on.

jqyao@jqyao-x61t:~/dev/git-yaominator/makefile$ git pull

remote: Counting objects: 7, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 4 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (4/4), done.

From git@github.com:yaominator/yaominator

f874c59..375f09e  master     -> origin/master

Merge made by recursive.

blogs/php-apc |   36 ++++++++++++++++++++++++++++++++++++

1 files changed, 36 insertions(+), 0 deletions(-)

jqyao@jqyao-x61t:~/dev/git-yaominator/makefile$ git push origin master

Counting objects: 23, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (17/17), done.

Writing objects: 100% (19/19), 2.61 KiB, done.

Total 19 (delta 3), reused 1 (delta 0)

To git@github.com:yaominator/yaominator.git

375f09e..98b56d3  master -> master

I like moving moving

As you may know from my previous post, I just bought a new hard disk and installed Windows 7 on it. But you know me, I won’t let Ubuntu down , so I installed it today. I was thinking to use dd to move my whole Linux partition to new hard disk, but I have several issues with this method.

1. I only allocated 20G for my old Ubuntu and it’s running out of space. This is one of the key reason why I want to buy a new / bigger hard drive .

2. I only use one partition for my old Ubuntu which means I may have to move again when Ubuntu 10.04 comes.

Finally I decided to partition my drive the way I described below

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              25G  2.5G   22G  11% /
udev                  1.5G  368K  1.5G   1% /dev
none                  1.5G  272K  1.5G   1% /dev/shm
none                  1.5G   84K  1.5G   1% /var/run
none                  1.5G     0  1.5G   0% /var/lock
none                  1.5G     0  1.5G   0% /lib/init/rw
none                   25G  2.5G   22G  11% /var/lib/ureadahead/debugfs
/dev/sda2              74G  9.6G   61G  14% /home
/dev/sdb5              18G   15G  2.5G  86% /media/42e33181-23cf-41b0-b59f-73768d6c1ac9
/dev/sdb2              51G   39G   12G  77% /media/BA8C7FBC8C7F722D
/dev/sda3             196G   27G  169G  14% /media/06DA0A15DA0A01A3

As you can see, I created a 74G partition for my /home directory and 25G for my root / directory. Those 3 media partitions are my Windows 7 on new drive, Windows XP and Ubuntu on my old one.

When Ubuntu 10.04 comes, I can easily to do a refresh install in / and keep my /home untouched. This way I don’t need to do the backup and restore as I am going to describe.

To move my old Ubuntu to new hard disk, here are the steps what I did

1. Download Ubuntu desktop ISO from Ubuntu website

2. Transform iso into usb flash drive using UNetBootin.

3. Boot from usb drive and install Ubuntu as normal

4. Mount old hard disk in external enclosure on Ubuntu

5. Using rsync to create and restore old home to /home/jqyao_old .

sudo rsync -axS –exclude=’/*/.gvfs’ /media/42e33181-23cf-41b0-b59f-73768d6c1ac9/home/jqyao/ /home/jqyao_old/

It took my x61t around 5 minutes to finish this step. The reason to use rsync is because it can keep all the permission and group/user information for all my files.

6. sudo mv jqyao jqyao.bak ; sudo mv jqyao_old jqyao

Restart and I am seeing all my personal staff back. The drawback is that I still need to manually install packages. Trying to find a way to generate installed packages list using apt-get/aptitude so we can easily restore from that package list. I think this could be very useful and I need to do more research on this.

Anyway, I am pretty happy with my new 7200rpm hard drive and Windows 7 / Ubuntu 9.10 dual boot on my x61t.

Update: I just found this article http://www.cyberciti.biz/tips/linux-get-list-installed-software-reinstallation-restore.html and it says you can use dpkg for backup/restore purpose. I haven’t tried yet, but will keep this update.

Update , I had installed these packages

jqyao@jqyao-x61t:~$ history | grep apt | grep install
150  sudo aptitude install php5-dev
176  sudo aptitude install php-codesniffer
416  sudo aptitude install flashplugin-nonfree
437  sudo aptitude install cellwriter
440  sudo aptitude install ibus-pinyin
442  sudo aptitude install xournal
444  sudo aptitude install thunderbird
446  sudo aptitude install pidgin
460  sudo aptitude install vim-gnome
462  sudo aptitude install emcacs23-nox
468  sudo aptitude install ctags
470  sudo aptitude install sun-java6-jdk
471  sudo aptitude install eclipse
499  sudo apt-get install virtualbox-3.1
503  sudo aptitude install git subversion php5-dev php5 php5-cli
505  sudo apt-get install build-essential
506  sudo apt-get install ruby
512  sudo apt-get install irb

Installed windows 7 on my x61t

I always love to try new operating system and tried so many Windows and Linux distributions. Since Windows XP, I stopped trying and using Windows operating system. Why? Because I don’t have powerful enough machine to play with Vista. My X61t came with Vista and I have to wait for 3 minutes or so to use applications. Wasting people’s time is KILLING people. I don’t want to kill myself so I gave up Vista.

I tried Ubuntu on my X61t since 9.04 and I love it since then. Of course, I started using Ubuntu since 6.06 here and there, therefore I am pretty familiar with Ubuntu.

My X61t 80G is getting less and less disk space after installing XP and Ubuntu on it, so I decided to change another hard disk. Today, I bought this Hitachi 320G 7200rpm 2.5″ hard disk from Fry’s for $54 before tax. This at least gives me more space and I also want it to provide me speed boost because my previous one is only 5400rpm.

It’s pretty easy to change hard disk for Thinkpad X61t and it only took me 3 minutes. I also bought a 2.5″ disk enclosure for my previous 80G so I can transfer my old systems to new one. I think I will use dd to copy the old ones, but I heard it’s hard to install Ubuntu after Windows 7 installation, therefore I installed Windows 7 first.

Windows 7 does have good hardware support. Windows update helped me to find many drivers and hand writing also works which is pretty useful.

I don’t want to hate Windows because I LOVE Linux. Being open sometimes is more important than being smart.

ubuntu 9.10 runs perfect on my x61t

I am always a huge thinkpad fan, ubuntu fan as well. The pre-installed Vista slows my x61t like a 10 year old computer that drove me crazy. I tried Linux from 1999 with RedHat Linux 5.1 on my 486 machine that I can only have 640×480. Ubuntu 9.10 is the new gadget on my thinkpad x61 tablet and I love it.

Here are some software I really like so far :

1. CellWriter ( http://risujin.org/cellwriter/ ). Awesome handwriting recognition software.

2. Xournal ( http://xournal.sourceforge.net/). You can take note by your pen.

3. Prism . My screen is small so I like to maximize its usage.

4. Boxee . Best media center software for my ubuntu/mac os x /xp

Test drive Git

I read some interesting articles about Git these days and looks like it is really useful when you don’t have any internet access ( plane , no wifi coffee shop … ) . I can have your own local copy of repository ( because hard disk is so cheap !) .

To install Git on my Mac OS X , I used sudo port install git-core ( or maybe git , i am old, hard to remember ;( ). To mimic some of the centralized VCS , I did these tests.

1. Test to create(init) a repo

[jqyao@localhost ~/dev]$ mkdir git-test
[jqyao@localhost ~/dev]$ cd git-test/
[jqyao@localhost ~/dev/git-test]$ touch a.txt b.txt
[jqyao@localhost ~/dev/git-test]$ git init
Initialized empty Git repository in /Users/jqyao/dev/git-test/.git/
[jqyao@localhost ~/dev/git-test]$ git add .
[jqyao@localhost ~/dev/git-test]$ git commit -m “init repo”
Created initial commit a78b4f1: init repo
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
create mode 100644 b.txt
[jqyao@localhost ~/dev/git-test]$ ls
a.txt   b.txt

2. Test to clone a repo so that I can work on my local copy

[jqyao@localhost ~/dev]$ git clone -l git-test/ git-test-clone1
Initialized empty Git repository in /Users/jqyao/dev/git-test-clone1/.git/
[jqyao@localhost ~/dev]$ ll git-test-clone1/
total 0
-rw-r–r–  1 jqyao  users  0 Oct 10 17:46 a.txt
-rw-r–r–  1 jqyao  users  0 Oct 10 17:46 b.txt

3.Test to work in origin repo and check if we can get those change from clone

jqyao@localhost ~/dev/git-test]$ touch c.txt
[jqyao@localhost ~/dev/git-test]$ git add .
[jqyao@localhost ~/dev/git-test]$ git commit -m “add c.txt”
Created commit de09435: add c.txt
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
[jqyao@localhost ~/dev/git-test]$ cd ../git-test-clone1/
[jqyao@localhost ~/dev/git-test-clone1]$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From /Users/jqyao/dev/git-test//
a78b4f1..de09435  master     -> origin/master
Updating a78b4f1..de09435
Fast forward
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
[jqyao@localhost ~/dev/git-test-clone1]$ ls
a.txt   b.txt   c.txt
[jqyao@localhost ~/dev/git-test-clone1]$

4. Test to do some work in clone and push to origin repo
[jqyao@localhost ~/dev/git-test-clone1]$ touch d.txt
[jqyao@localhost ~/dev/git-test-clone1]$ git add .
[jqyao@localhost ~/dev/git-test-clone1]$ git commit -m “clone1 add d.txt”
Created commit 9eb3513: clone1 add d.txt
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 d.txt
[jqyao@localhost ~/dev/git-test-clone1]$ git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 265 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /Users/jqyao/dev/git-test//.git
de09435..9eb3513  master -> master
[jqyao@localhost ~/dev/git-test-clone1]$ cd ../git-test
[jqyao@localhost ~/dev/git-test]$ ls
a.txt   b.txt   c.txt
[jqyao@localhost ~/dev/git-test]$ git checkout
[jqyao@localhost ~/dev/git-test]$ ls
a.txt   b.txt   c.txt   d.txt

5. Test to do work in clone2 and pull from clone 1
[jqyao@localhost ~/dev/git-test]$ cd ..
[jqyao@localhost ~/dev]$ git clone -l git-test git-test-clone2
Initialized empty Git repository in /Users/jqyao/dev/git-test-clone2/.git/
[jqyao@localhost ~/dev]$ cd git-test-clone2/
[jqyao@localhost ~/dev/git-test-clone2]$ ls
a.txt   b.txt   c.txt   d.txt
[jqyao@localhost ~/dev/git-test-clone2]$ touch e.txt
[jqyao@localhost ~/dev/git-test-clone2]$ git add .
[jqyao@localhost ~/dev/git-test-clone2]$ git commit -m “e.txt added by clone2”
Created commit 67c5e33: e.txt added by clone2
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 e.txt
[jqyao@localhost ~/dev/git-test-clone2]$ git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 245 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /Users/jqyao/dev/git-test/.git
9eb3513..67c5e33  master -> master
[jqyao@localhost ~/dev/git-test-clone2]$ cd ../git-test-clone1/
[jqyao@localhost ~/dev/git-test-clone1]$ ls
a.txt   b.txt   c.txt   d.txt
[jqyao@localhost ~/dev/git-test-clone1]$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From /Users/jqyao/dev/git-test//
9eb3513..67c5e33  master     -> origin/master
Updating 9eb3513..67c5e33
Fast forward
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 e.txt
[jqyao@localhost ~/dev/git-test-clone1]$ ls
a.txt   b.txt   c.txt   d.txt   e.txt

Actually these tests are to mimic how the centralized VCS works.

1.Create a repo

2.Worker 1 can pull source code from central repo and do work. After finishing his work, he can push back to central repo.

3.Worker 2 can work on source code and push back (check in ) central repo. Then worker 1 can pull(check out ) the  changes and continue work .

I am just trying to understand Git in the old way and will test more distributed way. will keep you posted 😉

Enjoy !

continuous integration

I am interesting in continuous integration these days and wanna integrate into my/my team daily development process. There are some choices like phpundercontrol and xinc.

I think these two posts will be interesting to read

http://www.slideshare.net/sebastian_bergmann/phpundercontrol-a-quick-start-to-continuous-integration-presentation?type=powerpoint

http://www.slideshare.net/arnoschn/continuous-integration-and-php

I will keep you all update once I found it’s useful.