Kudos for teaching the "Local History" and the "Scrapbook" capabilities
of Eclipse. I have noticed that even experienced users underutilize these
powerful features of Eclipse. With the scrapbook, you introduce the
notion of Java scripting which will undoubtedly become more widely used in
a Web 2.0 world. Introducing the use of quality 3rd-party packages like
XStream reinforces the advantages of object-oriented code. Great idea!
Just a few suggestions about the code in the Persistence lessons:
Nothing wrong with the code but I think it betrays a previous
background using procedural languages like C. I've written
that idiom myself countless times checking for the end
of file (EOF) sentinal. Object-oriented languages like Java
usually have a method that does the check explicitly without
bothering the user with implementation details. Below
is an alternative approach.
Mark,
Kudos for teaching the "Local History" and the "Scrapbook" capabilities
of Eclipse. I have noticed that even experienced users underutilize these
powerful features of Eclipse. With the scrapbook, you introduce the
notion of Java scripting which will undoubtedly become more widely used in
a Web 2.0 world. Introducing the use of quality 3rd-party packages like
XStream reinforces the advantages of object-oriented code. Great idea!
Just a few suggestions about the code in the Persistence lessons:
-------------------------------------------------------------------------
1. In getStringFromFile() within MyUtilities.java (Lesson 5), you
wrote:
try {
String s;
while ((s = br.readLine()) != null) {
s.append(s);
s.append("\n");
}
br.close();
}
Nothing wrong with the code but I think it betrays a previous
background using procedural languages like C. I've written
that idiom myself countless times checking for the end
of file (EOF) sentinal. Object-oriented languages like Java
usually have a method that does the check explicitly without
bothering the user with implementation details. Below
is an alternative approach.
try {
while (br.ready()) {
s.append(in.readLine() + "\n");
}
br.close();
}
2. Since you are using Java 1.6, I would suggest introducing
the Scanner class. For example,
public static String getStringFromFile(String filename) {
StringBuilder s = new StringBuilder();
try {
Scanner scan = new Scanner(new File(filename));
while (scan.hasNextLine()) {
s.append(scan.nextLine() + "\n");
}
scan.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
return s.toString();
}
If you use Scanner for input, I would then use PrintWriter
for file output.