Lecture 1 Slides

Download Report

Transcript Lecture 1 Slides

CSCI E-70
Java for Graphical User Applications
02 February 2005
Instructor: Daniel Bromberg, Mitsubishi Electric Research Labs
[email protected]
Teaching Fellow: Pat Greninger
[email protected]
CSCI E-70 Lecture 1 / Bromberg
1 of 16
Welcome to E-70!
• Extend Java skills to rich, vast client-side libraries
– the java.awt and javax.swing package families
• Apply skills with generic libraries
– java.util.Collection et. al, java.net, java.lang, ...
• Improve programming fluency
– Apply data structures to solve cool problems
– Learn more Object-oriented design, techniques
– Refine Java language knowledge: syntax, idioms, limitations
• Learn the multi-threaded, event-driven, framework-based,
model/view way of life
• Make programs ordinary people can actually use
• Think hard, code a lot, have fun
CSCI E-70 Lecture 1 / Bromberg
2 of 16
Course Layout
• Lectures
– Every Wednesday from Feb. 02 to May 18 excl. holidays
• Science Center 101B, 5:30-7:30 PM
• 5 minute break at the hour
– Primarily presentation and demonstrations by Instructor
• Theory, example, motivate, guide to important study points
• Present homeworks, projects, tests; outline requirements
• Announce changes in policy, schedule
– Questions and discussions as needed
• Section
– Tentative After lecture, 7:45-8:45 PM, 53 Church St. Rm. 203
– Led by your Teaching Fellow: Pat
– Largely driven by student questions and needs
• Help us know ahead of time what to focus on!
CSCI E-70 Lecture 1 / Bromberg
3 of 16
Resources
• Web Site
– http://www.fas.harvard.edu/~libe70/current
• Check constantly for policy updates, materials
– Please read entire syllabus page now – many important details
• Ultimate Bulletin Board
– For any technical question/discussion – be an active contributor!
– Moderated by staff – both TF and I contribute
• E-mail libe70@fas (or just TF if you prefer) with
private questions, grading issues
• Attend office hours
– TF may establish regular hours
– Office hours with instructor by appointment
• Come to us one way or another; don’t sink or disappear
CSCI E-70 Lecture 1 / Bromberg
4 of 16
Workload
• 1st half: 3-4 problem sets: 40%
– Exercises, short programs, practice project
• Mid-game summary: Midterm Exam: 15%
– Keep you on-target; gauge individual mastery
– root out technical weaknesses before final project
• SPRING BREAK!
• 2nd half: The Final Project (approx. 5 weeks) 45%
– 3 stages (progressive stages)
• Proposal (2-3 pages)
• Design charts & Class skeletons (5-8 pages)
• Final package (code + documentation, 15-30 pages)
CSCI E-70 Lecture 1 / Bromberg
5 of 16
Books & References
Required:
Graphic Java 2, Volume 2: Swing (3rd Edition)
by David M. Geary: Prentice Hall PTR; ISBN: 0130796670;
3rd edition (March 12, 1999)
Recommended:
Swing, Second Edition
by Matthew Robinson, Pavel Vorobiev: Manning Publications
Company; ISBN: 193011088X; (February 1, 2003)
Java 2D Graphics
by Jonathan Knudsen: O’Reilly &Associates; ISBN:
1565924843; Paperback (May 1999)
(Especially if you think final project will involve drawing)
Others: see “recommended reading” handout
Topley: Advanced text & document formatting
Zukowswi: Extra JBuilder practice
Robinson et al.: Practical GUImiddleware
Lewis et al.: Multithreaded applications
CSCI E-70 Lecture 1 / Bromberg
6 of 16
Prerequisites
• Have used a computer and know how you want it to work
• no GUI-driven programming experience needed
• Data Structures experience: beyond int x; float y; ...
– one-dimensional arrays and loops should be “old hat”
– understand tables, trees, and graphs in order to apply them
• Encouraged to use library classes: java.util.Collection et al.
• Java/OO experience: beyond one big main()...
– Declaring base classes, derived classes
• Polymorphism (just another Big Word?)
– Reference semantics of objects, copy semantics of primitives
• Passing an Object as a parameter sends a reference to receiver
– Notion of “incomplete” classes
• pure functional: interfaces
• mixed implementation/functional: abstract classes
– Don’t panic – we’re here to practice all of this!
CSCI E-70 Lecture 1 / Bromberg
7 of 16
Submitting Work
• Use the ‘submit’ facility on Harvard Unix system
– workstation, fas.harvard.edu, ice.harvard.edu
– NO other method will be accepted! (no paper)
– man submit(1): see examples; course is cscie70
• Late penalty of 5% per day including weekends
– However: 8 free late days. Entirely self-budgeted.
– Intended for occasional “soft” extension – water pipe burst – kid
threw up on homework – got sick – snow storm – disk crashed
• It will happen
• MAKE BACKUPS EVERY DAY PLEASE!
– Any other extension only for documented medical emergencies
• Deadlines fall on Friday just before midnight
– Gives you time to mull over Wednesday’s section
CSCI E-70 Lecture 1 / Bromberg
8 of 16
Getting Started with Development
• In two weeks, be able to
– Edit, compile, test Java/Swing programs in JBuilder
– JBuilder will be installed in 53 Church St. labs
– JBuilder 2005 Foundation is free download
• Establish work environment now
– at Harvard, work, home, laptop, or combination
– See HASCS guide off of www.fas.harvard.edu
• Will distribute free CD next week
– Online AWT book, JDK 1.5 JavaDoc, JBuilder 2005,
readings, code
Stop for Questions
CSCI E-70 Lecture 1 / Bromberg
9 of 16
Submission Standards
• Clean code
–
–
–
–
Header comments: name, date, purpose, implementation notes
Thoughtfully chosen variable, constant, and class names
Consistent indentation and spacing style
Comments describing inputs, outputs, errors, and “side effects” of
every major function
• Evidence of testing
– Show graceful error handling & non-trivial, valid inputs
• Often means 2-3 well-chosen screendumps of a GUI in action
• Accompanying documentation as requested
– Projects: UML diagram, user manual, architectural overview...
• Standards will become stricter as we introduce formalisms
– Try your best for now; focus on clean code
CSCI E-70 Lecture 1 / Bromberg
10 of 16
Java: my take
• Best widely available OO language I know of
– Far from perfect
• too “safe”? bounds checking slows performance
• too compromised by C legacy? primitive vs. object dichotomy
• Sun/Micro$oft clashes
– Court battles largely resolved: Windows out of Java biz
– But C# is an up-and-comer? Will .NET dominate?
• Industry battles: What can a developer do?
– Java not independently standardized (like C)
• May not last forever
• As a developer, be flexible and switch when the time comes
– Learn good Object Oriented programming
• applicable from C through Python and beyond!
CSCI E-70 Lecture 1 / Bromberg
11 of 16
IDEs and APIs: My take
• Vast quantity of code already developed
– We are integration specialists, not hand-GUI coders
– Apply powerful patterns to:
• attack huge APIs
• manage hundreds or thousands of objects used in a program
• Glue Swing objects, rendering instructions, and application
logic together with solid, thread-aware infrastructure
• IDEs are like reference materials for writing
– wonderful time-saver but only a tool
• Equivalent to dictionary, encyclopedia, thesaurus…
– Advertising implies drag-and-drop all that’s needed
• IDEs won’t sense underlying visual/design patterns you need
• Must still hand-code highly customized visual components
• Integration to app. data models, other layers up to you
CSCI E-70 Lecture 1 / Bromberg
12 of 16
Let’s Swing!
• AWT/Swing libaries are a monstrous hairy beast
– Fear not for ye shall wrestle them to the ground
• Explain architecture on-demand for now
– Get your feet wet
– Tie code to visuals
• Let’s put up a window
–
–
–
–
–
–
import: the GUI packages
JFrame et al.: “Heavyweight” objects
contentPane: access to body area
BorderLayout: basic component layout manager
JButton: interactive control
ActionListener / ActionEvent: event handling
CSCI E-70 Lecture 1 / Bromberg
13 of 16
start
Visual States
standard windows
decoration & titlebar;
inside controlled by pure
Java renderers
pressed inside button
highlights
released outside
un-highlights
• Note dotted outline; means
component has focus
• can use space bar to fire
• more on focus later
resizable unless specified
otherwise. centered component
grows to fill bounds
pressed inside
highlights
released outside
un-highlights
released inside
un-highlights; msgs printed
CSCI E-70 Lecture 1 / Bromberg
14 of 16
State Machines
a
• In essence
– Encapsulation of program’s execution thus far
• Only what you need to react correctly to future events
b
– Theoretical basis of the “data models” I will be
rambling about
• Big Stuff
– Underlies Computer Science and Computer
Engineering at all levels: logic chips to servlets
• Practical and efficient once discipline learned
– Ideally suited for processing unpredictable input over
long periods
– Puts things “in the computer’s language” -- solidifies
fluffy ideas into discrete transitions
CSCI E-70 Lecture 1 / Bromberg
15 of 16
Follow-up
Review and additional detail:
http://java.sun.com/docs/books/tutorial/uiswing/14start/index.html
Problem Set 1:
• Student Survey
• Programming
–
–
–
–
–
–
due at end of class
due Friday Feb 18 23:59:59.999...
Install JBuilder 2005/J2SE SDK v1.5
Make program modifications
Turn in screen dumps, code listing
Turn in modified state diagram
Answer questions to exercises
submit(1) package to cscie70 account on FAS Unix system
You’ve got questions? We’ve
got homework.
CSCI E-70 Lecture 1 / Bromberg
16 of 16