OOP /EBUSS Teachers: Kasper B. Graversen Uffe Kofod Tutors: Johannes Beyer Christian Stærmose.
-
date post
21-Dec-2015 -
Category
Documents
-
view
222 -
download
0
Transcript of OOP /EBUSS Teachers: Kasper B. Graversen Uffe Kofod Tutors: Johannes Beyer Christian Stærmose.
OOP /EBUSSOOP /EBUSS
Teachers:
•Kasper B. Graversen
•Uffe Kofod
Tutors:
•Johannes Beyer
•Christian Stærmose
Copyright 2001 Kasper B. Graversen
Today’s programToday’s program
• 9-11 General information on the course and introduction to OOP.
• 11-12 lunch• 12-15 Lab exercises (in room 3.17)
– Install & setup editor– Compile a working program– Compile failing programs
Copyright 2001 Kasper B. Graversen
Course materialCourse material
• Java Gently, 3rd edition by Judy Bishop
• Various tutorials (found on the course webpage)
• Assignments (found on the course webpage)
• www.it-c.dk/~kbilstedwww.it-c.dk/~kbilsted
Copyright 2001 Kasper B. Graversen
Course structure
• 12 sessions (of which this is the first)
• 900-1200 lectures
• 1300-1600 computer lab exercises
• 10 homework assignments of which 8 must
be approved in order to attend the 4 hour
exam.
• Group work solving assignments is
encouraged. Max. group size = 2
Copyright 2001 Kasper B. Graversen
Handing-in rulesHanding-in rules
• Deliver within deadline in the course folder
• Only printouts are accepted (and don’t count on the printers are working 10 min. before deadline)
• Clearly state your name (and of your collaborator if any)
• Be honest! If it doesn’t work explain what happens and how you got stuck.
• Remember documentation– UML
– Short tutorial
• Don’t cheat! (don’t copy others work)
Copyright 2001 Kasper B. Graversen
Top 10 Ways to Piss off your LecturerTop 10 Ways to Piss off your Lecturer• Don't think, just take notes in lectures/tutorials.
• Don't participate in tutorials.
• Skip lectures or lab exercises and then ask for help.
• Ask "Is this on the exam?".
• Don't explore.
• Don't do the lab exercises.
• Copy someone else's lab exercises.
• Talk in lectures.
• Disrupt lectures with mobile phones/laser pointers & showing up late.
• Cheat on assignments.
by Andrew Taylor
Copyright 2001 Kasper B. Graversen
The course in general 1The course in general 1
• Learn how computers work
• Be able to handle and transform a given problem to be suited for computers
• Gain programming skills
• And for the less ambitious: to be able to laugh at scenes in the movie “antitrust” (which otherwise is a good movie.)
Copyright 2001 Kasper B. Graversen
The course in general 2The course in general 2
Procedural programming in an object-orientated context
The basic data types used in procedural programming
Levels of abstraction in describing software systems.
Copyright 2001 Kasper B. Graversen
The course in general 3
• Learn the basics of programming-> “DOS programs” – Programs with no interaction– Programs with interaction from text window
• Learn OOP and GUI framework -> “Ordinary programs”– Programs with interaction from windows
• Learn network and Servlet framework -> dynamic webpages (i.e. e-shops)
Copyright 2001 Kasper B. Graversen
How to study
• Programming is a craft – Can not be mastered through reading (just like
any other craft)• Read a bit
• try at the keyboard
– Practice the fundamentals again and again!
Copyright 2001 Kasper B. Graversen
How to group workHow to group work
• Find someone at the same level at you
• Take turns at the keyboard
• Make time for individual “figuring out”
• Use each other: Discuss,there exists several solutions to an assignment.
• You should not just divide up the work
between you!
Copyright 2001 Kasper B. Graversen
How to read the book
• The first 2-3 chapters are hard to read since they try cover on many aspects of programming.
• Expect reading them several times.
Copyright 2001 Kasper B. Graversen
How computers work 1How computers work 1
• What is the biggest number?
34 91 72• How did you find it?
Copyright 2001 Kasper B. Graversen
How computers work 2How computers work 2What is the biggest number now?32343 09889 58342 23987 34763 19854 33487 28458
78343 64398 33487 28458 62983 09847 98377 84399
20934 89348 10298 78329 34029 44392 38733 94283
62837 97230 23094 35783 23829 24089 62983 09847
89402 78239 90012 34940 12984 34098 23829 24089
23849 93404 23489 23048 23847 23498 12984 34098
84359 34833 26784 29384 03984 39484 03984 39484
92734 38733 94283 83743 23984 34842 34029 44392
09889 58342 23987 34763 19854 40338 12984 34098
78343 64398 33487 28458 62983 09847 10298 78329
20934 89348 10298 78329 34029 44392 78239 90012
62837 97232 23094 35783 23829 24089 97232 23094
89402 78239 90012 34940 12984 34098 89348 10298
23849 93404 23489 23048 23847 23498 64398 33487
Copyright 2001 Kasper B. Graversen
How computers work 3How computers work 3
• Natural language is ambiguous
• Programming languages are unambiguous– Distinguish between = and ==– Everything has to be “spelled out”
Copyright 2001 Kasper B. Graversen
The Java language
• abstract boolean break byte case catchchar class const continue default dodouble else extends final finally float for goto if implements import instanceof
int interface long native new packageprivate protected public return short staticsuper switch synchronized this throw throwstransient try void volatile while ++ -- % == = []
Green = important Yellow = covered Gray = not covered
• Not a lot - but think of it as the alphabet and what
you can do with mere ~26 building blocks
Copyright 2001 Kasper B. Graversen
What Java adds to C objects, inheritance, interfaces exceptions garbage collection proper modularization facilities better support for arrays, strings multi-threading rich set of platform-independent APIs introspection/meta-operations
by Andrew Taylor
Copyright 2001 Kasper B. Graversen
Procedural Programming
• We say functional programming languages such as Haskell/Prolog are declarative.
• A declarative program defines more what is to be computed rather than how to compute
• i.e. sets up a maze and define movement - the program will then automatically find its way out.
Copyright 2001 Kasper B. Graversen
Programs and states
• Programs in procedural programming language such as C, C++, Basic, Pascal or Java give a sequence of operations (actions) to produce result.
• A Java program must defines explicitly how to compute a result.
• We say procedural programming languages such as Java are imperative.
by Andrew Taylor
Copyright 2001 Kasper B. Graversen
Imperative programs• A state could be a certain position in the maze.
• The only way to get out of the maze is by developing an algorithm for finding out.
• Algorithm: A precise “recipe” for solving a problem.
Copyright 2001 Kasper B. Graversen
State change• Procedural programs work by state-change.
• The state of a program: variables (mutable typed containers)
position (place in code where executing)
external files (input/output file positions)
• The program comprises: declarations - (description of variables: names and types)
statements - (list of operations to be performed)
• State is dynamic; program is static. by Andrew Taylor
Copyright 2001 Kasper B. Graversen
Object Oriented Programs 1
• Object Oriented programming is procedural programming encapsulated in objects.
• These objects can be named to represent entities in the problems being solved.
• Reading code describing the solution, one reads words expressing the problem.
• OOP allows descriptions of problems and solutions in “ordinary” language, rather than in a language specific to computer platform or programming language.
Copyright 2001 Kasper B. Graversen
Object Oriented Programs 2Object Oriented Programs 2
• Code has, over time, become self-contained and easy to describe.
• Through objects code can be passed around and be reused in various places in the program or in several programs.
• Programs are usually newer written from scratch
• One of the reason why Java is popular is the 1732 classes big library of code ready to be used.
• But reuse requires documentation
Copyright 2001 Kasper B. Graversen
Object Oriented Programs 3Object Oriented Programs 3
• Any drawbacks in using this fantastic technology?– Small programs relativly are bigger– Keeping track of objects
Copyright 2001 Kasper B. Graversen
The world from an OO perspective
• A car
• A Shop
Wheel Wheel
WheelWheelMotor
Steering mechanism
articles customer
customer
customer
customer
Shop
Bank
Accounting
Body
Copyright 2001 Kasper B. Graversen
The world from a OO perspective
Attributes• Attributes describes properties of a class
• Car– color– price– cleanness
• Motor– speed
• Wheel– mm rubber
Wheel Wheel
WheelWheelMotor
Steering mechanism
Bodyspeed
colorprice cleanness
Copyright 2001 Kasper B. Graversen
The world from a OO perspective
Methods• Methods declares functionality of a class• Body
– openDoor– closeDoor
• Motor– on/off– speedup– brake
• Steering mechanism– left/right
Wheel Wheel
WheelWheelMotor
Steering mechanism
Bodyspeed
colorprice cleanness
openDoor
openDoor
on/off
left right
speedup
brake
Copyright 2001 Kasper B. Graversen
Using UML to sketch
BodypricecolorcleannessopenDoorcloseDoor
Motorspeedonoffspeedupbrake
Steering mechanism
leftright
Wheelrubber
1
4
Copyright 2001 Kasper B. Graversen
Grouping classes
Copyright 2001 Kasper B. Graversen
How java works
Java source code
Java Byte code
Machine code
Compiler
Virtual machine
ExecutionExecution
Editor
Ultraedit
javac
java
(Foo.java)
(Foo.class)
Copyright 2001 Kasper B. Graversen
Writing code
Java source code
Compiler
Editor
ultraedit
javac Failure
•Very picky•“;” at the end of (almost) every line•“a” is different from “A” (case sensitive)•A missing parenthesis, the slightest misspelling etc. gives failure
Copyright 2001 Kasper B. Graversen
““Hello world” in Java 1Hello world” in Java 1
• The smallest program in java
class Hello
{
public static void main(String[] args)
{
System.out.print(“Hello world!“);
}
}
• Saved in a file called “Hello.java” (notice the capital H)
Copyright 2001 Kasper B. Graversen
““Hello world” in Java 2Hello world” in Java 2
• To translate it to something the computer understands we run the compiler
javac Hello.java
• To run the program we type
java Hello