490 likes | 586 Views
Introductory Programming (GP) Spring 2006 Lecture 1 – Welcome! We start at 16:00 Slides are available from the course home page Feel free to print them now www.itu.dk/courses/GP/F2006. Martin Lillholm. Language. This course is taught in English Using an English book and
E N D
Introductory Programming (GP)Spring 2006Lecture 1 – Welcome!We start at 16:00 Slides are available from the course home pageFeel free to print them nowwww.itu.dk/courses/GP/F2006 Martin Lillholm
Language ... This course is taught in English • Using an English book and • supplementary notes in English Do, however, feel free to ask questions in Danish • We’ll translate them and • answer in English
Who are we ? Lecturer and course responsible • Associate Professor Thomas Hildebrandt • Office: 4C12 • e-mail: hilde@itu.dk Lecturer • Assistant Professor Martin Lillholm • Office: 4D16, • e-mail:grumse@itu.dk Teaching assistants: • Mads Troest, • Priyadarsini Seetharaman • Jesper Mouritzen
Today'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
Motivation 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 • There’re 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 • You’ll not only learn Java … although it may seem like it
Prerequisites • 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. • Don’t despair … • Are you already a (skilled) programmer?(forces course completion, shopping-period)
GP contents (1) Three tracks: GUIs Programming Object oriented (Graphical User paradigm Interfaces)
GP 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)
Lectures • 12 Mondays during spring 2006 from 13:00–16:00 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 – you’re here to learn! • Breaks … probably 15 minutes per lecture hour … up to you
Lab 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 ?
Mandatory 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! Don’t 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.
Expected 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
Final 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
Home 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
GP and my computer … Do I need a computer to take GP? • No is the short answer • Computers with Java, editors, IDE’s 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
4-weeks projects • 4 weeks after this course • Topic of your choice • Typically inspired by one or more the courses you’ve 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 GP 7,5 ECTS ? 7,5 ECTS ? 12 7,5 ECTS 4
What do I do ? Observed world (3D) Girl sitting on grass in front of building. Tanja? ITU Ørestaden • Inference (machine) • Abstraction • Prior knowledge (models)
What 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 ...
A very simple computer Monitor Keyboard Harddisk Internal memory Floppy disc ”Machine language” External “memory” CPU Programmer og data i filer Input og output
What 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 can’t improvise, adapt, or understand … however … • Computers are really fast and sometimes programs come across as being smart … it’s all an illusion
How does a computer execute a program? Monitor CPU Keyboard Hard disc Internal memory Floppy disc • 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 …
Networks • A network connects two or more computers or units (printers, scanners, ...) • Today’s 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 • …
Local Area Network (LAN) LAN • A LAN typically connects computers in the same building or area. Hubs, switches, … Wireless (typically 11+Mbit) Clients Typically 100+Mbit Server (e.g. file server H:) Back bone (Gbit or fiber)
Wide-Area Networks (WANs) LAN LAN • 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 …
WWW, URL, HTML, ... • The internet is used for communication, exchange of services and information: e-mail, images, sound, text, number or in short data. • Wasn’t 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”.
More HTML ... • Text and media formatting language ... text (ASCII) documents (.html, .htm) <HTML> <HEAD> ... </HEAD> <BODY> ... </BODY> </HTML> <HTML> <HEAD> <TITLE>Our first HTML document</TITLE> </HEAD> <BODY> Here’s the beginning of the main text. <H1>Here’s a heading</H2> More main text and an <IMG SRC="C:\home\figs\746.jpg">image</A> <P>and now a new paragraph with a <A HREF = "http://www.itu.dk/courses/GP/F2006/">link</A> </BODY> </HTML> Start tag End tag URL (Uniform Resource Locator) Reference or link to text, images, sound ...
A few words on files • Text files • ASCII (typically) • Extensions - .txt .html .htm . Java • Conventions ~ content • Binary filer • .zip, .doc, .mp3, .wav
Programming 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# C++ ML LISP Fortran C Pascal Assembler Maskinkode
More 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
What 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?
From 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
From 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)
An example … Source i Notepad Hello.java Compiled using javac Hello.java Executed using java Hello Command Line Interpreter/prompt SUN’s Java compiler SUN’s JVM (runtime environment)
Integrated Development Environments (IDEs) • An IDE combines • Text editing (and often enhances it) • Compilation to bytecode • Excution • Often has support for e.g. a language’s syntax. BlueJ JCreator
The 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 language’s Syntax. • The meaning/result of a command or an entire program is called a language’s 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, it’s (roughly speaking) executable. Execution starts a the first instruction in the main method.
The 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
White 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– L&L side 28 • Lincoln2.java– L&L side 34 • Lincoln3.java– L&L side 35
Comments 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
Reserved words • Java’s reserved words … abstract boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
Three 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?
Hello.java • Hello.java(see home page)
HelloGUI.java • HelloGUI.java (see home page)
HelloApplet.java • HelloApplet.java (se home page) • HelloApplet.html (se home page)
Object Oriented Programming 101 • A program is typically written to solve a problem • How do understand the problem and then design a solution that’s 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
More 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 …
More 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 • Object’s 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 …
More OO – an example A class (concept) An object (realisation) Bank-konto John’s bank account Balance: 5257,- Jens’ bank account Balance: 1245069,- Several object from one class Tanja’s bank account Balance: -16833,-