Introduction to Programming Using Java

K

k.vidura

Checkout this link,

http://www.viduranet.com/bookstore/index.php


Introduction to Programming Using Java is a free, on-line textbook. It
is suitable for use in an introductory programming course and for
people who are trying to learn programming on their own. There is
probably enough material for a full year College programming course.
There are no prerequisites beyond a general familiarity with the ideas
of computers and programs.
 
R

Rhino

Checkout this link,

http://www.viduranet.com/bookstore/index.php


Introduction to Programming Using Java is a free, on-line textbook. It
is suitable for use in an introductory programming course and for
people who are trying to learn programming on their own. There is
probably enough material for a full year College programming course.
There are no prerequisites beyond a general familiarity with the ideas
of computers and programs.
I took a brief look at "Section 2.1 The Basic Java Application" in your
course and was very disappointed to see you frequently and consistently use
the term "subroutine" in referring to Java methods.

It's all very well to explain that a method is similar in concept to a
subroutine for the sake of readers who are familiar with the latter term but
not the former but it is a very bad practice, in my opinion, to consistently
use the wrong term and _not even introduce the correct term_. I've just
skimmed the next few sections and you are STILL using the word subroutine
exclusively. I have not even _seen_ the correct word, method, yet and I've
gone through all of Chapter 2.

That's a shame; the rest of what you've done seems reasonably good. Mind
you, I have only skimmed it and may be missing other problems.

I would strongly suggest that you rework your use of "subroutine" and use
"method" instead. Your students will inevitably get confused if you use
terms different from what they encounter in the real world, like this
newsgroup.

Also, two other small but fixable annoyances:
- I think most people would find it more intuitive to have the "previous
chapter" navigation link to the _left_ of the "next chapter" link, not to
the right. Also, I think you should consider imitating the Java Tutorial and
put the navigation links at the top _and_ the bottom of each topic. That is
more convenient for people trying to page ahead several pages quickly.
- I get a "the page cannot be" in the top right hand corner of each page, to
the right of the animated gif of the dog. That's annoying because I don't
know what should be there. (I'm not sure why the animated gif is there
either; perhaps it's just to liven up the page or make it feel 'fun'. Some
people would call that unprofessional in learning materials but I can live
with it.)
 
O

Oliver Wong

- I get a "the page cannot be" in the top right hand corner of each page,
to the right of the animated gif of the dog. That's annoying because I
don't know what should be there. (I'm not sure why the animated gif is
there either; perhaps it's just to liven up the page or make it feel
'fun'. Some people would call that unprofessional in learning materials
but I can live with it.)

The stuff in the top right corner are advertisements. Perhaps you have
some software blocking requests from IP where the ads are originating from
(perhaps because it is a known source of spam or spyware?). Either way,
you're not missing much.

- Oliver
 
P

Patricia Shanahan

Rhino said:
I took a brief look at "Section 2.1 The Basic Java Application" in your
course and was very disappointed to see you frequently and consistently use
the term "subroutine" in referring to Java methods.

I agree with Rhino's comments, and have a similar problem with the use
of "real number" to refer to one or both of the floating point types, as in:

"For example, to compute 37.4 + 10, the computer will convert the
integer 10 to a real number 10.0 and will then compute 37.4 + 10.0."
[Section 2.5]

Each of float and double represents a subset of the rationals, plus
infinities and not-a-numbers that do not correspond to any real numbers.
Floating point arithmetic has its own rules, and often gives different
answers from real arithmetic. For example, real addition is associative.
Floating point addition isn't.

The Java Language Specification uses "float" or "double" when talking
about only one of them, and "floating point" when talking about the
things float and double have in common.

Given the amount of care and work that obviously went into the book, I
have to assume the choice of terminology was deliberate, but I don't
understand it.

Patricia
 
P

Patricia Shanahan

Checkout this link,

http://www.viduranet.com/bookstore/index.php


Introduction to Programming Using Java is a free, on-line textbook. It
is suitable for use in an introductory programming course and for
people who are trying to learn programming on their own. There is
probably enough material for a full year College programming course.
There are no prerequisites beyond a general familiarity with the ideas
of computers and programs.

I've found quite a basic problem in the suggested solution to
Programming Exercise 2.4, the program CountChange at
http://www.viduranet.com/bookstore/javab1/c2/ex-2-4-answer.html

Here is the output from running it, with completely reasonable input:

Enter the number of quarters: 2
Enter the number of dimes: 3
Enter the number of nickels: 5
Enter the number of pennies: 10

The total in dollars is $1.1500000000000001

The program uses double for currency calculations with no precautions
against rounding errors appearing in the output. The discussion of the
exercise solution does not give any warnings about the dangers of
applying binary floating point to currency.

The problem could, of course, have been avoided by working in int or
long cents, or by using BigDecimal. Given the assumption that the
amount of money is pocket change, it could even have been avoided by
using double but formatting the output to show only two decimal places.

Incidentally, it would be helpful to have a search facility, or an index
as distinct from a table of contents. I would have liked to have
searched for "rounding" to see whether rounding errors are mentioned
anywhere.

Patricia
 
P

Patricia Shanahan

Patricia said:
I've found quite a basic problem in the suggested solution to
Programming Exercise 2.4, the program CountChange at
http://www.viduranet.com/bookstore/javab1/c2/ex-2-4-answer.html

Here is the output from running it, with completely reasonable input:

Enter the number of quarters: 2
Enter the number of dimes: 3
Enter the number of nickels: 5
Enter the number of pennies: 10

The total in dollars is $1.1500000000000001

I've since discovered that the author is aware of the floating point
rounding error issue, so it is a matter of failing to apply the knowledge
to the sample solution:

"For real numbers, there is the added complication that most real
numbers can only be represented approximately on a computer. A real
number can have an infinite number of digits after the decimal point. A
value of type double is only accurate to about 15 digits."

[Section 9.1, http://www.viduranet.com/bookstore/javab1/c9/s1.html]

Unfortunately, the paragraph before contains an incorrect statement
about floating point in Java:

"For example, the result of dividing by zero or taking the square root
of a negative number is Double.NaN."

Division of zero by zero does result in a NaN. Division of a finite
non-zero number by zero results in an infinity:

public class BadDivision {
public static void main(String[] args) {
System.out.println("0.0/0.0="+0.0/0.0);
System.out.println("1.0/0.0="+1.0/0.0);
}
}

prints:

0.0/0.0=NaN
1.0/0.0=Infinity

I've only looked at some floating point issues, and that area of the
book definitely needs some fact checking. I don't know whether the
author has a special problem with floating point - many programmers do -
or whether there is a similar need for checking in the rest of the book.

Patricia
 
O

Oliver Wong

Patricia Shanahan said:
Incidentally, it would be helpful to have a search facility, or an index
as distinct from a table of contents. I would have liked to have
searched for "rounding" to see whether rounding errors are mentioned
anywhere.

It has come to my attention that this online textbook seems to be a
plagiarism. The original version seems to be located at
http://math.hws.edu/javanotes/ (which incidentally DOES have a search
facility).

The book is available for free under the GNU Free Documentation license.
This license states:

<quote>
You may copy and distribute a Modified Version of the Document [...]
provided that you release the Modified Version under precisely this License
[...] In addition, you must do these things in the Modified Version:

A. Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions (which
should, if there were any, be listed in the History section of the
Document). You may use the same title as a previous version if the original
publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified Version,
together with at least five of the principal authors of the Document (all of
its principal authors, if it has less than five).
[...]
D. Preserve all the copyright notices of the Document.
[...]
F. Include, immediately after the copyright notices, a license notice giving
the public permission to use the Modified Version under the terms of this
License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections and
required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section entitled "History", and its title, and add to it an
item stating at least the title, year, new authors, and publisher of the
Modified Version as given on the Title Page. If there is no section
entitled "History" in the Document, create one stating the title, year,
authors, and publisher of the Document as given on its Title Page, then add
an item describing the Modified Version as stated in the previous sentence.
</quote>

I've only bothered to quote the restrictions that the
copied-and-modified version violated.

I'm also forwarding a copy of this message to the original author.

- Oliver
 
C

Chris Smith

Patricia Shanahan said:
I've only looked at some floating point issues, and that area of the
book definitely needs some fact checking. I don't know whether the
author has a special problem with floating point - many programmers do -
or whether there is a similar need for checking in the rest of the book.

Hmm. I have a bit of a clue, after glancing through briefly. For
example:

Section 2.3:
Values of type String are objects.

Section 2.5:
x -= y; // same as: x = x - y;

Section 3.6:
break statement (found in loops and switch statements only)

Section 4.7:
When a variable declaration is executed, memory is allocated for the
variable.

Section 5.2:
If you don't provide any initial value for an instance variable, a
default initial value is provided automatically.

Section 5.5:
[Header] The Special Variables this and super
Java provides a special, predefined variable named "this"
Java also defines another special variable, named "super"
It [invoking superclass c'tor] involves the special variable, super

Section 5.6:
In Java, a nested class or inner class is any class whose definition
is inside the definition of another class. [equating the two terms]

Like any other item in a class, a named inner class can be either
static or non-static.

Section 9.3:
[Diagram claiming that Throwable is an unchecked exception type.]

Section 10.1:
For people who use Western alphabets, character data is generally
stored in files in ASCII code, which uses only 8 bits per character.

The Reader and Writer classes take care of this translation [between
byte and char]...

Section 12.1:
Java 1.5 introduces templates that are similar to C++ class
templates.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Uppal

Chris said:
Section 2.3:
Values of type String are objects.

What are you objecting to here ? Are you taking the word "value" to imply
something other than an object (i.e. a primitive type in Java). Or do you
dislike using the word "type" for an object rather than a reference ?

Section 2.5:
x -= y; // same as: x = x - y;

What's wrong with this ? Are you taking "x" to be a meta-variable ranging over
expressions which might have side-effects ?

Section 4.7:
When a variable declaration is executed, memory is allocated for the
variable.

Are you claiming that an implementations which did exactly that would be
non-conforming ? (Taking "variable" here to exclude fields -- which may not be
a legitimate interpretation).

Section 5.2:
If you don't provide any initial value for an instance variable, a
default initial value is provided automatically.

The only thing I can see wrong with this is that the default initial value is
provided automatically even if you /do/ provide an initial value.

These all seem to me to be quite reasonable approximations for an introductory
text to make. I don't see how a more correct presentation could also be as
clear. (The same doesn't apply to your other sample observations which I've
elided).

-- chris
 
C

Chris Smith

Chris Uppal said:
What are you objecting to here ? Are you taking the word "value" to imply
something other than an object (i.e. a primitive type in Java). Or do you
dislike using the word "type" for an object rather than a reference ?

You seem to have read this differently from I. Had I read it with your
interpretation, then I would have objected to exactly those things: use
of "value" to mean "object", and use of "type" to mean "class".
However, I actually read it differently. I took the text at face value
when it talked about values of types. I would have corrected it to
read:

Values of type String are references to objects.
What's wrong with this ? Are you taking "x" to be a meta-variable ranging over
expressions which might have side-effects ?

It's equivalent to:

x = (T) (x - y);

where T is the type of X. Only if x is at least as "large" a type as y
defined in terms of range, and if that type of x is not byte or short or
char, is this actually equivalent to the original expression.

Perhaps it's just because this definition of the operator seems so
surprising that I think it's important to point it out, rather than
shoving that detail under the rug.
Are you claiming that an implementations which did exactly that would be
non-conforming ?

No, but I think it's misleading to make such an absolute statement.
The only thing I can see wrong with this is that the default initial value is
provided automatically even if you /do/ provide an initial value.

Yes, that's my complaint. Given that there are circumstances (which I
don't see the book warning against) in which it is possible to observe
that default initial value, I don't think it's unreasonable to expect
the book to at least provide a correct statement, even if it's not a
very helpful one. It certainly wouldn't be any less clear to say that
all fields are initialized to a default value of 0, false, or null, and
then any initializer expressions change those default values as part of
the object initialization.
These all seem to me to be quite reasonable approximations for an introductory
text to make.

Granted, there's nothing on my list quite so bad as claiming that
dividing any floating-point number by zero yields NaN... but I think the
book still shows a very broad lack of careful technical editing
throughout.

I will say that it's FAR from the worst Java book I've seen.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roger Dodger

While this book may have several errors, I highly recommend it. I
basically learned Java using this book (at least the one by the
original author, David Eck). Code examples are complete programs. It
supplies a great reader class for text file and keyboard input. It
does a good job of explaining a number of data structures. All of the
nitpicky stuff mentioned above would be discovered in documentation
when a (good) programmer investigates his errors. As for the use of
"subroutine" instead of method, since I learned other languages before,
I immediately understood the concept of the subroutine, and since this
was not the only Java book I read, I knew exactly what he was getting
at.

By the way, it can also be found at
http://www.faqs.org/docs/javap/index.html
 
C

Chris Smith

Roger Dodger said:
While this book may have several errors, I highly recommend it.

I am certainly not saying it is a bad book. I've certainly seen worse,
even just from an accuracy standpoint. Nevertheless, it makes sense to
accompany a recommendation to read the book with a warning about the
many errors that it contains. I certainly wouldn't classify all of them
as nitpicky (though certainly some are a little technical). Regardless
of whether this is a good book or not, someone reading it ought to know
that these are errors.
All of the nitpicky stuff mentioned above would be discovered in
documentation when a (good) programmer investigates his errors.

The question, for me, is how much poor code will be written before then.
If some of that poor code uses double for monetary calculations in an
inappropriate way, for example, then I would be rather worried.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top