Lectures 1,2 and 3 – Course Overview/Using Objects/Defining Classes

I will add into this post first three courses of this series. The course focuses on Java examples to present some general concepts about data structures and object oriented concepts.

Let’s juts briefly go through the three courses and comment some of the most interesting parts.

I like at 00:37 the way he teaches his students to pronounce his name … by the way, the guy has a little bit a kind of gay attitude… during the class just look at the way he raises his hand when requesting for questions from his students. Interesting also the way in which he writes with his left hand.

A pre-requirement for this course are CS 61A & E 77N and probably it would be a good idea to go through this one also on this blog (05:37).

16:59 … the big picture, the overview of this class: Learn efficient Data structure & algorithms, Design and write large programs, Understanding & designing data abstractions & interfaces, Learn Java;

19:25 He starts to introduce the Object Oriented concepts. what is an OBJECT, what is a CLASS, what are METHODS, what is INHERITANCE, what is POLYMORPHISM >> the BIG thing that distinguishes object oriented languages from other procedural languages like C, Fortran or Pascal.

25:57 an important thing to know about object oriented languages:

Each object knows about its class

29:37 it is introduced the concept of String in Java, different with respect to other programming languages, mainly C

String myString;
myString = new String();

… two different things are accomplished by this: 1. it creates a variable called myString .2 the assignment operator causes that variable to reference a String object.

32:28 there are traced the differences between Java and Scheme, but basically any other compiled language can be a good example instead of Scheme, C or C++ for example.

Let’s go to the second course below:

A very important thing is that in those courses it is stressed the difference between a reference and the object that this points to. A reference can be changed to point anywhere, but a string is a constant object. Once declared it cannot be changed, it is read-only. (remember the discussion about character arrays and descriptors)

All the explanations about references and Strings starting from 03:22 until 12:12 are good to know: how can you make two references indicate the same String object, how can you make two references point to different objects.

Nice to hear Bjarne Stroustrup words,I mean just the second part of this phrase, at 11:25:

Java does not allow you to access random memory locations, it protects you from shooting into your foot

Between 12:09 and are presented the three ways of creating a String:
1. using the default constructor from String class, which creates an empty string; some kind of default constructor in C++
2. by hand, typing whatever you want the string to contain; some kind of parameter constructor in C++
3. by making a copy of an existing reference to a string; some kind of copy constructor in C++

An important thing to know about Java, at 16:06

you can call a constructor only via the new keyword in Java

Also interesting at 17:51 the explanations about how can you create a copy directly from a string, not by using a reference to it and the way in which the original string is lost.

Another thing to keep in mind:

A string is represented only by double quotes. Single quotes represent just one character, this has nothing to do with Java strings, they are not objects, they do not have any methods associated with them.

31:58 – the discussion about how I/O is handled in Java starts .. good to know where the notorious System.out.println comes from
other useful points: a Java program must have the name of the class that contains main, how main function is declared (it takes, quite similar to C++, an array of String’s as parameter)

interesting to know also how are read lines from the keyboard and from a web-page…

Course 3

at 3:15 you can see that in Java access modifiers are declared on the same line with the variable. It is not like in C++ where you use the notation

// variables

at 6:58 again the difference between simply declaring a reference and to make it point to an object.

9:31 you can clearly see how a String type behaves differently than a primitive type like int

15:40 – an implementation of a Java-style copy constructor

Let’s juts skip the statements about constructors and jump to 28:43 where this keyword is introduced. What is it in fact? A hidden parameter, it helps to differentiate between same methods or members belonging to different objects. How would you know which age member variable is the program referring to, is it Kayla’s or Rishi’s, this tells you that.

One rule of thumb concerning this pointer, 36:19:

You cannot change the value of “this”

37:08 static keyword in Java: as you may already know it from C++, a static variable exist in one single copy for every instances of a class – class variable, shared by the entire class and accessible via class name, even if a call via an instance is perfectly legal (it will be treated as a bad coding style)

40:31 in Java everything that is not explicitly initialized gets a default value of 0; static variables need to be initialized explicitly.

42:34 like in C++, static functions do not take by default an object as a parameter, in other words they do not have this pointer, this is why those are not considered methods or class functions.

49:00 Lifetimes of variables – it is so easy that we can skip this 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: