Computer Science 225
Advanced Programming
Spring 2017, Siena College
Lecture 3: Classes
Date: Friday, January 27, 2017
Agenda
- Announcements
- If your group has not yet completed Lab 1, you have until
start of your lab period on Wednesday to wrap it up
- Next readings: Horstmann Chapter 8
- Reminder about phones and tablets in class
- Discussion of Homework Project 1: Chutes and Ladders simulation
(details in Blackboard), due in a week
- Kinds of errors
- A little more of: some Java you know and some Java you probably do not
- Conditionals: ternary operator
- Control structures: if-then[-else], switch, while, do-while, for, enhanced for, iterators, return, break, continue
- Classes
- All Java code (variables and methods) is stored in classes
(note interfaces and enums do not have actual code)
- Support for data encapsuation and information hiding
- a simple example: a tree node
- class variables and methods vs. instance variables and methods (what's up with static?)
- constructors
- destruction - handled by garbage collection
- reference variables
- access control modifiers: public, protected,
private, and default (package level)
- another simple example: a coordinate pair
- A design tool: Unified Modeling Language (UML) class diagrams
- three sections in a rectangle for each class:
- top: class name
- middle: data members/attributes
- bottom: operations
- include access control information: public:
+
,
protected: #
, private: -
, and default:
~
- include static information
Terminology
- order of operations
- associativity
- ternary operator
- enumerated types
- data encapsulation
- information hiding
- class members vs. instance members
- constructors
- reference variables
- access control
- UML class diagram
Links
Examples