-
Title:
Objects Demo - Intro to Java Programming
-
Description:
-
Here we hear from BlueJ. And it would really good idea if you fire up your own
-
BlueJ and move to lesson two days as your project. When you open it, you will
-
see the screen with a Day block here. And this is what gives us objects. Let me
-
show you how to make an object. You right-click on it, and you select the line
-
that says New Day. You can now give it a name. For right now, we'll accept the
-
default. Down here, you'll find your first object. This is how BlueJ represents
-
objects. As little blobs, it's a little-known fact that all objects are red.
-
And to manipulate an object, you again, right-click on it. You can ask it to
-
get the current year. Here's the answer. This particular day is somewhere in
-
2013. See when, the month is March, 3, the day of the month, is the 20th.
-
That's the day that I recorded this lesson. We can make another day object. And
-
now, let's pick, the first line here. Now, we ask which year month and day we
-
might actually want. Let's fill in something. Then, we'll pick a year of 1964.
-
The month of 11 or November, and the day of 28, as I'm sure everyone remembers,
-
on November 28th, 1964, the first spaceship was, to Mars, was launched. Now
-
here, we have another day object. It looks just like the first one. It has a
-
different name. But if we wanted to find out anything about it, so we can in
-
the same way ask it what's your year, and here it tells us. Now, let's do
-
something more interesting. Let's take our first object here and let's ask it
-
what day comes a hundred days later. Now, it doesn't look like it, but this
-
object now has changed. It has moved itself a hundred days later. Remember, it
-
was originally March 20th. Now, when we ask it what's your month, you'll see
-
it's June. That makes sense, from March, 100 days is June, or maybe it would be
-
July. Somehow, this thing knows how to do this computation. How about the day?
-
It's June 28th. I wouldn't have known how to do that. Except by tediously
-
getting out a calendar and counting the days, but our day object knows. How
-
does it know? I don't know, and I don't care. It doesn't matter. I can use it,
-
as long as I understand what it does for me. So, that's a great example of an
-
object. Something that knows how to do a very specific thing, namely to deal
-
with calendars, just like the water heater knows how to do very specific thing,
-
namely to heat water.