Lecture 8 | Programming Methodology (Stanford)
ฝัง
- เผยแพร่เมื่อ 28 มิ.ย. 2024
- Lecture by Professor Mehran Sahami for the Stanford Computer Science Department (CS106A). Professor Sahami reviews what he covered on methods and functions and then goes into more detail.
CS106A is an Introduction to the engineering of computer applications emphasizing modern software engineering principles: object-oriented design, decomposition, encapsulation, abstraction, and testing. Uses the Java programming language. Emphasis is on good programming style and the built-in facilities of the Java language.
Complete Playlist for the Course:
th-cam.com/users/view_play_list...
CS106A at Stanford Unversity:
www.stanford.edu/class/cs106a/
Stanford Center for Professional Development:
scpd.stanford.edu/
Stanford University:
www.stanford.edu
Stanford University Channel on TH-cam:
/ stanford
00:23 Information Hiding
04:41 The Void Return Type
05:48 Parameter Passing Between Methods
14:24 Bad Times With Methods
20:54 Using Classes
24:55 Instance Variables Vs Local Variables
31:31 The RandomGenerator Program Example
36:23 The RollDice Program Example
42:33 The SetSeed() Method
where do I get these assignments? And will I become a real programmer if I continue this course? Please help.
I don't know guys, the things he talks about seem a lot easier than the things written in Eric Roberts' book. Especially those programming tasks by the end of each chapter.
Anyway, a great professor and I am really thankful that this thing exists online.
The material is way too easy as I already have some programming experience but I just can`t stop watching... Well done, Professor Mehran Sahami!
Topics: Information Hiding, The Void Return Type, Parameter Passing Between Methods, Bad Times with Methods, Using Classes, Instance variables vs Local Variables, The RandomGenerator Program Example, The RollDice Program Example, The setSeed() Method.
Professor Mehran Sahami is amazing, he should do these lectures in a superman costume (complete with cape) that's how good he is.
I lecture Java myself, but it's really a pleasure to watch this course.
Rock on! :)
LMAO @ the toast example for Information Hiding and the Mona Lisa example for method calls. Mehran is such an awesome professor,. =)
Ok. I know all this stuff for like few years. I can't stop watching him anyway. Its like opposite of most of my lecturers. I dont know anything they teach me and still I prefer learn from book.
He's just brilliant.
dammit, my toaster is giving me random numbers.
these lectures are incredible i think i will direct anyone to these when they ask me about learning to code
this guy is my favorite teacher! anyways wish this was in higher res... sometimes little bit hard to read the code but use your imagination and it kinda makes sense.
lecture 8 amazing stuff..
good times :P
every time he says "I'll see you next week " Im like " Not for me , I'll see you again tomorow :D "
Love these lectures its such a good work !!
I totally love the do da do's
I'm thoroughly enjoying this lecture series, I also have 3 Java books as well as the Java for dummies 5th edition.
Been pouring myself into Java for last month and half. This series as a companion to the books and practicing is soo wonderful. Major thank you to Stanford and to Professor Mehran
:)
Isn't just " RandomGenerator rGen = new RandomGenerator();" enough for creation of object?
1.Does the function RandomGenerator.getInstance() contains the same piece of code?
2.What is the difference between "new class()" and "class.getInstance()"
I'm wondering why none of the students asked this question. :/
Incredible. ROCK ON!
Great stuff!!
that analogy with his mona lisa story was superb, some of the best teaching and trying to make students understand concepts i have EVER seen! :D Mehran, now i want to go to Standford and take CS106A just to meet you!
@donkeyq It's because you have to use their version of eclipse that has some things predefined like the run() method. If you don't want to you can use a public void main(String[] args) that will do the same thing.
Don't worry that you're learning the ACM library while you're learning Java because you're STILL LEARNING JAVA. As you gain experience, one thing you'll realize about software engineering, especially when you get to higher levels, is that YOU WILL ALWAYS BE LEVERAGING NEW LIBRARIES. You might not be using ACM later on but that's beside the point. The faster you embrace the fact that you'll always be learning and leveraging something new, the faster you'll be able to level up.
Thank you..
Cool! I like your way to teach about Programming Methodology. This is a hard topic to attract student to listen the subject. However, you can do. Please publish more lectures as you can!
I wish i could go to stanford :[
@TheMrRobdawg I believe in his programming assignments, the classes are set up so that certain things are already imported, so typing "System.out" is no long a hassle. Similar case : readInt(), where you have to import a Scanner from the java library to be able to receive input from a client.
"doot tadoo..."
nice classes, is there an hd version of these?
to use the acm stuff, do i put the acm.jar file in my workspace (on eclipse)?
probably the best teacher there is :)
one question: is it ok to learn java with that ACM library ? i shouldn`t learn java more generally? this feels like i learn one library(acm), not one language(java).
It is just training wheels. Like learning Karel.
They're probably using an additional library (ACM Library) and it is not the standard way to output strings which the way you've learned already.
You're welcome.
Are the local variables declared in methods still taking up memory space or is their space reallocated after the methods life?
if Eclipse is crashing regularly, i recommend going to preferences and checking for updates. it has saved me a lot of time and frustration, Eclipse has not crashed once since updating to 3.2 ( the stanford plugins still work! )
Really good lecture. :) One small issue though: on the add 5 code, x is never assigned the value returned from the AddFive method. So the value of x returned will always be 3 even if a return statement is used in the AddFive method.
so when he put return, he was passing the value of x from one method to the value of x to another?
11:27 "The only thing that remains of you is the value you returned."
i glance over all the ACM library related exercises in the text in general but the problem is they like to use it also when demonstrating pretty important ideas... oh well
ROCK ON MAN!! :)
on his dice program where he determines the maxrolls, why didnt he make it so the loop kept going while the number on the die wasnt the maxroll, instead of making the loop true?
From 2021
thanks
23:30 Is there a difference between why/when ‘new’ is used to construct a new object of a class vs. having to use getInstance() instead? Is it just an implementation specific thing.
Has anybody tried the SimpleRandom program. I get five with any seed :S
I suposse Mehran will talk about that in the next lesson.
You rock Mehran!
you should use only few global variables
but in PHP its also a little bit different and not as critical
I was familiar with Random myRandom = new Random();
Is his way (getInstance) a different way, specific to acm library?
DONE!
That toaster analogy is awesome
27:20 that vis became vision
knowledge
there is, but unfortunately the site they have in the description only has the assignments and code up to lecture 5. :/ unless they have it somewhere else, i'll have to keep pausing the video again and again to try to do it myself.
Just to clarify something, Say I write something like:
ClassName instanceVariable = new ClassName();
is the object the 'new Classname()' part in terms of the code? Also is the instanceVariable actually a pointer to the object and the variables it stores actually the instance variables in terms of a drawing?
you got me at the Knight Rider theme intro ;)
‘The method getInstance() is undefined for the type RandomGenerator'
My eclips showed me this.Why was that?
@pecolier
your getCandy method must return data of type chocolate!
@lawl94xD only if unScrew() on waterBottle did it like this for(i=0;i
Could someone explain to me the purpose of a random number generator that always produces the same set of numbers?
I think the purpose of setting the seed to get the same set of numbers is to make your program easier to debug. If shipping the software, remove the setSeed statement and the random generator will produce different sets of numbers
Also in video games today using seed numbers in procedurally generated games which is largely the new shiny tech in gaming thanks to Minecraft helps people to go back and get a result from before. Say in a space simulator that produces random meshes for your spaceship based on an algorithm. You can change the way your spaceship looks randomly by changing the seed number but if you decide later on that one of the randomized ship configurations you came across awhile back was sufficient, if you remember the seed number, you can go back and retrieve that result. Pseudorandom numbers are great for those types of games because while a lot of it seems very random when the gamer needs to he can replicate previous results.
@TheMrRobdawg it is
i love these lectures but for some reason, i cannot get this public void run method to work at all.
Am I missing something?
with all due respects.. i might have this wrong.. but.. 40:50 you can see that he did a break; when the num dice was equal to 18.. what is the rolling of the dice makes it go above the max num of rolls?
There is no maximum _number_ of rolls. You may be confusing "maxRoll" with "numRolls." Those variables store two entirely different pieces of information.
maxRoll is the highest number you can get with however many 6-sided dice the user requests (the math behind this is simply 6 times the number of dice).
numRolls is how many rolls it takes before maxRoll is achieved (each roll is performed by the rollDice method; if maxRoll is not achieved, the while loop in the run method adds 1 to numRolls and the rollDice method is called again; this continues indefinitely until rollDice comes up with maxRoll).
I just started learning programming and these vids help me understand a lot. I'm still a little confused about classes and objects. I understand that classes are like templates of objects, but is it fair to say that some objects can also be classes of some other objects? Like "Dogs" is the object of the "Animal" class, but it can also become a class for different breeds of dogs?
Would really appreciate if someone could clear this up for me. Thanks so much in advance
"Dogs" is an instance of the class of objects known as "Dogs". A class is the blueprint from which individual objects are created. Objects are instances of a class. You are an object, therefore, you are an instance of the "Human" class. Does that help at all or are you passed this question since it was a month ago
: D
Dogs are a subclass of animal. They extend the class mammal which in turn means they are extending animal, they are not actually an instance of the class animal. As far as the different breeds go. All the different breeds would be subclasses of the Dog class. So Rottweiler, Poodle and Labrador would all be subclasses of Dog and Dog would be their superclass. They are all subclasses of Mammal and Animal though. There's a really good illustration in the text book for this class which is called The Art and Science of Java. It has great diagrams representing class hierarchy. I highly suggest doing the reading assignments mentioned on the syllabus, and if you're truly serious, doing the review questions and programming exercises at the end of each chapter. They really help your understanding a lot more than the lectures alone. So far I haven't encountered a programming exercises that I couldn't accomplish although some made me sit there and think/experiment for quite awhile but that's what learning is all about. Programming is largely about learning through the process of doing.
I didn't get
roll dice (num dice )
@PajamaSnake same here
@Michaeltippett All OO languages are similar.
Why am I using a random generator seed that unrandomizes the randomness? Did that make sense?
He said:
there is no such thing is real random on CS.
So we have two choices.
One: use method we can't control.
Two: use other method we can control a bits.
Hi this seems an excellent programming series and quora brought me here. My question is i have started learning python and can anyone please advise whether this videos will be helpful or not, since it is around 9 yrs back.
I study programming sometimes and i have to say these lectures are the best that i have seen so far. Professor Mehran Saham explains very well and makes classes fun. He uses Java, but it should be useful at least for any object oriented programming.
thanks a lot for ur reply
Do Stanford Professors have to take a test for blackboard writing speed?
I really don't get it the way how I see the source code for the java programs he writes for each lecture it is so much different from videos that I have seen on the web. like if you want to show a text he would write "println" and this is what I see in other videos "System.out.println"
can some one please enlighten on what is happening.
45:28 with all due respect sir, the right seed number is 42. I rest my case.
i can't i will give up ...
please help
any one can give me an example for instance lives with object. .
what means it visible in entire object?
+The gamer Read and re-read handout 18... Don't give up!!!!!!!!
For some reason, don't ask me why, the acm.jar that I downloaded from Stanford (the one that comes in their assignment materials for the class), DOES NOT INCLUDE getInstance()... I had to go to the acm website (jtf dot acm dot org) to get one that does.
I've been tested seeds. It changes the result starting from 10.000 & then you have to multiply * 10 for further changes. This progression seems kind of useless but there should be a reason... I guess ... xD
EDU + FREE = HUMANITY
Hi guys! I have Eclipse Luna i imported Stanford Eclipse Plugin from here: web.stanford.edu/class/cs106a/software/
,but how get it to work? I mean how to use those utilities Mehran is talking about?
Completely different.
Sorry, I prematurely added my comment. So, the static instance variable is accessible by class name not instance name. if 'counter' is a static variable in class BankAcct, you'd use: BankAcct.counter to access it (provided it is public).
Instance variable: private String name; would be accessible by instance variable. Since it is private, you'd need accessors and mutator methods for it( i.e. getName(), setName(String name).
So. keep in mind how static variables/methods are used in Java.
this is so hectic...the book im following just doesnt match what hes teaching cuz they are using the acm library
"Toast toast = Toast.makeText(context, text, duration);" From Android Developers.
Functions are toasters - brilliant
27:40 weren't those class variables?
It depends on your POV. He is calling them instance variables because the class defines the object that is instantiated at run time, and variables associated with that object instance would be called instance variables. If you are looking at code and not thinking about when it is running, you could view them as class variables.
So that's what the whole seed thing on minecraft is about i guess :P
is he giving them candy when they ask questions?!
3ly I feel like they just started to figure it out and they want candy
It's probably a mixture of Conditioning in Psychology and also Positive Reinforcement www.britannica.com/topic/conditioning
The people in the class will A) be more engaged and learning more through asking questions and B) it makes them want to participate more in A) due to the above 2 mentions.
Don't forget to call your toaster method on Pop-Tarts and Eggo Waffles!
popTart.Toaster("CRAZY GOOD!")
eggo.Toaster("Let go my Eggo!")
well technically I guess you'd provide them as arguments for the Toaster method that would return the cooked versions and that the poptart and eggo wouldn't actually be the receivers. But then again they could be if they were instances of toaster which I guess doesn't make a whole lot of sense.
Chen@Viewed
These videos are great but I can't help imagining that the class is full of seals and the bag is full of fish!
really? you think java is completely different to C#? have you ever used C#?
Its a VERY similar language.
who's watching this in 2019 :d
Me but I’m struggling because some of the syntax has changed
Do you have any other good resources for learning java?
@@jacobzanders551 this lectures are really good and not much is changed , he's not teaching ordinary java ,he's teaching it with stanford libraries which is much easier, if you go through the whole thing it is really worth it ,im gonna do the last assignment now and continue watching c++lectues , there is really not a better source for studying programming than these lectures.
@@annakh9543 where do I get these assignments? And will I become a real programmer if I continue this course? Please help.
I will never eat a toast again
most of it is exactly the same
@Desmolas he has an infinite bag of candy :o
In Java there is no concept of Global variable. Instead it is either Class variable or Intance variable. In fact, class variables are a type of instance variables:
For example:
public static int counter = 0;
44:05 that makes you wanna KILL! :-)
system.out.print();
class was quite at the end lol
du-du-du
thats one complaint i have....
Let's say you're a method, and I'm a method. If we both have declared that myGirlfriend = Stacie, and we all had to share a room one day, that would be OK because the Stacie in my hood and the Stacie in your hood are totally different Stacies - and we're both fully aware of that. Otherwise, bad times.
LoL I sampled it!
Thumbs way up if watching this class made you wanna listen to the "The Seed 2.0 ft. Cody ChesnuTT " by The Roots. ;)
LOL!!
LOL he sounds like aziz ansari
Java In A Nutshell, 5th Edition on amazon