G51PR1

47
G51PR G51PR 1 1 Introduction to Programming I 2000-2001 University of Nottingham Unit 1 : Introduction

description

G51PR1. Introduction to Programming I 2000-2001 University of Nottingham Unit 1 : Introduction. Background Teaching Staff Course Details Assessment PR1 Summary Resources Programming Programming Languages High Level Languages Interpreters / Compilers. Introduction to Java - PowerPoint PPT Presentation

Transcript of G51PR1

Page 1: G51PR1

G51PR1G51PR1

Introduction to Programming I2000-2001

University of NottinghamUnit 1 : Introduction

Page 2: G51PR1

Overview

Background– Teaching Staff– Course Details– Assessment

PR1 Summary Resources Programming

– Programming Languages– High Level Languages– Interpreters / Compilers

Introduction to Java– Java History– Java Properties– Types of Programs– JDK tools– The HelloWorld program

Using CourseMaster

Page 3: G51PR1

Teaching Staff

Lecturer : Tsintsifas Athanasios (thanassis)– [email protected] Room:C73 (mon 10-12) (wed 9-10) (fr 10-12)

CourseMaster Administrator : Pavlos Symeonidis – [email protected] Room:C73 (tues 2-6) (thur 2-6)

Help Desk: Tarek Hegazy,– [email protected] Room : C75

Lab Assistants (terminal room - lab hours). CourseMaster help (via email), [email protected]

Page 4: G51PR1

Course Details

20ish lectures plus lab sessions. One to three coursework exercises per week. You will be assigned to 1 of 4 lab sessions

– 2-4 & 4-6 Tuesday – 2-4 &, 4-6 Thursday

Prerequisites : None (but you must do CUA concurrently). Objectives : To learn to think algorithmically and to express in

sound implementations.

Page 5: G51PR1

Assessment 100% coursework via the CourseMaster system (used to be

called Ceilidh, check www.cs.nott.ac.uk/~ceilidh).

Page 6: G51PR1

Assessment

Starting on Friday 13th of October Exercises close 10 days after opening (every Monday 12:00) Usually you have three attempts to submit. The last attempt is always the final. Feedback after each submission gives you enough information to

infer the correct the solution. More on the process of using CourseMaster on Friday.

Page 7: G51PR1

Summary of PR1

9-10 units of 1-2 lectures

G51PR1

1INTRODUCTION

ELEMENTARYPROGRAMMING

CONDITIONALS LOOPS METHODS

ARRAYS

CLASSES

I/OSTRINGS

23 4 5

6

7

8

GUI

910

Variables

Identifiers

Types

Ope

rato

rsLa

yout

Background

Programming

Java

Compiling

Running

If...else...

switc

h.. c

ase.

.

for

whi

le

do

...w

hile Syn

tax

nest

ing

nestin

g

Par

amet

ers R

ecursion

Syntax

Algorithms

objects

Files

Streams

Processing

overview

abstractionprotection

design

Page 8: G51PR1

Resources

Sun file servers (jdk is installed in solaris) PCs (jdk is installed in all lab PCs) CourseMaster installed in all lab PCs PFE editor or Emacs-JDE JDK 1.3 Course Transparencies : http://www.cs.nott.ac.uk/~azt/pr1

Page 9: G51PR1

ReadingRecommended: Java Gently by Judy Bishop (Addison-Wes). Java. How to Program by Deitel & Deitel (Prentice Hall). Developing Java Software by Winder & Roberts (Wiley). Java in a Nutshell by Flanagan (O’Reilly). Thinking in Java (Bruce Eckel) (available on the web)Other Sources of Information: CourseMaster : http://www.cs.nott.ac.uk/CourseMaster Sun Java Tutorial :

– http://java.sun.com/docs/books/tutorial/getStarted/index.html WWW – general : search in www.google.com! Intense Java Course : http://www.cs.nott.ac.uk/~azt/java.htm

Page 10: G51PR1

Programming

"A program is a sequence of instructions. A recipe, a musical score, and a knitting pattern are all programs."

P Grogono, Programming in Pascal.

- The way to deal with an impossible task is to chop it down into a number of merely very difficult tasks, and break each one of them into a group of horribly hard tasks, and each one of them into tricky jobs, and each one of them...

(Terry Pratchet, Truckers)

Page 11: G51PR1

Programming Languages

There are four basic programming language levels:– machine language– assembly language– high-level language– fourth-generation language

Each CPU has its own specific machine language The other levels were created to make programming easier

Page 12: G51PR1

Programming Languages

A program must be translated into machine language before it can be executed on a particular type of CPU

This can be accomplished in several ways A compiler is a software tool which translates source code into a

specific target language Often, that target language is the machine language for a

particular CPU type The Java approach is somewhat different

Page 13: G51PR1

High Level LanguagesOld-fashioned languages include:

BASIC - often used by beginners on home computers. FORTRAN - old but still popular with some scientists and engineers,

new versions are introduced every few years. Algol - an elegant little-used internationally designed language, whose

features are being incorporated into other languages. COBOL - a widely used and well standardised language used in

commerce. APL - an interactive scientific language with a very mathematical

notation. PL/I - a failed attempt by IBM at achieving an all-purpose language,

now almost dead.

Page 14: G51PR1

High Level LanguagesOther Languages :

Pascal - good for beginners, often taught as a first language. Modula2 - a development of Pascal to make it more realistic for large

programs, and to enable modern program design techniques to be used.

C - a practical language, see below. C++ - an object-oriented development of C. ADA - a USA Department of Defense standard, now adopted by the

UK Ministry of Defense also, aimed at safe programming for real-time embedded systems.

Java – A robust, secure, portable, network enabled variation on C/C++.

Page 15: G51PR1

High Level Languages

Compare the COBOL:rate_per_hour multiplied by hours_worked gives gross_pay with C/C++:pay = rate * hours

Some language aims:understanding, documentation –> commercial (eg COBOL). handling vectors or complex numbers –> scientific/engineering (FORTRAN). simplicity –> beginners (Basic, Pascal). safety –> real time systems (ADA, Modula-2). complexity –> object-oriented (C++, Eiffel, Java).

Page 16: G51PR1

Interpreters vs Compilers

Interpretation : BASIC & APL are interpreted. Each line is decoded and interpreted by the computer as it is executed. Instructions in loops may have to be interpreted many times. This is inefficient and causes the computer to run slowly.Compilation : Most other languages are compiled. Whole program first analysed by a compiler (another program). Converted into a machine executable form. Runs much faster (an order of magnitude or more). Can apply many types of optimisation during or after compilation. In two parts – compilation into an object module, then loading/linking into the

executable.

Page 17: G51PR1

Java: What is it?

Simple Object Oriented Distributed Interpreted Robust Secure

Sun’s Description….Java is a :

• Architecture Neutral• Portable• High Performance• Multithreaded and

Dynamic

programming language. It contains an extensive library of classes for graphics programming, input/output, string handling, maths functions, basic data structures, etc.

Page 18: G51PR1

Java History C language was evolved as a portable operating system language Dennis Ritchie (at Bell labs) developed it from B (which came from

BCPL). Originally ran on a DEC PDP-11 computer in 1972. C++ is an object-oriented extension to C developed by Bjarne

Stroustroup early 80’s. Sun had an internal corporate research project, Green, in 1991, to

develop intelligent consumer devices. Project lead to the language Oak (James Gosling) based on C/C++. Oak about to be cancelled when WWW came along. Sun saw renamed Oak to Java and saw potential for use on the web Java formally announced in May ’95. Since then, Java generated huge interest.

Page 19: G51PR1

Java’s Versions

Java was officially announced in May 1995

9991 92 93 94 95 96 97 98

First Idea

Green Project OAK

Java 1.02

Java 1.1Java 1.2

00

Java 1.3

Java 1.2.2

Page 20: G51PR1

Simple

Has a small set of Language Constructs. Borrows the C and C++ syntax. Is free from pointers. Uses Garbage Collection. Does not use header files and preprocessors.

Page 21: G51PR1

Object Oriented

Not hybrid like C++. Supports the basic notions of OO :

– Abstraction,– Modularity,– Encapsulation,– Hierarchy,– Typing,– Concurrency,– Persistance.

Page 22: G51PR1

Distributed

Works on a variety of platforms. Provides support for :

• Networking,• Internet,• Remote Objects.

Page 23: G51PR1

Interpreted

Java Compiler

Java Source

File

Java Bytecode

FileJava

Bytecode File

Java Bytecode

File

JVM

The Java compiler translates Java source code into a special representation called bytecode

Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into

machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral

Page 24: G51PR1

Robust

Exception and Error handling. Multi-Tasking. Memory protection and management. Allows Modular development. Extensive compile-time checking.

Page 25: G51PR1

Secure The features of bytecode and its interpretation, prevent

unintentional or intentional sabotage of compiled programs. Security has been considered in many levels.

Page 26: G51PR1

Architecture Neutral

Bytecode can run on any JVM on any platform. “Write Once run Anywhere”. JDK implementation on many platforms.

Java Bytecode

MacVM

Win95VM

SolarisVM

MacOS Win95 Solaris

JavaHW

Page 27: G51PR1

Portable

The bytecode can run on virtual machines (VM) above different operating systems :

• MacOS • Windows95/NT/CE• Solaris • OS2 • etc

It can also run directly on hardware.

Page 28: G51PR1

High - Performance

Multithreading allows more than one task in a program. With JIT compilers the interpreted code compiles at run time and

gives almost native code speed.

Java Bytecode

Native

Operating System

Hardware

JIT JavaVM Java

OSJavaHW

Page 29: G51PR1

Dynamic

Java has been built to support the development of dynamically extendable systems.

Java provides dynamic linking of the binary code at runtime.

Page 30: G51PR1

Java’s Genealogy

Page 31: G51PR1

Java : Types of Programs

Applets :• Execute on HTML Browsers.• Have severe security restrictions.

GUI Applications :• Are Interpreted and Executed.• Use the current’s platform’s GUI widgets.• Mostly use Java’s AWT or JFC packages.

Console Applications :• Simple Text Console.

Page 32: G51PR1

JDK basic tools

javac (Compiler) .java->.class• The Java Language Compiler that you use to compile

programs written in Java into bytecodes. Example : java HelloWorld.java

java (Interpreter) executes .class• The Interpreter that you use to run programs written in Java.

Example : javac HelloWorld javadoc (Doc. generator) .java html

• Generates documentation in HTML format from Java source code. Example : javadoc HelloWorld.java

Page 33: G51PR1

public class HelloWorld {

public static void main(String argv[] ) { System.out.println("Hello World!!!"); }}

The First Java Program

Filename: HelloWorld.java

Page 34: G51PR1

CourseMaster

CourseMaster is a “Courseware” system that provides for :– The presentation of Information

• summaries, notes, coursework questions, hints, daily messages– The administration of coursework

• coursework delivery, • submission management, • overall class management

– The automatic assessment of coursework • solution space modeling, • assessment and feedback mechanisms, • plagiarism checking tools

Page 35: G51PR1

Logging in CM client:

To login to CM you need both a windows and a unix password. Once you are in windows you can click the “CM” icon This will get you to the login screen :

Unix Password!

Page 36: G51PR1

Message of the day :

Informs you about the latest in exercises Do read it!

Page 37: G51PR1

CourseMaster Course Level :

Options Exit

MOTD Notes Summary

Page 38: G51PR1

CourseMaster Unit Level

Notes Summary

Page 39: G51PR1

CourseMaster Exercise Level :

Setup Develop Submit Question View TD Marks Run Run TD

Page 40: G51PR1

Setup :

Puts the skeleton source and other files in your working area

Do not setup over your solution

Page 41: G51PR1

Develop :

PFE is CM’s standard editor for Java source

You can always change it later on!

Page 42: G51PR1

Compile :

From Menu : Execute->javac

Page 43: G51PR1

After Compilation :

Good News

Bad NewsCtrl + G Gets you to any line number

Page 44: G51PR1

Run a program

Two options : 1. From PFE, Execute->java

– PFE : Options->Preferences->Execute Menu->java->Edit :– Start command (as independent process OR capture output)

2. From CourseMaster, Exercise Level->Run

Page 45: G51PR1

Submit

After having developed the solution you need to refresh the CM browser by refreshing the course tree structure.

You will be asked to confirm and then wait for the result.

ExpandedResult tree

Submission NumberFeedback for every check

Page 46: G51PR1

Other Options :

View TD : Allows you to see the testing input that CM uses for the particular exercise.

Marks : Allows you to check the exercise’s last submission

Options : Allows you to change : – Visual properties.– Editor command.

Page 47: G51PR1

Summary

Background– Teaching Staff– Course Details– Assessment

PR1 Summary Resources Programming

– Programming Languages– High Level Languages– Interpreters / Compilers

Introduction to Java– Java History– Java Properties– Types of Programs– JDK tools– The HelloWorld program

Using CourseMaster