I tried a new Java (OOP) Training technique yesterday, and you'll dig it
Tue, 18 Oct 2005 06:40 PM GMT

I taught a custom class yesterday... for 8 hours! This is a long time to talk about Java. I am still reeling from all of the hours that I spent standing up and talking about my favorite programming language. Although I am still feeling exhausted, I am pretty excited that my little experiment worked.

Of what experiment do I speak? Well, in a class of 6 students, (if you plan to do this, make sure there are at least 5 students) I had four students huddle in a mass at the right side of the classroom and then grouped two on the left side. I gave each student a piece of paper and a marker. The next thing I did was whip up a quick Java class called “Human.” This was a simple class that looked like this:

public class Human {
   private String firstName;

   public void setFirstName(String var) {
       firstName = var;
   } 

   public String getFirstName() {
       return firstName;
   }
}

The reason that I have firstName = var instead of this.firstName = var, or any of the other variations using the keyword this, is that the term this can require at least 30 minutes of full explanation, and at that point in time, I wasn't ready to go into it.

So after I put my Java class, “Human,” onto the projector screen, I added a main method and two pointers:

Human x = null;

and

Human y = null;

I asked the two people grouped on the left to be “x” and “y” - the pointers. I told them that their job, since they were now acting as “Human” pointers, was to point to Humans all day long. I asked them to mark their pieces of paper with their new names and roles (“Human” pointers called “x” and “y”) accordingly. I told them that as pointers, they would also serve as communicators to the objects to which they were pointing. I also mentioned that they were really pointing to nothing, since I set them (the pointer values) to null. So now, I’ve got two people (my “Human” pointers) pointing to nothing. I threw in a few jokes as they were pointing to empty air.

The next thing that I did was to tell the class that I was the VM and would now create a new Human. I did this by bringing one student out from the huddle of people on the right and having him write “firstName” on his piece of paper and nothing else, since I, the VM, hadn't assigned a name yet. I told my pointer “x” (on the left side of the classroom) to point to this new “Human.” Then, on the projector screen, I typed the following:

x = new Human();

So now, I have one person pointing to another person in the classroom. To extend my experiment further, I decided to assign a first name to the “Human” object that “x” was pointing to. So I told “x” that, as VM and on behalf of the great Java programmer, I would like to set the firstName of my Human object to Bob, Sue, Stan, Carlos or whatever the volunteer’s name happens to be. This, by the way is a great way to learn students' names. ;) I then typed the following on the projector screen:

x.setFirstName("Bob");

The Human object was then instructed to take his marker and write his name next to "firstName:.” I got another student and did the same thing, except now using my “y” pointer to point to the new “Human” object and set a name:

y = new Human();
y.setFirstName("Sue");

Then, I created another new Human and told my “x” pointer to point to this new Human object. I also told “x” to give the new object a firstName. I then informed my first Human that there were no pointers referring to him anymore, so he had better prepare himself, because the garbage collector would soon come by to get rid of him. I also mentioned that a programmer really has no idea when the garbage collection will happen, only that it will. I then typed the following up on my projector screen:

x = new Human();
x.setFirstName("Stan");

I added to this live example by getting two pointers to refer to the same Human:

y = x;

I then asked my “y” pointer to set the first name of the Human object to "Rob." The Human object was then instructed to cross his name out and replace it with "Rob". To get an idea of how my experiment was running, I asked “x”, “What is the firstName of the Human object that you are pointing to?” Since “x” was pointing right at a person holding up a sign that said "firstName: Rob", “x” answered correctly.

The great thing about this experiment is that students got to see the code work right in front of their eyes; it also helped them to get a good understanding of references. Another benefit of this exercise, as I mentioned earlier, was that we all got a chance to learn everyone’s name real quick.

This was a terrific ice breaker and I believe that it gave everyone in class a head start in OOP development.

3 comments for I tried a new Java (OOP) Training technique yesterday, and you'll dig it
carlos orrego
Wed, 19 Oct 2005 02:06 PM GMT

excelente example i will definitly use this on my classes thanks very much
steve
Sat, 22 Oct 2005 12:09 AM GMT

Hmmm ... absolutely terrific!
zzcoke.com
Mon, 9 Jan 2006 07:16 AM GMT

Thanks for the extra info..
Podcasting to teach java.
Wed, 12 Apr 2006 04:32 PM GMT

I did a search a couple of minutes ago on Podcast.net. I was looking for Java podcasts to subscribe to. I typed in 'java' and was surprised to see that a professor at Harvard Extension School had his computer science podcasts up online. The content he provides is an XML and J2EE course for the spring 2006 semester.

The course, which you can listen to now, covers XML, DTD, Schemas, SVG, and what looks like every other conceivable X*. Click here to review the podcasts for yourselves.

I found the idea of educational podcasts pretty interesting and quite groundbreaking. Educational podcasts may possibly evolve into the new university curriculum standard, reducing the university campus to an amusement park where students go only to find parties and sex.

2 comments for Podcasting to teach java.
Scott Mark
Wed, 12 Apr 2006 05:46 PM GMT

This is very cool - thanks for pointing it out. This might not be quite as meaty or detailed as what you are looking for, but check out the RedMonkRadio podcasts and Drunk and Retired - I like both of those. Cote' and I are also starting a feed of dev-related podcasts that we find interesting - try subscribing to http://feeds.feedburner.com/podcasts4u
Danno
Wed, 12 Apr 2006 05:51 PM GMT

Thanks Scott!