1 Programming James King 12 August 2003 2 Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple.

Slides:



Advertisements
Similar presentations
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Advertisements

The Web Warrior Guide to Web Design Technologies
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Introduction To System Analysis and Design
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 Programming Week 2 James King 12 August Creating Instances of Objects Basic Java Language Section.
Objects First with Java A Practical Introduction using BlueJ
Classes and Instances. Introduction Classes, Objects, Methods and Instance Variables Declaring a Class with a Method and Instantiating an Object of a.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
HST 952 Computing for Biomedical Scientists Lecture 2.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
C++ fundamentals.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Platforms for Learning in Computer Science July 28, 2005.
TCU CoSc Introduction to Programming (with Java) Getting to Know Java.
Object Oriented Software Development
A First Program Using C#
M1G Introduction to Programming 2 1. Designing a program.
Dr. Ken Hoganson, © August 2014 Programming in R STAT8030 Programming in R COURSE NOTES 1: Hoganson Programming Languages.
1 Web Based Programming Section 6 James King 12 August 2003.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Introduction to Object-Oriented Programming
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
20-753: Fundamentals of Web Programming 1 Lecture 1: Introduction Fundamentals of Web Programming Lecture 1: Introduction.
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
Introduction to Java and Object-Oriented Programming AJSS Computer Camp Department of Information Systems and Computer Science Ateneo de Manila University.
Introduction To System Analysis and Design
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Module Overview n Module Title: OO Programming n Module Code: MIT3446 n Module Value: 3.0 n Duration: 15 weeks n Class-Contact Hours: Lecture15 hrs n Lab/Tutor30hrs.
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
Computer Science II 810:062 Section 01. How is CS I different from CS II? When you teach Java there are a series of decisions that have to be made…
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
1 Web Based Programming Section 8 James King 12 August 2003.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Week 2 2 Inheritance Basic Java Language Section.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Introduction to JavaScript Objects, Properties, Methods.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
INM205 Object Oriented Programming in JAVA Dr. Michael Casey Department of Computing.
1 Programming 2 Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple web and network applications.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
OOP - Object Oriented Programming
Objects First with Java A Practical Introduction using BlueJ
Server Concepts Dr. Charles W. Kann.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
CompSci 230 Software Construction
Objects First with Java A Practical Introduction using BlueJ
COS 260 DAY 2 Tony Gauvin.
Java Applets.
Objects First with Java A Practical Introduction using BlueJ
Introduction to AppInventor
Workshop for Programming And Systems Management Teachers
Objects First with Java A Practical Introduction using BlueJ
CMSC 202 Exceptions.
Presentation transcript:

1 Programming James King 12 August 2003

2 Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple web and network applications

3 Warning THIS IS NOT A WEB AUTHORING COURSE We will not teach HTML, PSP, etc… We will show you how to write Java applications that use the web and internet We will (hopefully) improve your programming ability We will teach Object orientated concepts, good programming practice and how to debug/document your code It is vital to bring the code examples with you to the lecture

4 The Course Topics Object orientation and Java programming Applets and GUI programming File handling Input and Output Streams Multiple threads of execution Network programming

5 Useful Resources These slides are the course book hopelive.hope.ac.uk/imc/kingj The BlueJ development environment is available free from The blueJ book is useful if you want additional practical exercises. Barnes, D and Kolling, M. Objects first with Java – A practical introduction using BlueJ. Prentice Hall site contains a freely downloadable version of Java for most operating systems and computer hardware. It also contains the very useful Java tutorial and Java language documentation.

6 Advice You can’t learn to program just by understanding the theory Programming requires practice and more practice. Don’t give up because it is not easy to start with once you grasp the concepts it will get easier Don’t be surprised when you make mistakes - learn from them No programming language or environment is perfect sometimes the error messages are difficult to understand or don’t point you to the cause of the problem

7 A few Words about the Labs The labs are designed for you to learn how Java program behave and experiment and have fun You will learn faster and have more fun if you take the programming examples and modify them to see what happens. You will get used to the error messages Try to run them in your head or on paper before you run them on the computer you will get a feel for what the language can and can not do All the examples are carefully chosen to illustrate a point. Don’t worry that they are not all useful programs

8 This Weeks Topics Object Orientated Concepts Objects Methods and Attributes Messages, parameters and protocols Classes Instances Inheritance and overriding

9 Objects Basic Java Language Section

10 Objects model real world entities such as a person, food, car, house, umbrella Objects only need to model the “interesting” information and behaviours For a personnel database person may contain name, address, age, current wage etc. and behaviours such as change address, promotion In a computer game health, current weapon and direction may be important and behaviours such as shoot, walk, run and change direction Object oriented concepts Objects

11 Anatomy of an object - Terminology The individual pieces of information such as the health of a monster or the number of bullets are called attributes The entire information stored inside an object can be referred to en masse as its state

12 Anatomy of an object The behaviours of on object such as change address are implemented inside methods Methods are bundles of code When invoked the code in a method is executed line by line Methods may examine and modify any of the attributes inside the object they are part of

13 Java Language Structure Basic Java Language Section

14 Java Structure – Based around blocks Blocks are defined between a { and a } { must be balanced by a } A Method is a block with a name Attributes also require names Names cannot contain spaces or start with a number such as 2 A block may be nested totally inside a block but no block may be partially inside another block

15 Java Class Example class Hero { int bullets; void shoot() { bullets=bullets-1; } Name of class Indicates start of class Indicates end of class Indicates start of method Name of method Indicates end of method Name of attribute

16 class Monster { int health; void take_damage() { health=health-10; } Java Class Example2 This is the body of the class it contains one method and one attribute This is the body of method it contains one line of code and is inside the body of the class

17 Java Structure – Based around blocks {}{} {}{} {}{} {}{} {}{} {}{} One block followed by another block is fine One block inside by another block is fine One partially inside by another block is an error

18 Object oriented concepts What is a program? A program is a collection of objects (possible many different types) that interact together by calling each other’s methods. For example in a computer game if the hero shoots a monster several methods are called: The hero's gun uses one bullet (shoot method) The monster loses health (take damage method)

19 Object oriented concepts Terminology Invoking a behavior by calling a method is referred to as sending the object a message The set of messages an object understands is called its protocol Sending an object a message it does not understand usually results in a error and your program stopping/crashing

20 Collaborating Objects bullets = bullets -1 Shoot message health = health - 10 Take damage message user hits the mouse button Hero object receives a shoot message Monster object receives a take_damage message

21 Objects Summary The state of the object is stored inside the object in attributes e.g. the age of the person Responses to messages are stored as executable code (the code associated with a message is called a method). The set of messages an object can understand is its protocol

22 Messages and Objects Basic Java Language Section

23 Simple Messages Sometimes receiving a message is enough information to perform your behaviour For instance receiving a message that it is your birthday is enough to increment your age

24 class Monster { int health; void take_damage() { health=health-10; } Object oriented concepts Objects – Java Example Indicates it’s a simple message Name of method

25 Messages with Parameters Sometimes you need additional information to perform a behaviour. For instance if the monster is hit by a non- standard weapon we need to know how much damage the weapon did. This additional information is presented as one or more parameters (also called arguments in some older books)

26 class Monster { int health; void take_unusual_damage(int damage) { health = health - damage; } Objects – More complex Messages Name of parameter The attribute health is modified to take the same value as the parameter minus its old value. When modified its overwritten its old value is then lost forever Type of parameter (more about types later)