Programming Class 9 LBSC 690 Information Technology.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Introducing JavaScript
Chapter 1: Computer Systems
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
The Java Programming Language
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
Programming Week 5 LBSC 690 Information Technology.
Programming Week 5 LBSC 690 Information Technology.
Outline Java program structure Basic program elements
Structured Programming and UML Overview Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Hello, world! Dissect HelloWorld.java Compile it Run it.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
1 Programming Languages Examples: C, Java, HTML, Haskell, Prolog, SAS Also known as formal languages Completely described and rigidly governed by formal.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introducing Java.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
DAT602 Database Application Development Lecture 5 JAVA Review.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Hello World 2 What does all that mean?.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Introduction to Computer Systems and the Java Programming Language.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Compiling and the Java Virtual Machine (JVM). The syntax of Pseudocode is pretty loose –visual validation encourages a permissive approach –emphasized.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CS 106 Introduction to Computer Science I 01 / 22 / 2007 Instructor: Michael Eckmann.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introduction to Java John Lewis. Course Overview Introduction Object Orientated Programming Java Structure and Syntax Using the Java Platform Advanced.
CSCI 212 Object-Oriented Programming in Java. Prerequisite: CSCI 111 variable assignment statement while loop for loop post-increment (i++) strong typing.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
Programming Session 6 LBSC 690 Information Technology.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
Chapter No. : 1 Introduction to Java.
Hello World 2 What does all that mean?.
Chapter 1: Computer Systems
Fundamentals of Programming
Week 5 LBSC 690 Information Technology
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Chap 1. Getting Started Objectives
Class 5 LBSC 690 Information Technology
Presentation transcript:

Programming Class 9 LBSC 690 Information Technology

Agenda Questions Programming –The mythical person-month –History of programming –Object oriented programming –Programming exercise in Java

Software Software models aspects of reality –Input and output represent the state of the world –Software describes how the two are related Examples –Ballistic computations –Alta Vista –Microsoft Word

Programming Languages Used to specify every detail of the model Special purpose –Able to specify an entire class of models Spreadsheets (Excell, Quatro Pro,...) Databases (Access, Paradox,...) General purpose –Able to specify any possible model Pascal, C, Java,...

The Mythical Person-Month If it would take one person three months, why does it take four people SIX months? Four causes –It wouldn’t have taken 3 months anyhow! –Partitioning strategy –Training time –Communications effort

How long will it take? Rules of thumb –1/3 specification –1/6 coding –1/2 test planning, testing, and fixing! Add time for coding to learn as you go, but don’t take time away from the other parts! –Reread the section on “gutless estimating” if you are tempted

Training Time Simple Example –Full time person = 2,000 hours/year –Part time person = 288 hours per year –No training -> 7 part time people –With training -> 10 part time people Learning the specification takes lots of time –Learning organizational “rules” takes longer

Communications Sort of like continuous training –Who needs to know what I just learned? Can be minimized by good partitioning –Limit the number of interfaces Can be facilitated by computers –Asynchronous communication techniques , BBS, voice mail

History of Programming Machine code –Zeroes and Ones Assembly language –“Assembler” changes names to machine code High-level languages –“Compiler” translates math to machine code Independent of machine “architecture” –FORTRAN, COBOL

History of Programming Structured (Modular) Programming –Group instructions into meaningful abstractions –C, Pascal Object-oriented programming –Group “data” and “methods” into “objects” –C++, Java

Your First Java Program Log in to WAM cd ~/../pub cp /users/rba/pub/java/*. –DONT FORGET THE DOT AT THE END!!! tap java javac HelloWorld.java java HelloWorld

What You Just Did First you got some Java program files –Each.java file specifies one “class” Then you “compiled” one using javac –This produced HelloWorld.class Then you ran it using java –.class files are a “bytecode” representation An “interpreter” (“java”) is needed to run them –You don’t specify.class when you run it

Java Bytecode “Machine language” depends on the machine –Programs compiled for a Sun won’t work on a PC Java claims “write once, run anywhere” –Without recompiling Traditional interpreters are slow –Because they must read every character every time Java compiles to a standardized bytecode –Web browsers include a bytecode interpreter

Changing the Program Use pico to edit HelloWorld.java –Change “Hello, world!” to something different –Be careful not to change anything else! Use javac to compile it –This produces the bytecode in the.class file Use java to run it –It should print whatever you told it to –It won’t work if you include “.class” in the name

Using Java with the Web Web browsers render HTML –But HTML lacks control and data structures Newer browsers can interpret java bytecode –Java applets are programs designed for the web This allows programs to be “rented” –They still execute on the client machine –But some classes can be obtained on the web

Java Applet Example Change HelloWorldApplet.java –Make it say whatever you want javac HelloWorldApplet.java Fire up Netscape or Internet Explorer – –You should get whatever you told it to say You can also change hello.html –Then select “reload” to reload the web page

Object Models Represent things in the world as “objects” –The simplest objects are “variables” Represent actions with “methods” –The simplest methods are “operations” “Classes” group objects with methods –Classes model aspects of reality Objects are instances of classes

A Simple Example Variables: Height, Weight, Shoe size Operations: Multiply, Divide Method: Shoe size=4*Weight/Height Class: Person Object: George

Instances Classes model kinds of things –“person” is an example of a class A Class may be instantiated –I am an instance of person Object-Oriented Programming –Define simple classes with variables & operations –Define more complex classes using simple objects –Invoke a method in some class to start things

Data Types int –Like integers, but there is a biggest and smallest float –Like real numbers, but there are a finite number char –Any character in any language (Unicode) boolean –True or false

Arrays Lists of elements, each of the same data type –For example, the number of days in each month Each element is assigned an integer index –The index is used to refer to the element (x[4]) –In Java, the index numbers start at zero An string acts like an array of characters

Some Basic Operations Negate- int produces int Addint + int produces int Multiplyint * float produces float Compareint < int produces boolean Comparechar == char produces boolean

Statements Simple assignment statements –numberOfBirds = numberOfHawks + numberOfOrioles; –note difference with comparison == Statements that invoke a method –airForceOne = new Airplane(“747”); This is called a “constructor method” –Altitude = airForceOne.readAltitude(); Return a value from a method –return numberOfBirds;

Making Methods Three ways to combine statements: –Sequential {… ; …; …; …} –Conditional if (i= =3) then {…} else {…} try {…} catch (exception e) {…} –Loop do {…} while (i<5) for (i=0;i<10;i++) {…}

A Full-Featured Example TestDate computes Julian dates –The number of days since January 1 You type in the year, month, and day –The program expects these to be integers It prints out the Julian date –And it knows about leap years

Testing the Date Program javac *.java –This will compile everything java TestDate.java –TestDate contains a magic incantation to start it Answer the questions –If you make a mistake, it should complain Try lots of possibilities –February 29, 1900 is particularly interesting

Examining the Classes TestDate exercises methods in the Date class –It looks a lot like HelloWorld –Don’t mess with it - it works! TermInput reads input from the terminal –Comments at the top describe what it does –The rest is very grungy - don’t mess with it! But don’t forget to compile it!

A Full-Featured Example ValInt is a class, but it contains only data –Public data can be seen by methods in other classes Date has all the really interesting stuff in it. –This is what you will modify for homework –Use “pico” or “more” to read it

Date.java Braces and semicolons indicate sequential –Notice how layout is done for readability –Java does not care where line breaks happen But not in the middle of a word! if (boolean) {;;;} is a conditional do {;;;} while (boolean) is a loop –for (;;) {;;;} is another kind of loop

Date.java Comments explain what each part does –// indicates a comment to the end of the line Lots of attention to error handling –People WILL make mistakes –Many are easily corrected

The Key Ideas Java is a general purpose language –Sequential, conditional, and iteration Java is object oriented –Combine objects and methods to make classes Java can be used to make applets –Which can be run by web browsers