| Sign In/My Account | View Cart |
This is the second in a series of articles that looks at how programming
in Java is taught to new programmers. In the first article, I looked at the traditional first program, HelloWorld. I argued that although it was a
good "systems check," it was not a good first program for a course in Java
or in object-oriented programming. Despite the C-like syntax, we should not
teach Java as if it were C with objects. Objects really need to come first.
Your feedback was wonderful. Take a look back at last month's article and the accompanying talkback and feel free to join in any of the threads. Many people provided suggestions for tools and approaches that were thought-provoking. There were some who thought that we shouldn't be teaching objects first (you need to teach pointers and memory allocation) and some who suggested that Java was a toy language that is fine for teaching but not for serious development. Students and developers should learn about memory and they should learn more than one language and more than one approach. OOP in Java provides a solid introduction to programming. This series will continue to explore taking an extreme programming approach to this introductory course.
A group of responses felt that OOP is just a layer on top of procedural programming, and that method calls are, at their core, the same as procedure calls. In a future article, we'll focus more on the concept of "an object is at least a certain type." A polymorphic method call means that you are making a procedure call -- you're just making it without knowing which object or even which type of object will respond. At compile time, the object that you end up calling at runtime may not exist.
|
In This Series
Cooking with Java XP, Part 3
Cooking with Java XP, Part 2
Cooking with Java XP
Top 12 Reasons to Write Unit Tests
Rethinking the Java Curriculum: Goodbye, HelloWorld! |
In this article, we'll start looking at a test-first approach to programming and to learning. In extreme programming you have a task you want to accomplish. Within that task, you choose a small measurable result. You think about how you would verfiy that you've accomplished that result. You write the test and then you write the code that will pass the test.
In this article, I'll use an ad hoc framework for this process. Next, I'll use JUnit, but I want to separate what's being done from the tools used to do it. Please join the discussion at the end of each article and feel free to suggest future topics in the forum or by emailing me at DSteinberg@core.com.
Fundamentally, object-oriented programming is all about objects communicating with each other through their visible interfaces. You will learn to be stingy about what you expose to the outside world. Ideally, you will expose very little about the object's structure and only reveal those behaviors you are allowing others to invoke.
In a first programming assignment, I would like to see the newbie accomplish the following tasks:
As an example, consider the following two lines of code:
Friend friend = new Friend();
String yourName = friend.getName();
// somehow I will display yourName once I have it
Your first programming task is to write the code that makes those two lines
work. Sure, this seems trivial to you now. You quickly whip up a file, Friend.java,
that looks like this:
public class Friend {
public String getName(){
return "Daniel";
}
}
You compile it and somehow run the program and you expect to be greeted by name. Again, it's hard to remember back to when you didn't know anything. There's a lot here. I taught freshman calculus for a dozen years or so; on the last day of each semester I would write all that we had learned that semester on the board and step back. There, on a pair of blackboards at the front of the room, was everything we had covered over the past fifteen weeks. Looking back, it didn't look like much -- but it had taken us an entire semester and countless blackboards to get to this point. I'm asking you to go back to when you didn't know how to program and think about this assignment.
|
Related Reading Learning Java |