CSC153, Class 29: An Introduction to Java Overview: * Object-oriented programming Notes: * Read lab J2 for tomorrow. * I went to an interesting conference. I'll describe a problem another computer scientist at that conference told me about. (The problem has nothing to do with the focus of the conference, but it's fun anyway.) * Warning: I wrote our Java stuff five years ago. Java has changed. So have some of my opinions on how best to teach this stuff. * Today is mostly lecture, little lab. * Are there questions on exam 2? Do I need to rewrite type preconditions? No How should I document Curried procedures? Just like they're normal proceduresa Should I document my helper procedures? At least a little for every one. Internal helpers only need a sentence or two. External helpers need six P's. Discussion of various questions Bring more questions tomorrow. ---------------------------------------- Java is an "Object Oriented" language What does it mean to be object-oriented? * Basic unit of the language is "the object" * What is an object? A collection of values and things you can do with those values E.g., a book Values: Number of pages: 334 Author(s): Ken Arnold and James Gosling Title: The Java Programming Language Contents: ... Adjectives: ... ISBN: ... Many more ... Capabilities: read, given a reader burn, given a match openTo(pagenumber) getIndex returns an index that supports lookupPageNumber(topic) Note: Be careful on your abstractions so that they can handle appropraite concrete thingys. * What else goes in an object-oriented language? * Procedures? Not in a pure OO language. * Classes abstract commonalities between objects Every book has author, title, ... Every book can do x, y, and z ... A lot like a higher-order procedure: Can be used with many things that take the same form. * What else goes in an object-oriented language? (other than objects and classes) * Inheritance: You can define new classes based on existing classes. + E.g., a library book is a book + Add values (attributes, fields) + Change 'em + Change capabilities + Add capabilities * Polymorphism: Many forms One procedure can act on many different types of data * Encapsulation You can know *what* an object/class does, but not *how*. Object-oriented programming is the embodiment of two key strands of ancient Greek philosophy * Plato: Everything (object) is an instantaition of a an ideal class. * Aristotle: Hierarchical categorization of nature Inheritance