SOFTWARE AND PROGRAMMING 1

Slides:



Advertisements
Similar presentations
Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to XHTML Programming the World Wide Web Fourth edition.
1 Roger L. Costello 16 June 2010 XQuery
Basic Java Constructs and Data Types – Nuts and Bolts
Copyright © 2002 Pearson Education, Inc. Slide 1.
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 2 Getting Started.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 1.
BASIC SKILLS AND TOOLS USING ACCESS
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Manuscript Central Training Author Center Module 2.
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
Foundations of Programming and Problem Solving Introduction.
OPERATING SYSTEMS Lecturer: Szabolcs Mikulas Office: B38B
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
SOFTWARE AND PROGRAMMING 1 Lecture 3: Ticketing machine: Constructor, method, menu Instructor: Prof. Boris Mirkin web-site
Mike Scott University of Texas at Austin
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Using Java without BlueJ BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
1 NatQuery 3/05 An End-User Perspective On Using NatQuery To Extract Data From ADABAS Presented by Treehouse Software, Inc.
Photo Slideshow Instructions (delete before presenting or this page will show when slideshow loops) 1.Set PowerPoint to work in Outline. View/Normal click.
Break Time Remaining 10:00.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Lilian Blot TO PROGRAMMING & PYTHON Introduction Autumn 2012 TPOP 1.
Chapter 17 Linked Lists.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
Campaign Overview Mailers Mailing Lists
Vanderbilt Business Objects Users Group 1 Reporting Techniques & Formatting Beginning & Advanced.
Understanding class definitions Looking inside classes 5.0.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
1..
1 Review Quisioner Kendala: Kurang paham materi. Praktikum Pengaruh teman.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
1 How Do I Order From.decimal? Rev 05/04/09 This instructional training document may be updated at anytime. Please visit and check the.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 7: Recursion Java Software Structures: Designing and Using.
: 3 00.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
Chapter 2 JAVA FUNDAMENTALS
Clock will move after 1 minute
PSSA Preparation.
Select a time to count down from the clock above
Introduction to Programming G51PRG University of Nottingham Revision 1
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
Using Java without BlueJ
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
SOFTWARE AND PROGRAMMING 1 Lecture: Gor B4 7:40-9:00 (from ) Lab: SH131, BBK536 6:00-7:30 (from ) [each student must have obtained access.
POS 406 Java Technology And Beginning Java Code
SOFTWARE AND PROGRAMMING 1 Lecture: MB33 7:30-9:00 (except 11& ) Lab: B43, MB321, MB536 6:00-7:30 (from ) [each student must have obtained.
SOFTWARE AND PROGRAMMING 1 Lecture: UCL BC57:30-9:00 (9& – from 6:00) Lab: SH 131, SH B12 6:00-7:30 (from ) (students will be assigned.
SOFTWARE AND PROGRAMMING 1 Lecture: MB33 7:30-9:00 (11& – from 6:00) Lab: B43, MB321, MB536 6:00-7:30 (from ) EACH student must have obtained.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0.
Using Java without BlueJ BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files.
Presentation transcript:

SOFTWARE AND PROGRAMMING 1 EACH student must have obtained access to Birkbeck computing by 26.01.11 – otherwise no use in the lab Instructor: Prof. Boris Mirkin DCSIS, room 744 MAL, tel. 020 7631 6746 E-mail: mirkin@dcs.bbk.ac.uk Course Assistant: Lab/WebCT/Tests/Assignments: Mr Martin O’Shea E-mail: martin@dcs.bbk.ac.uk (FROM 26 January: Lectures 6.00-7.30, Labs 7.30-9.00)

Webpage The course web page is currently at my open web-site, with lecture notes and other relevant materials: http://www.dcs.bbk.ac.uk/~mirkin/sp109

Texts: Any, including Quentin Charatan & Aaron Kans [CK] JAVA in Two Semesters, 2nd Edition, McGraw-Hill, 2006, ISBN-10 0077108892 David J. Barnes & Michael Kölling [BK] Objects First with Java: A Practical Introduction using BlueJ, 2nd edition, Pearson Education, 2005, ISBN 0-13-124933-9 The publisher supplies a helpline in installing related software 3. I. Pohl, C. McDowell [PM] Java by dissection, Addison-Wesley, 2000, ISBN 0201751585 4. J. Farrell [F] Java Programming, 2-4 editions, Course Technology, Thompson, 2003-7, ISBN 0-619-21500-3 etc. 5. Free: ON-LINE text by D. Eck (on my web site); other URLs

Teaching Goal: Coding in Real   FRAMEWORK: the interpreter/compiler Java working; classes, objects and instances; variables and static variables; Java data types: primitive and user-defined; arithmetic and Boolean expressions; for/while and if…elseif…else structures; processing strings; elements of input/output in Java; methods and constructors; arrays and their usage, including arrays of a user-defined type

Teaching Goal   PRACTICE: To have developed skills in practical programming of small but real-world problems e.g. keeping transaction records, assigning seats to customers, managing a bus schedule, etc.

Control Final exam: 75% of mark Course-work: 25% of mark 2 open-book in-class tests, 9.02 & 9.03, 2 assignments for home work via WebCT, 9.02-9.03 & 23.02-23.03 Composition of CW 25% mark: T1 5% T2 7% A1 5% A2 8%

Control: Example Let marks of a student be as follows: A2 0 (hasn’t submitted) The total mark will be 48 because it rounds up the result: 50*0.75 + 12*0.05 + 65*0.07 + 100*0.05 + 0*0.08= =37.5 + 0.6 + 4.55 + 5 + 0 = 47.65

Teaching Philosophy (extracts) Huge respect for part-time students The bulk of students to get trained No student’s question is stupid since Software is invented Better to have simple things learnt well rather than complex things learnt not well Instructor’s small errors - a good teaching device for activation of the student’s brain Learning a language in a college differs from consuming a lunch in a diner in many ways Fast feedback on students’ issues if raised

OOP concepts you already know of How a Java program works: interpret/compile Variable Expression Data type Loop If/elseif/else structure Class Method Parameter These will be expanded to more realistic environments You don’t always need to show all these slides in class. These are intended as summaries. Discuss these topics with a demo, or in a dialog, or in any way you like.

Two JAVA environments Will be using both: Java Developer Kit JDK (currently, J2SE) (Conventional) Blue J (A public project to make JAVA coding easier) some remarks about editing warning: word is not good!

Conventional JDK: Editing A source code can be edited in any text editor: Notepad, emacs, PFE, ... MS Word caveat: by default, Word does not save in ASCII text format Make sure to save the code before compiling! The file name: the same as that of the class, with extension: say, class NicTe{…} must be saved as file NicTe.java, case sensitive some remarks about editing warning: word is not good!

Command line invocation compilation and execution of Java in JDK are done from a command line On Microsoft systems: DOS shell On Unix: Unix shell Must make sure that the commands for compiler and runtime (JVM) are in the command path. On laptop: open DOS window, show command line commands

Getting JDK on a system’s path Click “Properties” on right-buttoned “My computer” Click “Advanced” Click “Environmental variables” Enter new path (to the directory in which javac.exe and java.exe reside)

Compiling with JDK Name of the JDK compiler: javac To invoke: javac <source name> compiles <source name> and all classes it depends on into an executable on JVM file <source name>.class Example: javac NicTe.java produces file NicTe.class do the same live: edit, then compile a class

Execution in JDK “java” starts the Java virtual machine: java NicTe The named class is loaded and execution is started. Other classes are loaded as needed. Only possible if class has been compiled into a file, say, NicTe.class show execution (at least an attempt). Do this first with a class that has no main.

JDK Problem: Execute what? How does the system know which of the methods in a class to execute? This error should be reported. Explain.

“main” method in JDK BlueJ executes what the user says; The JDK java system always executes a method called main, it should have a certain signature: Signature _______________________ public static void main(String[ ] args) { ... } To work with JDK, such a method must be present in your program! Now write a main method, then try again.

A primer program (=class) /* HelloWorld.java Purpose: printing a message to the screen */ class HelloWorld { // Each program is organised as a class         public static void main(String[] args) {          System.out.println("Hello World!");         } } // end of class HelloWorld /* Always Three Types of Elements ONLY: -comments -class (with modifiers) -methods (with modifiers & parameters/arguments) */

BlueJ coding BlueJ programs are organised in the so-called projects A BlueJ project is stored in a project-specific directory on disk Some files store the source code, some store the compiled code, some store additional BlueJ related information. use laptop show BlueJ example package on disk, using Windows explorer

The BlueJ directory structure c:\bluej\calculator\ project: calculator bluej.pkg bluej.pkh Calculator.java Calculator.class Calculator.ctxt UserInterface.java UserInterface.class UserInterface.ctxt CalcEngine.java CalcEngine.class CalcEngine.ctxt Calculator UserInterface look at package in BlueJ then look at directory compare files in directory to classes in package CalcEngine

The BlueJ file structure bluej.pkg - the package file. Contains information about classes in the package. One per package. bluej.pkh - backup of the package file. *.java - standard Java source file (text). One per class. *.class - standard Java code file. One per class *.ctxt - BlueJ context file. Contains extra information for a class. One per class. explain purpose of each file type (leave .class and .java for next slide)

Software is free Available on BBK’s network Java JDK (which allows you to compile and execute your program) BlueJ (Preferred editor) Installing BlueJ (for home use) First download the Java JDK from http://java.sun.com/j2se/1.5.2/download.jsp Then download BlueJ from http://www.bluej.org/download/download.html Run “bluejsetup-202.exe” and follow the given instructions

Objects and classes Classes: program templates Objects === instances represent all objects of a kind (example: “student”) Objects === instances A template copy to represent a specific element of the class (“an individual student”) Instances are created with the so-called constructors, explicitly in JDK or somewhat easier in BlueJ

Variables, methods and parameters classes contain data stored in the so-called variables and operations which can be invoked (they are called methods in Java) methods may have inputs (they are called parameters in Java) to get additional data needed to have them executed

Remarks Many instances can be created from a single class An object has attributes/variables: values stored in fields (memory locations). The class defines what fields any its object has (a template), but each object may store its own set of values (the state of the object) A variable is initialised with assigning it a value, an object – with a constructor

More on Method Method in Java is a named set of instructions that transforms some input into an output. This is, actually, a machine implementation of the concept of algorithm which itself is a computational analogue to the mathematical concept of function. Static method: is shared by all instances.

Example of a method (1) Square function y = x2 x y 1 1 2 4 5 25 11 121 1                1 2                4 5               25 11            121 The table can be used for invoking a specific value, like, 72 = 49 or 102 = 100.

Example of a method (2)  A Java method to calculate the square function:  public int sq(int x){ return xx;}   To make it work, variables are needed: int sevs=sq(7); //puts 49 into sevs int tens=sq(10);// puts 100 into tens

Structure of a method modifiers return-type name ( parameter-list ) { Output’s type Inputs modifiers return-type name ( parameter-list ) { statements; return variable/expression;   //if return type is not void } Modifiers: static -       method/variable that belongs to class as whole and is shared by all instances public -    method/variable that is accessible from anywhere private -    method/variable that is accessible from only within the class

HelloWorld with a method // Hello-world program to demonstrate BlueJ class Hello{ // Method that does the work of printing public void go() { System.out.println("Hello, world"); } // main method for working outside BlueJ public static void main(String[] args) { Hello hi = new Hello(); //instance hi.go(); //method in instance hi

HelloWorld : WHY Why dots in ? System.out.println("Hello, world"); hi.go(); ? To take method from a specific class instance To take a class from a set of classes: Java is organised as a hierarchically structured set of classes in individual files

Assigning values Values are stored into fields (and other variables) via assignment statements: variable = expression; price = ticketCost; The value on the right is assigned to a variable on the left. A variable stores a single value, so any previous value is lost.

Variable It provides for multiple uses of the same program A variable is a name for a location in memory that can hold data. Variables are declared and/or initialised A variable declaration includes the following: A data type that identifies the type of data that is stored in the variable An identifier that is the variable’s name An optional assigned initial value

In memory: int p; p = 4; p 4

Scope of a variable:        The range of statements that can access the variable. It stretches from the declaration point to the end of the block containing the declaration Q: WHAT is BLOCK ? (part within curly braces{…} ) Q: WHAT is DECLARATION? (type name ; 3-part command)

HelloWorld N times BlueJ public class HelloN { int number; \\ variable declared public void go() { System.out.println("Hello, world"); } public HelloN(int howmany) {number=howmany; } \\constr to initialise object public void prrt() \\printing number times { for(int i=1;i<=number;i++) \\loop go(); System.out.println("ok"); } }

Loop for for(int var=1;var<=st;var++){do operation depending on var} Two types of parentheses: () and {} The expression in () consists of three different items: initialising a variable, variable update, and stop-condition Given a value of var, {} is executed, after which var is updated, then stop-condition checked and, if yes, {} is executed again; if no, the program proceeds further on

No { } in for-loop in HelloN Why? Let us add { }: where? Is there any difference between before and after “ok”?

Arithmetic Expressions  2 * 6 / 4 + 5 – 2 * 3 = 3 + 5 – 6 = 2 2 * 6.0 / (4 + 5) – 2 * 3 = 12.0/9 – 6 = – 4.67 (note: reals, not integers) 2 * 6 / 4 + (5 – 2) * 3 = 12 Java uses a natural precedence structure of arithmetic operations. If you are not sure, use parentheses!!!

Basic class structure The outer wrapper of TicketMachine public class TicketMachine { Inner part of the class omitted. } public class ClassName { Variables Constructors Methods } The contents of a class

Concepts considered: overview Compiler & interpreter JDK/JDS and BlueJ environments Method Variable; declaration and intialisation Primitive variable types Class type Arithmetic operators and expressions Class and instance HelloWorld class in three versions