Sunday, March 4, 2007

Access modifier : "private" for distinct instances of the same class

Many of us who are reading this blog might have learned the use of access modifiers in Java. I found that there is a small confusion about the use of "private" access modifier.

private
member
Accessible only in its class(which defins it).
protected
member
Accessible only within its package and its subclasses
public
class

interface

member

Accessible anywhere

Accessible anywhere

Accessible anywhere its class is.

Let us create a new class named "Student".

public class Student {
private int score;

public Student() {
score = 89;
}

public void modifyScore(Student that,int newValue){
that.score = newValue;
}

public String toString() {
return "Score = " + score;
}

}


Imagine a situation where instance "A" of class "Student" trying to modify the "score" member of instance "B" of the same class, The misunderstanding is this cannot be done because of the score's access modifier is private. In fact, it can be done correctly. As the rule states that private members are accessible only in its class. So instances could access the private members of other instances too.

Windows Vista : Upgrade versus Clean Install


I have just clean installed the final version of Windows vista few hours ago. The installation process took only 30 minutes! That was fast, compared to previous versions of Windows.

However, when I installed Windows Vista (RC1) for the first time. It took around 2-2.5 hours for the installation process to finish. I was using the "Upgrade" option at that time to upgrade from my Windows XP SP2.

So for those who are planning to upgrade to Windows Vista, my suggestion is to do the clean install instead of upgrade from previous version. Addition to the shorter setup time, I think clean installation gives the system more stabilities too.

Thursday, February 1, 2007

My first simple .NET Framwork 3.0 app

My friends and I had just submitted the project proposals for Imagine Cup 2007: Software Design (You can find more info about Imagine Cup at http://www.imaginecup.com). One of the requirements of the project, only for the first round here in Thailand, is to build the application on the .NET Framework 3.0 which means it's time to start learning WPF, WCF, WF now!

To get started, make sure you have Visual Studio 2005 and these extensions.


First, I created a new project of type Windows Application under .NET Framework 3.0 category. I named it "HelloWPF".

I then designed the form. The Visual Studio's WPF designer is seperated into 2 panes : one for the visual designer and the other for editing raw XAML code. You can click on the "swap" button to swap the XAML pane and visual designer pane too. However, this CTP version of designer is hard to use and is not very impressive.

After that, I tried to add an event handler to the click event of the button. But there is no same old "Events" tab in the property window. Double clicked the button in the designer also not work. It takes me some time to figured out that I has to map event to code in XAML or to map it in the code under the constructor. I choose the latter way. Here is my C# code.



public partial class Window1 : System.Windows.Window
{

public Window1()
{
InitializeComponent();
btnSayHello.Click +=
new RoutedEventHandler(btnSayHello_Click);
}

void btnSayHello_Click(object sender,
RoutedEventArgs e)
{
txtMessage.Text = "WPF : สวัสดี ว่าไง";
}

}


I could finally press the F5 button and this is the result.