Search |
|||||
Java/CS1 Cheat SheetPosted by cayhorstmann on October 6, 2009 at 8:31 PM PDT
The next edition of my CS1/Java book is going to print soon. At the last minute, we decided to put the real estate of the inside covers to good use and include a “cheat sheet” with the most important Java control structures and libraries. Since it would be particularly embarrassing to have a typo here, I am hoping to enlist the aid of the community.
PDFs for the inside covers are here and here. If you spot a typo, please let me know in the blog comments. (But don't tell me about If you have other comments about what should be included/excluded in the cheat sheet, please let me know too. Your suggestions may not make it into this edition, but I do keep track for the next edition...which always comes sooner than I think. (But don't tell me that the Thanks for your help! When the book goes into print, I'll update the cheat sheet links with the final versions so you can point the Java learners among your friends and family to them.
»
Comments
Comments are listed in date ascending order (oldest first)
variable 'in' is defined twice
Submitted by jinux9 on Tue, 2009-10-06 23:55.
You declare 'Scanner in' twice with two different input sources... it won't compile and you'll confuse your students :)
This is not a typo, but it
Submitted by wwwizard on Wed, 2009-10-07 05:43.
This is not a typo, but it might be worth changing:
if (u.equals("HELLO"))
to:
if ("HELLO".equals(u))
to get rid of those pesky NPEs.
- Bob
Not a typo again
Submitted by wwwizard on Wed, 2009-10-07 05:49.
Not a typo, but instead of declaring an ArrayList names = ... and LinkedList names = ..., maybe consider declaring those vars as List. - Bob
do...while and subtyping
Submitted by forax on Wed, 2009-10-07 05:56.
Hi Cay,
In the do .... while example, 'input' is not declared.
In the second page, you use
It seems there is no example of size() on a collection.
Moreover, this page is not coherent,
You use interface for Set and Map but not for List.
ArrayList
It was deliberate not to use
Submitted by cayhorstmann on Wed, 2009-10-07 07:04.
It was deliberate not to use interfaces for array lists and linked lists. The Java List interface does not bring happiness to the CS1 instructor. We like to talk about efficiency of operations, but with a List you can only assume that linear traversal and insertion at the end is O(1). Sure, there is the RandomAccess marker interface, but that's a kludge.
Tag "final" in "final double" declaration
Submitted by anphilli on Wed, 2009-10-07 08:36.
In the "Variable and Constant Declarations" section (http://horstmann.com/bigj4/Cover2.pdf), would it be useful to tag "final" as a modifier? Otherwise it just sits there, potentially leaving readers to wonder if "final double" is some special type, or something equally confusing.
Consistent comment
Submitted by slavomir on Thu, 2009-10-08 15:24.
Cay,
Not a typo, but it would make comments more consistent if in the Linked Lists, Sets, and Iterators (should you really use the comma before "and"?) section you changed "Adds to set" to "Adds to set if not present". That would be consistent with your next comment for deletion from the set.
Typeface and annotations
Submitted by ptux on Fri, 2009-10-09 22:43.
Nice work, Doctor.
The most confusing thing I noticed is the choice of typeface for annotations - it seems somewhat consistent, but in code, what is the difference between the occasions in which "cursive" font is used, and those in which a plain serif font is used? Perhaps this can be made more uniform (I would recommend converting the serif portions since they are not as immediately distinguishable from the code as the cursive font).
The section on Conditional loops seems quite confusing after the first block; what is optional is not clear for the else-if and the else blocks... also, a bracket could be used to show that the entire contents of if (...) is the condition, not just the comparison operator, as the line may indicate. Perhaps it was the intent that the student actually read the book and use this only as a cheat sheet; if the student was not already familiar with the material, I suppose the cheat sheet is not intended to instruct.
Also, the "foreach" construct appears on both pages... both are arguably relevant, but still redundant.
The method declaration section labels everything but the method name... same argument as for labeling the conditionals.
Thanks to everyone who
Submitted by cayhorstmann on Tue, 2009-10-13 12:34.
Thanks to everyone who replied! The PDF links now point to the final version, with those suggestions that we were able to accommodate. Feel free to point any Java learners to them.
Cheers,
Cay
|
|||||
|
|
do loop