Code for teaching
What care should be taken with the code we give our students
A student emailed me a link to where the following code was posted for their class. Note: I am not soliciting for other examples of code like this.
public class Team
{
private int teamSize = 0;
private BallPlayer player1, player2, player3, player4, player5, player6, player7, player8, player9;
public void getPlayer()
{
teamSize++;
switch(teamSize)
case 1: player1 = new BallPlayer("first baseman");
System.out.println(player1.getPosition() + " added to team");
break;
case 2: player2 = new BallPlayer("pitcher");
System.out.println(player2.getPosition() + " added to team");
break;
case 3: player3 = new BallPlayer("catcher");
System.out.println(player3.getPosition() + " added to team");
break;
case 4: player4 = new BallPlayer("left fielder");
System.out.println(player4.getPosition() + " added to team");
break;
case 5: player5 = new BallPlayer("right fielder");
System.out.println(player5.getPosition() + " added to team");
break;
case 6: player6 = new BallPlayer("shortstop");
System.out.println(player6.getPosition() + " added to team");
break;
case 7: player7 = new BallPlayer("third baseman");
System.out.println(player7.getPosition() + " added to team");
break;
case 8: player8 = new BallPlayer("Centerfielder");
System.out.println(player8.getPosition() + " added to team");
break;
case 9: player9 = new BallPlayer("second baseman");
System.out.println(player9.getPosition() + " added to team");
break;
}
}
public int getNumberPlayers()
{
return teamSize;
}
}
The students were asked to clean up code in a class titled BallPlayer and one titled TeamUser, but the proper usage of Team is to call getPlayer nine times. This is code intended to teach students the switch statement in their first course in Java. I'm scratching my head over much of it starting with the void return type for getPlayer() and the use of switch in the first place for this example.
As a child I hated hearing adults say "do what I say and not what I do." As a teacher, I often fall short but I do aim to model the behavior I'm trying to teach. If I want the students to write test-first then I better do the same when possible. I know there's lots of bad code out there, but this class struck me.
In today's Weblogs, Navaneeth Krishnan blogs about Poor Man's Web Services. He's looking at RSS in the context of a web service.
Chet Haase blogs on Miscellaneous Stuffn Things. He shares his thoughts on JavaOne call for papers and the Netbeans release and Swing/2D effects for rich clients.
Do we respect our elders enough? John Reynolds has started a conversation in Too old to program? He asks " Is programming just a career for young whipersnappers? "
In Also in Java Today , ONJava is featuring a collection of goodies and gotchas from Elliote Rusty Harold's newly-updated Java Network Programming, 3rd Edition. In URLs and URIs, Proxies and Passwords, he illustrates character-encoding hazards with URL's, how to build a URI, how to get fine-grained control of proxy server communication, how to get data with an HTTP GET, and how to work with password-protected sites with Java.
With J2SE 5.0, it has become easier to figure what is going on inside the JVM as your application is running. In Building Manageability Satadip Dutta provides an overview of the new Java Management Extensions (JMX) that make monitoring, tracking, and control easier. After surveying internal and external monitoring and control, he writes "The exposed management information from an application can alert IT operators about impending problems. The application can also use the JVM information to throttle the application and prevent it from getting into an unrecoverable state. By throttling the application, the garbage collector may get a chance to run and thereby prevent memory or thread-related problems."
In Projects and Communities, the NetBeans community announces NetBeans IDE 4.0 is now available. The 4.0 release is the first open source IDE to support J2SE 5.0 and provides a release announcement with more details on latest release and pointers to the download page.
From the JXTA community, James Todd blogs about Chat JXTA Style NonStop. He writes with "MyJXTA 2.3.2 launched unto the world we are now sharing ideas as to what features to take on" and invites you to contribute.
Kelly O'Hair responds to comments about More flexible builds in today's Forums. "Debug builds in particular are an issue (the debug DLL's from Microsoft are not on the system, or in the free compilers, and cannot be re-distributed). One thought is to by default only build the optimized J2SE (currently by default both an optimized and debug version is built), and anyone wanting a 'debug' build would need to 'make debug' and perhaps have purchased a set C/C++ of compilers/tools that can build a debug version. I'm curious what people think of this."
With regards to extending primitives, Walter Bruce begins "Perhaps it might help the discussion if we looked at what would have to be changed in Java (compiler and/or JVM) to support extended primitives."
In today's java.net News Headlines :
- Java Compatibility Kit Source Released
- Sun Java Studio Enterprise 7
- JOnAS 4.2.2
- Annogen First Release - Override JSR175 Annotations
- Berkeley DB XML 2.0.7
- JXMLPad 3.0
- yFiles v2.3 - Diagramming Library
Registered users can submit news items for the java.net News Page using our news submission form. All submissions go through an editorial review before being posted to the site. You can also subscribe to thejava.net News RSS feed.
Current and upcoming Java Events :
- December 13-17, 2004 JavaPolis, 2004
- December 14, 2004 Club-Java: J2SE 5.0 Update
Registered users can submit event listings for the java.net Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.
Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.
What care should be taken with the code we give our students- Login or register to post comments
- Printer-friendly version
- daniel's blog
- 356 reads





