Title: Introductory Programming GP Spring 2006 Lecture 1 Welcome We start at 16:00 Slides are available fro
1Introductory Programming (GP)Spring
2006Lecture 1 Welcome!We start at 1600
Slides are available from the course home
pageFeel free to print them nowwww.itu.dk/cours
es/GP/F2006
2Language ...
- This course is taught in English
- Using an English book and
- supplementary notes in English
- Do, however, feel free to ask questions in Danish
- Well translate them and
- answer in English
3Who are we ?
- Lecturer and course responsible
- Associate Professor Thomas Hildebrandt
- Office 4C12
- e-mail hilde_at_itu.dk
- Lecturer
- Assistant Professor Martin Lillholm
- Office 4D16,
- e-mail grumse_at_itu.dk
- Teaching assistants
- Mads Troest,
- Priyadarsini Seetharaman
- Jesper Mouritzen
4Today's Agenda
- Motivation, prerequisites, and course contents
- Practical information
- Lectures, lab work/exercises, mandatory
assignments, home page, - Computers
- Hardware, software, networks
- Programming
- Tasks, algorithms, data structures
- Programming languages, syntax and semantics
- Program development
- Java
- On Java and Java programs
- Hello.java, HelloGUI.java og HelloApplet.java
5Motivation
- Why would I want to learn how to program ?
- Prerequisite for most technical courses on the
ITU - Solid basis for understanding possibilities and
indeed limitations of modern information
technology (IT) - Even though you may not end having a technical
job/educational profile - Therere still quite a good job possibilities for
skilled programmers - Structured analysis
- Why Java ?
- Solid, modern high level object oriented
programming language. - Well suited for graphical and internet
applications - Not too bad as a first programming language
- Youll not only learn Java although it may seem
like it ?
6Prerequisites
- User level computer skills
- e-mail, browsers (e.g. Outlook and Internet
Explorer) - Some word processing (e.g. Word)
- Files, directories, ..
- Familiarity with ITU computer systems
corresponding to the introduction given by
Sysadm. - Dont despair
- Are you already a (skilled) programmer?(forces
course completion, shopping-period)
7GP contents (1)
- Three tracks
-
GUIs - Programming Object oriented
(Graphical User - paradigm
Interfaces) -
8GP contents (2)
- Computer systems basics
- The programming process Design, algorithms,
data structures, programming, testing - Variables, identifiers
- Flow of control (if-then-else, for, while, do...)
- Data types (int, float, double, classes, ...)
- Algorithms (searching and sorting)
- Object oriented programming 101 (classes,
objects, abstraction, encapsulation, inheritance,
and polymorphism) - Exceptions
- Graphical User Interfaces (GUIs)
- Applets (program that can run in a browser)
9Lectures
- 12 Mondays during spring 2006 from 13001600 in
Aud 2 - First time today, Monday January 30.
- Mondays until and including April 24(Excluding
Easter break April 17.) - All in all approx. 36 hours First half by me
and second half by Thomas - Lectures will present main points from the
curriculum - Read before lectures
- And again afterwards
- ALL questions are welcome youre here to learn!
- Breaks probably 15 minutes per lecture hour
up to you
10Lab work/exercises
- 11 Mondays in spring 2005 from 9-12 or from 16-19
In one of the following rooms (4A54, 4A56,
4A58) - Same day as the lectures not today though.
- All in all 33 hours
- Additional help before assignment deadline ??
- Exercises, programming, mandatory assignments
- Assignments sheets will be made public on Fridays
- Teachings assistants (TAs) use them, ask
questions! - Computers with Java, editors, IDEs and Word etc.
available on the ITU and in the lab rooms - Printers
- Distribution in lab classes will be made public
during this week. - How do I change class ?
11Mandatory Assignments
- 10 mandatory assignments will be given.
- Evaluated as either pass or not pass.
- Can (should) be solved in groups of two.
- At least 8 of 10 assignments must get a pass to
qualify for the final exam. - Assignment must be handed in on time!
- Dont cheat ?
- Skill training you do not learn to program by
reading a book! - No mandatory assignment this first week.
- Made public on Fridays should be handed in the
following Friday. - Feedback at lab classes.
12Expected efforts
- Read before and after lectures
- Solve assignments both mandatory and voluntary
ones! - Write programs like mad ...
- All in all at least 77 hours ... That is at least
6.5 hours per week beyond lectures and lab
classes. - Access to ITU and computers 24x7
13Final Exam
- Monday den June 12 2006
- Four hours written exam
- All written but non-electronic aids are allowed
- Evaluated using the Danish 13-scale
- Examples of old exam sets can be found on the
course home page - Trial-exam at the end of the semester. One of
the mandatory assignments
14Home page and curriculum
- http//www.itu.dk/courses/GP/F2006/index.html
- Primary source of information
- Curriculum, lectures
- Assignment sheets
- Additional materials
- Mandatory assignment status
- Curriculum
- Java Software Solutions, Foundations of Program
DesignJohn Lewis og William Loftus, ISBN
0321312465 - 2 notes by Peter Sestoft (see home page)
- More notes if needed
15GP and my computer
- Do I need a computer to take GP?
- No is the short answer
- Computers with Java, editors, IDEs and Word
available at the ITU. - Access ITU 24x7
- Is it an advantage to have my own computer?
- Really depends on your working habits
- How can I use my own computer for GP?
- All programs you need is available for download
all are free - Some of them can be found on the CD that comes
with the book - Otherwise check course home page
16Is GP a difficult course ... ?
174-weeks projects
- 4 weeks after this course
- Topic of your choice
- Typically inspired by one or more the courses
youve followed - Find groups and think of a topic!
- Intro lecture later this semester
- The sooner we/you agree on topic the better your
project will be ?
7,5 ECTS ?
7,5 ECTS ?
7,5 ECTS GP
12
7,5 ECTS
4
18What do I do ?
19Computer Vision / Image Analysis
20What is a computer anyway?
- Hardware
- chips
- hard discs
- keyboard
- monitor
- memory
- CPU (Central Processing Unit)
- ...
Hard disc
- Software
- Operating system
- Windows , Linux, Unix, Mac OS, ...
- Applications
- Word, Notepad, Matlab, browsers, ...
Computers PCs, Laptops, mobile phones, dish
washers, cars ...
21A very simple computer
Machine language
External memory
CPU
Programmer og data i filer
Input og output
22What is a computer program anyway?
- A program is a collection of internal commands
(machine code) for a computer - Internal commands can yield external and visible
results - E.g. calculation and displaying of a graph, . .
- The execution of a program is completely
automatic - A program can solve a lot of problem of a
specific kind but - Programs are stupid they cant improvise,
adapt, or understand however - Computers are really fast and sometimes programs
come across as being smart its all an illusion
?
23How does a computer execute a program?
- The program is read into memory from disc or some
other storage media - The first instruction is fetched from memory to
the CPU - The CPU executes that instruction
- The CPU perhaps saves the result of the
calculation in memory or on the hard drive - The CPU may write the result of the calculation
on the monitor - The CPU may receive some input from the user
- And then the next instruction
24Networks
- A network connects two or more computers or units
(printers, scanners, ...) - Todays standard have almost all computers
connected to some kind of network - Clients
- Thin clients (dependent on a server)
- Thick clients (independent computer)
- Servers
- File servers (h)
- Web servers
- Database servers
- Print servers
- Mail servers
25Local Area Network (LAN)
- A LAN typically connects computers in the same
building or area.
Hubs, switches,
Wireless (typically 11Mbit)
Clients
Typically 100Mbit
Server (e.g. file server H)
Back bone (Gbit or fiber)
26Wide-Area Networks (WANs)
- A WAN typically connects two or more LANs.The
best known one being the Internet ... A network
of networks (internetworking) - The basic internet is just connections betweena
whole lot of networks and a simple communication
protocol
27WWW, URL, HTML, ...
- The internet is used for communication, exchange
of services and information e-mail, images,
sound, text, number or in short data. - Wasnt always as easy a today ftp, telnet, nn,
... - World Wide Web (WWW) is a system that uses the
internet to ease the communication of especially
text, images, and sound. - Hypertext and hypermedia ... browsers(Mosaic,
Netscape, Internet Explorer, Mozilla, ...) - HTML (HyperText Markup Language) is used to write
pages for the WWW home pages.
28More HTML ...
- Text and media formatting language ... text
(ASCII) documents (.html, .htm)
... ... ML
Our first HTML
document Heres the
beginning of the main text. Heres a
heading More main text and an SRC"C\home\figs\746.jpg"image and
now a new paragraph with a "http//www.itu.dk/courses/GP/F2006/"link BODY
Start tag
End tag
URL (Uniform Resource Locator) Reference or link
to text, images, sound ...
29A few words on files
- Text files
- ASCII (typically)
- Extensions - .txt .html .htm . Java
- Conventions content
- Binary filer
- .zip, .doc, .mp3, .wav
30Programming Languages
- How do we move from own ideas/task to a
completed program that can run on a computer? - Using programming languages as e.g. Java.
Haskell
Miranda
Prolog
BASIC
C
ML
C
LISP
Fortran
C
Pascal
Assembler
Maskinkode
31More on programming and analysis
- Problem / task
- Analysis
- Algorithms data structures
- Design (perhaps object oriented OO)
- Implementation (i e.g. Java)
- Compilation
- Testing
- Find the largest of 10 positive numbers
32What is a programming language?
- A (high level) programming language is a set of
rules for how to - write instructions for the computer. Syntax vs.
semantics. - You have to be very careful with computer
instructions - Correct
- label.setForeground(Color.blue)
- Completely wrong
- label.setforeground(color.blue)
- (Java differentiates between upper and lower case
letters!) - How do we make the transition from an arbitrary
high level language to - machine instructions the only thing a computer
can actually execute? -
33From source code to executable program (general
case)
Using a compiler
Source (Editor)
Compiler
Linker
Result
Hello.c (text/ASCII)
Hello.o (machine code)
Hello.exe
Using an interpreter
- The interpreter simplifies the process but will
add an extra layer during execution - Normally lowers execution speed
Source (Editor)
Interpreter
Resultat
Hello.c
34From source code to executable program (java)
Using a compiler and an interpreter
Java Virtual Machine
Source (Editor)
Compiler
Interpreter (JVM)
Resultat
Hello.java text (ASCII)
Hello.class (Java bytecode)
Why all this ?
- Platform independence (platform architecture
operating system) - PC (AMD/Intel) Windows
- PC (AMD/Intel) Linux
- Mac Mac OS X
- Browser
- Arbitrary gadget med JVM
- Faster than end anormal interpreter (bytecode is
quite close to machine code)
35An example
Source i Notepad Hello.java
Compiled using javac Hello.java
Executed using java Hello
Command Line Interpreter/prompt
SUNs Java compiler
SUNs JVM (runtime environment)
36Integrated Development Environments (IDEs)
- An IDE combines
- Text editing (and often enhances it)
- Compilation to bytecode
- Excution
- Often has support for e.g. a languages syntax.
BlueJ
JCreator
37The structure of a Java program
- When we choose Java, we also choose a set of
rules (or a notation) for how can/must write
programs. - These rules are often called a languages Syntax.
- The meaning/result of a command or an entire
program is called a languages Semantics. - A Java-program consists of
- One or more classes
- A class can have 0 or more attributes
- A class can have 0 or more methods
- A method can have 0 or more commands/instructions
- If a class has a main method, its (roughly
speaking) executable. Execution starts a the
first instruction in the main method.
38The structure of a Java program
// comments about the class
blok start
public class MyProgram
// comments about the method
public static void main (String args)
class body
method header
method body
blok end
39White spaces and layout
- Space, tab stops and, newlines.
- All used to separate instructions, characters,
and words. - At least one is necessary the rest is matter of
convention individual taste, and indentation - Lincoln.java LL side 28
- Lincoln2.java LL side 34
- Lincoln3.java LL side 35
40Comments in programs
- Describes and documents the inner workings of a
program - Do not affect what the program does
- All classes and methods should be described using
short comments - Do use comments that is on a higher level of
abstraction than the code their describing - To types exist
- // A single line comments
- // Another one
- / A multiple line
- comment /
- Avoid unnecessary comments
- x x 2 // Two is added to x
41Reserved words
abstract boolean break byte case catch char class
const continue default do double
else enum extends false final finally float for go
to if implements import instanceof
int interface long native new null package private
protected public return short static
strictfp super switch synchronized this throw thro
ws transient true try void volatile while
42Three types of Java programs
- Ordinary
- Input and output using keyboard, files, and/or
the command line. - Programs with GUI
- Programs with Graphical User Interfaces
- Windows, dialogue boxes, buttons, ...
- Mouse, keyboard
- Applets
- Programs that can be executed in a browser
- Apart from that often like GUI programs
- Why applets?
43Hello.java
- Hello.java (see home page)
44HelloGUI.java
- HelloGUI.java (see home page)
45HelloApplet.java
- HelloApplet.java (se home page)
- HelloApplet.html (se home page)
46Object Oriented Programming 101
- A program is typically written to solve a problem
- How do understand the problem and then design a
solution thats suited for computer
implementation - The OO paradigm is an option
- One of the basic ideas is to not only write code
that solves the problem but also to model the
problem domain
47More OO - objects
- Objects are well suited to model things from any
problem domain - State
- Behaviour, services (methods)
- A bank account has
- A balance
- An interest rate
- A credit limit
-
- Given a bank account you can
- Get the balance
- Deposit money
- Withdraw money
- Max out your credit limit ...
- Methods can and often will change the state of an
object - The largest of ten numbers again
48More OO Classes
- Classes serve as the blueprint of objects
- Classes are abstractions/concepts and actually
seldom used in running programs per se. - Objects are realisations/instances of classes and
the bread and butter of running programming but
again - Objects attributes and methods are described
using classes - From one class one can make several
objects/instances - More OO later in this course except for the
simple bank account example
49More OO an example