Henry Huang said:
course from stanford university on itunes u.
Some weeks ago, I also posted these comments here:
Message-ID: <
[email protected]>
I decided to watch lecture videos from the Stanford
University about »programming methodology«, which actually
teach Java.
I was somewhat surprised that the lectures of the renowned
Stanford university do not have such a high overall
quality at all.
For example, the lecturer (
http://en.wikipedia.org/wiki/Meh
r*n_S*h*mi, where *=a) wrote on the blackboard
»off by one error«,
but what he meant clearly was an
»off-by-one error«.
. Regarding Java, he explained the import statement as if
this was required to make a class »available«, while it does
nothing more than to provide a simple name for a class
instead of its fully qualified name. (To make a class
available, the »-cp« option of java(c) is used.)
He also explained that Java programs were linked by creating
a JAR archive for them. (While in fact the creation of a JAR
archive is not necessary and the linking [that is, replacing
symbolic references by their referents] takes place when the
classes are loaded by the JVM, independently of whether they
come from class files or JAR files.)
But I have watched only the first lectures so far.
Message-ID: <
[email protected]>
I just watched another lecture and noticed the following:
He said something to the effect that the type »int« was there
to store an int value. I would say that an int /variable/ is
there to store a value, while the /type/ int can also be the
type of an expression (like »2«) that is not necessarily
stored anywhere at run-time.
He said that a variable had a name. This is not always true
in Java (he referred to Java, since he is exclusively using
Java). In Java there also are anonymous variables, like the
variables of an array.
He said that the remainder operator »%« can only be applied
to integers. This also is not true in Java IIRC.
Message-ID: <
[email protected]>
Sven Köhler said:
To be honest, the notion "anonymous vairable" is really not necessary to
understand how arrays work - and to be honest, your posting is the first
time I read that term.
The JLS, while being technical, actually sometimes is quite
easy to read:
One can open the table of contents, spot chapter »10. Arrays«,
and immediately read near the very beginning of that chapter:
»An array object contains a number of variables.« (JLS7 10)
»The variables contained in an array have no names« (JLS7 10)
The expression »new int[ 3 ]« has as its value an array of three
variables, but neither this object nor those variables have
a name.
I know that you are particular precise about thing, but I'm pretty sure,
he will teach that arrays have elements.
»These variables are called the components of the array.« (JLS7 10)
Message-ID: <
[email protected]>
Well, I hope you are not annoyed yet. But I just spotted the
first major software-methodology error! He explained the
scope of a variable as the lifetime of the variable. It was
even displayed as text: »Scope: lifetime of variable«. This
really hurts!
For those of you, who have not yet learned the distinction
(untested code ahead), after:
class Object
{ /* begin of scope of i */
final int i; public Object( final int i ){ this.i = i; }
/* end of scope of i */ }
and then in »main«:
{ { final Object o = new Object( 4 );
java.lang.System.out.println( o ); }
{ final Object o = new Object( 7 );
java.lang.System.out.println( o ); }}
, after execution, there were two instances of »i« (with
values 4 and 7) that had the same scope (as identifiers),
but different lifetimes (as variables), and two instances of
»o« which indeed have different scopes (as identifiers).
A scope is a region of the source text. Identifiers
have a scope.
A lifetime is a period of time during the execution
of a program. Variables and objects have lifetimes.
This has no special relation with Java, this is
software engineering (or »programming methodology«).