Learning Java by Patrick Niemeyer and Jonathan Knudsen Unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. This page was updated September 09, 2003. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification UNCONFIRMED errors and suggestions from readers: [xvi] 3rd p; link "http://rendezvous.com/java" does not exist [1] anywhere; no license number or key given for JBuilder *** Note *** Serial number and Activation key are obtained by going to Borland's site and filling out their forms. The URL is - http://www.inprise.com/jbuilder/foundation/download/ The book refers to download code from your site - WHERE? *** Note *** example code can be found at the book's web page - http://www.oreilly.com/catalog/9781565927186/ (Sample Chapter) The combo box example has the Italian word for ten as "deici" instead of "dieci." {22} 2nd paragraph; (Error in -> Chapter 1: Yet another language?) The paragraph finishes a discussion about application and user-level security in Java by giving a general explanation about the use of digital signatures and certificates. It states that the details of this topics will be covered in Chapter 3 (Tools of the trade). This is incorrect because it is until Chapter 20 (Applets) that the digital signatures and certificates are adressed in full. [31] top example HelloJava1.java; I spent hours installing and playing with the JBuilder3.5 software (on Windows) obtained from the book's CD. I went through the tutorial supplied with Jbuilder and was able to make their tutorial Hello World sample program operate. However, when it comes to making the book's example programs operate on JBuilder3.5, there is no instruction on how to get book examples to work with JBuilder3.5. What are the steps required to make HelloJava1.java which is a book example compile and execute with the supplied Software JBuilder3.5? JBuilder is so complicated and featured, that a first time user has no clue how to get book examples running with it. A user ought to be able to have instant success compiling and running all these book examples. The examples and the supplied JBuilder are not integrated as a training experience. The two ought to install and be instant turn key success. Please tell me how to compile book examples with JBuilder in a step by step fashion. [31] In the examples HelloJava1 - 4 To me it seems quite interesting that the constructor for the class HelloJavaX() is called within the class itself. public class HelloJava1 extends javax.swing.JComponent { public static void main(String[] args) { ...new HelloJava1( )); ... } ... } This isn't explicitly mentioned and I wonder if the examples wouldn't be easier to understand if the ideas were seperated in different classes: //file: Main1.java public class Main1 { public static void main(String[] args) { javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1"); f.setSize(300, 300); f.getContentPane().add(new HelloJava1()); f.setVisible(true); } } class HelloJava1 extends javax.swing.JComponent { public void paintComponent(java.awt.Graphics g) { g.drawString("Hello, Java!", 125, 95); } } Also of interest: When I compile the examples HelloJava2 - 4 (with jdk1.2.2 under Linux) besides from the expected results HelloJavaX.class I get classes HelloJavaX$1.class. I have no idea why, and this is not mentioned in the chapter. (37) The second paragraph reads: "JComponent is really the tip of another iceberg called SwingSwing." It should read: "JComponent is really the tip of another iceberg called Swing." (45) Last sentence before the "Events" section.; The book currently has: "mechanism, which .we discuss next." The . before "we discuss" is extraneous. [59] In the second edition of "Exploring Java" I had difficulty understanding why the the blinking example was titled "Netscape's Revenge" Then at least it was an applet and could therefore run within Netscape. In this edition of "Learning Java" it is not an applet any more, so the heading "Netscape's Revenge" is misleading. {59} paintComponent method; When running HelloJava4 under OS X, the paintComponent method has an odd side effect. Since the default window on OS X is actually stripped, drawing theMessage with the color set to the background color actually leaves a white outline of the text against the stripes. I was able to resolve this by changing the code from public void paintComponent(Graphics g) { g.setColor(blinkState ? getBackground() : currentColor()); g.drawString(theMessage, messageX, messageY); } to public void paintComponent(Graphics g) { if(blinkState) g.drawString(theMessage, messageX, messageY); } [73] 3rd paragraph (sample command); No matter how I format my command and policy files, I can't get the example command to work though my "EvilEmpire" class connection to a local system via port 21 (ftp). The same class without the security manager args works just fine however. Suggestions? Sample policy file (latest attempt, called EvilEmpire.policy and found in same path as given below): /* AUTOMATICALLY GENERATED ON Tue Feb 06 10:20:59 CST 2001*/ /* DO NOT EDIT */ grant codeBase "file://home/tim/netbeans/Development/examples/ch03/" { permission java.net.SocketPermission "192.168.3.2", "connect"; }; {82} In the last paragraph it says that: "Java source code can be written using the Unicode character set encoding and stored either in its full 16-bit form or with ASCII-encoded Unicode character values" "...the first 256 characters are defined to be identical to the first 256 characters in the ISO8859-1 (Latin-1) encoding..." I think this may be true of UTF-8, but not of Unicode. JDK 1.3 javac is horribly confused by source code stored in Unicode format. (Chapter 4)I would like to see more code examples in chapters 4-7. These are important concepts for learning Java and I need programming examples to run and play with to help me understand the concept. (83) Last paragraph; In the May 2000 printing edition, the erroneous line reads: "A doc comment is designed to be extracted by automated documentation generators, such as the DSK's javadoc program." That should be SDK's not DSK's, i.e.: "A doc comment is designed to be extracted by automated documentation generators, such as the SDK's javadoc program." {85} The datatypes in table 4.2 should start with a lower case character and not upper case. This detail is important because changing the case for datatype means different things in java. {94} A not on unreachable statements: javac under JDK 1.3 or 1.2.2 does not complain about unreachable statements (not by default, anyway). In fact, I'm sure I saw this mentioned somewhere as a recommended technique for conditional compilation, in lieu of #ifdefs. (95) In Table 4-3, the decrement operator is at the very top of the table as: - while it should be: -- [129] In the end of first paragraph, it says: "In the previous example, print() has been overloaded to support two reference types: Object and String." In the previous example, print() was overloaded to also support char []. (All arrays are reference types.) Therefore it should read something like: "In the previous example, print() has been overloaded to support three reference types: Object, String, and char []." (141) In the last paragraph, last sentence; "Even if we create an instance of a subclass, our code has never seen..." The comma after subclass should not be there. Therefore it should be something like: "Even if we create an instance of a subclass our code has never seen..." (144) last sentence, 1st paragraph; shouldn't "...toward the most specific overloaded method..." really be "...toward the most specific overloaded or overridden method..."? P.S. The following errata for page 153 is incorrect. The code is correct as printed. It does not create an "instance" of an interface (TextUpdateable), rather a reference (receiver) to the interface. This reference is later populated with an interface. See text on page 152 just before code snippet. [153] The code segment: TextUpdateable receiver; should probably read: TickerTape receiver; Or else you are creating an instance of an interface. (164) second code example; The java.util.Iterator interface has a boolean hasNext() method not hasMore(). This is also true for pp 165 & 168 where hasMore() and hasMoreElements() should both be hasNext() (166) Code snippet in 'Inner Classes Within Methods'; 'Class' should be 'class' (not capitalized), twice. (167) Third code snippet: "Import" should be "import" [168] In the third last paragraph, in the last line: getIteratgor() should read: getIterator() [170] How do inner classes really work? never explains purpose of the "javap" utility program. [173] Below the code snippet where is says "Using equals() is not the same as:"; See where it says "Using equals() is not the same as: if (userName == suspectName ) //Wrong". The example in the book is misleading. Actually Object.java implements equals() as: public boolean equals(Object obj) { return (this == obj); } which therefore in the default case means equals() behaves as ==. [174] 2nd paragraph: "...from the contents of the object."; 2nd Paragraph: "...A hashcode is like a signature or checksum for an Object; it's a random-looking identifying number that is usually generated from the contents of the Object." seriously contradicts Object.java's comments for hashCode() which states the hashcode "is typically implemented by converting the internal address of the object into an integer". (182) 4th paragraph, 4th sentence; "An exception occurs if we try to access to a field" should read "An exception occurs if we try to access a field" (199) 2nd paragraph, 2nd sentence; "... to have the existing thread begin again., rather ..." Remove the period before the comma. {221} 3rd line of text, from the top; Text refers to: "...just like the C routine string():" The correct name of the routine is "strcmp" so the sentence should read: "...just like the C routine strcmp():" (228) Title of section "The java.math Class"; The title should probably be "The java.math Package", since the section describes classes contained in that package. (230) last paragraph, first line; The line as printed reads "You also need a wraper..." The word "wrapper" should have an extra 'p' in it. [231] Table 9-6. Random Number Methods, Learning Java indicates that the methods nextFloat() and nextDouble() have the range: nextFloat() -1.0 to 1.0 nextDouble() -1.0 to 1.0 However, according to the Java 1.3 docs, the range is: nextFloat() 0.0 to 1.0 nextDouble() 0.0 to 1.0 see http://java.sun.com/j2se/1.3/docs/api/java/util/Random.html {239} description of List interface methods (5th paragraph); Incorrect return type for remove, get, set methods: Book has: public void remove(int index) ... public void get(int index) ... public void set(int index, Object element) ... Should be (per Java 2 Platform SE v1.3 API documentation) public Object remove(int index) ... public Object get(int index) ... public Object set(int index, Object element) ... {247} In the last code excerpt: e.hasMoreElements should be: e.hasMoreElements() {247} At the bottom, inside the for loop; In the line : String name = e.nextElement(); Function e.nextElement() returns an Object object. Type of the returned value should be changed to String. String name = (String) e.nextElement(); {248} 1st sentence of "System Properies" section; The sentence "The java.lang.System class provides access to basic system environment information through the static System.getProperty() method." should say that System.getProperties() is the method to do this. The following sentence states that getProperty() returns a Properties table, but it is getProperties() that does this. (248) "Loading and Sorting"; It is mentioned that the properties can be saved to a file by using a FileOutputStream as the first argument to save(). However, save() seems to be a deprecated mentod and the book fails to mention this. "PropTest.java:25: Note: The method void save(java.io.OutputStream, java.lang.String) in class java.util.Properties has been deprecated. props.save(out, "Application Parameters");" {254} second to last paragraph; Paragraph states that the ISO standard for country codes is ISO639, and for languages is ISO3166. This is backwards: ISO639 is the set of codes for languages, and ISO3166 is the set of codes for countries. {257} 2nd code snippet; The formatting example for percentages will only print 44% if the value of progress is 0.44. Change the declaration of progress to: double progress = 0.44; [275] The fourth paragraph reads: 'run()' is the only 'InputStream' method that 'FilterInputStream' overrides. It should read: 'read()' is the only 'InputStream' method that 'FilterInputStream' overrides. [282] The code example after fourth paragraph reads: FileInputStream foois = new FileOutputStream( fooFile, true); It should read: FileOutputStream foois = new FileOutputStream( fooFile, true); Same is true on the next line. {320} 2nd; I don't know if the page is right, because I have a pdf version of the book 13.2 Containers. You wrote : Three of the most useful container types... . JFrame is derived from JWindow, which is pretty... 13.2.7 Windows and Frames You wrote : Windows and Frames are the top-level... . JFrame, on the other hand, is a subclass of JWindow that has a border... JFrame IS NOT a subclass of JWindow. Object -> Component -> Container -> Window -> Frame -> JFrame Object -> Component -> Container -> Window -> JWindow [321] 2nd Example: public class MyRemoteObject; Shouldn't "public RemoteObjectImpl()" be "public MyRemoteObject()" ? Isn't this the constructor for the MyRemoteObject class? {344} In the example: // read results... if ( urlcon.getResponseCode() != HttpURLConnection.HTTP_OK ) System.out.println("Posted ok!"); else { System.out.println("Bad post..."); return; } ... it should either have the != changed to == or the cases reversed since this if provides the reverse functionality of what you were going for. (364) last 3rd paragraph, '...function in Java But they' missing a period. [371] 3rd line, last sentence; "The name is returned by toString()." The name that you set with setName() is actually returned by getName(). Therefore the sentence should read: "The name is returned by getName()." (Note: toString() will return a bunch of pieces of information of which one of the things is the name set by setName(). However, getName() should definitely be used if you want to get the name that you set in setName().) (390) just after 2nd paragraph In Actual Code for vegomaticAdapter1; IN the third line of code, the word vegomatic is spelled wrong. It is spelled Vegotmatic. (391) 3rd paragraph; In the last line in the 3rd paragraph on page 391 in the May 2000 first edition of Learning Java, "...an event source It'sand its listener" should read "...an event source and its listener". (428) 2nd paragraph, 2nd line; The first sentence ends with a method, the second begins with one. The period between them is formatted as if it is all one expression: savefile().loadfile() creates .... instead of: savefile(). loadfile() creates .... [454] method "private float element()": The example throws a compile-time error: "value may be used uninialized" This is because the branch of the second if statement does not assign anthing to this member. if one moves the line "value = Float.valueOf(svalue).floatValue(); outside the scope of the second 'if' statement, then the program works correctly, and will compile. {516} last line drawImage should be g.drawImage (517) Second code snippet: "SCALE_AREA_ AVERAGING" Should read: "SCALE_AREA_AVERAGING" (588) Second paragraph, next to last line: "container environment It also..." Should read: "container environment. It also..." (595) Sixth paragraph, first line; "... expects to be embedded in GUI" should read "... expects to be embedded in a GUI" (605) Second code snippet, lines 4 and 5: The applet width and height specifications are reversed: "width = pixels_high" Should read: "width = pixels_wide" "height = pixels_wide" Should read: "height = pixels_high" [617] Certificate example; Note that the example certificate expired in January 2000, rendering this example unusable. If nothing else, the downloadable sample code and certificate should be updated. (643) between the two code samples; Under the section titled "Scripted Methods and Objects", there are two code samples. Between these two samples is a single line o f text reading: "BeanShell methods may also have dynamic (loose) argument and return types." This line is printed in the code font (ie "Constant width") rather than the straight-text font, despite it being distinctly NOT cod e or a comment. (643) between the two code samples; Under the section titled "Scripted Methods and Objects", there are two code samples. Between these two samples is a single line o f text reading: "BeanShell methods may also have dynamic (loose) argument and return types." The word "argument" should spelled "arguement".