MindView Inc.

Current Active Comments for the 2nd edition of "Thinking in Java"

Remember to press your browser's "refresh" button if you've just added a comment


Comment ID: 1030118-121519-fangzhihua_-sina-_com.cmt
From: fangzhihua
simple chinese Chapter:4
Search for Text: DeathCondition.java

i compile this program and don't get any result.so i corect it:

//: c04:DeathCondition.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Using finalize() to detect an object that 
// hasn't been properly cleaned up.

class Book {
  boolean checkedOut = false;
  Book(boolean checkOut) { 
    checkedOut = checkOut; 
  }
  void checkIn() {
    checkedOut = false;
  }
  public void finalize() {
    if(checkedOut)
      System.out.println("Error: checked out");
  }
}

public class DeathCondition {
  public static void main(String[] args) {
    Book novel = new Book(true);
    // Proper cleanup:
    novel.checkIn();
    // Drop the reference, forget to clean up:
    new Book(true);
    // Force garbage collection & finalization:
   System.out.println(""); 
    System.gc();
      }
} ///:~

but i don't why .can you tell me? 

Add a comment to this suggestion
Comment ID: 1030118-121434-fangzhihua_-sina-_com.cmt
From: fangzhihua
simple chinese Chapter:4
Search for Text: DeathCondition.java

i compile this program and don't get any result.so i corect it:

//: c04:DeathCondition.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Using finalize() to detect an object that 
// hasn't been properly cleaned up.

class Book {
  boolean checkedOut = false;
  Book(boolean checkOut) { 
    checkedOut = checkOut; 
  }
  void checkIn() {
    checkedOut = false;
  }
  public void finalize() {
    if(checkedOut)
      System.out.println("Error: checked out");
  }
}

public class DeathCondition {
  public static void main(String[] args) {
    Book novel = new Book(true);
    // Proper cleanup:
    novel.checkIn();
    // Drop the reference, forget to clean up:
    new Book(true);
    // Force garbage collection & finalization:
   System.out.println(""); 
    System.gc();
      }
} ///:~

but i don't why .can you tell me? 

Add a comment to this suggestion
Comment ID: 1030023-084431-imran_javaid_82_-hotmail-_com.cmt
From: imran javaid
2nd edition Chapter:whole book
Search for Text: hardware


i want to programming of hardware aceessing from diffrent lang. that's why i want that you give me the
help about that things

Add a comment to this suggestion
Comment ID: 1021026-194326-id___-hotmail-_com.cmt
From: Ivan Dimov
12 Chapter:14
Search for Text: //: c14:BangBean2.java

A simple Question
p.866
//: c14:BangBean2.java
// You should write your Beans THIS WAY so they 
// can run in a multithreaded environment.
...
  // Notice this isn't synchronized:
  public void notifyListeners() {
    ActionEvent a =
      new ActionEvent(BangBean2.this,
        ActionEvent.ACTION_PERFORMED, null);
    ArrayList lv = null;
    // Make a shallow copy of the List in case 
    // someone adds a listener while we're 
    // calling listeners:
//WHAT IF some1 REMOVES listener while we are calling listeners!!
//THIS IS THE QUESTION of importance here:
    synchronized(this) {
      lv = (ArrayList)actionListeners.clone();
    } //End of SYNC
SLEEP(50000); // suppose some listeners removed here even gc.run() ;-)))
    // Call all the listener methods:
    for(int i = 0; i < lv.size(); i++)
      ((ActionListener)lv.get(i))
        .actionPerformed(a);
  }
Conclusion:

Yes we should write Beans so they can run in a multithreaded environment but THIS IS NOT the way...


From: suresh vora [sureshvora_-hotmail-_com]
i don't know comment

Add a comment to this suggestion
Comment ID: 1021011-074401-sun_-hit-_edu-_cn.cmt
From: Sunner Sun
2nd and 3rd Chapter:8: Interfaces & Inner Classes
Search for Text: c08:Parcel2.java

The last lines you used:

    Parcel2.Contents c = q.cont();
    Parcel2.Destination d = q.to("Borneo");
  }
} ///:~

And you said:


"If you want to make an object of the inner class anywhere except from within a non-static method of
the outer class, you must specify the type of that object as OuterClassName.InnerClassName, as seen in
main( )."

But after deleting "Parcel2.", the code still works.

My jdk version is 1.4.1

Add a comment to this suggestion
Comment ID: 1020931-003141-baric14_-hotmail-_com.cmt
From: antony
1.1.1 Chapter:1
Search for Text: Comments

sorry bout this the comments page did not work so heres my praise:)


Your book is great!!. Im a 13 Year old programmer(really!) and this is fabulous. I've read different
books on java they were to fast (one in perticular)they just spat onu info but your book is great it
takes everything nice and slow explaining everything in depth and complete deatail. The next book i buy
will be thinking in c++ i gurntee it since this is such a good book:)

Add a comment to this suggestion
Comment ID: 1020913-150250-id___-hotmail-_com.cmt
From: Ivan Dimov
12 Chapter:9
Search for Text: ALL THE COUNTRIES of the world and their capitals.


1. I dont know what "Version of Thinking in Java, 2nd edition: : means but my copy says REVISION 12 .
Is it the same???

Thinking in Java 2nd ed. MS Word version:
p.452 near the end of page:

The static rsp, geography, countries, and capitals objects provide prebuilt generators, the last three
using ALL THE COUNTRIES of the world and their capitals. 

ALL THE COUNTRIES ??? I can't see my own coutry there - country with more than 1300 years history?!?


Either correct p.454 - Europe or Easter Europe or at least CHANGE the ABOVE statement "ALL THE COUNTRIES
of the world..." to s.th. more precise like "MOST OF THE CONTRIES"
Please add:
{"BULGARIA","Sofia"}, 
its located at the Black Sea Coast between Turkey, Greece, Romania, Albania and Yugoslavia 

You can see its location here: http://visualroute.visualware.com/ Trace 4: www.dir.bg IP: 194.145.63.12


...and something more: (your comment)

"  This data was found on the Internet, then processed by creating a Python program (see www.Python.org)."


- I don't know who to blame YOU or Python.org or ... you actually didn't reveal real source of this info
but IT'S NOT RELIABLE source.


INTERESTING FACT: I saw that book translated into Bulgarian (...by Soft Press Publishing I think...)
and as it seems even translator didn't check those sources ;-))) ...or ...er.. perhaps this isn't yout
FIRST Letter on the subject?

P.S. I think you should also FIX this CODE:
TIJ2-Word\TIJ-2nd-edition-code\com\bruceeckel\util\CountryCapitals.java

P.P.S. I see same mistake in HTML version of the book: Thinking in Java, 2nd edition, Revision 12


Add a comment to this suggestion
Comment ID: 1020623-192326-tculliton_-profitlogic-_com.cmt
From: Tom Culliton
print Chapter:9, page 432 
Search for Text: and produces a negative value if the argument is less than the current object


The last sentence in the second paragraph describing the return values of Compareable.compareTo conflicts
with the sample code.


"This method takes another Object as an argument, and produces a negative value if the argument is less
than the current object, ..."

The sample code says:

public int compareTo(Object rv) {
  int rvi = ((CompType)rv).i;
  return (i < rvi ? -1 : (i == rvi ? 0 : 1));
}

I believe that the code is correct and the text is wrong.


From: Tom Culliton [tculliton_-profitlogic-_com]
Whoops!  This appears to be fixed in the current electronic version.


Add a comment to this suggestion
Comment ID: 1020603-052607-qindegang_-sina-_com.cmt
From: Qin Degang
PDF Chapter:4
Search for Text: this keyword

In page 204, chapter 4, it mentions that: 
The this keyword-which can be used only inside a method-...
However, the this keyword can also be used in data fields, for example:

public class Test {
	Test t=this;
}

It is compiled successfully.
Thanks.


Add a comment to this suggestion
Comment ID: 1020530-022918-trbhargava_-hotmail-_com.cmt
From: trbhargava
yes Chapter:ALL
Search for Text: ALL

HELLO SIR I read thinking c++ was nice so struggling for java

Add a comment to this suggestion
Comment ID: 1020529-013827-linuxhippy_-web-_de.cmt
From: Clemens Eisserer
latest Chapter:the start-page
Search for Text: link broken


The link for the word-viewers on the start-page is broken. But I think nobody would use that ms-stuff
;-)

Add a comment to this suggestion
Comment ID: 1020430-193050-luigi_-javaextreme-_net.cmt
From: Luigi Viggiano
2nd edition, printed version bought last year Chapter:ch9 Pitfall: the lost exception 
Search for Text: a missing case


Very nice paragraph. But you should also insert the case in which the programmer puts a "return" in the
finally block. The exception in the try {} block is also lost.
example:

try { 
  //...
  anObject.aCodeThatRaiseAnException(); //this throw an Exception 
  //...
} finally {
  return "something"; //here the Exception thrown in the try is lost!!
}

Best regards.
~Luigi Viggiano



Add a comment to this suggestion
Comment ID: 1020427-161155-bret-_b_-usa-_net.cmt
From: Bret Bailey
MS Word Chapter:2
Search for Text: Here is the first Java program again


There is a blank character preceding this initial sentence of the paragraph. I suggest removing it so
that your indentation is consistent.

Add a comment to this suggestion
Comment ID: 1020401-184328-david_-handysoftware-_com.cmt
From: David Handy
9 Chapter:5
Search for Text: You can also do it by inheriting (Chapter 6) from that class.


The footnote on page 265 of the printed version, or footnote [37] of Revision 9 of the HTML version is
entirely wrong and should be removed.


The context of the footnote is a statement saying that making all constructors   private prevents "anyone
but you, inside a static member of the class, from creating an object of that class."


That statement is true, but unfortunately is followed by a footnote reference with the following text:
"You can also do it by inheriting (Chapter 6) from that class." This statement is absolutely false. You
cannot inherit from a class that only has private constructors.
You'll probably want to remove this footnote altogether.

Add a comment to this suggestion
Comment ID: 1020305-212906-pinarkirsentam35_-hotmail-_com.cmt
From: sema
very good Chapter:all
Search for Text: classes and objects

s<eryry

Add a comment to this suggestion
Comment ID: 1020302-182132-doron-_yafe_-bigfoot-_com.cmt
From: Doron Yafe
Revision 12 Chapter:9
Search for Text: c09:Collection1.java


Maybe i miss the point here but in the Collection1.java example appeas the following lines of code:
    .
    .
    .
    // Keep all the elements that are in both
    // c2 and c3 (an intersection of sets):
    c2.retainAll(c3);
    System.out.println(c);
    // Throw away all the elements 
    // in c2 that also appear in c3:
    c2.removeAll(c3);
    System.out.println("c.isEmpty() = " +
      c.isEmpty());
    .
    .
    .


Now... either c2(!) value is printed, <System.out.println(c2)> instead of <System.out.println(c)>,
or (what seems to be the original aim), c(!) value is to be modified <c.retainAll(c3)> instead
of <c2.retainAll(c3)>.

It works just fine the way it is, only it seems to have no point to modify c2(!) if we only print c(!).
The same goes for the second, removeAll, example.


Other than that, Thanx for a great (online) book, i hope it helps me get the right foot into the java
world.


Add a comment to this suggestion
Comment ID: 1020220-021435-wenjinp_-163-_net.cmt
From: pan
2 Chapter:0-19
Search for Text: java

java

Add a comment to this suggestion
Comment ID: 1020219-163927-Thomas_Bolioli_-alumni-_adelphi-_edu.cmt
From: Thomas Bolioli
11 Chapter:7
Search for Text: Diagram on page 321 above "c07:music3:Music3.java"

Chapter 7: Polymorphism page 321 of 11 rev
Tune is missing from the diagram as a member of Instrument.


Add a comment to this suggestion
Comment ID: 1020207-101933-golden-rock_-sohu-_com.cmt
From: John Ren
12 Chapter:2
Search for Text: heap, stack, primitive


Thank you very much for your great TIJ2, which is guiding me to Java World. We are Chinese students,
in our country this book is very popular, we call it classical book of Java and OOP.

Possibly because of the difference of language, we have the following question:


In the section 'Where storage lives' in Chapter 2, about heap we get the information "This is a general-purpose
pool of memory (also in the RAM area) where all Java objects live. "


In the section 'Special case: primitive types' in the same chapter, in the first paragraph there is an
information "That is, instead of creating the variable using new, an "automatic" variable is created
that is not a reference. The variable holds the value, and it's placed on the stack so it's much more
efficient. " 


The question is that if a object has only one data member(field) of a primitive type and the object lives
on the heap, where is that field placed? According to the 2nd information, it should be placed on stack,
but the object is living on the heap.


Beg another help, would you tell us the actual size of the Boolean variable? Some books tell readers
it's 1 bit, otherwise, other books tell us it's 1 byte/8-bit, even there's the third issue: it's 1 int/32-bit.
Which one is right? We're really confused.


Add a comment to this suggestion
Comment ID: 1020201-113422-Thomas_Bolioli_-alumni-_adelphi-_edu.cmt
From: Thomas Bolioli
11 Chapter:4
Search for Text: MultiDimArray Code example


Use curlys when you do your for loops to create explicit blocks. In most cases people can figure out
the implicit blocks and follow but it helps more  to be explicit and in the case of MultiDimArray code
example it makes a world of difference. 
I have inserted an amended copy below.

// Creating multidimensional arrays.
import java.util.*;

public class MultiDimArray {
    static Random rand = new Random();
    static int pRand(int mod) {
        return Math.abs(rand.nextInt()) % mod + 1;
    }
    
    static void prt(String s) {
        System.out.println(s);
    }
    
    public static void main(String[] args) {
        int[][] a1 = {
            { 1, 2, 3, },
            { 4, 5, 6, },
        };
        
        for(int i = 0; i < a1.length; i++){
            for(int j = 0; j < a1[i].length; j++){
                prt("a1[" + i + "][" + j + "] = " + a1[i][j]);
            }
        }
        // 3-D array with fixed length:
        int[][][] a2 = new int[2][2][4];
        for(int i = 0; i < a2.length; i++){
            for(int j = 0; j < a2[i].length; j++){
                for(int k = 0; k < a2[i][j].length; k++){
                    prt("a2[" + i + "][" + j + "][" + k + "] = " + a2[i][j][k]);
                }
            }
        }
        // 3-D array with varied-length vectors:
        int[][][] a3 = new int[pRand(7)][][];
        for(int i = 0; i < a3.length; i++) {
            a3[i] = new int[pRand(5)][];
            for(int j = 0; j < a3[i].length; j++){
                a3[i][j] = new int[pRand(5)];
            }
        }
        for(int i = 0; i < a3.length; i++){
            for(int j = 0; j < a3[i].length; j++){
                for(int k = 0; k < a3[i][j].length; k++){
                    prt("a3[" + i + "][" + j + "][" + k + "] = " + a3[i][j][k]);
                }
            }
        }
        // Array of nonprimitive objects:
        Integer[][] a4 = {
            { new Integer(1), new Integer(2)},
            { new Integer(3), new Integer(4)},
            { new Integer(5), new Integer(6)},
        };
        for(int i = 0; i < a4.length; i++){
            for(int j = 0; j < a4[i].length; j++){
                prt("a4[" + i + "][" + j + "] = " + a4[i][j]);
            }
        }
        
        Integer[][] a5;
        a5 = new Integer[3][];
        for(int i = 0; i < a5.length; i++) {
            a5[i] = new Integer[3];
            for(int j = 0; j < a5[i].length; j++){
                a5[i][j] = new Integer(i*j);
            }
        }
        for(int i = 0; i < a5.length; i++){
            for(int j = 0; j < a5[i].length; j++){
                prt("a5[" + i + "][" + j + "] = " + a5[i][j]);
            }
        }
    }
} ///:~

Add a comment to this suggestion
Comment ID: 1020124-232507-keesan_-world-_std-_com.cmt
From: Morris Keesan
Prentice Hall paperback (6th printing) Chapter:3
Search for Text: If you use it with type byte or short, you don't get the correct values.

If you use it with negative values of type byte or short, you don't get 
the expected results.

(The results are "correct", just not what the novice programmer expects,
and that happens only when the initial values are negative.)

You'll get the "expected" values if you force the values, after the cast
to (int), to have only the bits of the smaller type, using the bitwise & operator described
in the previous section: e.g.

short s = -1;
s = (((int)s) & 0xFFFF) >>> 10;

b = -1;
b = (((int)b) & 0xFF) >>> 10;



Add a comment to this suggestion
Comment ID: 1020124-231720-keesan_-world-_std-_com.cmt
From: Morris Keesan
Prentice Hall paperback (6th printing) Chapter:13
Search for Text: Most of the time you'll just want to let a JScrollPane do it's job

Most of the time you'll just want to let a JScrollPane do its job

Add a comment to this suggestion
Comment ID: 1020114-151044-halt00_-hotmail-_com.cmt
From: Todd Stephan
12 Chapter:9
Search for Text: ", "


In chapter 9 (TIJ2 page ~420), the print function could be more efficient.  There is no need to do the
if check inside the loop.  When there are thousands of items in the array this may make a difference.


        if ( from < to )
            System.out.print(a[from]);
        for (int i=from+1 ; i < to ; i++)
            System.out.print(", " + a[i]);                  


Add a comment to this suggestion
Comment ID: 1020106-105348-rafic_-atl-_fundtech-_com.cmt
From: Rafi Cohen
hard copy as well as the HTML copy Chapter:1, Introducing to objects, the hidden implementation
Search for Text: protected acts like private, with the exception that


According to what I've found about the 'protected' DEFINITIONS in the book, it's accessible only for
'this' as well as for extended classes of 'this'.

However, as you probably know, it also allows access to classes from the same package of 'this', regardless
to the fact of whether they've extended 'this' or not. quoting from "The Java tutorial -Controlling Access
to Members of a Class" (although I'm sure there's no need for that):
"...
Protected

The next access level specifier is protected, which allows the class itself, subclasses (with the caveat
that we referred to earlier), and all classes in the same package to access the members. ...".

I've seen other readers's notes about the levels of access control ORDER as mentioned in the book, but
couldn't find anyone mentioning the CAUSE for the wrong order.
P.S. it's very kind of you to put your books on the WEB. thank you :)

Add a comment to this suggestion
Comment ID: 1020031-164203-mallikarjun-_garipally_-ps-_ge-_com.cmt
From: Mallikarjun
Revision 12 Chapter:13
Search for Text: How to import com.bruceeckel.swing.*

How do i import com.bruceeckel.swing.*

Add a comment to this suggestion
Comment ID: 1020031-082554-lal_swain_-satyam-_com.cmt
From: Lal Swain
It is very good Chapter:Appendix
Search for Text: microsoft and java


I want the electronic version of the book Thinking in Java Ist edition.Can you plz send it accross to
me.

Add a comment to this suggestion
Comment ID: 1020028-220258-cdj-vallejos_-prodigy-_net.cmt
From: Jorge Vallejos
ISBN 0-13-027363-5 Chapter:7
Search for Text: class LivingCreature

The member function finalize() in the class LivingCreature calls a
base class finalize(). Nevertheless, the definition of the class
LivingCreature is not derived from any base class.

The solution seems to be:

Replace:

class LivingCreature {
    ...
}

With:

class LivingCreature extends Characteristic {
    ...
}



Add a comment to this suggestion
Comment ID: 1020021-065710-alex_-tf-_com-_pl.cmt
From: Aleksander Atanassow
12 Chapter:9
Search for Text: ex 13

Dear MR Eckel,

I enjoy very much working through your book TIJ2e. I do each exersize before I turn to 
the next chapter. It's really educating and entertaining. Great work.

    Since you probably have enough of  words of admiration, here is why I write to you:
- in chapter 9 ex13 you ask me to "Fill an array and an  ArrayList with objects of your 
class, using the geography generator". I couldn't do it. geography returns a Pair 
reference. Pair is not for use outside the package. So I wrote my own (based on yours) 
generator method, but it eats me inside "what is it that you had in mind?" How can I use 
the geography in an outside class method?

- the second reason is less important. There is a country in Europe that you omited in 
CountryCapitals.java I happen to be a citizen of it. It's not really my bussiness but maybe 
You missed it incidentaly  and would not mind putting it in. {Bulgaria, Sofia}

Thank you for reading this message. Once again Good Luck with all you do. My next 
stop is Python.

Sincerely

Aleksander.

Add a comment to this suggestion
Comment ID: 1020010-164906-hallorant_-acm-_org.cmt
From: Tim Halloran
paper Chapter:298
Search for Text: Final arguments


Your note that you can still assign a null reference appears to have changed as the following code doesn't
work.  You do get an error about assigning the null to g in the with method.

class Gizmo {
    public void spin() {}
}

public class FinalArguments {
    void with(final Gizmo g) {
        g = null;
    }
    void without(Gizmo g) {
        g = new Gizmo();
        g.spin();
    }
    void f(final int i) {
        // i++
    }
    int g(final int i) {
        return i + 1;
    }
    public static void main(String[] args) {
        FinalArguments bf = new FinalArguments();
        bf.without(null);
        bf.with(null);
    }
}

Add a comment to this suggestion
Comment ID: 1020009-035944-xmh_8088_-sina-_com.cmt
From: fd
d Chapter:ds
Search for Text: df

sdaf

From: turke [alturke_-ayna-_com]
welcom

abo

turke

Add a comment to this suggestion
Comment ID: 1011125-234541-stefan-_zielinski_-ps-_net.cmt
From: Stefan Zielinski
11 Chapter:8
Search for Text: received( )

Replace it with: receiveD( )

Add a comment to this suggestion
Comment ID: 1011108-181748-nunung3_-yahoo-_com.cmt
From: herry wibowo
all Chapter:all
Search for Text: to know about this program and study make a web


i really want have java book because with this book i hope  can make a web  a better before.otherwise,this
program more flexibel in many aplication

Add a comment to this suggestion
Comment ID: 1011022-143039-wefing_-gmx-_de.cmt
From: Stephan Wefing
Revision 12 Chapter:14
Search for Text: public class Sharing2 extends JApplet

hi,

the access to the static variable "accessCount" in class Sharing2 should be synchronized:

  public synchronized static void incrementAccess() {
    accessCount++;
    aCount.setText(Integer.toString(accessCount));
  }

if i run the original code, the output in the text field "Access Count" 
varies wildly and the machine (intel linux 2.4.10, 2xPII, sun sdk 1.3.1) 
starts heavily beeping. The same remark applies to Sharing1.java of the same
chapter.

regards, stephan


Add a comment to this suggestion
Comment ID: 1011022-061010-alex_-etas-_kharkov-_ua.cmt
From: Alexander Pershin
Revision12 Chapter:13
Search for Text: Running applets inside a Web browser


I think IE5(IE6) doesn't support a package name at all. It doesn't depend on a form of tag. Whether you
use <applet> or <object> tag the result will be the same : your IE browser won’t be able
to find applet beginning with
 “package mypackage;
  import javax.swing.*;
  class MyClass extends JApplet{}”

Do not even try to change CLASSPATH environment variable. Or is there anybody knowing this secret? 


Add a comment to this suggestion
Comment ID: 1010827-052122-jani-_latvala_-iki-_fi.cmt
From: Jani Latvala
revision 12 Chapter:11 The Java I/O System
Search for Text: Compression

Hi


You could tell something about this bug ( http://developer.java.sun.com/developer/bugParade/bugs/4244499.html
) when using zip classes.


Add a comment to this suggestion
Comment ID: 1010827-042628-tony_-hcsco-_freeserve-_co-_uk.cmt
From: Tony Hughes
ISBN 0-13-027363-5 Chapter:13
Search for Text: Menus.java


In the menus.java program, the ActionListener ml, presumably intended for the "Open" menu item on the
file menu is never used. THe place where it is intended to be implemented (I think) is shown below.

    for(int i = 0; i < file.length; i++) {
      file[i].addActionListener(ml);   //  changed fl to ml
      f.add(file[i]);


I think you also need to set the action command for the Open menu item, before it will be found in the
ML listener, as below
	
    file[0].setActionCommand("Open");


Add a comment to this suggestion
Comment ID: 1010827-042135-tony_-hcsco-_freeserve-_co-_uk.cmt
From: Tony Hughes
ISBN 0-13-027363-5 Chapter:13
Search for Text: Console.java


In the Console.java program, the commented out version of setDefaultCloseoperation for JDK1.3 is shown
as:

frame.setDefaultCloseOperation(EXIT_ON_CLOSE)

it should actually be

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

Add a comment to this suggestion
Comment ID: 1010823-102936-alexander_popoff_-hotbox-_ru.cmt
From: Alexander Popoff
11 Chapter:7
Search for Text: Constructors and polymorphism

When describing the order of initialization in
"Order of constructor calls" ("Constructors and polymorphism", Chapter 7),
you implied that the reader must keep in mind the order of class members
initialization, including static ones.

I believe it would be more intelligible to give
a reader an explicit description of initialization:

1. The static members are initialized in the order of declaration.
   This step is repeated recursively such that the static members
   of the root class of the hierarchy are initialized first, followed
   by next-derived class, etc.

2. In the same order, for every class, beginning with the root one, followed
   by next-derived class, etc.:
	a)  The class members are initialized in the order of declaration.
	b)  The class constructor is called.


This order can be illustrated with a slightly modified c07:Sandwich.java example:

//: c07:SandwichModified.java
// Order of constructor calls.

class Meal {
  Meal() { System.out.println("Meal()"); }
  Lettuce ll = new Lettuce(" in Meal");
  static  Lettuce l = new Lettuce(" in Meal, static");
  Cheese c = new Cheese(" in Meal");
  static Cheese cc = new Cheese(" in Meal, static");
  Bread b = new Bread(" in Meal");
  static  Bread bb = new Bread(" in Meal, static");
}

class Bread {
  Bread(String s2) { System.out.println("Bread()" +s2); }
}

class Cheese {
  Cheese(String s3) { System.out.println("Cheese()" +s3); }
}

class Lettuce {
  Lettuce(String s4) { System.out.println("Lettuce()" +s4); }
}

class Lunch extends Meal {
  Lunch() { System.out.println("Lunch()");}
  Lettuce ll = new Lettuce(" in Lunch");
  static  Lettuce l = new Lettuce(" in Lunch, static");
  Cheese c = new Cheese(" in Lunch");
  static Cheese cc = new Cheese(" in Lunch, static");
  Bread b = new Bread(" in Lunch");
  static  Bread bb = new Bread(" in Lunch, static");
}

class PortableLunch extends Lunch {
  PortableLunch() {
    System.out.println("PortableLunch()");
  }
  Lettuce ll = new Lettuce(" in PortableLunch");
  static  Lettuce l = new Lettuce(" in PortableLunch, static");
  Cheese c = new Cheese(" in PortableLunch");
  static Cheese cc = new Cheese(" in PortableLunch, static");
  Bread b = new Bread(" in PortableLunch");
  static  Bread bb = new Bread(" in PortableLunch, static");
}

class SandwichModified extends PortableLunch {
  SandwichModified() { 
    System.out.println("SandwichModified()");
  }
  Lettuce ll = new Lettuce(" in Sandwich");
  static  Lettuce l = new Lettuce(" in Sandwich, static");
  Cheese c = new Cheese(" in Sandwich");
  static Cheese cc = new Cheese(" in Sandwich, static");
  Bread b = new Bread(" in Sandwich");
  static  Bread bb = new Bread(" in Sandwich, static");
  public static void main(String[] args) {
    new SandwichModified();
  }
} ///:~


The output is:

Lettuce() in Meal, static
Cheese() in Meal, static
Bread() in Meal, static
Lettuce() in Lunch, static
Cheese() in Lunch, static
Bread() in Lunch, static
Lettuce() in PortableLunch, static
Cheese() in PortableLunch, static
Bread() in PortableLunch, static
Lettuce() in Sandwich, static
Cheese() in Sandwich, static
Bread() in Sandwich, static
Lettuce() in Meal
Cheese() in Meal
Bread() in Meal
Meal()
Lettuce() in Lunch
Cheese() in Lunch
Bread() in Lunch
Lunch()
Lettuce() in PortableLunch
Cheese() in PortableLunch
Bread() in PortableLunch
PortableLunch()
Lettuce() in Sandwich
Cheese() in Sandwich
Bread() in Sandwich
SandwichModified()


Add a comment to this suggestion
Comment ID: 1010729-002251-wxm_-leedu-_com.cmt
From: wxm
TIJ2code Chapter:TIJ2code
Search for Text: TIJ2code.zip

TIJ2code.zip

Add a comment to this suggestion
Comment ID: 1010725-055544-storm_31_-latinmail-_com.cmt
From: Nilsa
Prentice Hall Chapter:B.Eckel
Search for Text: www.bruceeckel.com

thanks

Add a comment to this suggestion
Comment ID: 1010711-185544-forbesjhb_-prodigy-_net.cmt
From: Jason Forbes
w97 Chapter:8
Search for Text: If you do want extra type safety, you can build a class like this


The main for Month2.java should be placed in a seperate class or the fields should be final.  By placing
it in the same class, the comment about type safety is not completely valid.  The main method works fine:

public static void main(String[] args) {
    Month2 m = Month2.JAN;
    Month2.JAN="ANYTHING";
    System.out.println(m);//prints ANYTHING, not JAN
    m = Month2.number(12);
    System.out.println(m);
    System.out.println(m == Month2.DEC);
    System.out.println(m.equals(Month2.DEC));
  }

Of course, in any real work situations, there would not be any methods like this in the class, but since
it's showing "extra type safety," it should not allow any changes, even internally.

Add a comment to this suggestion
Comment ID: 1010711-013652-niranjan002_-yahoo-_com.cmt
From: niranjan
total Chapter:1-25
Search for Text: java

i  suggest  asu  like



Add a comment to this suggestion
Comment ID: 1010708-180301-jack7777766_-hotmail-_com.cmt
From: Jack Dabah
Revision 12 Chapter:9
Search for Text: com:bruceeckel:util:Arrays2.java


In Arrays2.java the print method might cause slight confusion.  When printing part of an array the start
method will print the range as [a:b]

The confusion is that "a" is the array element as counting from 0, and "b" is the array element as counting
from 1. This is caused because the for loops prints the array elements up to but not including "b". Not
printing b is necessary for the methods that use the array objects length method, since an array of length
5 is actually from 0 to 4. However I suggest "a+1" should be the output instead of "a" so as to confirm
that we are printing array elements counting from 1 not 0, and avoiding confusion on the range of the
print method.

Add a comment to this suggestion
Comment ID: 1010707-085855-Larry_-DefinitiveSolutions-_com.cmt
From: Larry Leonard
paperback? Chapter:15: Distributed Computing
Search for Text: they can vendor independent


Two problems in this sentence.  Correct "EJB's" to "EJBs".  Correct "they can vendor independent" to
"they can be vendor independent".

Wonderful book, BTW, as was TIC++... looking forward to reading "TIDesign Patterns!

Add a comment to this suggestion
Comment ID: 1010707-030750-amolspawar_-hotmail-_com.cmt
From: amol s pawar
2 Chapter:4
Search for Text: projects

please send the projects of the applets .these i have to submitt in my college.

Add a comment to this suggestion
Comment ID: 1010626-124252-rohun2000_-hotmail-_com.cmt
From: rohun
2nd Chapter:ch13
Search for Text: servelets

i net servlets for ur programs where to get them from??????

Add a comment to this suggestion
Comment ID: 1010625-202753-shiwz_-163-_net.cmt
From: shiwz
2 Chapter:all
Search for Text: java

aaa

Add a comment to this suggestion
Comment ID: 1010612-083947-balaji280283_-eth-_net.cmt
From: Balaji
1 Chapter:1
Search for Text: java

ere

Add a comment to this suggestion
Comment ID: 1010610-135108-steitelb_-yahoo-_com.cmt
From: Steve Teitelbaum
revision 12 Chapter:15
Search for Text: There's one other issue when using HttpServlet


It appears that a plausible reason for using doGet in HttpServlet (over using a single generic service
method to handle both GET and POST) is that the http spec states that GET should be safe and idempotent
but POST is not. Thus if invoking service() could produce different side effects for multiple invocations
then technically service() could support POST, but not GET. Hence, one would presumably need to provide
a separate doGet in this case.

Add a comment to this suggestion
Comment ID: 1010609-033825-micael_-pisem-_net.cmt
From: Mikhail Gusarov
printed :) Chapter:15
Search for Text: JPyton

JPython never exists, right name is Jython :)

Add a comment to this suggestion
Comment ID: 1010605-144058-kmadhavan_-hotmail-_com.cmt
From: Madhavan Kasthuri
2 Chapter:6: Reusing Code & Class
Search for Text: There is know way that I know of to make the array handles themselves final

There is no way that I know of to make the array handles themselves final

From: lerabo bogatsu [jbogatsu_-atraxis-_com]

(What do you want me to  do for you ? There is no limit to the text in this box -- please submit entire
code listings if appropriate: )


Add a comment to this suggestion
Comment ID: 1010603-002011-gino-_marckx_-bigfoot-_com.cmt
From: Gino Marckx
11 Chapter:3
Search for Text: Precedence Revisited

In the table describing operator precedence, the unary bitwise operator ~ is not listed.
It should be listed in the first row with the other unary operators.

regards,
Gino.

Add a comment to this suggestion
Comment ID: 1010601-000239-mandgar76_-yahoo-_com.cmt
From: Mahboubeh  Mandegar
2 Chapter:1,2,3,4,5
Search for Text: aplet

please learn easy

Add a comment to this suggestion
Comment ID: 1010527-195940-judel_-kornet-_net.cmt
From: Jeong Jun
1 Chapter:1
Search for Text: 1

111

Add a comment to this suggestion
Comment ID: 1010526-084337-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:15
Search for Text: Along with Jini for local device networks, this chapter has introduced some


The paragraph in the "Summary" section of Chapter 15 that begins with "Along with Jini for local ..."
is accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays as one long
line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-084117-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:15
Search for Text: Create and install a security manager that supports RMI

Under the section "Implementing the remote interface" of chapter 15:

The formatting on the HTML version is not well formatted, sentences are cut in the middle and the numbering
of the items is wrong.


Add a comment to this suggestion
Comment ID: 1010526-083905-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:15
Search for Text: as it many span several client requests and pages.

Under the section "Implicit objects" in chapter 15:
"...as it many span several client requests and pages."
I think the word in this phrase should be 'may' and not 'many'.

Add a comment to this suggestion
Comment ID: 1010526-083519-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:15
Search for Text: The leading percent sign may be followed by other characters 


The paragraph in the "Java Server Pages" section of Chapter 15 that begins with "The leading percent..."
is accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays as one long
line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-083222-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: This chapter was meant only to give you an introduction to the power of Swing 


The paragraph in the "Summary" section of Chapter 13 that begins with "This chapter was meant..." is
accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays as one long line
that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-083026-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: You’ll need to put it into the new (messy, complicated) form shown earlier 


The paragraph in the "Packaging an applet into a JAR file" section of Chapter 13 that begins with "You’ll
need to put it into..." is accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and
displays as one long line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-082610-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: Swing contains all the components that you expect to see in a modern UI


The paragraph in the begining of Chapter 13 that begins with "Swing contains all the components..." is
accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays as one long line
that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-032834-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: In general you’ll want to design your classes so that each one does 


The paragraph in the "Separating business logic from UI logic" section of Chapter 13 that begins with
"In general you’ll want to design your classes..." is accidentally inside an HTML PRE tag.  Therefore,
it does not get wrapped and displays as one long line that goes way beyond the edge of the browser window.



Add a comment to this suggestion
Comment ID: 1010526-032709-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: Of course, you could also control the two using a listener


The paragraph in the "Sliders and progress bars" section of Chapter 13 that begins with "Of course, you
could also control..." is accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and
displays as one long line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-032530-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: The way that this is accomplished in Swing is by cleanly 


The paragraph in the "Capturing an event" section of Chapter 13 that begins with "The way that this is
accomplished..." is accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays
as one long line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010526-032028-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:13
Search for Text: Swing contains all the components that you expect 


The paragraph in the begining of chapter 13 that begins with "Swing contains all the components..." is
accidentally inside an HTML PRE tag.  Therefore, it does not get wrapped and displays as one long line
that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010520-052743-lemburg_-aixonix-_de.cmt
From: Christian Lemburg
Revision 12 Chapter:All - Source Code Correction
Search for Text: Makefiles

IMHO, you should change the line "JVC = javac" in your makefiles
to "JVC = javac -g" to make debugging of the source files easier.
This short one-liner did it for me on Linux (standing in the toplevel of the code directory tree):

find . -name 'makefile' | xargs perl -i.bak -pe 's/JVC = javac/JVC = javac -g/'

Also, in chapter 15, there are two DOS-only makefiles where the line
containing the "copy" command (which is not there on linux) has to be
commented out to get a running make:

c15/jsp/makefile
c15/servlets/makefile

From: sgs [fgsfgs_-zdfafdf-_com]
fgsfg

Add a comment to this suggestion
Comment ID: 1010513-113012-jlawrence_-gr-_com.cmt
From: Jeff Lawrence
? Chapter:1 Introduction

Search for Text: You may wonder why, if it’s so beneficial, a singly-rooted hierarchy isn’t it in C++
.


This sentence appears as the first sentence of the last paragraph of the section entitled "The singly-rooted
hierarchy". The word "it" is unnecessary here, "...isn’t it in C++."

Add a comment to this suggestion
Comment ID: 1010513-065804-gheeglyerm_-bol-_com-_br.cmt
From: Guilherme Nogueira
Release 11 Chapter:1

Search for Text: assume that you have had experience in a procedural programming language, although not
necessarily C.

...language, although not necessarily Pascal. (or other procedural language)

I always thought of C being a 'modular' programming language.

Add a comment to this suggestion
Comment ID: 1010506-115057-chris_-gravesnetwork-_com.cmt
From: Chris
revision 11 Chapter:6
Search for Text: Perform the initialization of the blank final inside a method (not the constructor

Text is from question 21.

Is this supposed to be a trick question?  I'm assuming not due to the way the entire question is worded.
 The error then, is that final fields are guaranteed to be initialized by the COMPILER either at the
point of definition, in an initialization section or in all constructors.  You cannot assign a final
variable anywhere else, so it is difficult to demonstrate anything except compiler errors... Am I missing
something?

Add a comment to this suggestion
Comment ID: 1010501-034639-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:11
Search for Text: A “pipe,” which works like a physical


The "Types of InputStream" section has a list of items, the 4th item is not well formatted (on my html
version), so the list restarts to 1 on the next line.
Also on the 4th item the comma is inside the double quote ("pipe,").

Add a comment to this suggestion
Comment ID: 1010431-062643-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:10
Search for Text: When the compiler creates the default constructor, it which automatically 

This phrase doesn't seem correct...
I think the word 'which' shouldn't be there.

Add a comment to this suggestion
Comment ID: 1010429-090942-pauloya_-yahoo-_com.cmt
From: Paulo Santos
11 Chapter:8
Search for Text: This example should move you a long way toward appreciating the value


The paragraph in the "Inner classes & control frameworks" section of Chapter 8 that begins with "This
example should move you..." is accidentally inside an HTML PRE tag.  Therefore, it does not
get wrapped and displays as one long line that goes way beyond the edge of the browser window.


Add a comment to this suggestion
Comment ID: 1010429-033824-nivasss_-usa-_net.cmt
From: B.Nithiyanandan
Revision 11 Chapter:9
Search for Text: Map1.java



In the program Map1.java I would like to point out what may not be a bug but a misleading code in the
program.

In the statements,

public static void test(Map m) {
Collections2.fill(m, geo, 25);
// Map has 'Set' behavior for keys:
Collections2.fill(m, geo.reset(), 25);
...


Obviously,the intention is to fill the Map with the same set of keys twice to show it's Set functionality
for keys.This correctly happens the first time when the method is called for testing HashMap.But when
testing TreeMap you can see that first call to fill the Map follows a geo.reset() and since we dont have
a reset there , the next 25 keys with values are filled.


The result is that when executed ,we have 25 entries for HashMap and nearly double that for TreeMap ,which
is apparently confusing since they are both supposed to follow the Set functionality.

Obviously, the solution is ,

public static void test(Map m) {
Collections2.fill(m, geo.reset(), 25);
// Map has 'Set' behavior for keys:
Collections2.fill(m, geo.reset(), 25);
...


I would also like to point out to a typographical error.In the HTML version

in some chapters - like ch.8 and 9 the sentences just before the end of a section are not wrapped up
and they are also in the same font as that of the code.


Apart form these small errors yours has been an excellent work and i am very much impressed by your conceptual
treatment of not only the language features ,but also the libraries, which i haven't seen in other books.



Add a comment to this suggestion
Comment ID: 1010428-184154-Bruce_-EckelObjects-_com.cmt
From: Bruce Eckel
11 Chapter:1
Search for Text: test

Testing the CGI config

Add a comment to this suggestion
Comment ID: 1010026-132640-gary_-calpc-_org.cmt
From: Gary Benjamin
11 Chapter:TOC
Search for Text: Index


The Index link in both the framed and non-framed version of the table of contents opens the additional
stuff page; and there is no link named "Additional Stuff".

The current html is:

<A HREF="Adstuff.html">Index</A><BR>

In FrameContents.html it should be changed to:

<A HREF="Adstuff.html">Additional stuff</A><BR>
<A HREF="FrameDocIndex.html">Index</A><BR>

and in Contents.html it should be changed to:

<A HREF="Adstuff.html">Additional stuff</A><BR>
<A HREF="DocIndex.html">Index</A><BR>


Add a comment to this suggestion
Comment ID: 1010026-131723-gary_-calpc-_org.cmt
From: Gary Benjamin
11 Chapter:5
Search for Text: Sandwich

In this code example:

//: c05:Lunch.java
// Demonstrates class access specifiers.
// Make a class effectively private
// with private constructors:

class Soup {
  private Soup() {}
  // (1) Allow creation via static method:
  public static Soup makeSoup() {
    return new Soup();
  }
  // (2) Create a static object and
  // return a reference upon request.
  // (The "Singleton" pattern):
  private static Soup ps1 = new Soup();
  public static Soup access() {
    return ps1;
  }
  public void f() {}
}

class Sandwich { // Uses Lunch
  void f() { new Lunch(); }
}

// Only one public class allowed per file:
public class Lunch {
  void test() {
    // Can't do this! Private constructor:
    //! Soup priv1 = new Soup();
    Soup priv2 = Soup.makeSoup();
    Sandwich f1 = new Sandwich();
    Soup.access().f();
  }
} ///:~


I do not think that there is anything incorrect. My comments are mainly about why you chose to include
extra code that does not illustrate the reasons for using a private constructor, nor a mechanism to implement
it. Specifically,

1. I can not figure out what Sandwich illustrates in this context.


2. I can not figure out why you chose to use the same method name f() in Sandwich as in Soup, especially
since it is not used.


3. How can you have "new Lunch()" in the body of Sandwich without either assigning it to a field, as
in:
Lunch meal = new Lunch();
or as a parameter to a method call, as in:
boy.eat(new Lunch);
or as a prefix to calling a method, as in:
new Lunch.test;

Perhaps it is syntactically correct, but an explanation of the circumstances when you would do this would
be helpful.


4. I think the implications of creating a new Sandwich() in Lunch, and a new Lunch in Sandwich() is worthy
of discussion (although off topic for this section on class access).

Add a comment to this suggestion
Comment ID: 1010024-070810-chuck_-ddi-_com.cmt
From: chuck Conlin
Revision 9 Chapter:13
Search for Text: c13

Chapter 13 is missing from the HTML download. 
I downloaded all four zip files,
but there was no Chapter 13.

I went to a 2nd web site:
http://www.perlpeople.com/eckel/

Same problem.

Thank you.

Chuck Conlin

Add a comment to this suggestion
Comment ID: 1010024-001015-oamdg_mb_-yahoo-_com.cmt
From: Milan Babiak
Release 11 Chapter:3. Controlling Program Flow
Search for Text: Precedence revisited

To the table in "Precedence revisited" I would like to add following:

2nd row, 3rd column, Unary operators:
	! boolean complement operator is missing,
	~ bitwise inversion operator is missing,

3rd row, 3rd column, Arithmetic (and shift) operators:
	- the unsigned right shift >>> operator is missing,

4th row, 3rd column, Relational operators:
	- the "instanceof" is missing.

Add a comment to this suggestion
Comment ID: 1010023-083732-michael-_bane_-man-_ac-_uk.cmt
From: Michael Bane
Revision 11 Chapter:04
Search for Text: death condition example

Not sure why but couldn't get you DeathCondition.java example to work.

It doesn't give me "Error: checked out" message at all.  This is on both a Linux box (java version "1.1.7B")
and 
an SGI Origin2000 (java version "1.2.1"; Classic VM (build JDK-1.2.1, 
green threads, mipsjit)

Please advise!

Thanks
MICHAEL


Add a comment to this suggestion
Comment ID: 1010023-083629-michael-_bane_-man-_ac-_uk.cmt
From: Michael Bane
Revision 11 Chapter:04
Search for Text: garbage collector example

Not sure why but even with any of the arguments I couldn't get your 
example Garbage.java to give the same number of finalized and 
created chairs.  This is on both a Linux box (java version "1.1.7B") and 
an SGI Origin2000 (java version "1.2.1"; Classic VM (build JDK-1.2.1, 
green threads, mipsjit)

Please advise!

Thanks
MICHAEL


Add a comment to this suggestion
Comment ID: 1010011-100554-james_jia_-providian-_com.cmt
From: James Jia
Revision 9 Chapter:11, the Java IO System
Search for Text: FileInputStream, FileReader


In the section StreamTokenizer, the FileReader is used to read in a file in the example program SortedWordCount.
However, the text after the example refers to FileInputStream ( which should be FileReader).

public class SortedWordCount {
  private FileReader file;
  private StreamTokenizer st;
  // A TreeMap keeps keys in sorted order:
  private TreeMap counts = new TreeMap();
  SortedWordCount(String filename)
    throws FileNotFoundException {
    try {
      file = new FileReader(filename);
      st = new StreamTokenizer(
        new BufferedReader(file));
      st.ordinaryChar('.');
      st.ordinaryChar('-');
    } catch(FileNotFoundException e) {
      System.out.println(
        "Could not open " + filename);
      throw e;
    }
  }
  

To open the file, a FileInputStream is used, and to turn the file into words a StreamTokenizer is created
from the FileInputStream. 


Add a comment to this suggestion
Comment ID: 1010010-065714-pstein_-mail-_cslf-_org.cmt
From: Peter Stein
Revision 11 Chapter:8
Search for Text: c08:BigEgg2.java


This is a suggestion to improve comprehension on the order in which inner class construction takes place.
 In the BigEgg2 example, even though you explain in text, I still found the two outputs of "Egg2.Yolk()"
confusing.  If I'm not alone, maybe an additional line to the BigEgg2 constructor will clear things up:


  public BigEgg2() { 
  System.out.println("New BigEgg2()");
  insertYolk(new Yolk()); 
  }

This will cause the output to read:

Egg2.Yolk()
New Egg2()
New BigEgg2()
Egg2.Yolk()
BigEgg2.Yolk()
BigEgg2.Yolk.f()

The revised example is included below in its entirety:

//: c08:BigEgg2.java
// Proper inheritance of an inner class.

class Egg2 {
  protected class Yolk {
    public Yolk() {
      System.out.println("Egg2.Yolk()");
    }
    public void f() {
      System.out.println("Egg2.Yolk.f()");
    }
  }
  private Yolk y = new Yolk();
  public Egg2() {
    System.out.println("New Egg2()");
  }
  public void insertYolk(Yolk yy) { y = yy; }
  public void g() { y.f(); }
}

public class BigEgg2 extends Egg2 {
  public class Yolk extends Egg2.Yolk {
    public Yolk() {
      System.out.println("BigEgg2.Yolk()");
    }
    public void f() {
      System.out.println("BigEgg2.Yolk.f()");
    }
  }
  public BigEgg2() { 
  System.out.println("New BigEgg2()");
  insertYolk(new Yolk()); 
  }
  public static void main(String[] args) {
    Egg2 e2 = new BigEgg2();
    e2.g();
  }
} ///:~




.  I was having trouble with the order of constructor

Add a comment to this suggestion
Comment ID: 1010007-041755-songjing_-computer-_org.cmt
From: Song Jing
Revision 9 Chapter:9
Search for Text: //: c09:ArraySize.java

//: c09:ArraySize.java
// Initialization & re-assignment of arrays.

class Weeble {} // A small mythical creature

public class ArraySize {
  public static void main(String[] args) {
    // Arrays of objects:
    Weeble[] a; // Null reference
    Weeble[] b = new Weeble[5]; // Null references
    Weeble[] c = new Weeble[4];
    for(int i = 0; i < c.length; i++)
      c[i] = new Weeble();
    // Aggregate initialization:
    Weeble[] d = { 
      new Weeble(), new Weeble(), new Weeble()
    };

    // Compile error: variable a not initialized:
    //!System.out.println("a.length=" + a.length); 
   
    // Dynamic aggregate initialization:
    a = new Weeble[] {
      new Weeble(), new Weeble()
    };
    System.out.println("a.length = " + a.length);
    System.out.println("b.length = " + b.length);
    // The references inside the array are 
    // automatically initialized to null:
    for(int i = 0; i < b.length; i++)
      System.out.println("b[" + i + "]=" + b[i]);
    System.out.println("c.length = " + c.length);
    System.out.println("d.length = " + d.length);
    a = d;
    System.out.println("a.length = " + a.length);

    // Arrays of primitives:
    int[] e; // Null reference
    int[] f = new int[5];
    int[] g = new int[4];
    for(int i = 0; i < g.length; i++)
      g[i] = i*i;
    int[] h = { 11, 47, 93 };
    // Compile error: variable e not initialized:
    //!System.out.println("e.length=" + e.length);
    System.out.println("f.length = " + f.length);
    // The primitives inside the array are
    // automatically initialized to zero:
    for(int i = 0; i < f.length; i++)
      System.out.println("f[" + i + "]=" + f[i]);
    System.out.println("g.length = " + g.length);
    System.out.println("h.length = " + h.length);
    e = h;
    System.out.println("e.length = " + e.length);
    e = new int[] { 1, 2 };
    System.out.println("e.length = " + e.length);
  }
} ///:~
Here’s the output from the program:

a.length = 2
b.length = 5
b[0]=null
b[1]=null
b[2]=null
b[3]=null
b[4]=null
c.length = 4
d.length = 3
a.length = 3
f.length = 5
f[0]=0
f[1]=0
f[2]=0
f[3]=0
f[4]=0
g.length = 4
h.length = 3
e.length = 3
e.length = 2


From: Charlie Guttenberg [charles-_guttenberg_-med-_ge-_com]
When I compile and run this example (unchanged from the downloaded
version), I get the following output (note that a.length = 3 both times):

b.length = 5
b[0]=null
b[1]=null
b[2]=null
b[3]=null
b[4]=null
c.length = 4
d.length = 3
a.length = 3
a.length = 3
f.length = 5
f[0]=0
f[1]=0
f[2]=0
f[3]=0
f[4]=0
g.length = 4
h.length = 3
e.length = 3
e.length = 2


Add a comment to this suggestion
Comment ID: 1010002-091314-bcowen_-osmotic-_com.cmt
From: Bradley Cowen
Revision 11 Chapter:9
Search for Text: fill an array, then to produces values

line should read:

fill an array, then to produce [instead of produces] values

Add a comment to this suggestion
Comment ID: 1001131-150916-shilkrot_-brown-_edu.cmt
From: Leonid Shilkrot
Hard copy Chapter:Source code from this web page
Search for Text: makefiles


The makefiles that you include with the source code are written in DOS. I'm using LInux, and my make


produces an error because of the DOS's \r character at the end of each line.  If you remove these \r's,

make works fine.  Just in case, I'm using this version of make:

[shilkrot@en737l c04]$ make -v
GNU Make version 3.77, by Richard Stallman and Roland McGrath.


Leo.


Add a comment to this suggestion
Comment ID: 1001131-140449-ericlee_-sympatico-_ca.cmt
From: Eric Lee
printed, PDF Rel. 11 Chapter:13
Search for Text: not like the combo box in Windows

On p. 751:

"Java’s JComboBox box is not like the combo box in Windows, which lets
you select from a list or type in your own selection. With a JComboBox
box you choose one and only one element from the list."

JComboBox is in fact editable (type in or edit a selection) if:

JComboBox c = new JComboBox();
// ...
c.setEditable(true);   // defaults to false

The editable item defaults to [0] if there is one and is replaced by the chosen item.
It is referred to as [-1] if it has been edited before being chosen or there was no [0].


Add a comment to this suggestion
Comment ID: 1001129-140503-erikbuljan_-email-_com.cmt
From: Erik Buljan
book Chapter:3
Search for Text: test2


Exercise 3 in Chapter 3 mentions the method "test2()" to be found in either the "if-else" or "return"
sections.  There is no test2() in either of these sections.  There are two test1()'s, and they are identical
.

Add a comment to this suggestion
Comment ID: 1001128-083340-pstein_-mail-_cslf-_org.cmt
From: Peter Stein
11 Chapter:6
Search for Text: // Cannot be compile-time constants


The source code example c06:FinalData.java contains a comment that needs to be corrected.  The comment


     // Cannot be compile-time constants

should be changed to

     // Does not have to be compile-time constants

                  or

     // Value determined at run-time


Add a comment to this suggestion
Comment ID: 1001122-144937-chiarettir_-libero-_it.cmt
From: Roberto Chiaretti
Prentice-Hall published edition Chapter:11: The Java I/O System
Search for Text: Decorator classes FilterInputStream and FilterOutputStream



The FilterInputStream and FilterOutputStream classes are supposed to be abstract all over the chapter,
while they are reported as 'regular' public classes in the JDK 1.3 on line documentation.

Add a comment to this suggestion
Comment ID: 1001120-051907-yt16613_-glaxowellcome-_com.cmt
From: Ryan Tang
Revision 9 Chapter:13
Search for Text: entire chapter 13 is missing

chapter13.html file is missing from download and installation.


Not sure if the following errors are related to the above sympton, I got two errors during the unzip
process (no error during the download, though):

1. tij-2ndEdition-code2.zip
   Bad CRC 2194b097 (should be 5319e439)

2. tij-2ndEdition-html
   bad CRCb06f62cd (should be da9eba54)

Thanks.

Ryan Tang

Add a comment to this suggestion
Comment ID: 1001119-214620-jingjinyu_-hotmail-_com.cmt
From: Jingjin Yu
Current Chapter:15
Search for Text: localhost does not work with RMI


Actually, it does work. I've successfully run the ComputePi example from sun's website. I've tried both
machine name and localhost, both work fine. I've also tried JDK1.2.2 and JDK1.3.

Add a comment to this suggestion
Comment ID: 1001119-065613-tangtony_-hotmail-_com.cmt
From: Tony Tang
revision 11 Chapter:13
Search for Text: Menus.java

Sorry, the following post should be posted to correction instead of comment.

In chapter 13, sample program Menus.java, there are two typos in the fuction  public void init(){}

The first typo:
   Error
      ......
      ......
      safety[1].setActionCommand("Hide");
 ===> safety[0].setMnemonic(KeyEvent.VK_H);
      safety[1].addItemListener(cmil);
   Correct
      ......
      ......
      safety[1].setActionCommand("Hide");
 ===> safety[1].setMnemonic(KeyEvent.VK_H);
      safety[1].addItemListener(cmil);

The second typo:    
   Error
      ......
      ......
      for(int i = 0; i < file.length; i++) {
 ===>   file[i].addActionListener(fl);
        f.add(file[i]);
      }
   Correct
      ......
      ......
      for(int i = 0; i < file.length; i++) {
 ===>   file[i].addActionListener(ml);
        f.add(file[i]);
      }



Even with those two typos, the program can still be compiled and run. But it just doesn't run correctly.



Keep the good work.
Tony Tang


Add a comment to this suggestion
Comment ID: 1001114-160034-car_door_-hotmail-_com.cmt
From: Josh Adams
1 Chapter:13
Search for Text: A display framework


In Console.java, you perform extra work to get the name of the class. Consider this excerpt from the
source:

String t = o.getClass().toString();
// Remove the word "class":
if (t.indexOf("class") != -1)
  t = t.substring(6);

The following code is much more concise:

String t = o.getClass().getName();

Add a comment to this suggestion
Comment ID: 1001114-050348-angelarnal_-worldonline-_es.cmt
From: Angel Arnal
Rev. 11 Chapter:2
Search for Text: It's only a syntactic difference

It's only a semantic difference

From: Morris Keesan [keesan_-world-_std-_com]
It's neither a syntactic nor semantic difference.  It's a terminology or vocabulary difference.
"Function" and "method", as used, are semantically and syntactically identical.


From: ppp [p_-uiu-_es]
dfw45rwre wrtwr rwr

Add a comment to this suggestion
Comment ID: 1001111-175225-rod_-fast-_fujitsu-_com-_au.cmt
From: Rod Lee
Revision 11 Chapter:3
Search for Text: Auto increment and decrement


Your explanation of the workings of the prefix and postfix operators is back to front.  The actual timing
of the associated operation and the updating of the variable's value is probably obvious to people studying
the output of the example, though.  Your explanation following the sample output is also (consistently,
at least) incorrect.

I appreciate your efforts with the book very much.  Thank you.

Add a comment to this suggestion
Comment ID: 1001111-045530-dieter-_noack_-bam-_de.cmt
From: Dieter Noack
Rev. 11 Chapter:Example
Search for Text: CopyConstructor.java

In the example CopyConstructor.java a NullPointerException is thrown

Exception in thread "main" java.lang.NullPointerException
        at Fruit.<init>(CopyConstructor.java:55)
        at Tomato.<init>(CopyConstructor.java:73)
        at CopyConstructor.ripen(CopyConstructor.java:109)
        at CopyConstructor.main(CopyConstructor.java:120)


This is because the creation of the array Seed[] s in the constructor of class Fruit is outside the scope
of the copy-constructor in Fruit. I suppose the statement s = f.s; should be inserted.

...
class Fruit {
  private FruitQualities fq;
  private int seeds;
  private Seed[] s;
  Fruit(FruitQualities q, int seedCount) { 
    fq = q;
    seeds = seedCount;
    s = new Seed[seeds];
    for(int i = 0; i < seeds; i++)
      s[i] = new Seed();
  }
  // Other constructors:
  // ...
  // Copy constructor:
  Fruit(Fruit f) {
    fq = new FruitQualities(f.fq);
    seeds = f.seeds;
    s = f.s; // insert this statement to avoid NullPointerException
    // Call all Seed copy-constructors:
    for(int i = 0; i < seeds; i++)
      s[i] = new Seed(f.s[i]);
    // Other copy-construction activities...

BTW.: Your book is great and I enjoy reading it.

From: Bill Love [blove_-allstate-_com]

Inserting "s = f.s" is not quite correct, as it misses the point of the copy constructor idea, since
we want to copy the data, not the reference.

It's necessary to create a new Seed array with "s = new Seed[seeds]", as in the other constructor.

Add a comment to this suggestion
Comment ID: 1001106-153336-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:Chaper 08
Search for Text: InterfaceCollision.java 

In the InterfaceCollision.java

Inside class C2 and C3 comments say next to:

public int f(int i) { return 1; }  // overloaded

They are not overloaded, both are just implementation of the interface methods.


Also something might worth mentioning.
At the very beginning of Chapter 08 Eckel says,

"C++, for example does not contain such mechanisms, ..."

referring to interfaces and inner classes.

There are Nested classes in C++, may be worth mentioning.

Add a comment to this suggestion
Comment ID: 1001030-015454-estelag_-arrakis-_es.cmt
From: Estela González
any Chapter:homepage
Search for Text: translation


In "electronic translations", (http://www.bruceeckel.com/TIJ2/index.html), it should say "portuguese"
instead of "portugese".

Add a comment to this suggestion
Comment ID: 1001029-203735-rmtwede_-gotoworld-_com.cmt
From: Randall Twede
11 Chapter:13
Search for Text: Applet default layout

you state:


"The normal behavior of an applet is to use the BorderLayout, but that won’t work here because (as you
will learn later in this chapter when controlling the layout of a form is examined in more detail) it
defaults to covering each control entirely with every new one that is added. However, FlowLayout causes
the controls to flow evenly onto the form, left to right and top to bottom."

then later:


"The applet uses a default layout scheme: the BorderLayout (a number of the previous example have changed
the layout manager to FlowLayout). Without any other instruction, this takes whatever you add( ) to it
and places it in the center, stretching the object all the way out to the edges."

the default layout of Applet is FlowLayout not BorderLayout! 

From: Frank Kruchio [frank-_kruchio_-paradise-_net-_nz]
The default layout manager for an Applet is FlowLayout
on the other hand for JApplet (in JFC, Swing) it is BorderLayout.


Add a comment to this suggestion
Comment ID: 1001029-202040-rmtwede_-gotoworld-_com.cmt
From: Randall Twede
11 Chapter:14
Search for Text: stop() method


"The reason that the stop( ) method is deprecated is because it doesn’t release the locks that the thread
has acquired, and if the objects are in an inconsistent state (“damaged”) other threads can view and
modify them in that state." 

if the thread doesn't release the locks, how can any other thread view the object?

it cannot! the thread releases all locks when stop() is called!

Add a comment to this suggestion
Comment ID: 1001029-175858-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:5
Search for Text: Now this package name can be used as an umbrella name space for the


A small error. In the creating unique package names section in chapter 5 inside the Vector class you
print: com.bruceeckel.util.Vector;

It should be:
System.out.println("com.bruceeckel.simple.Vector");

same error in the List class where it should be

System.out.println("com.bruceeckel.simple.List");




It's worth mentioning that when the Java interpreter will search the CLASSPATH defined directories in
order and will find a class name like "List" for example what Eckel defined, then it will try to use
that.

And you get an error in this case
[frank@babe Chapter_04]$ javac LibTest.java
LibTest.java:8: List is abstract; cannot be instantiated
        List l   = new List();
                   ^           
This is because Java found the built in java utility class first and not yours.
If you change the order of the directories in the CLASSPATH or
you fully define the object at creation as:

com.bruceeckel.simple.List l = new com.bruceeckel.simple.List();

it will work.
Another option to import them individually as:

import com.bruceeckel.simple.Vector;
import com.bruceeckel.simple.List;

Add a comment to this suggestion
Comment ID: 1001029-144144-bill_-truewill-_net.cmt
From: Bill Sorensen
the physical book Chapter:11
Search for Text: Multifile storage with Zip


In c11:ZipCompress.java, there are several pieces of code similar to "while((c = in.read() != -1) out.write(c)".
 In testing, I found that zipping was unacceptably slow on large files.  When I switched to doing my
own buffering (reading and writing a byte array), I saw an order of magnitude speed increase, even with
buffered streams.  It appears that the overhead of all those read/write method calls is significant.
You might consider changing the code to reflect this, as many people will base their code on yours.

Add a comment to this suggestion
Comment ID: 1001028-063311-nick-_hudson_-compaq-_com.cmt
From: nick hudson
11 Chapter:13
Search for Text: TextFields.java

In this example program, you have the line:

  DocumentListener dl = new T1();


I don't think this line is necessary - the variable "dl" is not subsequently used at all, and you already
created a T1 a couple of lines earlier where you had:

  ucd.addDocumentListener(new T1());


The program doesn't seem to behave any differently if the "dl" declaration is removed; maybe I'm missing
something subtle but I can't see that it is doing anything useful...

regards




Add a comment to this suggestion
Comment ID: 1001024-194726-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:3
Search for Text: ListCharacters.java program

Just a question about the ListCharacters.java program.

value: 25 character:
value: 26 character: ?
value: 27 character:
alue: 28 character:
value: 29 character:
value: 30 character:

This is part of the output, on Red Hat Linux 7.0, using 
glibc-2.1.94-3 and SDK v1.3. Compiled with javac.

It seems to print character number 26 without clearing the screen.



Add a comment to this suggestion
Comment ID: 1001024-191446-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:3
Search for Text: The conditional expression for the while says "keep doing this loop

In WhileTest.java explanation

The conditional expression for the while says "keep doing this loop until 
the number is greater."

Probably you meant to say:

The conditional expression for the while says "keep doing this loop until 
the number is SMALLER."

Number is r and the expression says(r < 0.99d)




Add a comment to this suggestion
Comment ID: 1001024-021024-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:3
Search for Text: while, do-while and for control looping and are

The very first line under the iteration subsection:

while, do-while and for control looping and are sometimes classified

Probably you meant:

while, do-while and for control looping are sometimes classified

Add a comment to this suggestion
Comment ID: 1001024-012159-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
version 11, 2nd edition Chapter:3
Search for Text: c03:IfElse2.java

In the IfElse2.java program.

Just an idea.
I would remove the
int result = 0;

to avoid confusion. It is not used for anything just declared, so redundant anyway.

Add a comment to this suggestion
Comment ID: 1001023-221050-frank-_kruchio_-paradise-_net-_nz.cmt
From: Frank Kruchio
Version 11, 2nd edition Chapter:Chapter 3
Search for Text: there's no ambiguity, so an L after the 200 would be superfluous.

Small correction only. Below the line you find the following code fragment:

float f4 = 1e-47f;               // 10 to the power

The compiler issues the following error message if you add this line 
to any program:

floating point number too small
        float f4 = 1e-47f;               // 10 to the power 
                  ^

From: Sheng-Ying Hsiao [wawo_-ethome-_net-_tw]
The code frament may be:

float f4 = 1e-47f;               // 10 to the power

Then the compiler issues the following error message:

possible loss of precision
found   : double
required: float
		float f=1e-47;
                        ^



Add a comment to this suggestion
Comment ID: 1001023-074954-nwebre_-post-_harvard-_edu.cmt
From: Neil Webre
Revision 9 Chapter:15
Search for Text: final int maxthreads

The sentence 

"The maximum number of threads allowed is determined by the final int maxthreads."


is misleading, and also not in conformance with the code for class MultiJabberClient. It leads one to
think that maxthreads (actually MAX_THREADS) is the number of threads to be generated by the client.
A careful reading of the code clears it up, but I suggest the sentence be changed to read


"The maximum number of threads allowed to exist simultaneously is determined by final int MAX_THREADS
in class MultiJabberClient."

Add a comment to this suggestion
Comment ID: 1001022-231114-oamdg_mb_-yahoo-_com.cmt
From: Milan Babiak
Release 11, ISBN 0-13-027363-5, To be published by Prentice-Hall mid-June, 2000 Chapter:Index
Search for Text: inizialization

Small typing error on the page 1107
Instead "inizialization: lazy · 273" should be "initialization: lazy · 273"

Add a comment to this suggestion
Comment ID: 1001022-082107-nick-_hudson_-compaq-_com.cmt
From: Nick Hudson
11 Chapter:13
Search for Text: BorderLayout


In your description for BorderLayout, you say that when you're adding an object to a panel, "you can
use the overloaded add() method that takes a constant value as its first argument".  In the subsequent
example, "BorderLayout1" you have code of the form:

Container cp = getContentPane();
cp.add(BorderLayout.NORTH,
  new JButton("North"));
.
.

I think the method you're picking up by doing this is
"Container.add(String name, Component comp)".  In the Sun JAVA docs it

says "It is strongly advised to use the 1.1 method, add(Component, Object) in place of this method."


In fact I think that for your example you should be using 
"Container.add(Component comp, Object constraints)", which would make your
code look like this instead:

Container cp = getContentPane();
cp.add(new JButton("North"),
  BorderLayout.NORTH);
.
.

i.e. the arguments are the other way round.  If you look at the API docs
for "BorderLayout", you'll see they have some example code which does

it this way (or at least there's a comment there which shows it being done this way) - it has the following
line of code:

p2.add(new TextArea()); // same as p.add(new TextArea(), BorderLayout.CENTER);

Incidentally, as I type that I can see that there's a typo in the Sun docs,
where they have "p.add" instead of "p2.add" in the comment but I think my point is still valid...

Regards




Add a comment to this suggestion
Comment ID: 1001021-091332-Marc-Etienne-_Vargenau_-alcatel-_fr.cmt
From: Marc-Etienne Vargenau
11 Chapter:9
Search for Text: DJIBOUTI

Errors in the capitals list:

The capital of DJIBOUTI is Djibouti (of course), not Dijibouti
CETE D'IVOIR should be CÔTE D'IVOIRE (O with circumflex)
The funny ones are:
1) the capital of GUINEA-BISSAU is Bissau
instead of capital of GUINEA is "-" and the capital of BISSAU is Bissau
2) the capital of BOSNIA-HERZEGOVINA is Sarajevo.
The last two show (as explained in the note) that the text was 
processed automatically.

Add a comment to this suggestion
Comment ID: 1001017-092819-khall_-talient-_com.cmt
From: Kurt Hall
Revision 11 Chapter:10
Search for Text: Rethrowing an exception


You could mention that a try block does not need a catch block.  I'm not sure how often I would use this
myself since it may be helpful to keep the catch block simply for documentation or a placeholder for
future exception handling, but there are quite a few instances in our own code where we catch and simply
rethrow an exception.  A common example is when the main reason we have a try block is because we need
a finally block to free some resource.

try {
   sw.on();     // throws exception
}
finally {
   sw.off();
}

Add a comment to this suggestion
Comment ID: 1001017-092309-khall_-talient-_com.cmt
From: Kurt Hall
Revision 11 Chapter:10
Search for Text: Pitfall: the lost exception


At least with Solaris java (Solaris VM (build Solaris_JDK_1.2.1_02, native threads, sunwjit)), I am able
to ignore the HoHumException and allow the VeryImportantException to continue unimpeded.  I don't know
if this is due to the compiler or the intent of the Java spec.

Instead of:

    try {
      lm.f();
    } finally {
      lm.dispose();
    }

Do the following:

    try {
      lm.f();
    } finally {
      try {lm.dispose();} catch( HoHumException} {;}
    }

The output is:
Exception in thread "main" A very important exception!
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.<init>(Throwable.java:82)
        at java.lang.Exception.<init>(Exception.java:33)
        at customerService.test.VeryImportantException.<init>(TestExceptions.java:8)
        at customerService.test.TestExceptions.f(TestExceptions.java:22)
        at customerService.test.TestExceptions.main(TestExceptions.java:31)


Add a comment to this suggestion
Comment ID: 1001015-182907-amitchell_-optusnet-_com-_au.cmt
From: Andrew Mitchell
Revision 11 Chapter:8: Interfaces & Inner Classes
Search for Text: (since protected also gives package access—that is, protected is also “friendly”)

Sentence should read:

PDestination is protected, so no one but the Parcel3 class, its inner classes, and its 
inheritors can access it.

Explanation:

Protected access is not friendly!

Java seems to be consistent with the C++ definition of protected which is 
basically that protected is the same as private, except the inheritor can still have
access.

For example, here's a new listing for the Test package:

  class Test {
    public static void main(String[] args) {
      Parcel3 p = new Parcel3();
      Contents c = p.cont();
      Destination d = p.dest("Tanzania");
      
      // Illegal -- PDestination is protected!  Only Parcel3 and
      // its inheritors can access PDestination!
      //!PDestination pd2 = new PDestination("Australia");

      // Illegal -- can't access private class:
      //! Parcel3.PContents pc = p.new PContents();
    }
  } ///:~

The line attempting to create Australia does not compile as PDestination cannot
be used outside Parcel3 (even though Test is in the same package as Parcel3 as stated
in the text).

Going further, it appears to me that the Java language is inconsistent 
with the use of the Private keyword in inner classes.  In the Parcel3 example, I would have 
thought that not even the Parcel3 class would be able to create a PDestination instance
since its constructor is declared private.  Java is inconsistent here.  If PDestination
was a standalone class, no-one would be able to create that class.  Parcel3 should not
get special treatment just because the PDestination class is an inner class.  The rules for
private constructors should be consistent.  In fact, the inheritors of Parcel3 do not
get special treatment - they can't create a PDestination, even though its declared protected
in Parcel3!  

A minor issue, as its only a class and its inner classes which have this
feature, but is seems inconsistent to me.

From: Andrew Mitchell [amitchell_-optusnet-_com-_au]
Ok, I'm wrong, protected *is* friendly.  But I still can't believe it!

In the example above the 'privateness' comes from that of the constructor, not the
protected keyword.  As an ex C++ and Ada programmer, I can't understand the reason
behind making the protected keyword the same as 'friendly'.  This seems very dodgy to
me.

My comment regarding the strange nature of the private constructor in the example in
the text still stands, but there no mistake in the text per se.

Andrew

Add a comment to this suggestion
Comment ID: 1001003-033001-verhagent_-logica-_com.cmt
From: Tjeerd Verhagen
release 11 Chapter:11, page 575
Search for Text: method to the list( )

The text'method to the list( )' was inserted twice, where it should be only once.

paragraph:
----------
It says all that this type of object does is provide a method called
accept( ). The whole reason behind the creation of this class is to provide
the accept( ) method to the list( ) method so that list( ) can “call back”
accept( ) to determine which file names should be included in the list.
----------


Add a comment to this suggestion
Comment ID: 1001003-023924-hamer_-csd-_uu-_se.cmt
From: John Hamer
Revision 10 Chapter:A
Search for Text: The copy-constructor


This whole section is a red herring.  The code doesn't "work" in Java, and the code doesn't "work" in
C++.  In both languages, a call to new Tomato(t) will return a Tomato.  And so it should; that's what
the programmer asked for.

Your explanation of "Why does it work in C++ and not Java"? is gobbledygook.  I suggest you remove it.



Add a comment to this suggestion
Comment ID: 1000931-224225-E-_S-_Brinkman_-zonnet-_nl.cmt
From: Emile Brinkman
Revision 11 Chapter:1
Search for Text: -


In the last alinea of the sub-paragraph "Java" in the paragraph "Client-side programming" you wrote:



"If you’re a Visual Basic programmer, moving to VBScript will be your fastest solution, and since
it will probably solve most typical client/server problems you might be hard pressed to justify learning
Java."


This is a dangerous statement! I think you must note that VBScript as a client-side scripting language
is only supported in Microsoft Internet Explorer. JavaScript (or JScript in IE) is the standard for client-side
programming.

As for server-side programming VBscript is a popular solution because it the most chosen scripting language
in ASP.

I have another remark.
You wrote in the sub-paragraph "Scripting languages" of the same paragraph:


"The most commonly discussed browser scripting languages are JavaScript (which has nothing to do with
Java; it’s named that way just to grab some of Java’s marketing momentum)"


Before I began programming in Java I've programmed in JavaScript. I think you are giving here a wrong
impression. The syntax of the languages is very similar in my opinion (and I should know). I'm convinced
that it helped me quite a bit when learning Java. 


Moreover Java applets and JavaScript can communicate with each other. You can call Java methods and variables
from JavaScript and vice versa. So the bond between the two languages is stronger than most people believe.




Don't get the wrong idea because of my critics. My compliments for your cristal clear explanations and
keep up the good work!

Add a comment to this suggestion
Comment ID: 1000930-063654-Douglas_-McKirahan-_com.cmt
From: Douglas McKirahan
Revision 11 Chapter:5
Search for Text: "Access specifiers in Java give valuable control "


The following paragraph appears in the Summary of Chapter 5 "Hiding the Implementation".  The words do
not wrap as a <PRE> tag is used; specifically, "<BLOCKQUOTE><FONT SIZE = "+1"><PRE>".



"Access specifiers in Java give valuable control to the creator of a class. The users of the class can
clearly see exactly what they can use and what to ignore. More important, though, is the ability to ensure
that no user becomes dependent on any part of the underlying implementation of a class. If you know this
as the creator of the class, you can change the underlying implementation with the knowledge that no
client programmer will be affected by the changes because they can’t access that part of the class."

Add a comment to this suggestion
Comment ID: 1000929-014158-Douglas_-McKirahan-_com.cmt
From: Douglas McKirahan
Revision 11 Chapter:13
Search for Text: n/a

The download contains 
"TIJ-2nd-edition-code-1.zip" and TIJ-2nd-edition-code-2.zip";
they both contain a "c13" folder with different contents.

Also, in Chapter 2, the "c02" in the line
"Move to subdirectory c02 and type:"
looks like "co2" when viewed;
(in Netscape 4.76 under Windows 98).

Add a comment to this suggestion
Comment ID: 1000926-060911-rothgi_-nswccd-_navy-_mil.cmt
From: Gary Roth
Print Edition Chapter:9
Search for Text: then to produces values to search for:

Minor grammar mistake.  Should be "then to produce values to search for:"


(Technically, you also can't use for to end a sentence, but changing that would cause an akward construction.
)

Add a comment to this suggestion
Comment ID: 1000923-230824-gerhard-_eymann_-dwd-_de.cmt
From: G. Eymann
Rev. 3 Chapter:Appendix A
Search for Text: JNI, Passing and Using Java Objects in/from C


The listing of the C source file UseObjImpl.c on page 953 has errors, it should be: (*env)->Get...
rather than: env->Get... etc. The previous example on page 950 is correct. 


The example does not run (JDK 1.3.0-C, Windows NT). CallVoidMethod produces an HotSpot VM error (EXCEPTION_ACCESS_VIOLATION,
without HotSpot it doesn't run either). According to Sun's bug parade, an error with the given ID has
already been reported.


From: G. Eymann [gerhard-_eymann_-dwd-_de]

My first remark on the syntax is not correct, the syntax in the book is OK. With Visual Studio "cl" command
line compiler, the file extension must be cpp, not c. Sorry for that. 
The reported error still occurs. 

Add a comment to this suggestion
Comment ID: 1000921-123851-geldin_-mac-_com.cmt
From: Jeremy Sherman
Revision 11 Chapter:Introduction
Search for Text: and complained of me mumbling over my algebra problems.


The full sentence reads "The book design, cover design, and cover photo were created by my friend Daniel
Will-Harris, noted author and designer (www.Will-Harris.com), who used to play with rub-on letters in
junior high school while he awaited the invention of computers and desktop publishing, and complained
of me mumbling over my algebra problems."  The part of the sentence that reads "and complained of me
mumbling over my algebra problems," is wrong; more specifically, the "me mumbling" is wrong.  It should
be "my mumbling," as what he complained about was the mumbling, not you.  Also, as it stands now, it
could be read to mean that he complained about you while mumbling over your algebra problems; that most
likely is not what you meant.

Add a comment to this suggestion
Comment ID: 1000921-121134-geldin_-mac-_com.cmt
From: Jeremy Sherman
Revision 11 Chapter:Introduction
Search for Text: It then examines subject of directory paths and file names.


Under the section of the Introduction entitled "Chapter 5: Hiding the Implementation," you will find
"It then examines subject of directory paths and file names."  This sentence is missing a "the" before
the "subject."

Add a comment to this suggestion
Comment ID: 1000921-101924-geldin_-mac-_com.cmt
From: Jeremy Sherman
11 Chapter:Preface
Search for Text: one-on-one, but also in groups and, as a planet.


The full sentence is "I think that perhaps the results of the communication revolution will not be seen
from the effects of moving large quantities of bits around; we shall see the true revolution because
we will all be able to talk to each other more easily: one-on-one, but also in groups and, as a planet."



The error is in the latter half of the sentence, after the colon ("one-on-one, but also in groups and,
as a planet.").  The comma after the "and" has no reason to be where it is and makes for a really strange
break when reading aloud.  The post-colon section should read: "one-on-one, but also in groups and as
a planet."

Add a comment to this suggestion
Comment ID: 1000921-090907-abha_t_-rocketmail-_com.cmt
From: Abha Thakur
PDF/Printed Chapter:Chapter 14
Search for Text: The program ThreadGroup1.java on page 886

// Get the system thread & print its Info:
		ThreadGroup sys = Thread.currentThread().getThreadGroup();
		sys.list(); // (1)
---------------

this section is supposed to display the name of the Threadgroup as system, but the output I obtained
is "main" same as the name of the main thread "main". 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Look at a new thread's priority before
		// and after changing it:
		t = new Thread(g1, "C");
		g1.list(); // (6)
--------------------------------------------------

This section says that the output of the program should show the default priority of the new thread "C"
to be 6, independent of what the maximum priority of the ThreadGroup to which it belongs to is. But C
started with a priority 3 instead of 6, 3 being the priority of ThreadGroup g1 to which it was assigned.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thread[] all = new Thread[sys.activeCount()];
		sys.enumerate(all);
		for(int i = 0; i < all.length; i++)
			if(!all[i].isAlive())
				all[i].start();
		// Suspends & Stops all threads in
		// this group and its subgroups:
		System.out.println("All threads started");
		sys.suspend(); // Deprecated in Java 2
		// Never gets here...
		System.out.println("All threads suspended");
		sys.stop(); // Deprecated in Java 2
		System.out.println("All threads stopped");
------------------------------------------

You cannot get hold of the active threads by using enumerate() because active according to JDK1.3 SE
documentation is a thread that was started but never stopped, and none of the Threads in that program
were ever started, they are 'new' not 'runnable'; since you cannot get a reference to them this way,
the output shown in the book saying the std output shows "All threads started" is never reached, instead
a nullPointerException is thrown.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Comment:Code compiled using JDK1.3 SE compiler, on Windows 98.

Add a comment to this suggestion
Comment ID: 1000921-080459-markvenn_-yahoo-_co-_uk.cmt
From: Mark Venn
Revision 11 Chapter:4
Search for Text: non-static Bowl b3 prior


P. 226 The sentence "Note that Cupboard creates a non-static Bowl b3 prior to the static definitions."



I find this misleading. I think the point Bruce is trying to make here is that although non-static Bowl
b3 is defined before the static Bowl objects in the Cupboard class definition, b3 will be created after
the static Bowl objects b4 and b5 (as demonstrated by the console output the program produces).

Regards

Add a comment to this suggestion
Comment ID: 1000917-020050-rothgi_-nswccd-_navy-_mil.cmt
From: Gary Roth
Book Chapter:9
Search for Text: Collecions

Misspelling.  Should be Collections.  Occurs in a comment to Reverse.java.

Add a comment to this suggestion
Comment ID: 1000916-175554-oamdg_mb_-yahoo-_com.cmt
From: Milan Babiak
Release 11 Chapter:The Java I/O System/Object serialization/Finding the class - page 619
Search for Text: This program opens the file and reads in the object mystery successfully.

The example program //: c11:xfiles:ThawAlien.java reads serialized object from the file "X.file"

//: c11:xfiles:ThawAlien.java
// Try to recover a serialized file without the
// class of object that's stored in that file.
import java.io.*;

public class ThawAlien {
   public static void main(String[] args)
   throws IOException, ClassNotFoundException {
      ObjectInputStream in =
         new ObjectInputStream(
            new FileInputStream("X.file"));
      Object mystery = in.readObject();           // line 12
      System.out.println(mystery.getClass());   // line 13
   }
} ///:~

In the book is written:

"This program opens the file and reads in the object mystery successfully. However, as soon as you try
to find out anything about the object—which
requires the Class object for Alien—the Java Virtual Machine (JVM)
cannot find Alien.class (unless it happens to be in the Classpath, which
it shouldn’t be in this example). You’ll get a ClassNotFoundException."

That means, I should get ClassNotFoundException in the line 13:

   System.out.println(mystery.getClass());

But I got this exception already in the preceding line 12:

   Object mystery = in.readObject();


The fact that class of the object is needed already in the process of reading the object (not until in
the getClass() method call) is written in the JDK 1.2.2 documentation:

   java.io.ObjectInputStream, method:

   public final Object readObject()
                        throws OptionalDataException,
                               ClassNotFoundException,
                               IOException
Method Detail:


"Read an object from the ObjectInputStream. The class of the object, the signature of the class, and
the values of the non-transient and non-static fields of the class and all of its supertypes are read.
"

Add a comment to this suggestion
Comment ID: 1000916-175535-oamdg_mb_-yahoo-_com.cmt
From: Milan Babiak
Release 11 Chapter:The Java I/O System/Object serialization/Finding the class - page 619
Search for Text: This program opens the file and reads in the object mystery successfully.

The example program //: c11:xfiles:ThawAlien.java reads serialized object from the file "X.file"

//: c11:xfiles:ThawAlien.java
// Try to recover a serialized file without the
// class of object that's stored in that file.
import java.io.*;

public class ThawAlien {
   public static void main(String[] args)
   throws IOException, ClassNotFoundException {
      ObjectInputStream in =
         new ObjectInputStream(
            new FileInputStream("X.file"));
      Object mystery = in.readObject();           // line 12
      System.out.println(mystery.getClass());   // line 13
   }
} ///:~

In the book is written:

"This program opens the file and reads in the object mystery successfully. However, as soon as you try
to find out anything about the object—which
requires the Class object for Alien—the Java Virtual Machine (JVM)
cannot find Alien.class (unless it happens to be in the Classpath, which
it shouldn’t be in this example). You’ll get a ClassNotFoundException."

That means, I should get ClassNotFoundException in the line 13:

   System.out.println(mystery.getClass());

But I got this exception already in the preceding line 12:

   Object mystery = in.readObject();


The fact that class of the object is needed already in the process of reading the object (not until in
the getClass() method call) is written in the JDK 1.2.2 documentation:

   java.io.ObjectInputStream, method:

   public final Object readObject()
                        throws OptionalDataException,
                               ClassNotFoundException,
                               IOException
Method Detail:


"Read an object from the ObjectInputStream. The class of the object, the signature of the class, and
the values of the non-transient and non-static fields of the class and all of its supertypes are read.
"

Add a comment to this suggestion
Comment ID: 1000916-170853-oamdg_mb_-yahoo-_com.cmt
From: Milan Babiak
Release 11 Chapter:The Java I/O System/Compression/Java ARchives (JARs)
Search for Text: jar cmf myJarFile.jar myManifestFile.mf *.class

Following jar command example:

   jar cmf myJarFile.jar myManifestFile.mf *.class

should be as follows:

   jar cfm myJarFile.jar myManifestFile.mf *.class


The letters 'm' and 'f' right after jar command need to be exchanged, because jar documentation states:


"   Usage: jar {ctxu}[vfm0M] [jar-file] [manifest-file] [-C dir] files ...
...

The manifest file name and the archive file name needs to be specified in the same order the 'm' and
'f' flags are specified. ..."

Add a comment to this suggestion
Comment ID: 1000916-052929-elam_-phone2networks-_com.cmt
From: Elam Birnbaum
Print Edition Chapter:7, pages 343-344
Search for Text: 343 344 extending diagram


This is more of an organizational comment. On pages 343 and 344, the same diagram is repeated. From the
surrounding text, it seems like the second diagram (on page 344) is meant to show the problems with downcasting.
A new diagram is probably in order...

Add a comment to this suggestion
Comment ID: 1000916-044209-michel_maquino_-ig-_com-_br.cmt
From: Michel Masiero de Aquino
Revision 11 Chapter:04

Search for Text: Here's an example that shows both overloaded constructor and overloaded ordinary methods
:

import java.util.*; // Bruce, this import not is necessary.

class Tree {
	int height;
	Tree() {
		prt("Plantando a semente");
		height = 0;
	}
	Tree(int i) {
		prt("Criando uma nova µrvore que ‚ " + i);
		height = i;
	}
	void info() {
		prt("A µrvore tem " + height + " de altura");
	}
	void info(String s) {
		prt(s + ": A µrvore tem " + height + " de altura");
	}
	static void prt(String s) {
		System.out.println(s);
	}
}

public class OverloadingOrder {
	public static void main(String[] args) {
		for (int i=0; i <5; i++) {
			Tree t = new Tree(i);
			t.info();
			t.info("m‚todo de Sobrecarga de Construtor");
		}
		new Tree();
	}
}

/*
I love your book!! It's the best.
Thanks a lot.

Eu amei o seu livro!! Ele é muito bom.
Muito Obrigado.
*/

Add a comment to this suggestion
Comment ID: 1000909-071306-maindude_-cyberdude-_com.cmt
From: Bob Williams
Annotated Solutions Guide - 2nd Edition Chapter:2
Search for Text: c02:Storage.java

In this example, I believe the statement...

System.out.println("storage(s) = " + storage(s));

should be

System.out.println("Storage(s) = " + Storage(s));


please advise me if this is correct, as I hope to be able to change my resume to include the following
accomplishment "Helped to debug Bruce Eckel's java programs." This will go in right in front of "Helped
Al Gore invent the internet". ;))

Add a comment to this suggestion
Comment ID: 1000905-011543-rothgi_-nswccd-_navy-_mil.cmt
From: Gary Roth
Print Edition Chapter:9
Search for Text: //: com: bruceeckel:util:Arrays2.java


There is a bug in the print(Object[] a, int from, int to) methods.  This is a problem in all of the methods,
not just the Object[] method.


If from, to is 0, a.length, then print works correctly.  However, if to is anything other then a.length,
then print prints 1 fewer array member than it should.  For example, for print(a, 2, 4), only the a[2]
and a[3] will
be printed, not a[4].  This is because of the loop "for(int i = from; i < to; i++)".

Add a comment to this suggestion
Comment ID: 1000903-151631-fungkw_-hongkong-_com.cmt
From: King-Wai Fung
PDF Chapter:9

Search for Text: In the last case, all the elements of s1 point to the same object, but s2 has five unique
objects.


In fact, the "five objects" in s2 are one single object. You can see the difference from the following
modified code:

//: c09:ComparingArrays.java
// Using Arrays.equals()
import java.util.*;

public class ComparingArrays {
  public static void main(String[] args) {
    int[] a1 = new int[10];
    int[] a2 = new int[10];
    Arrays.fill(a1, 47);
    Arrays.fill(a2, 47);
    System.out.println(Arrays.equals(a1, a2));
    a2[3] = 11;
    System.out.println(Arrays.equals(a1, a2));
    String[] s1 = new String[5];
    Arrays.fill(s1, "Hi");

    // Modified:
    String[] s2 = {"Hi", "Hi", "Hi", "Hi", new String("Hi")};
    System.out.println(s1[0] == s2[0]); // true
    System.out.println(s2[0] == s2[1]); // true
    System.out.println(s1[0] == s2[4]); // false
    System.out.println(s2[0] == s2[4]); // false

    System.out.println(Arrays.equals(s1, s2));
  }
} ///:~

Add a comment to this suggestion
Comment ID: 1000902-203002-grzegorz_o_-hector-_com-_pl.cmt
From: Grzegorz Olszewski
Release 11 Chapter:8
Search for Text: // Cannot access a member of the interface

.
.
.
public static void main(String[] args) {
A a = new A();
// Can't access A.D:
//! A.D ad = a.getD();
// Doesn't return anything but A.D:
//! A.DImp2 di2 = a.getD();
// Cannot access a member of the interface:
//! a.getD().f();     <---------------------------------------
// Only another A can do anything with getD():
A a2 = new A();
a2.receiveD(a.getD());
}


I believe you can access function a.getD().f(). a.getD() returns reference to class A.DImp2 upcasted
to interface A.D. Try uncomment signed line - it works.


From: zach knoll [picof_-aol-_com]

I second that last post. Not only does that work but you can more explicitly say, A.DImp2 watchThis =
new A().new DImp2();

From: Paulo Santos [pauloya_-yahoo-_com]
I tried uncommented signed line and it didn't work. 
This is what i got:

-----------------------------------------------
>javac NestingInterfaces.java

NestingInterfaces.java:85: f() in A.D is not defined in a public class or interface; cannot be accessed
from outside package
    a.getD().f();
          ^
1 error
-----------------------------------------------
So, I would say the book is correct on this one.


Add a comment to this suggestion
Comment ID: 1000828-060327-Li-Feng_Zhang_-baylor-_edu.cmt
From: Li-Feng Zhang
Release 11 Chapter:9
Search for Text: c09: ArraySize.java


The output of this program(c09:ArraySize) listed on the book(page 411) is incorrect. It is a small mistake.
Hard to discribe. Very easy easy to find out by simply running the code.

Add a comment to this suggestion
Comment ID: 1000824-021949-ronlusk_-alum-_mit-_edu.cmt
From: Ron Lusk
Paper, 1st(?) printing Chapter:15
Search for Text: implemeted

"implemented"

Truly a nit

Also, in same chapter: decide on a standard form: "EJBs" (common) vs "EJB's" (appears once)

"--including mainframes that do not have visual displays--An EJB..."
try making that "--an EJB"



Add a comment to this suggestion
Comment ID: 1000824-021542-ronlusk_-alum-_mit-_edu.cmt
From: Ron Lusk
Paper, 1st(?) printing Chapter:15
Search for Text: another vendors' application server

"another vendor's application server"

Truly a nit

Add a comment to this suggestion
Comment ID: 1000824-021458-ronlusk_-alum-_mit-_edu.cmt
From: Ron Lusk
Paper, 1st(?) printing Chapter:15
Search for Text: if a certain criteria

if a certain criterion (or "if certain criteria")

Truly a nit

Add a comment to this suggestion
Comment ID: 1000824-020544-ronlusk_-alum-_mit-_edu.cmt
From: Ron Lusk
Paper, 1st(?) printing Chapter:Index
Search for Text: inizialization: lazy - 273

Spelling fix

Add a comment to this suggestion
Comment ID: 1000821-172923-lviggiano_-tiscalinet-_it.cmt
From: Luigi Rocco Viggiano
may be 10 ? Chapter:Chapter 3 page 155
Search for Text: an Oak can be cast to a Tree and vice-versa, but not foreign type such as a Rock.


In my opinion that's not so true: you cannot always cast a superclass to a child type class. In other
words, an Oak is a Tree, but not all Trees are Oaks. I.E. if I create a Pine inheriting from Tree, I
can cast it to a Tree, but after that I cannot cast it again to an Oak, because... A Pine is not an Oak.
In this cas I am unable to cast a tree to the Oak.
I'm continuing reading it, that's fantastic.

Thanks for the book and regards!
Luigi

Add a comment to this suggestion
Comment ID: 1000820-200956-andrius_-vb-_lt.cmt
From: Andrius Masiulis
Revision 11 Chapter:04
Search for Text: that reference is given a special value of null (which is a Java keyword

null is not a java kyeword but literal

From: Luigi Rocco Viggiano [lviggiano_-tiscalinet-_it]
A literal is also a keyword. it's an hinerited type :)

Ciao
Luigi

Add a comment to this suggestion
Comment ID: 1000820-181326-lviggiano_-tiscalinet-_it.cmt
From: Luigi Rocco Viggiano
may be 10 ? Chapter:3 page 152 "The comma operator"

Search for Text: The sole place that the comma operator is used in java is in for loops, which will be
described later in this chapter.

I think it's not very correct.
Also in declaration you can use the comma operator as follows:

int a, b=10, c;

I don't remember now if there are more places where the comma can be used even.

Thanks for the great book. I buyed the "paper" version (but in italy it's very expensive).
Regards Luigi

From: Larry Leonard [Larry_-DefinitiveSolutions-_com]
That's a "comma separator", not a "comma operator" - see page 175.

Add a comment to this suggestion
Comment ID: 1000813-134303-bcowen_-osmotic-_com.cmt
From: Bradley Cowen
2nd, Release 11 Chapter:2
Search for Text: @exception


The @throws method documention tag is listed. However, in the "HelloDate.java" program example, the @exception
tag is used with no mention that @throws is a synonym for @exception added in Javadoc 1.2.

Add a comment to this suggestion
Comment ID: 1000813-024734-dhelrod_-rivendell-_com.cmt
From: David Elrod
Book - 1st Printing Chapter:2
Search for Text: Everything is an Object

I wish your statements at the beginning of chapter two (including
the title) were true.

However, the primitive data types are not objects.

When I first started using Java, I wanted to do:
  int i = 5;  
  String s = i.toString();

I can understand, from a performance standpoint that the
primitive types might have been considered necessary. (I
would have put the optimization burden on the compiler 
and treated these basic types (char, boolean,int, float, ...)
as "special" objects - like "String".)

I was excited to learn that others had found this to be an
issue, and there there was an Integer class that WAS an object.
I was disappointed to learn that I couldn't do this:

  Integer i = new Integer(5);
  Integer j = new Integer(6);
  Integer k = i * j;
OR
  Integer k = i.mult(j);	// Multipy i * j

If Integer, Double, etc. supported the full set of operations
then one could teach an "Everything Is An Object" approach.

In any case, I think you mislead people when you tell them that
everything is an object. MOST things are objects... :>

David

P.S. Java is the best language I've seen so far for the things I
like to do. Your book is good. I bought version 1, I bought 
version 2, and I'll happily buy version 3. Thanks!


Add a comment to this suggestion
Comment ID: 1000813-021855-dhelrod_-rivendell-_com.cmt
From: David Elrod
Book - 1st printing Chapter:3
Search for Text: Note that boolean is quite limited.

This might be a nit, but there are a number of "other type[s] of 
operations" one might want to perform on a boolean.

You can use the "and", "or", etc. operations to create new booleans
with new more meaningful values.

Suppose you have a "inputPort" object which has a "dataAvailable"
boolean that is tied (via JNI??) to a bit in a device.

Suppose you have a "outputPort" object which has a "okToXmit"
boolean that is tied to a bit in a different device.

You could have something like:

boolean okToGo = inputPort.dataAvailable & outputPort.okToXmit;

You might then use okToGo in other calculations before finally
testing it.



Add a comment to this suggestion
Comment ID: 1000806-205825-andrius_-vb-_lt.cmt
From: Andrius Masiulis
Revision 11 Chapter:14: Multiple Threads
Search for Text: JavaBeans revisited

Very serious logical error !!!

// Make a shallow copy of the List in case 
// someone adds a listener while we're 
// calling listeners:
        synchronized(this) {
          lv = (ArrayList)actionListeners.clone();
        }
// Call all the listener methods:
        for(int i = 0; i < lv.size(); i++)
          ((ActionListener)lv.get(i))
            .actionPerformed(a);

What happens if someone removes a listener ? The user can still get message
for his acction listener though it was removed ! I think this can lead to 
unpredictable results.

Add a comment to this suggestion
Comment ID: 1000804-193643-simon-_blanchard_-philips-_com.cmt
From: Simon Blanchard
Apr 24 Chapter:All
Search for Text: ' or "

In machines that do not have the Verdana or Georgia fonts installed the
the apostrophe and inverted comma (' and ") do not appear. This is because
they are encoded in the HTML as ’. My suggestion is to run a perl script
over the HTML before publishing to replace the numbers with the real character.
In this way it will display nicely on all browsers.

Background: I'm reading TIJ on the Psion Series 7 - which make a very nice ebook
but there is no support in the browser for the fonts.

Thanks!

From: Rob Kelley [composer_-thekeyboard-_com]
Even more of a nit than most!

In the following text excerpt from the HTML version (Chapter 03) the first (‘) character
appears different from all the others (different font?, size??).

----Quote from Chapter 3, "Using Java Operators":
Almost all operators work only with primitives. The exceptions are ‘=’, ‘==’ and ‘!=’, 
which work with all objects (and are a point of confusion for objects).
----End Quote

Your book is fantastic!  I'm learning much more from your book than I did with the Sun
tutorials.

Cheers,
Rob K

From: ASDFASDF [ASDFSADF_-EATMAIL-_COM]
sdfSFDF

Add a comment to this suggestion
Comment ID: 1000802-031020-drfrank02_-worldnet-_att-_net.cmt
From: Frank P. Ferraro
PDF Chapter:3, Page 172
Search for Text: return else

In the Return section the LAST else in the snippet is not needed.

It compiles and runs like this:

	static int test(int val1, int val2) {
		int result = 0;
		if (val1 > val2)
			result = +1;
		else if (val1 < val2)
			result = -1;
		return result;
		}

From: David Elrod [dhelrod_-rivendell-_com]
In the Book, TIJ2
Chapter: 3
Page 172
In the section on "return"

There is no need for ANY "else" in your example:

  if(testval > target)
      return +1;
  if(testval < target)
      return -1;
  return 0;



Add a comment to this suggestion
Comment ID: 1000729-184649-george_-za-_didata-_com.cmt
From: George Leonard
PDF Chapter:8
Search for Text: class Test {

The closing bracket before class Test {  and class Test { itself is not needed.

it should read 

   public Destination dest(String s) {
      return new PDestination(s);
   }

   public static void main(String[] args) {
      Parcel3 p = new Parcel3();
      Contents c = p.cont(8);

thx

George


Add a comment to this suggestion
Comment ID: 1000729-170921-george_-za-_didata-_com.cmt
From: George Leonard
PDF Chapter:8
Search for Text: m = Month2.month[12];

m = Month2.month[12]; 

This should be 

Month2.month[11]. 

0 based arrays otherwise an out of boud array error is raised.

Page 360

Code Example Month2.java

   public static void main(String[] args) {
      Month2 m = Month2.JAN;
      System.out.println(m);
      m = Month2.month[12];              // ERROR

Should Be

   public static void main(String[] args) {
      Month2 m = Month2.JAN;
      System.out.println(m);
      m = Month2.month[11];             // Arrays is 0 based so position 11 is December;  

thx

George


From: Frank Kruchio [frank-_kruchio_-paradise-_net-_nz]
Eckel's example IS correct. 
The array is size 13, so 12 as an index is fine, DECEMBER in this case.

The example has two JAN inside the array for offset, Eckel explains it nicely right 
after the code.


Add a comment to this suggestion
Comment ID: 1000725-175613-ZKUMAR_-USA-_NET.cmt
From: K.SANTHA KUMAR,
Revision 11 Chapter:5
Search for Text: package: the library unit/Creating unique package names

PLEASE CHANGE THE String INSIDE THE  System.out.println();

//: com:bruceeckel:simple:Vector.java
// Creating a package.
package com.bruceeckel.simple;

public class Vector {
  public Vector() {
    System.out.println(
      "com.bruceeckel.util.Vector");
  }
} ///:~
In the above example you are trying to explain the location package file.
so System.out.println should be
System.out.println("com.bruceeckel.simple.Vector");
because location of  Vector.java file is com/bruceeckel/simple/Vector.java


SIMILAR CHANGE IN THE NEXT PROGRAM

//: com:bruceeckel:simple:List.java
// Creating a package.
package com.bruceeckel.simple;

public class List {
  public List() {
    System.out.println(
      "com.bruceeckel.util.List");
  }
} ///:~
The System.out.println should be
System.out.println(çom.bruceeckel.simple.List");
because location of List.java is  com/bruceeckel/simple/List.java 

Add a comment to this suggestion
Comment ID: 1000723-061607-mark-_borges_-attws-_com.cmt
From: Mark Borges
Revision 9 Chapter:4
Search for Text: Depth o = new Depth();

On page 222, there is an apparent typo:


  You can also initialize nonprimitive objects in this same way. If Depth is a class, you can insert
a variable and initialize it like so:

    class Measurement {
      Depth o = new Depth();
      boolean b = true;
      // . . .

Shouldn't that be,

      boolean o.b = true;


to be consistent with the leading sentence? If not, can someone please explain the point that is trying
to be made in greater detail?

Add a comment to this suggestion
Comment ID: 1000711-071356-mbarton_-chi-_navtech-_com.cmt
From: Mark Barton
Final (printed book) Chapter:2
Search for Text: This can be a flashpoint

This concerns a footnote on page 102 in the printed book.  It also concerns Appendix A.


Perhaps I'm missing something.  This footnote quotes another author as saying that in Java you're always
"passing an object reference by value", rather than simply passing a reference.  The footnote then goes
on to dismiss this as a "language-laywer" type of issue, and as "convoluted".


I would suggest that this is a vital, practical distinction.  The distinction matters when the receiving
method associates the reference with a new object, or sets it to null.  When the receiving method returns,
the reference in the calling method still refers to the original object.


This is puzzling unless the programmer understands that Java is "passing an object reference by value",
and that it was a copy of the reference that was changed, not the original reference.


There's a similar discussion in Appendix A, "Passing & Returning Objects", starting on page 1013 of the
book.  Neither the footnote nor the appendix mentions this fundamental issue of Java parameter-passing.



There's a good discussion of this in "The Java Programming Language, Second Edition", by Ken Arnold and
James Gosling, starting on page 38.


(Having attended a wonderful Eckel/Venners course in Dec '99, I don't doubt that Bruce knows this stuff,
but I think a reader of the book could be confused by the lack of explanation.)
--Mark Barton

Add a comment to this suggestion
Comment ID: 1000709-230800-mblei_-uol-_com-_ar.cmt
From: Marcela Blei
Revision 11 Chapter:3
Search for Text: precedence revisted


In the table where you refer to operator precedence by the mnemonic "Ulcer Addicts Really Like C A lot".
you write the precedence of bitwise and logical operators in the following order: && || & | ^ 

but the order is: && || & ^ |  

first xor and then or



Add a comment to this suggestion
Comment ID: 1000709-125709-rjhenn_-yahoo-_com.cmt
From: Roger J. Henn
Revision 11 Chapter:3
Search for Text: conventional to indent the body of a control flow statement


The text "It is conventional to indent the body of a control flow statement so the reader might easily
determine where it begins and ends." should be normal text, not part of the code.

Add a comment to this suggestion
Comment ID: 1000709-125459-rjhenn_-yahoo-_com.cmt
From: Roger J. Henn
Revision 11 Chapter:3
Search for Text: //! long l6(200); // not allowed

I have no idea what that line is or how it relates to the surrounding text.

Add a comment to this suggestion
Comment ID: 1000709-125305-rjhenn_-yahoo-_com.cmt
From: Roger J. Henn
Revision 11 Chapter:3
Search for Text: expression begins with a String

First you say:

"If an expression begins with a String, then all operands that follow must be Strings"

then you say:
 
"And if you say:

System.out.println(x + sString);

Java will turn x into a String."

But, in this case, the expression does not begin with a string, but with an int.

From: Radu [rrradu_-usa-_net]
OK, the expression begins with an int but this was not the point. 
  x + sString 
will convert x to a String, but you cannot say
 sString + x 
because if the first element is a String then the second should also be one
(and is not).


From: David Levine [david-_levine_-acm-_org]

<String> + <int>    and  <int> + <String>   are defined to convert the int's
to String.
  Pushing the limits here can get you in trouble.  Try


From: David Levine [david-_levine_-acm-_org]

<String> + <int>    and  <int> + <String>   are defined to convert the int's
to String.
  Pushing the limits here can get you in trouble.  Try:

    2 + 2 + " = four"
and
    "seventy-seven = " + 7 + 7

This is due to way the expressions are parsed.  Use parentheses!



Add a comment to this suggestion
Comment ID: 1000707-042441-rothgi_-nswccd-_navy-_mil.cmt
From: Gary I. Roth
1st print editon/11 Chapter:3
Search for Text: The char value is a zero, which prints as a space.

I am using Visual Cafe Standard Edition 4.  My char value of zero printed as an 'a', not a space.

Add a comment to this suggestion
Comment ID: 1000630-080053-eucastro_-terra-_es.cmt
From: Esteban U. C. Castro
Revision 9 Chapter:01
Search for Text: This term is explored in Chapter 16: Design Patterns. (footnote #16)


 Yet another reference to missing chapter 16. The reference should probably point to the standalone book
"Thinking in Patterns".  

Add a comment to this suggestion
Comment ID: 1000628-124152-rothgi_-nswccd-_navy-_mil.cmt
From: Gary I. Roth
1st print editon/11 Chapter:3
Search for Text: //: c03:IfElse2.java

Two things:
1. The definition of int result=0 in this program seem unnecessary as result is never used.

2. After the code, you state that "There's no need for *else* because the method will not continue after
executing a *return*."  However, you still kept the unnecessary else's in the code.

Add a comment to this suggestion
Comment ID: 1000627-193657-simmond_-hello-_to.cmt
From: Byung Jin Kim
Release 11 Chapter:6
Search for Text: The variables v1 through v4 demonstrate the meaning of a final

The FinalData.java does not exist v4. I think that "v1 through v3 and a" is correct.

From: Jeremy Zucker [zucker_-zurich-_ai-_mit-_edu]
I believe this was an oversight in the transition from 1st Edition TIJ to 2nd Edition TIJ.  
1st Edition claims that pre-Java 1.1 did not allow you to create a blank final, so uncommenting 
the following  code:
<code>
//! final Value v4;    //  Pre-Java 1.1 Error
		// no initializer
</code>
verifies this was, indeed, an illegal declaration.  Unfortunately,
 uncommenting the code also caused an error in 
post-Java 1.1 implementations because Value has no default constructor, so v4 cannot be 
initialized anywhere!

<code>

FinalData.java:23: Blank final variable 'v4' may not have been initialized. It must be assigned a value
in an initializer, or in every constructor.
    final Value v4;
                  ^
1 error
</code>

Anyway, this whole discussion was rendered moot in the 2nd Edition, since Bruce only 
covers post-Java 1.1 implementations.  Nonetheless, while he remembered to remove v4
from the code, he apparently forgot to remove it from the text!



Add a comment to this suggestion
Comment ID: 1000625-131103-prpedersen_-aol-_com.cmt
From: Paul Pedersen
Revision 11 Chapter:4
Search for Text: if(i == 47)

I believe this is a bug, for the following reason.


Here we are searching for the point at which Chair 47 is collected. However, there is no guarantee that
ANY particular chair will be collected while the program is running. As the loop in the main function
creates chairs at high speed and the garbage collector clears them, Chair 47 could remain happily off
in a corner somewhere, untouched by the garbage collector, which is busy elsewhere.



Add a comment to this suggestion
Comment ID: 1000622-103527-ivbov_-libero-_it.cmt
From: Andrea Bovo
Revision 11 Chapter:preface
Search for Text: Design Pattens

Design Patterns

Add a comment to this suggestion
Comment ID: 1000621-095754-emeade_-geekfarm-_org.cmt
From: Erik Meade
Release 11 Chapter:15
Search for Text: N/A

The Security model used in JDK1.2 requires added steps to get the RMI example running.

Sun's tutorial covers this at
http://java.sun.com/docs/books/tutorial/rmi/running.html

Add a comment to this suggestion
Comment ID: 1000621-095630-danlip_-lorax-_org.cmt
From: Dan Lipofsky
Revision 11 Chapter:9
Search for Text: So it makes sense that the hashCode


You indicate that the code for StringHashCode.java uses two different instances of the string "Hello".
 They are the same instance.  To get
two instances you must use new String("Hello").  Here is some code that
demos this

public class Test {
    // Show a string followed by its hashCode and identityHashCode.
    // The identityHashCode corresponds to the memory location.
    public static void show(String x) {
        System.out.println(x + "\t" + x.hashCode() + "\t" + System.identityHashCode(x));
    }
    public static void main(String[] args) {
        show("foobar");
        show("foobar");
        show("foobar");
        show(new String("foobar"));
        show(new String("foobar"));
        show(new String("foobar"));
    }
}

Here is the text and code I am refering to

So it makes sense that the hashCode() produced by two separate
instances of new String("hello") should be identical. You can
see it by running this program:

//: c09:StringHashCode.java
public class StringHashCode {
  public static void main(String[] args) {
    System.out.println("Hello".hashCode());
    System.out.println("Hello".hashCode());
  }
} ///:~




Add a comment to this suggestion
Comment ID: 1000619-224755-asaini_-quark-_stpm-_soft-_net.cmt
From: Anubhav Saini
Revision 3 Chapter:11
Search for Text: (Patterns 1 are the subject of

(Patterns 1 are the subject of Chapter 17.)

Add a comment to this suggestion
Comment ID: 1000619-072636-cwgeng_-hotmail-_com.cmt
From: Cheng Geng
9 Chapter:4
Search for Text: co4:Garbage.java


Thank you your book. I think it is best way to replace "i" with "finalized" in c04:Garbage.java program
shown following:

//: c04:Garbage.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Demonstration of the garbage
// collector and finalization
........
    if(i == 47) {
      System.out.println(
        "Finalizing Chair #47, " +
        "Setting flag to stop Chair creation");
      f = true;
    }
    finalized++;
.....

} ///:~


Add a comment to this suggestion
Comment ID: 1000618-111421-alstrehl_-edisto-_cofc-_edu.cmt
From: Alex Strehl
Revision 11 Chapter:3
Search for Text: break and continue

"The only place a label is useful in Java is right before an 
iteration statement. And that means right before—it does no good
to put any other statement between the label and the iteration. 
And the sole reason to put a label before an iteration is if
you’re going to nest another iteration or a switch inside it."

The above quotation, as well as other statements after it in the 
same section (titled "break and continue") has two problems. 
1) The wording seems to imply that the java language only allows 
a label directly before an iteration statement.  This is most 
noticable in the following quotation:
"Note that Java labels don’t suffer from this
problem, since they are constrained in their placement and can’t
 be used to transfer control in an ad hoc manner."
Although there is nothing wrong with the above quotation by itself,
combined with the previous quotations it can cause the reader to 
believe labels in java are only allowed before iteration statements.
They are also allowed before a block of code "{ code }".  They are 
probably not allowed before anything else (besides blocks of code
or iteration statements) but without a search in the language specification
I can not be sure about this.

2) The fact that the java language allows labels before arbitrary blocks
of code implies by itself that there may be a use for that.  This 
contradicts your claim that labels are only useful before looping 
structures.  Furthermore, I can think quickly of at least one useful 
situation for such a construct.  Consider a situation where you have
two or more loops and a special condition that can occur in the first loop.
Suppose that you want execution of the first loop to end if this 
special condition is met and you don't want the second loop executed if 
the first loop does not complete.  You could use a label and break 
as follows:


mylabel:
{
  while (loop1conditional())
  {
    // some code
    if (specialCondition ()) //conditon that stops this loop and next
      break mylabel;
  }
  while (loop2conditional ())
    //some more code 
}
// even more code

If I could think up a situation quickly where such a label might be useful
there is a good chance many other situations exist and will be found
by programmers deep in code on a particular problem.  I do admit that in
the above code I myself might choose to set a boolean flag to true if the
special condition occurs, and then use the flag to determine whether to
do the second loop.  The advantage of this is readability.  However, it 
could significantly hurt the performance of the application if, for
example my code above was itself in an iteration that executes many times.
Furthermore it adds code and some might find the earlier version more 
readable in certain situations.

My suggestion would be to explain that a label is also legal before a 
new block of code.  However, If you feel that such a lable should never
be used, give some reasons why.

Add a comment to this suggestion
Comment ID: 1000618-054628-jgangemi_-architag-_com.cmt
From: Joe Gangemi
Revision 11 Chapter:11
Search for Text: The File class

In the first paragraph under the heading "The File Class", change the text:

"we’ll look a utility"

to

"we'll look at a utility"

Add a comment to this suggestion
Comment ID: 1000617-053131-Larry-_Seltzer_-chase-_com.cmt
From: Larry Seltzer
Book version, 1st printing Chapter:15
Search for Text: // nothing needs to be cleaned up.

If an IOException is caught, a message ("Socket failed") is written to 
standard error, but the code then "falls through" to the try block that 
follows the catch block as if it can continue successfully without the 
new Socket.  Shouldn't there be a return at the end of the IOException 
catch block?

Add a comment to this suggestion
Comment ID: 1000614-005924-altuga_-koc-_net.cmt
From: Altug Altintas
2nd edition Chapter:8
Search for Text: //: c08:InterfaceCollision.java

interface I1 { void f(); }
interface I2 { int f(int i); }
interface I3 { int f(); }
interface I4 { int f(); }
class C { public int f() { return 1; } }

class C2 implements I1, I2 {
  public void f() {}
  public int f(int i) { return 1; } // overloaded -->this must be override
}

class C3 extends C implements I2 {
  public int f(int i) { return 3; } // overloaded -->this must be override
}

class C4 extends C implements I3 {
  // Identical, no problem:
  public int f() { return 1; } 
}

// Methods differ only by return type:
//! class C5 extends C implements I1 {}
//! interface I4 extends I1, I3 {} ///:~


From: Frank Kruchio [frank-_kruchio_-paradise-_net-_nz]
************************************************************************
Actually they are just implementation of the method's defined by the 
interface.

So they are neither, overloaded or override.


Add a comment to this suggestion
Comment ID: 1000612-153530-David-_Zitzelsberger_-firesentry-_com.cmt
From: David J. Zitzelsberger
11 Chapter:3

Search for Text: In the last line, the resulting value is not assigned back into b, but is printed directly
and so the correct behavior occurs.


In the last line, the resulting value is not assigned back into b, but is cast to an int and printed
as an int. This allows the same behavior as if b was an int, and you will notice that the value is the
same.

????? There is no way to obtain a negative short unsigned right shifted correctly ?????.


::: That last statement is left as a question because I do not fully understand java yet. I was disapointed
to find that the result did not match a short right shifted, which is what the text gave the impression
of.


Add a comment to this suggestion
Comment ID: 1000612-041000-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:10
Search for Text: HREF="C:


4 of the internal hyperlinks in Chapter 10 have invalid HREF values.  The C: does not belong.  Search
the HTML source for:

HREF="C:#getLocalizedMessage
HREF="C:#printStackTrace
HREF="C:
HREF="C:#fillInStackTrace

--Fred

Add a comment to this suggestion
Comment ID: 1000612-040150-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:10
Search for Text: Exceptions are not terribly difficult to learn, and are one of those features


The last paragraph in the "Summary" section of Chapter 10, beginning with "Exceptions are not terribly
difficult to learn, and are one of those features" is accidentally inside an HTML PRE tag.  Therefore,
it does not get wrapped and displays as one long line that goes way beyond the edge of the browser window.


--Fred

Add a comment to this suggestion
Comment ID: 1000611-151100-rothgi_-nswccd-_navy-_mil.cmt
From: Gary Roth
Print Edition Chapter:1
Search for Text: James H Jarrett

This is miniscule, but I thought that it should probably by

James H. Jarrett (with a .)

Add a comment to this suggestion
Comment ID: 1000607-162604-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:9

Search for Text: The solid arrows show that a class can produce objects of the class the arrow is pointing
to.

The first diagram in the "Container taxonomy" section of Chapter 9 is described as:

"The solid arrows show that a class can produce objects of the class the arrow is pointing to."

In the diagram, however, those arrows are dotted lines.

--Fred

Add a comment to this suggestion
Comment ID: 1000607-162214-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:9
Search for Text: don’t just want to return just

Typo:  "don’t just want to return just".  Drop one of the "just"s.

--Fred

Add a comment to this suggestion
Comment ID: 1000607-161842-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:9
Search for Text: The array a is initially just a null reference, and the compiler prevents


The output of the program shown in the "Arrays are first-class objects" section of Chapter 9 has not
been updated from version 1 of the book.  It still shows two consecutive lines reporting a.length in
the middle of the output and is missing the first line of output which should report a.length.

--Fred

Add a comment to this suggestion
Comment ID: 1000607-161230-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:9
Search for Text: Notice that the comparisons are only interested in the keys


The paragraph in the "Understanding hashCode()" section of Chapter 9 that begins with "Notice that the
comparisons are only interested in the keys" is accidentally inside an HTML PRE tag.  Therefore, it does
not get wrapped and displays as one long line that goes way beyond the edge of the browser window.

--Fred

Add a comment to this suggestion
Comment ID: 1000607-160817-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:8
Search for Text: Initially, these features may seem like they are added strictly


The paragraph in the "Nesting interfaces" section of Chapter 8 that begins with "Initially, these features
may seem like they are added strictly" is accidentally inside an HTML PRE tag.  Therefore, it does not
get wrapped and displays as one long line that goes way beyond the edge of the browser window.

--Fred

Add a comment to this suggestion
Comment ID: 1000607-160115-fred_-stluka-_com.cmt
From: Fred Stluka
Revision 11 Chapter:7
Search for Text: This can be thought of as pure substitution


In the 2nd diagram in the section "Pure inheritance vs. extension", you forgot to change "Line" to "Triangle".


--Fred

Add a comment to this suggestion
Comment ID: 1000606-194554-picof_-aol-_com.cmt
From: zach knoll
online version revision 11 Chapter:15
Search for Text: The basic servlet

Youre code for the basic servlet ServletsRule.Java will not work in most Java Servlet web-servers.

Since I am learning the material myself I can't tell you exactly what you did wrong but I can tell you
what

I did to get it to work so maybe you can fill in the explanation from there. (The relevant code will
be posted below).

You say ypurself that it seems more convenient to put all code in the service() method rather than following
Suns advice and using the doGet()
and other methods. The fact is that your code didn't work at all untill I changed your
service method into a doGet() and deleted the original service() method. It seemed
the server automatically calls service() which then calls doGet(). By 
overriding doGet() like you did, you messed up this process. Your code was:
//: c15:servlets:ServletsRule.java
     import javax.servlet.*;
     import javax.servlet.http.*;
     import java.io.*;

     public class ServletsRule extends HttpServlet {
       int i = 0; // Servlet "persistence"
       public void service(HttpServletRequest req, 
       HttpServletResponse res) throws IOException {
         res.setContentType("text/html");
         PrintWriter out = res.getWriter();
         out.print("<HEAD><TITLE>");
         out.print("A server-side strategy");
         out.print("</TITLE></HEAD><BODY>");
         out.print("<h1>Servlets Rule! " + i++);
         out.print("</h1></BODY>");  
         out.close();    
       }
     } ///:~

Again fix this by changing the method name to doGet() and things will work fine.

From: Gary Parset [Gparsy_-hotmail-_com]
I agree with all of Zach's comments he hit the nail on the head, I just want to
point out that the same goes for all the servlet examples that follow, for
example do get the EchoForm.java servlet to work you must rename the
service method as doGet() and make sure you have no other service() methods
that might ovveride the default.

Add a comment to this suggestion
Comment ID: 1000604-064117-kos_-iskratel-_si.cmt
From: Gorazd Kos
donwloaded pdf format Chapter:11: The Java I/O System
Search for Text: java.utils.Array.sort() method

java.util.Arrays.sort() method

Add a comment to this suggestion
Comment ID: 1000602-213149-rtt_-iname-_com.cmt
From: Slavic Lanovets
1 Chapter:13
Search for Text: c13:Menus.java

bug in source code on p763
    safety[0].setActionCommand("Guard");
    safety[0].setMnemonic(KeyEvent.VK_G);
    safety[0].addItemListener(cmil);
    safety[1].setActionCommand("Hide");
    safety[0].setMnemonic(KeyEvent.VK_H);
           ^ 1 here
    safety[1].addItemListener(cmil);


Add a comment to this suggestion
Comment ID: 1000602-212900-rtt_-iname-_com.cmt
From: Slavic Lanovets
1 Chapter:13
Search for Text: c13:TicTacToe.java

bug in source code on p775
  class BL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      JDialog d = new ToeDialog(
        Integer.parseInt(rows.getText()),
        Integer.parseInt(cols.getText()));
      d.setVisible(true);
    }
  }
  but ToeDialog constructor takes width as first parameter
  correct variant:
      JDialog d = new ToeDialog(
        Integer.parseInt(cols.getText()),
        Integer.parseInt(rows.getText()));


Add a comment to this suggestion
Comment ID: 1000602-190521-daniel_-cafe-_newcastle-_edu-_au.cmt
From: Daniel Le Berre
11 Chapter:12
Search for Text: //: c12:PetCount.java

The following code can be misinterpreted by a novice programmer:

    for(int i = 0; i < pets.size(); i++) {
           Object o = pets.get(i);
           if(o instanceof Pet)
             ((Counter)h.get("Pet")).i++;
           if(o instanceof Dog)
             ((Counter)h.get("Dog")).i++;
           if(o instanceof Pug)
             ((Counter)h.get("Pug")).i++;
           if(o instanceof Cat)
             ((Counter)h.get("Cat")).i++;
           if(o instanceof Rodent)
             ((Counter)h.get("Rodent")).i++;
           if(o instanceof Gerbil)
             ((Counter)h.get("Gerbil")).i++;
           if(o instanceof Hamster)
             ((Counter)h.get("Hamster")).i++;
         }

The i used in the for loop and the i used in the Counter class are confusing.
Should be better I think if Counter was defined such as:

class Counter { int i; public void inc() {i++;} }

and the code replaced by:

    for(int i = 0; i < pets.size(); i++) {
           Object o = pets.get(i);
           if(o instanceof Pet)
             ((Counter)h.get("Pet")).inc();
           if(o instanceof Dog)
             ((Counter)h.get("Dog")).inc();
           if(o instanceof Pug)
             ((Counter)h.get("Pug")).inc();
           if(o instanceof Cat)
             ((Counter)h.get("Cat")).inc();
           if(o instanceof Rodent)
             ((Counter)h.get("Rodent")).inc();
           if(o instanceof Gerbil)
             ((Counter)h.get("Gerbil")).inc();
           if(o instanceof Hamster)
             ((Counter)h.get("Hamster")).inc();
         }



In the c12:PetCount3.java example, a ++j appears as a for loop increment. It should be consistent to
use j++ instead.

At the end of the chapter, replace StripQualifiers.Strip() by StripQualifiers.strip().



Add a comment to this suggestion
Comment ID: 1000602-073947-luigi-_talamona_-bticino-_it.cmt
From: Luigi Talamona
1 Chapter:13
Search for Text: automatically lowercased

automatically uppercased

Add a comment to this suggestion
Comment ID: 1000601-033431-Andrew-_Premdas_-teleca-_com.cmt
From: Andrew Premdas
Revision 9 Chapter:3
Search for Text: Auto increment and decrement


The example for this whilst being correct is initially confusing and takes quite alot of study before
the point can be understood (well it did for me). The following example adds two lines and changes the
order. I hope it makes the point much easier to understand.


//: c03:AutoInc.java
// Demonstrates the ++ and -- operators.

public class AutoInc {
  public static void main(String[] args) {
    int i = 1;
    prt("i : " + i);
    prt("i++ : " + i++); // Post-increment
    prt("i : " + i);
    prt("++i : " + ++i); // Pre-increment
    prt("i : " + i);
    prt("i-- : " + i--); // Post-decrement
    prt("i : " + i);
    prt("--i : " + --i); // Pre-decrement
    prt("i : " + i);
  }
  static void prt(String s) {
    System.out.println(s);
  }
}

This gives an output of 

i : 1
i++ : 1
i : 2
++i : 3
i : 3
i-- : 3
i : 2
--i : 1
i : 1


Add a comment to this suggestion
Comment ID: 1000528-113243-ivan_-ik-_bme-_hu.cmt
From: Ivan Ketler
revision 9 Chapter:11
Search for Text: Java 1.1 IO streams


You're repeatedly suggesting that the "old" (Stream) and the "new" (Reader/Writer) input/output shouldn't
coexist. This is not exactly the case. As I see, the old one provides the byte I/O, and the new one provides
the character I/O. This is the most important difference between the two.

Add a comment to this suggestion
Comment ID: 1000527-152712-David-_Brown_-dbgcorp-_com.cmt
From: David Brown
Revision 11 Chapter:10: Exception guidlines
Search for Text: 8.Make your library and program safer


Unbalanced parenthesis in item 8:  "8.Make your library and program safer. (This is a short-term investment
for debugging, and a
     long-term investment (for application robustness.)"

Also, A few lines later in the "Summary" section, there's a line wrapping problem at:
  "Exceptions are not terribly difficult"

Add a comment to this suggestion
Comment ID: 1000527-141917-David-_Brown_-dbgcorp-_com.cmt
From: David Brown
Revision 11 Chapter:5
Search for Text: Access specifiers in Java


HTML formatting problem.  This paragraph does not wrap properly.  It continues off to the right side
of the browser for several screens.  It does this with both Netscape Communicator 4.7 and Explorer 5

Add a comment to this suggestion
Comment ID: 1000526-180952-eschmenk_-bellsouth-_net.cmt
From: Eric G Schmenk
1st Printing Chapter:3
Search for Text: The logical operators AND (&&), OR (||) and NOT(!) 


Both & and && are logical AND operators.  Furthermore, | and || are both logical OR operators.  Reference:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/opsummary.html#relational


With && and ||, the right-hand operand may not be evaluated; with & and |, the right-hand operand will
always be evaluated.  Other than that, & is identical to &&, and | is identical to ||.


Also, your mnumonic on the bottom of page 146 is misleading.  You say "since bits are 'small', there
is only one character in the bitwise operators".  Yes, but there may be only one character in the logical
operators, too.

Add a comment to this suggestion
Comment ID: 1000526-123005-jfheon_-hotmail-_com.cmt
From: Jean-Francois Heon
Revision 11 Chapter:8

Search for Text: In addition, the following example uses private inner classes so the implementation
is completely hidden and can be changed with impunity.


In addition, the following example uses private inner classes so the implementation is completely hidden
and CANNOT be changed with impunity.

From: Jean-Francois Heon [jfheon_-hotmail-_com]
Shame on me!

I withdraw my comment I had not understood well. The phrase is perfect as it is.

Sorry 8(

Add a comment to this suggestion
Comment ID: 1000523-021915-vincent-_j-_o'sullivan_-BritishAirways-_com.cmt
From: Vincent O'Sulivan
Electronic Chapter:4

Search for Text: The “gc” argument will call the System.gc( ) method (to force execution of the garbage
collector). 


Garbage collection cannot be 'forced' in Java, merely 'suggested' or 'encouraged'.  In fact, a garbage
collection mechanism isn't a mandatory part of the JVM implementation.  


This was certainly the case for J1.1 and also, I'm pretty sure, for J1.2.  I think it's worth checking
out for J1.3.

Vince.

From: Vince O'Sullivan [vincent-_j-_o'sullivan_-BritishAirways-_com]
'Remember that neither garbage collection nor finalization is guaranteed.'


Having read further and seen the above, I see you're aware of the situation.  Nevertheless, your earlier
use of the word 'force' is misleading.

Vince.

Add a comment to this suggestion
Comment ID: 1000522-103044-ckenned_-crosslink-_net.cmt
From: Charles Kennedy
Revision 11 Chapter:4
Search for Text: Specifying initialization

You state:

"What happens if you want to give a variable an initial value? One direct way to
do this is simply to assign the value at the point you define the variable in the
class. (Notice you cannot do this in C++, although C++ novices always try.)"


I admit that I am a C++ novice, but assigning values at the point of variable definition (e.g., int i=12345;)
seems to work fine for me in C++!  Note that Chapter 4 of Bjarne Stroustrup's The C++ Programming Language,
Third Edition, makes it clear that this is allowed.  In fact, this seems to be the method he prefers
to use when it makes sense.


From: Francesco Romano [franceromano_-netscape-_net]

Bruce is right of course. In c++ you can initialize a variable when you define it in the code but you
can't do that in a definition of a class and in fact it's quite annoying. Bruce, why is it in this way?


Add a comment to this suggestion
Comment ID: 1000521-014917-LiuXY_-Novasprint-_com.cmt
From: Liu Xi Yu
Revision 11 Chapter:6: Reusing Classes
Search for Text: Name hiding

Dear Sir,

About this seciton
///////////////////

As you’ll see in the next chapter, it’s far more common to override methods of the same name
using exactly the same signature and return type as in the base class. It can be confusing otherwise
(which is why C++ disallows it, to prevent you from making what is probably a mistake).
//////////////////
of the NAME HIDING of the Chapter 6 REUSEING CLASSES,

I have tried with Visual C++ and Borland C++, I find it's OK to override a bass class method with the
same name using exactly the same signature and return type in the base class.
I am not sure whehter it is right.

The code example
///////
class P{
public:
    int test(){ return 1; };
};

class C: public P{
public:
     int test(){return 2;};
};
///////


Regards,

Liu Xi yu




From: Vincent O'Sullivan [vincent-_j-_o'sullivan_-britishairways-_com]
Liu,


You misunderstand the comment in the book.  In C++ overriding with the same signature is OK, overriding
with a different signature isn't.

Vince.

Add a comment to this suggestion
Comment ID: 1000520-100606-hill_-berbee-_com.cmt
From: Ted Hill
printed book, 1st printing Chapter:8
Search for Text: in Chapter 13 and 16.

There is no chapter 16.

Add a comment to this suggestion
Comment ID: 1000520-081015-vincent-_j-_o'sullivan_-BritishAirways-_com.cmt
From: Vincent O'Sullivan
Revision 11 Chapter:3

Search for Text: With a widening conversion an explicit cast is not needed because the new type will
more than hold the information from the old type so that no information is ever lost.


The sentence above is incorrect when it states that 'no information is ever lost' in a widening cast.
 Information can easily be lost.

For example: in the following code information will clearly be lost...
      long  lg = 123456789012345678L;
      float ft = l;
      System.out.println("lg=" + lg);
      System.out.println("ft=" + ft);


A float is wider than either an int or a long, in that it can represent numbers of greater absolute magnitude,
however, the precision of the representation of a large number by a float is limited.  


Note: paradoxically a float is stored in 4 bytes and a long in 8.  Nevertheless a float is considered
wider and thus a safe destination for widening conversion.


PS.  If it's any comfort, Hortsmann and Cornell's 'Core Java' makes exactly the same mistake (which they've
acknolwedged).

From: Vince O'Sullivan [vincent-_j-_o'sullivan_-BritishAirways-_com]

Chapter 4: "You should be aware that this is a narrowing conversion, which means you might lose information
during the cast."


As with my original comment on Chapter 3.  Even with a widening conversion you might lose information.


PS.  Of course the second line of my example should have read:
      float ft = lg;

Vince.

Add a comment to this suggestion
Comment ID: 1000519-050050-jere_-sci-_fi.cmt
From: Jere Käpyaho
11 Chapter:Appendix C
Search for Text: jindent


In Implementation item #1 you mention that there is a free tool to indent Java source code, and mention
the address home.wtal.de/software-solutions/jindent. However, Jindent is not free, but there is a trial
version available with limited functionality.


Add a comment to this suggestion
Comment ID: 1000515-230849-venus_-bom2-_vsnl-_net-_in.cmt
From: Yashesh Bhatia
Revision 10 Chapter:6: Reusing Classes
Search for Text: BlankFinal.java

Hello, 

    The following line 

     "You’re forced to perform assignments to finals either with an 
expression at the point of definition of the field or in every
constructor. This way it’s guaranteed that the final field is always
initialized before use."

    should also indicate that blank finals can also be initialized 
in initialization code section of the classes, besides at the point
of defination or in the constructor.

The following program demonstrates it.

Thanks, 

-- Yashesh

------------------------ BlankFinal.java ------------------------

// BlankFinal.java
class Poppet{}

class BlankFinal
{
1000222-073936-massimo_-rcfmedia-_ch.cmt
/home/httpd/cgi-bin/TIJ2Suggestions/1000222-073946-massimo_-rcfmedia-_ch.cmt
/home/httpd/cgi-bin/TIJ2Suggestions/1000223-084508-nathan_banks_-consultant-_com.cmt
/home/httpd/cgi-bin/TIJ2Suggestions/1000223-123131-praveen-_naik_-bt-_com.cmt
/home/h
Add a comment to this suggestion
Comment ID: 1000515-210900-jrubin_-cise-_ufl-_edu.cmt
From: Jared Rubin
Version 11 Chapter:14
Search for Text: notify();

There is a source code error on pg 875 in the file
Suspend.java
in the method 
public synchronized void fauxResume()
need to change the line notify()
into the line this.notify()
otherwise you have deadlock and program never runs

From: Jared Rubin [jrubin_-cise-_ufl-_edu]

I want to correct what I suggested before about putting this.notify instead. This is not the solution.


The problem with Suspend.java is that sometimes it will work and sometimes it will not. The reason for


this is on timing issues. If you look at the constructor for class Suspendable you will see the following


public Suspendable() { start(); }

what happens here is the run method is called and in the run method you will be deadlocked when 
you arrive at the statement 

t.setText(Integer.toString(count++));

I think this may have to do with timing of the sleep(100) because when the method
public void init() is occuring in a separate thread from the run() the init() may arrive
at the statement

cp.add(t) 

at the same time as run arriving at t.setText(integer.toString(count++));
hence there may be a collision at JTextField t

I got the program to run all the time when I changed sleep(100) to sleep(1000).
Jared Rubin


Add a comment to this suggestion
Comment ID: 1000515-144435-billchestnut_-canada-_com.cmt
From: Bill Chestnut
Revision 11 Chapter:Chapter 13
Search for Text: "Event Model", Listener

Re: General Event Model, Event Listeners. Objects responding to events.

Bruce,

This is a general presentation comment. Your discussion of events and listeners lost me on several fronts.
I am having (as a complete novice) difficulty with understanding how an EventListener is able to discern
which object sent the message. For example if there are 3 buttons and an event listener is set up, your
code examples do not appear to show any sign of discerning which button was pressed, which would be necessary
before deciding what to do next. It appears that the code obtains the Eventtype that is associated with
the button, but i was expecting to see something which then passes an object reference to the listener
about which object (instance, not class), sent the message. I feel you are jumping into major detail
here before getting the basics clear. In case it helps, I am coming into Java from a background in PowerBuilder
with several years of  object oriented thinking and programming. This is the first section of your book
that has given me any difficulty.  

Add a comment to this suggestion
Comment ID: 1000514-175156-jrubin_-cise-_ufl-_edu.cmt
From: Jared Rubin
Release 11 Chapter:14

Search for Text: Sleeper2 provides a solution by making run() un-synchronized. Only the change() method
is synchronzied, which means that while run() is in sleep(), the Peeker can access the synchronized method
it needs, namely read().

The paragraph I referred to in the text to search for is an incorrect statement.
The peeker can access the read method of class Blockable as long as the 
Sleeper2 is not in the synchronized method change(). This is the only time
that Peeker would be blocked. The sleep(1000) is unnecessary in Sleeper2's 
run method. The only reason I looked at this in detail is because
I am writing a thesis on issues in real time Java.

Add a comment to this suggestion
Comment ID: 1000509-115843-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:Appendix C
Search for Text: Use data members for variation

In the Design section, these two items are essentially identical:

20.Use data members for variation in value and method overriding for 
variation in behavior.

30.Use inheritance and method overriding to express differences in 
behavior, and fields to express variations in state.

See also 19 & 29.

Implementation 12 & 31 restate Design 2.

Add a comment to this suggestion
Comment ID: 1000509-054640-fmi_-ccir-_ed-_ac-_uk.cmt
From: Fergus McInnes
Revision 11 Chapter:9

Search for Text: a negative value if the argument is less than the current object, zero if the argument
is equal, and a positive value if the argument is greater than the current object


a negative value if the current object is less than the argument, zero if the objects equal, and a positive

value if the current object is greater than the argument

From: Fergus McInnes [fmi_-ccir-_ed-_ac-_uk]
Of course, in my corrected text, "equal" should be "are equal".

Add a comment to this suggestion
Comment ID: 1000508-122235-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: or RMI-JRMP

Text:
or RMI-JRMP

JRMP is never defined.

Add a comment to this suggestion
Comment ID: 1000508-120525-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: update some attributes of the EJBS

Before:
update some attributes of the EJBS
After:
update some attributes of the EJBs

or

update some attributes of the EJB

Add a comment to this suggestion
Comment ID: 1000508-115417-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: CORBA and RMI/IIOP

Text:
CORBA and RMI/IIOP

IIOP is never defined.

Add a comment to this suggestion
Comment ID: 1000508-114622-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: —An EJB cannot make use

Before:
—An EJB cannot make use
After:
—an EJB cannot make use

Add a comment to this suggestion
Comment ID: 1000508-114146-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: techniques shown above, such as JNI or J/Direct.

Before:
techniques shown above, such as JNI or J/Direct.

Neither JNI nor J/Direct are discussed in this chapter
(nor in any chapter, although JNI is discussed in Appendix B).

After:
techniques shown in Appendix B: The Java Native Interface.

Add a comment to this suggestion
Comment ID: 1000508-113338-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: exactly the same thing: RMI (see Chapter 15).

Before:
exactly the same thing: RMI (see Chapter 15).

The text and the reader are already in Chapter 15, 
and RMI was just discussed in the previous section.

After:
exactly the same thing: RMI.

Add a comment to this suggestion
Comment ID: 1000508-111939-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: //# This file. See docs at java.sun.com

Before:
//# This file. See docs at java.sun.com
After:
//# this file. See docs at java.sun.com

Add a comment to this suggestion
Comment ID: 1000508-111642-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: Getting an object reference passing a string

Before:
Getting an object reference passing a string
After:
Getting an object reference by passing a string

Add a comment to this suggestion
Comment ID: 1000508-111408-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: as calling a method on local object

Before:
as calling a method on local object
After:
as calling a method on a local object

Add a comment to this suggestion
Comment ID: 1000506-142152-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: JSP expressions can found intermingled

Before:
JSP expressions can found intermingled
After:
JSP expressions can be found intermingled

Add a comment to this suggestion
Comment ID: 1000506-141217-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: If you use same key in a

Before:
If you use same key in a
After:
If you use the same key in a

Add a comment to this suggestion
Comment ID: 1000505-142342-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:15
Search for Text: SELECT to produce result set

Before:
SELECT to produce result set
After:
SELECT to produce a result set

Add a comment to this suggestion
Comment ID: 1000505-090148-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:14
Search for Text: c14:TestAccess.java

Running the example gives NullPointerException.  Suspecting a problem with
the source file, I pasted in the code from the chapter; same error.
WNT 4.0WS + sp6

C:\Downloads\Tij2ed\code\c14>java TestAccess
java.lang.ThreadGroup[name=x,maxpri=10]
    Thread[one,5,x]
    java.lang.ThreadGroup[name=y,maxpri=10]
        java.lang.ThreadGroup[name=z,maxpri=10]
            Thread[two,5,z]
two f()
java.lang.NullPointerException
        at TestThread2.run(Compiled Code)

C:\Downloads\Tij2ed\code\c14>java -version
java version "1.2"
Classic VM (build JDK-1.2-V, native threads)

C:\Downloads\Tij2ed\code\c14>type TestAccess.java
     //: c14:TestAccess.java
     // How threads can access other threads
     // in a parent thread group.

     public class TestAccess {
       public static void main(String[] args) {
         ThreadGroup
           x = new ThreadGroup("x"),
           y = new ThreadGroup(x, "y"),
           z = new ThreadGroup(y, "z");
         Thread
           one = new TestThread1(x, "one"),
           two = new TestThread2(z, "two");
       }
     }

     class TestThread1 extends Thread {
       private int i;
       TestThread1(ThreadGroup g, String name) {
         super(g, name);
       }
       void f() {
         i++; // modify this thread
         System.out.println(getName() + " f()");
       }
     }

     class TestThread2 extends TestThread1 {
       TestThread2(ThreadGroup g, String name) {
         super(g, name);
         start();
       }
       public void run() {
         ThreadGroup g =
           getThreadGroup().getParent().getParent();
         g.list();
         Thread[] gAll = new Thread[g.activeCount()];
         g.enumerate(gAll);
         for(int i = 0; i < gAll.length; i++) {
           gAll[i].setPriority(Thread.MIN_PRIORITY);
           ((TestThread1)gAll[i]).f();
         }
         g.list();
       }
     } ///:~



From: Carl B. [braesicke_-interconnect-_net]

After further research, this is a known bug in JDK 1.2.  The bug is that enumerate() returns only threads


for which isAlive() is true, whereas activeCount() returns the true count of threads.  This can be seen
by
capturing the return value from enumerate() and comparing it to activeCount().

From: Carl B. [braesicke_-interconnect-_net]
The JDC Bug Id is 4229558.


Add a comment to this suggestion
Comment ID: 1000505-084708-parubok_-surfree-_net-_il.cmt
From: Eliahu Rosenblum
Revision 11 Chapter:15: Distributed Computing
Search for Text: Remember that an interface and all of its methods are automatically public.

Interface is not automatically public. It may have package access.

Add a comment to this suggestion
Comment ID: 1000505-043140-gorazd-_bozic_-arnes-_si.cmt
From: Gorazd Bozic
Release 11 Chapter:9
Search for Text: Ljujiana

Only a minor typing mistake, I guess: in class CountryCapitals, the
capital of SLOVENIA is said to be Ljujiana, which is wrong. The correct
name of the capital is Ljubljana (pronounced Lyu-blya-nah).


Add a comment to this suggestion
Comment ID: 1000503-000449-amraotikar_-rediffmail-_com.cmt
From: Prasad Amraotikar
Revision 11 Chapter:04
Search for Text: DeathCondition

the DeathCondition code doesn't run on its present form the error message 
is not displayed with only one improper book object. when i added one 
line 
new Book(true); it displayed the error message as expected.
i think this not correction to the code but may be to the jdk implementation
my current jdk version is 1.2.2.

thank you very much for providing this space.

From: Rob Leachman [quazar_-NoSpamPls-_bitblaster-_com]
I too found this to be the case, also with JDK 1.2.2...
worriesome, isn't it? 

Especially as this is one of the first "hard" topics in the book!


Add a comment to this suggestion
Comment ID: 1000502-124631-slavav_-experient-_com.cmt
From: Slava Vaseykin
Revision 11 Chapter:2
Search for Text: @exception


In your explanations of javadoc tags, you're saying that @throws tag is used to specify what exceptions
the method can throw.
Yet in the example you use @exception tag for that purpose.
Does that mean that both tags are valid?

Add a comment to this suggestion
Comment ID: 1000502-123704-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:14
Search for Text: and resume( ) that restarts

Before:
and resume( ) that restarts
After:
and a method resume( ) to restart

Add a comment to this suggestion
Comment ID: 1000502-122245-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:14
Search for Text: The test code in TestBangBean2

"The test code in TestBangBean2..."

There is no "TestBangBean2".

Add a comment to this suggestion
Comment ID: 1000502-120748-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:14
Search for Text: "ActionEvent" + e

Before:
"ActionEvent" + e
After:
"ActionEvent " + e

Add a comment to this suggestion
Comment ID: 1000501-154713-nick_-heroicpath-_com.cmt
From: Glen "Nick" Knickerbocker
Revision 9 Chapter:9
Search for Text: //!System.out.println("a.length=" + a.length);


The above line of code will compile and work correctly in uncommented.  It is commented out with the
explanation "// Compile error: variable a not initialized:", which is incorrect because it was just initialized
in the previous line of code.  

Add a comment to this suggestion
Comment ID: 1000501-140014-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:13
Search for Text: that the calls to the drawing routines

Before:
that the calls to the drawing routines
After
than the calls to the drawing routines

Add a comment to this suggestion
Comment ID: 1000501-135922-braesicke_-interconnect-_net.cmt
From: Carl B.
Revision 11 Chapter:13
Search for Text: //: c13:ComboBoxes.java

I've noticed a problem with this example.  When run with
java ComboBoxes
the example will not choose the first (0th) entry in the list, either
with the mouse, or with keyboard navigation, provided that no
other entries are ever visited or chosen.  If any other entry is
chosen with the mouse, or any other entries are visited (whether
chosen or not) with the keyboard, then the problem disappears until
the next time the example is run.  If the example is run using
appletviewer ComboBoxes.java
under the same provisions, the first entry can be chosen by mouse,
or by typing the first letter of the (first) entry; pressing ENTER
or pressing SPACEBAR does not select the entry.  This looks like a 
JVM/runtime bug.  Dropping the combo box also varies between the
applet and the non-applet invocations: under the applet invocation,
the combo box is dropped by pressing DOWN ARROW; under the non-
applet invocation, the combo box is dropped by pressing ALT+DOWN ARROW.

C:\Downloads\Tij2ed\code\c13>java -version
java version "1.2"
Classic VM (build JDK-1.2-V, native threads)
NT 4.0 WS + SP6



Add a comment to this suggestion
Comment ID: 1000228-120825-dianne-_chin_-air2web-_com.cmt
From: D. Chin
Revision 9 Chapter:Chapter 9
Search for Text: will used

will be used

Add a comment to this suggestion
Comment ID: 1000227-125605-erikshelton_-netscape-_net.cmt
From: Erik Shelton
Revision 9 Chapter:13
Search for Text: JApplet applet = new Applet1b();

This is for example applet Applet1c().  Should be changed to:
JApplet applet = new Applet1c();

A cut & paste error, no doubt.

Add a comment to this suggestion
Comment ID: 1000227-123227-hrobinson_-licenergy-_com.cmt
From: Hugh Robinson
Revision 9 Chapter:2: Everything is an Object
Search for Text: Java determines the size of each primitive type


In the table following the search text, it says that the boolean type has a size of 1 bit. According
to section "2.4.1 Primitive Types and Values" in the JVM spec at Sun (http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#19511),
the size of the boolean type is not eexplicitly defined - all it seems to say is that it can take the
literal values true or false

Add a comment to this suggestion
Comment ID: 1000227-073430-nick-_linnenbruegger_-gmx-_net.cmt
From: Nick
revision 8 Chapter:1; "Analysis and design, Phase 5"
Search for Text: This term is explored in Chapter 16: Design Patterns.

I thought you're going to put this chapter in a separate book "Thinking in patterns with Java"!

Add a comment to this suggestion
Comment ID: 1000225-230613-dsafari_-netlink-_co-_nz.cmt
From: Holden Glova
the March 13? release Chapter:source
Search for Text: The example code

I couldn't get any of the example code to compile until I put them into packages.

I'm using Linux with java1.2.2 non RC. This was the error I got before i added a package declaration
to each .java file.

java.lang.ArrayIndexOutOfBoundsException
        at at.dms.kjc.CHandLexer.getJavaComment(CHandLexer.java:166)
        at at.dms.kjc.JavaScanner.getComments(JavaScanner.java:43)
        at at.dms.kjc.JavaScanner.getToken(JavaScanner.java:99)
        at at.dms.compiler.HandLexer.nextToken(HandLexer.java:157)
        at antlr.TokenBuffer.fill(TokenBuffer.java:84)
        at antlr.TokenBuffer.LA(TokenBuffer.java:93)
        at antlr.LLkParser.LA(LLkParser.java:75)
        at at.dms.kjc.JavaParser.jCompilationUnit(JavaParser.java:83)
        at at.dms.kjc.Main.parseFile(Main.java:481)
        at at.dms.kjc.Main.run(Main.java:119)
        at at.dms.kjc.Main.compile(Main.java:449)
        at at.dms.kjc.Main.main(Main.java:432)
HelloDate.java:22: Unexpected end of file

Love your book :) thanks for making it available over the internet.

Add a comment to this suggestion
Comment ID: 1000224-004130-sameetn_-yahoo-_com.cmt
From: Sameet Nasnodkar
Revision 7 Chapter:Appendix C
Search for Text: http://www.ulb.ac.be/esp/ip-Links/Java/joodcs/mm-WebBiblio.html 

The link no longer exists. 
Grateful if you could provide the correct as I feel that  
guidelines are very essential to coding.

From: Chris Buck [cbuck_-gwmail-_usna-_edu]
This page is now at a new URL:

http://www.meurrens.org/ip-Links/java/joodcs/mm-WebBiblio.html


Add a comment to this suggestion
Comment ID: 1000223-084508-nathan_banks_-consultant-_com.cmt
From: Nathan Banks
Revision 7 Chapter:4 Initialization and Cleanup

Search for Text: Of course, free( ) is a C and C++ function, so you’d need call it in a native method
inside your finalize( ).

The target sentence needs to be re-worded. The contraction should be dropped. Perhaps,


Of course, free( ) is a both a C and C++ function. Therefore, you would need to call it from a native
method inside your finalize( ).


Add a comment to this suggestion
Comment ID: 1000222-073946-massimo_-rcfmedia-_ch.cmt
From: Massimo Ferrari
Revision 8 Chapter:15
Search for Text: In the “File DSN” section I chose “Add,” 

In the “System DSN” section I chose “Add,” 

Add a comment to this suggestion
Comment ID: 1000221-174804-hrobinson_-licenergy-_com.cmt
From: Hugh Robinson
Revision 9 Chapter:Appendix D: Resources
Search for Text: books I recommend


The text under the book reference for "Core Java 2" is presumably meant to be "book I recommend" (rather
than the plural "books")

Add a comment to this suggestion
Comment ID: 1000221-172709-hrobinson_-licenergy-_com.cmt
From: Hugh Robinson
Revision 9 Chapter:D: Resources
Search for Text: http://java.sun.com


In the HTML version, I suggest making the URL's hypertext links so that you can just click on them to
jump to the web site concerned

Add a comment to this suggestion
Comment ID: 1000221-051432-zmija-_mariusz_-uk-_fid-intl-_com.cmt
From: Mariusz Zmija
8 Chapter:5
Search for Text: com\bruceeckel\util

Spotted a small error in the latest version of the TIJ2(chapter 5):


'When the compiler encounters the import statement, it begins searching at the directories specified
by CLASSPATH,

looking for subdirectory com\bruceeckel\util, then seeking the compiled files of the appropriate names
(Vector.class

for Vector and List.class for List). Note that both the classes and the desired methods in Vector and
List must be
public.'

In the 2nd edition the packages are re-coded as:

   com.bruceeckel.simple 


therefore the above needs to be altered from 'subdirectory com\bruceeckel\util,' to 'subdirectory com\bruceeckel\simple,'.

This can be found in Chapter 5, page 195 in 1st edition.

Add a comment to this suggestion
Comment ID: 1000221-005950-Frank_Lacher_-yahoo-_de.cmt
From: Frank Lacher
Release 8 Chapter:16
Search for Text: In The HTTP request

'The' is written with a great letter.



Add a comment to this suggestion
Comment ID: 1000221-005326-Frank_Lacher_-yahoo-_de.cmt
From: Frank Lacher
Release 8 Chapter:16
Search for Text: the the HTTP protocol

There is a double 'the' in the text.


Add a comment to this suggestion
Comment ID: 1000220-135557-starrseed_-aol-_com.cmt
From: Mark Horwath
2 Chapter:8
Search for Text: Using Collections


The table accompanying the "Using Collections" header capitalizes the boolean primitive return types
of the identified Collection methods, leading to potential confusion with the java.lang.Boolean class
type.  Other primitive return types are correctly identified.

Add a comment to this suggestion
Comment ID: 1000219-194517-AmandaM_-sovereign-_co-_nz.cmt
From: Amanda Milham
7 Chapter:Introduction
Search for Text: HTML version of this book (on the on the CD ROM bound into the back of this book,

Repetition found: 'on the on the'

Add a comment to this suggestion
Comment ID: 1000219-194305-AmandaM_-sovereign-_co-_nz.cmt
From: Amanda Milham
7 Chapter:Introduction
Search for Text: Chapter 14: Multiple Threads


The colon after '14' is in bold italics. The other colons after each chapter number are in normal style
.

Add a comment to this suggestion
Comment ID: 1000214-230502-rmvartak_-yahoo-_com.cmt
From: Rahul
2 Chapter:14
Search for Text: com.bruceeckel.swing.*

I cant find these files anywhere in my JDK1.2.2 where do I get them from, please suggest.
Regards
Rahul

Add a comment to this suggestion
Comment ID: 1000213-121258-caffeine_-widmayer-_net.cmt
From: Martin Widmayer
8 Chapter:9
Search for Text: c09:ArraySize.java


The code for the "Dynamic aggregate initialization:" is out of place in the example.  It should be placed
between the two identical lines: "System.out.println("a.length = " + a.length);" following the line "a
= d;".

Add a comment to this suggestion
Comment ID: 1000212-152852-mark_-terabyte-_co-_nz.cmt
From: Mark Easton
Revision 8 Chapter:15: Distributed Computing

Search for Text: Once the servlet is initialized - its init() method has run to completion - can clients
enter the service() method

Just a very very small one for you:


Once the servlet is initialized - its init() method has run to completion - can clients enter the service()
method

Should be:


Once the servlet is initialized - its init() method has run to completion - clients can enter the service()
method





Add a comment to this suggestion
Comment ID: 1000210-130541-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction

Search for Text: In the text of this book, identifiers (function, variable, and class names) will be
set in bold. Most keywords will also be set in bold,


In the text of this book, identifiers (function, variable, and class names) are set in bold. Most keywords
are also set in bold, 

Add a comment to this suggestion
Comment ID: 1000210-125937-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction
Search for Text: This chapter explains what RTTI is for,


This chapter explains what RTTI is for, how to use it, and how to get rid of it when it doesn’t belong
there. In addition, this chapter introduces the Java reflection mechanism.


Add a comment to this suggestion
Comment ID: 1000210-125619-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction
Search for Text: In addition, this chapter examines the process of taking an object, ...


In addition, this chapter examines the process of taking an object, “streaming” it (so that it can be
placed on disk or sent across a network) and reconstructing it, which Java handles for you with object
serialization. This chapter also examines Java’s compression libraries, which are used in the Java ARchive
file format (JAR).

Add a comment to this suggestion
Comment ID: 1000210-125003-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction

Search for Text: although it is a new concept to most and takes some time to become comfortable with
design using inner classes.


although it is a new concept to most.  It takes some time to become comfortable with design using inner
classes.

Add a comment to this suggestion
Comment ID: 1000210-124920-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction
Search for Text: The subject of directory paths and file names is also examined. 

It then examines the subject of directory paths and file names. 

Add a comment to this suggestion
Comment ID: 1000210-124201-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction
Search for Text: in such a way that no additional features are relied upon. 

without relying on additional features.

Add a comment to this suggestion
Comment ID: 1000210-124107-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Introduction
Search for Text: look them up in a book. (Plus it will be up-to-date.) 

look them up in a book (and the on-line documentation is probably more up-to-date).

Add a comment to this suggestion
Comment ID: 1000210-123154-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Preface
Search for Text: (and they’re working on making it easier all the time)

(and the Java language designers are working on making it even easier)

Add a comment to this suggestion
Comment ID: 1000210-122838-john-_cook_-kla-tencor-_com.cmt
From: John Cook
Revision 8 Chapter:Preface
Search for Text: This book became an enlightening experience

[A formatting correction: the HTML version shows this paragraph in the 
format of a code example.]

Add a comment to this suggestion
Comment ID: 1000209-184038-colburn_-ucar-_edu.cmt
From: Scot Colburn
Release 7 Chapter:3, page 161
Search for Text: However, you allowed use
superfluous casts in to make a point or to make your code more
clear.

This sentence is missing a few words.

Add a comment to this suggestion
Comment ID: 1000209-165847-nathan_banks_-consultant-_com.cmt
From: Nathan Banks
Revision 7 Chapter:1 Introduction to Objects
Search for Text: when you can creating

4. Use existing class libraries

The primary economic motivation for switching to OOP is the easy use of existing code in the form of
class libraries (in particular, the Standard Java libraries, which are covered throughout this book).
The shortest application development cycle will result when you can creating and use objects from off-the-shelf
libraries.


Add a comment to this suggestion
Comment ID: 1000129-074032-dieter-_noack_-bam-_de.cmt
From: Dieter Noack
Last Update:02/21/2000 Chapter:11
Search for Text: //: c11:NewIODemo.java

The example "c11:NewIODemo.java" contains the following code

...
      // 4. Line numbering & file output
      try {
        LineNumberReader li =
          new LineNumberReader(
            new StringReader(s2));
        BufferedReader in4 =
          new BufferedReader(li);
        PrintWriter out1 =
          new PrintWriter(
            new BufferedWriter(
              new FileWriter("IODemo.out")));
        while((s = in4.readLine()) != null )
          out1.println(
            "Line " + li.getLineNumber() + s);
        out1.close();
      } catch(EOFException e) {
        System.out.println("End of stream");
      }
...


The program returns the maximum line number for every line instead of the current line number. Since
I don't understand this, I have submitted a bug report to the java developers (Bug Id 4313203). Their
evaluation show that

LineNumberReader is already buffered (it extends BufferedReader). I think this is not a consistent design
in Java because LineNumberReader is the sole class that is buffered by default.


So please change the above code (delete the additional BufferedReader) and the program functions properly.


...
      // 4. Line numbering & file output
      try {
        LineNumberReader in4 =
          new LineNumberReader(
            new StringReader(s2));
        PrintWriter out1 =
          new PrintWriter(
            new BufferedWriter(
              new FileWriter("IODemo.out")));
        while((s = in4.readLine()) != null )
          out1.println(
            "Line " + in4.getLineNumber() + s);
        out1.close();
      } catch(EOFException e) {
        System.out.println("End of stream");
      }
...


Add a comment to this suggestion
Comment ID: 1000128-150409-vgendler_-socal-_rr-_com.cmt
From: Vladimir Gendler
All Chapter:12
Search for Text: Making many threads

TIJ:
Example: c14:Counter4.java.
Code fragment:
===============================================
  class StartL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      if(!started) {
        started = true;
        for (int i = 0; i < s.length; i++)
          s[i].start();
      }
    }
  }
===============================================

Note:
You are using here a field "started" as a flag in order to prevent
repeated start of threads in case of several clicks on the "Start"
button. You can do this nicer without using any flags. You have to
disable this button on the first click like this
===============================================
  class StartL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        start.setEnabled(false);
        for (int i = 0; i < s.length; i++)
          s[i].start();
      }
    }
  }
===============================================

In general if you have a desire to introduce many flags
it is an indication that something possibly wrong with
the design.

Add a comment to this suggestion
Comment ID: 1000127-112724-vgendler_-socal-_rr-_com.cmt
From: Vladimir Gendler
All Chapter:10
Search for Text: A directory lister

TIJ example:
//: c10:DirList.java
// From Thinking in Java, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Displays directory listing
package c10;
import java.io.*;

public class DirList {
  public static void main(String[] args) {
    try {
      File path = new File(".");
      String[] list;
      if(args.length == 0)
        list = path.list();
      else
        list = path.list(new DirFilter(args[0]));
      for(int i = 0; i < list.length; i++)
        System.out.println(list[i]);
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}

class DirFilter implements FilenameFilter {
  String afn;
  DirFilter(String afn) { this.afn = afn; }
  public boolean accept(File dir, String name) {
    // Strip path information:
    String f = new File(name).getName();
    return f.indexOf(afn) != -1;
  }
} ///:~


Note:
The construct
========================================
    String f = new File(name).getName();
    return f.indexOf(afn) != -1;
========================================
is only overhead because the paramater "name"
does not have a path name. So you can simply write
========================================
    return name.indexOf(afn) != -1;
========================================

Add a comment to this suggestion
Comment ID: 1000126-215755-sxie_-imsn-_net.cmt
From: Shawn Xie
lasted Chapter:5
Search for Text: “most access” to “least access”

Hi, Bruce,

When a friend told me your book says protected is less accessible than friendly. I replied that's imposible.
I said "Thinking in Java" is such a great book, I don't believe this kind of error is in book. Unfortunately,
I checked out lasted version of the book and found in Charter 5, there is a sentence: 


. The levels of access control from “most access” to “least access” are public,
“friendly” (which has no keyword), protected, and private.

Would you please verify this? I'd like to see the Java book I like most to be perfect.

Shawn Xie 



From: Christof Ulrich [ulrich_-eurexchange-_com]
Hi Shawn


Your sentence "Unfortunately, I checked out lasted version of the book ..." seems to contain a typo.


As far as I understand Bruce he wants to explain that friendly which is the default and means package
access imposes less restrictions than protetected. 
I don't see any error in that as package allows even for restricting access by subclassing.

Christof Ulrich

Add a comment to this suggestion
Comment ID: 1000122-103252-vgendler_-socal-_rr-_com.cmt
From: Vladimir Gendler
All Chapter:9
Search for Text: The class Throwable must appear in the exception specification

TIJ:
The class Throwable must appear in the exception specification for g( ) and main( )
because fillInStackTrace( ) produces a handle to a Throwable object. Since
Throwable is a base class of Exception, it’s possible to get an object that’s a
Throwable but not an Exception, so the handler for Exception in main( ) might
miss it. To make sure everything is in order, the compiler forces an exception
specification for Throwable. For example, the exception in the following program is
not caught in main( ):
//: c09:ThrowOut.java
public class ThrowOut {
public static void
main(String[] args) throws Throwable {
try {
throw new Throwable();
} catch(Exception e) {
System.out.println("Caught in main()");
}
}
} ///:~


Note:
"The class Throwable must appear" is not true.
If it would be so then we always must use
Throwable instead of Exception in any method
because we do not know if an exception was
thrown or re thrown. This example does not
proof anything because the original "exception"
was not an Exception but Throwable!
If you compare the returned object from the
method enew=e.fillInStackTrace() for
equality (enew==e) you will see that they
are the same!!! So we can safely use
throws Exception instead of throws Throwable
in the example "c09:Rethrowing.java".

From: Vladimir Gendler [vgendler_-socal-_rr-_com]
This is an excerpt from Java Documentation
==================================================================
fillInStackTrace

public Throwable fillInStackTrace()


    Fills in the execution stack trace. This method records within this Throwable object information
about the

    current state of the stack frames for the current thread. This method is useful when an application
is
    re-throwing an error or exception. For example: 

             try {
                 a = b / c;
             } catch(ArithmeticThrowable e) {
                 a = Number.MAX_VALUE;
                 throw e.fillInStackTrace();
             }
         

    Returns:
        this Throwable object.
==================================================================
As you see it says that the returned object is "this".

Add a comment to this suggestion
Comment ID: 1000119-095914-vgendler_-socal-_rr-_com.cmt
From: Vladimir Gendler
All Chapter:5
Search for Text: private: you can’t touch that!

This paragraph requires more explanations
regarding private access in Java. You
should mention somewhere that private
members of a class can be accessible
from any instance in any another
instance of the same class provided
we have the appropriate handle. It would
be very helpful to contrast this feature
with the same in other OOP languages
such as Smalltalk (by modulo that Smalltalk
has only protected mechanism) or even
in PowerBuilder (in spite of PB is not
fully OO). They have completely different
behavior.

Add a comment to this suggestion
Comment ID: 1000118-173120-hchann_-cooperaerial-_com.cmt
From: hans channaraj
tij2r3.doc Chapter:13
Search for Text: //: c13:TrackEvent.java


On the previous page you indicate that to derive your own "Button" class you should derive from "Canvas"
class; however the MyButton extends the "JButton" class.  Furthermore, it needs to have the paint() routine
inserted as reference is made to this at the end of the code section.

Add a comment to this suggestion
Comment ID: 1000118-143144-kazdan_-math-_upenn-_edu.cmt
From: Jerry Kazdan
Revision 6 Chapter:1
Search for Text: a

Thinking in Java, 2nd edition  html version

Since I use Linux, the Georgia etc. fonts are not available.  So the 
text certainly neither looks good nor is comfortable to read.

	- Alas, Jerry

From: Bruce Eckel [Bruce_-EckelObjects-_com]

If you click on "Viewing Hints" (at the beginning of every chapter) there's a note that might solve your
issue (it did on my Linux machine).

Add a comment to this suggestion
Comment ID: 1000024-174046-sruo_-yahoo-_com.cmt
From: Sung-Lu Ruo
Revision 1 Chapter:5 hiding the implementation

Search for Text: if a static member of that class is public, the client programmer can still access that
static member even though they cannot create an object of that class

Bruce:
I enjoy reading your books a lot.  They are well written and have good examples.

at the bottom of page 200:
As previously mentioned, if you don’t put an access specifier for class access it
defaults to “friendly.” This means that an object of that class can be created by any
other class in the package, but not outside the package. (Remember, all the files
within the same directory that don’t have explicit package declarations are implicitly
part of the default package for that directory.) However, if a static member of that
class is public, the client programmer can still access that static member even though
they cannot create an object of that class.

I have trouble understanding the last statement here. When you say client programmers,
do you mean package users?  

//in class FriendlyAccessViaStaticPublic.java
// package creator creates this package
package accessibility_pkg1;

class FriendlyAccessViaStaticPublic { // not a public class
  public static void tryMe() {
    System.out.println("FriendlyAccessViaStaticPublic.tryMe() called.");
  }
}

//in class TestAccessibility.java
//client programmers use accessibility_pkg1 
package accessibility_pkg2;
import accessibility_pkg1.*;

class TestAccessibility {
  public static void main(string[]) {
    // error here, can't access none public classes in other package
    // even though tryMe() is a public static function.
    FriendlyAccessViaStaticPublic.tryMe();
  }
}



Add a comment to this suggestion
Comment ID: 1000005-080911-paulroubekas_-ccnmail-_com.cmt
From: Paul Roubekas
Revision 1 Chapter:10

Search for Text: A DeflaterInputStream that Decompresses data that has been stored in the Zip file format
	

In Chapter 10 there is a two column table, column 1 is labeld “Java 1.1 Compression class”
and column 2 is labled “Function”.  I believe the second column in the last two rows is
incorrect.  See below. 

Is:
A DeflaterInputStream that Decompresses data that has been stored in the Zip file format	
Should Be :
A InflaterInputStream that Decompresses data that has been stored in the Zip file format	


Is:
A DeflaterInputStream that decompresses data that has been stored in the GZIP file format
Should Be :
A InflaterInputStream that decompresses data that has been stored in the GZIP file format

Add a comment to this suggestion
Comment ID: 1000004-125349-walterf_-lexis-nexis-_com.cmt
From: Walt Fitzharris
Revision 1 Chapter:14
Search for Text: c14:TestAccess.java

The for loop will cause a null pointer exception.

This is because enumerate() will only deliver threads that are
currently active...one of the threads in this program is never started
so it is not considered active...therefore the array delivered by 
enumerate has only one non-null element in it.
(The return value from enumerate() should be checked to confirm this.)

As the array has only one non-null element in it, the other one is null.
When the for loop hits it, the program barfs.

This is a known problem with the naming of this method...in a java.sun.com
bug report I suggested that they call the method enumerateActiveThreads()
instead of just enumerate() which implies all threads, active and inactive.



Add a comment to this suggestion
Comment ID: 991130-111442-awdunham_-hotmail-_com.cmt
From: Austin W. Dunham V
Revision 1 Chapter:13
Search for Text: MessageBoxes.java

Bruce,

   In your original book you recommended staying away from if-else blocks for handling events.  In the
MessageBoxes example you use an if-else block for just that.  I guess there are at least a couple ways
to avoid this: a unique actionlistener for each dialog, or an array.  I've included an array in the following
text listing.  I've also changed the yes/no dialog so that it updates the status bar.
   I'm not sure if it's any easier to read, but I thought I'd at least put out the suggestion.

//: MessageBoxes.java
// Demonstrates JOptionPane
// <applet code=MessageBoxes width=200 height=100></applet>
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class MessageBoxes extends JApplet
{
	JButton b[]=
	{ 
		new JButton("alert"), new JButton("yes/no"),
		new JButton("Color"), new JButton("Input"), 
		new JButton("3 vals") 
	};
	ActionListener al[] = 
	{
		new ActionListener()
		{
		// alert
			public void actionPerformed(ActionEvent e)
			{
				JOptionPane.showMessageDialog
					(null, "There's a bug on you!", 
					"Hey!", JOptionPane.ERROR_MESSAGE);
			}
		},
		new ActionListener()
		{
		// yes/no
			public void actionPerformed(ActionEvent e)
			{
				String options[] = {"Yes", "No"};
				int val=JOptionPane.showConfirmDialog
					(null, "or no", 
					"chooose yes", JOptionPane.YES_NO_OPTION);
				getAppletContext().showStatus(options[val]);
			}
		},
		new ActionListener()
		{
		// color
			public void actionPerformed(ActionEvent e)
			{
				Object options[] = {"Red", "Green"};
				int sel = JOptionPane.showOptionDialog
					(null, "Choose a Color!", 
					"Warning", JOptionPane.DEFAULT_OPTION, 
					JOptionPane.WARNING_MESSAGE, null, options, options[0]);
				if(sel != JOptionPane.CLOSED_OPTION)
					getAppletContext().showStatus
						("Color Selected: " + options[sel]);
			}
		},
		new ActionListener()
		{
		// input
			public void actionPerformed(ActionEvent e)
			{
				String val = JOptionPane.showInputDialog
					("How many fingers do you see?");
				getAppletContext().showStatus(val);
			}
		},
		new ActionListener()
		{
		// 3 vals
			public void actionPerformed(ActionEvent e)
			{
				Object selections[]={"First", "Second", "Third"};
				Object val=JOptionPane.showInputDialog
					(null, "Choose one", "Input", 
					JOptionPane.INFORMATION_MESSAGE,
					null, selections, selections[0]);
				if(val!=null)
					getAppletContext().showStatus
						(val.toString());
			}
		}
	};
	public void init()
	{
		Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		for(int i = 0; i<b.length; i++)
		{
			b[i].addActionListener(al[i]);
			cp.add(b[i]);
		}
	}
}

   Austin W. Dunham V
   The Eagle

Add a comment to this suggestion
Comment ID: 991129-123446-dleslie_-sterling-_com.cmt
From: David Leslie
Revision 1 Chapter:10
Search for Text: //: IOBug.java

IOBug.java does describe a bug. The bug was still there at least in the 1.2.1
version of the java compiler I have. However, you could mention some simple
work arounds.

If you stick to the 1.0 classes the streams are read correctly.
You do get the deprecation warning but its small worry compared to the bug.
Also, if the concern is mixing text and numbers you can use writeUTF() and
readUTF() instead of writeBytes() and readLine(). You do not even get a 
compiler warning in this case.

Either of these work arounds allow (or require) you to skip the use of the 
BufferedReader.

Here is a little program:
//: c10:myIoBugTest.java
// Revised From Thinking in Java, 2nd Edition
//  c10:IOBug.java
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Java 1.1 (and higher?) IO Bug
import java.io.*;

public class myIoBugTest {
  public static void main(String[] args) throws Exception {
      main1( args );
      main2( args );
      mainx( args );
  }



  /** By representing Chars as UTF strings, no bug, do not need BufferedReader and do not get deprecated
warning */
  private static void main2(String[] args) throws Exception {

    DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream("Data.txt")));

    out.writeDouble(3.14159);
    out.writeUTF("That was the value of pi\n");
    out.writeUTF("This is pi/2:\n");
    out.writeDouble(3.14159/2);
    out.close();


    DataInputStream in = new DataInputStream( new BufferedInputStream( new FileInputStream("Data.txt")));

    // The doubles written BEFORE the line of text
    // read back correctly:
    System.out.println(in.readDouble());
    // Read the lines of text:
    System.out.print(in.readUTF());
    System.out.print(in.readUTF());
    // Trying to read the doubles after the line
    // produces an end-of-file exception:
    System.out.println(in.readDouble());
  }

  /** If we mix Java 1.0 and 1.1 readers for the DataOutputStream then we run into trouble */
  private static void mainx(String[] args) throws Exception {

    DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream("Data.txt")));

    out.writeDouble(3.14159);
    out.writeBytes("That was the value of pi\n");
    out.writeBytes("This is pi/2:\n");
    out.writeDouble(3.14159/2);
    out.close();


    DataInputStream in = new DataInputStream( new BufferedInputStream( new FileInputStream("Data.txt")));

    BufferedReader inbr = new BufferedReader( new InputStreamReader(in));
    // The doubles written BEFORE the line of text
    // read back correctly:
    System.out.println(in.readDouble());
    // Read the lines of text:
    System.out.println(inbr.readLine());
    System.out.println(inbr.readLine());
    // Trying to read the doubles after the line
    // produces an end-of-file exception:
    System.out.println(in.readDouble());
  }

  /** If we stick to Java 1.0 DataOutputStream and DataInputStream we run OK but get the deprecated warning
at compile time. */
  private static void main1(String[] args) throws Exception {

    DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream("Data.txt")));

    out.writeDouble(3.14159);
    out.writeBytes("That was the value of pi\n");
    out.writeBytes("This is pi/2:\n");
    out.writeDouble(3.14159/2);
    out.close();


    DataInputStream in = new DataInputStream( new BufferedInputStream( new FileInputStream("Data.txt")));

    System.out.println(in.readDouble());
    System.out.println(in.readLine());
    System.out.println(in.readLine());
    System.out.println(in.readDouble());
  }
} ///:~


From: David Leslie [dleslie_-sterling-_com]
Oops. Forgot to remove old comments from main2(). Oh well.

Also, I like the book. 

From: Scott Huffman [scott-_m-_huffman_-mail-_sprint-_com]

IOBug.java does demonstrate a bug, however the bug is in the read operations not in the write operations
(contrary to the statement "It appears anything you write after a call to writeBytes() is not recoverable.").


Using 2 buffers on the same stream is causing the unexpected bad behavior 
of one of the buffered streams/readers.  The buffered streams/readers 
cause the lower level streams to get read in to fill their buffer.

In your example, IOBug.java, the FileInputStream gets read in up-to EOF when we first access the DataInputStream,
and the buffer in the 
BufferedInputStream is filled up (further access to the DataInputStream 
simply reads from its BufferedInputStream's buffer).  Then, when the 
BufferedReader is accessed, it sucks all the data out of the 
BufferedInputStream, into it's own buffer.  So any further access of the 
DataInputStream causes it to try to read past EOF.

The following variation on IOBug.java demonstrates various combinations of 
input streams/readers, and how reads from one affect the other.

//: NewIOBug.java
// tested in Java 1.2.2
// Demonstrates the behavior of multiple buffered streams accessing the
// same file.
import java.io.*;

public class NewIOBug 
{
	public static void main(String[] args) throws Exception
	{
		DataOutputStream out = new DataOutputStream(
								new BufferedOutputStream(
									new FileOutputStream("NewIOBug.txt")));
		out.writeDouble(3.14159);
		out.writeBytes("That was the value of pi\n");
		out.writeBytes("This is the value of pi/2:\n");
		out.writeDouble(3.14159 / 2);
		out.close();


// IOBug example - BufferedReader with a DataInputStream - one on top of the other (2 buffers) - it doesn't
work
		System.out.println("IOBug example - BufferedReader on top of DataInputStream");
		DataInputStream in = new DataInputStream(
								new BufferedInputStream(
									new FileInputStream("NewIOBug.txt")));
		BufferedReader inbr = new BufferedReader(new InputStreamReader(in));

		System.out.println(in.readDouble() + " after in.readDouble() - in.available(): " + in.available());


		System.out.println(inbr.readLine() + " after inbr.readLine() - in.available(): " + in.available());


		System.out.println(inbr.readLine() + " after inbr.readLine() - in.available(): " + in.available());

		System.out.println("Don't do in.readDouble() again - it will blow");
		in.close();
		inbr.close();
		System.out.println("It Doesn't Work!");
		System.out.println();


// try replacing the BufferedReader with a DataInputStream - one on top of the other (one buffer) - it
works
		System.out.println("Using 2 DataInputStreams one on top of the other");
		DataInputStream in2 = new DataInputStream(
								new BufferedInputStream(
									new FileInputStream("NewIOBug.txt")));
		DataInputStream inbr2 = new DataInputStream(in2);

		System.out.println(in2.readDouble() + " after in2.readDouble() - in2.available(): " + in2.available());


		System.out.println(inbr2.readLine() + " after inbr2.readLine() - in2.available(): " + in2.available());


		System.out.println(inbr2.readLine() + " after inbr2.readLine() - in2.available(): " + in2.available());


		System.out.println(in2.readDouble() + " after in2.readDouble() - in2.available(): " + in2.available());

		in2.close();
		inbr2.close();
		System.out.println("It Works!");
		System.out.println();

// try sharing lowest level stream - two seperate buffers on the same file - doesn't work
		System.out.println("Using 2 BufferedInputStreams on same file");
		FileInputStream fin = new FileInputStream("NewIOBug.txt");
		DataInputStream in3 = new DataInputStream(
								new BufferedInputStream(fin));
		DataInputStream inbr3 = new DataInputStream(
								new BufferedInputStream(fin));

		System.out.println(in3.readDouble() + " after in3.readDouble() - in3.available(): " + in3.available());


		System.out.println(inbr3.readLine() + " after inbr3.readLine() - in3.available(): " + in3.available());


		System.out.println(inbr3.readLine() + " after inbr3.readLine() - in3.available(): " + in3.available());


		System.out.println(in3.readDouble() + " after in3.readDouble() - in3.available(): " + in3.available());

		in3.close();
		inbr3.close();
		System.out.println("It Doesn't Work!");
		System.out.println();

// share the same buffer and same file - it works
		System.out.println("Using 2 DataInputStreams on same BufferedInputStream");
		BufferedInputStream bin = new BufferedInputStream(new FileInputStream("NewIOBug.txt"));
		DataInputStream in4 = new DataInputStream(bin);
		DataInputStream inbr4 = new DataInputStream(bin);

		System.out.println(in4.readDouble() + " after in4.readDouble() - in4.available(): " + in4.available());


		System.out.println(inbr4.readLine() + " after inbr4.readLine() - in4.available(): " + in4.available());


		System.out.println(inbr4.readLine() + " after inbr4.readLine() - in4.available(): " + in4.available());


		System.out.println(in4.readDouble() + " after in4.readDouble() - in4.available(): " + in4.available());

		in4.close();
		inbr4.close();
		System.out.println("It Works!");
	}
}///:~

Thanks so much for the book, and for making it so accessible.

Add a comment to this suggestion
Comment ID: 991119-102544-ryo_saeba_009_-yahoo-_com.cmt
From: Wirianto Djunaidi
Revision 1 Chapter:10
Search for Text: NewIODemo.java IOStreamDemo.java

For NewIODemo.java and IOStreamDemo.java
On both examples section 4. Line numbering & file output

You wrapped the LineNumberReader with Buffered Reader,
which resulted with the output files all list the last line number.
For examples the output will looks like:
Line 5 First line
Line 5 2nd Line
Line 5 third line
Line 5 another line
Line 5 last line

I don't believe this is your intentions, I tried by not wrapping
it with Buffered Reader to get the result where they list the 
line number correctyly.
I understand by wrapping it in BufferedReader to provide better
performance with buffering, but I can't figure out how to use it
without that problem.

I owned the 1st edition book, and I downloaded the 2nd Ed rev 3 
and they still have the exact same code.

Just want to thank you for such a wonderful books.

Sincerely,
Wirianto Djunaidi

Add a comment to this suggestion
Comment ID: 991029-175315-LeThuLP_-Louisville-_stortek-_com.cmt
From: Laurent LeThuaut
Revision 1 Chapter:7: Polymorphism

Search for Text: You can use this class for testing, but you don't need to include it in your shipping
product.

I found the idea of including test code as a static inner class very
attractive. What makes this idea pretty cool is for sure the option to
remove the inner .class file from the final code distribution. It should
be mentioned here though that removing the .class might be hazardous
while the outer class could be involved in a serialization process (which
is likely to be the case in some production code). If I'm not mistaken, it
looks like even if static members of a class are not serialized, the
presence of the .class is mandatory in order to check the modifiers of the
inner class (a runtime exception is thrown if the inner .class file is
missing while serializing the outer instance).

Add a comment to this suggestion
Comment ID: 991022-074307-richard-_heighton_-icl-_com.cmt
From: Richard Heighton
Revision 1 Chapter:2 or 12
Search for Text: String

It might be useful to add a few lines to clarify the distinction
between null and zero-length String objects.

For example, the declaration

               String s = "";

will mean that
               (s.equals(""))
but also that
               (s != null)

[More realistically perhaps, effectively the same declaration
could of course occur in the form:

               String s = textField.getText();

when the user enters no data in the JTextField.]

Regards, Richard Heighton



Add a comment to this suggestion
Comment ID: 990918-224643-pip_-ex2-_co-_uk.cmt
From: Philip Bath
Revision 1 Chapter:various
Search for Text: scope

Your book is a refreshing change from a bad training experience I have just 

completed! Haven't finished it yet, but I have a small comment, which bubbles underthe surface at various
points:


When I went to college in the 60's, "scope" was the region of the source 
program in which an identifier could be used (ie in which a name had a 
particular meaning). The Java language spec seems to take this view too. We
used the separate word "extent" for the temporal lifetime in a running 
program of the variable associated with the name. The Java spec doesn't use 
this word, but it is impossible to use a variable outside its extent in 
Java. Nevertheless, confusion between these two ideas is common among 
beginning programmers, so I don't think it's a good idea to bundle the 
concept of extent into the word "scope". 

TIJ:
"Most procedural languages have the concept of scope. This determines both
 the visibility and lifetime of the names defined within that scope."

Java Language Spec:
"The scope of a declaration is the region of the program within which the 
entity declared by the declaration can be referred to using a simple name"

The language Spec does not use any concept of (temporal) "lifetime of a 
name", and in fact I don't think you need it. The name exists even when 
the program is not running, and I am merely reading its source.


Add a comment to this suggestion
Comment ID: 990908-233002-cshing_-tm-_net-_my.cmt
From: Cheng Siang
Revision 1 Chapter:six 
Search for Text: bf.with(null);

class Gizmo {
  public void spin() { System.out.println("from spin");}
}

public class FinalArguments {
  void with(final Gizmo g) {
    //! g = new Gizmo(); // Illegal -- g is final
    g.spin();
  }
  void without(Gizmo g) {
    g = new Gizmo(); // OK -- g not final
    g.spin();
  }
  // void f(final int i) { i++; } // Can't change
  // You can only read from a final primitive:
  int g(final int i) { return i + 1; }
  public static void main(String[] args) {
    FinalArguments bf = new FinalArguments();
    bf.without(null);
    bf.with(null);
  }
} ///:~

As refer code above:-
The bf.without(null) work correctly. 
but bf.with(null) cause exception error occur.
But the book state that was not problem with this method?
Please rectify this problem. thanks !
i am using jdk 1.2.
 

  

Add a comment to this suggestion

 

Home