SOFTWARE AND PROGRAMMING 1 Lecture: Gor B4 7:40-9:00 (from 24.01.07) Lab: SH131, BBK536 6:00-7:30 (from 24.01.07) [each student must have obtained access.

Slides:



Advertisements
Similar presentations
SOFTWARE AND PROGRAMMING 1
Advertisements

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.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
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
Hello, world! Dissect HelloWorld.java Compile it Run it.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
DAT602 Database Application Development Lecture 5 JAVA Review.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
POS 406 Java Technology And Beginning Java Code
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
SOFTWARE AND PROGRAMMING 1 Revision Lecture 11/5/2011: Review of concepts involved in lectures and exam Review of questions in previous exam papers (they.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
SOFTWARE AND PROGRAMMING 1 Lecture 7/5/8: Review of concepts involved in lectures and exam Lecture 14/5/8: Review of questions in previous exam papers.
SOFTWARE AND PROGRAMMING 1 Lecture 2, 2011 Instructor: Prof. Boris Mirkin DCSIS, room 744, tel Labs: from 26/1,
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
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.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Mixing integer and floating point numbers in an arithmetic operation.
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.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
Copyright © – Curt Hill Types What they do.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
C++ / G4MICE Course Session 1 - Introduction Edit text files in a UNIX environment. Use the g++ compiler to compile a single C++ file. Understand the C++
By Mr. Muhammad Pervez Akhtar
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
SOFTWARE AND PROGRAMMING 1 Lecture 2, 2010 Labs start : DCSIS room 131 LAB SH room B29 Lecture EACH student must have obtained.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
SOFTWARE AND PROGRAMMING 1 Advert : NO TEST1 on 7/02: TEST1 will be 14/02 Lab: SH131, BBK536 6:00-7:30 (from ) [each student must have obtained.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Information and Computer Sciences University of Hawaii, Manoa
Intro to ETEC Java.
Completing the Problem-Solving Process
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Primitive Data, Variables, Loops (Maybe)
Chapter 3 Control Statements Lecturer: Mrs Rohani Hassan
User input We’ve seen how to use the standard output buffer
Programming Language Concepts (CIS 635)
Introduction to Java Dept. Business Computing University of Winnipeg
MSIS 655 Advanced Business Applications Programming
Sridhar Narayan Java Basics Sridhar Narayan
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Presentation transcript:

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 to Birkbeck computing] Lab SH131: students whose family names (surnames) begin A-L Instructor: Ms Marie-Helene Ng SCSIS, room NG26, tel Lab BBK536 : students whose family names (surnames) begin M-Y Instructor: Prof. Boris Mirkin SCSIS, room 111, tel

2 Webpages Course web page at webCT: Please check it regularly. It will be used for announcements and assignments. Another page, at an open-to-all web- site, functions with relevant materials too:

3 Formerly Recommended Texts 1.David J. Barnes & Michael Kölling Objects First with Java: A Practical Introduction using BlueJ, Second edition, Pearson Education, 2005, ISBN The publisher supplies a helpline (team’s telephone included) in installing the related software 2. J. Farrell Java Programming, Second edition, Course Technology, Thompson, 2003, ISBN I. Pohl, C. McDowell Java by dissection, Addison-Wesley, 2000, ISBN Free: ON-LINE text by D. Eck (on my web site) and other useful URLs

4 Currently Recommended Text Q. Charatan, A. Kans Java in Two Semesters, Second edition, The McGrow-Hill Education, 2006, ISBN In fact, either will do. One more: Edward Currie (2006), Fundamentals of Programming Using Java, Thomson Learning, ISBN-10: This book contains well explained examples but covers not all the material: an excellent text for slow learners.

5 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 –Download BlueJ from –Run “ bluejsetup-202.exe” and follow the given instructions Software is free

6 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

7 Compiling with JDK Name of the JDK compiler: javac To invoke: javac compiles and all classes it depends on into an executable on JVM file.class Example: javac NicTe.java produces file NicTe.class

8 Execution “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

9 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)

10 Concepts from lecture 1 Compiler (javac.exe) and Interpreter (java.exe), should be on system’s path JDK and BlueJ for running Java Class (template) and Object (its instantiation); every Java program must be a class Variable and its type; primitive types Method (input-output operation) and its Parameters (inputs - with their types at method’s declaration)

11 Concepts to be learnt Arithmetic expression and precedence Casting Boolean expression Statement Loops for, while Choice structure if/elseif/else

12 Five arithmetic operations in Java * multiplication 5  3=15 /division 36/9=4, 39/9=4, 39/50=0 (integers) 36.0/9=4.0, 39.0/9= , 39.0/50=0.78 (reals) %remainder 36%9=0, 39%9=3, 39%50=39 +summation5 + 3 = 8 -subtraction5 – 3 = 2 Other operators such as Abs or exp or log are in class Math of Java (to be explained later)

13 Arithmetic expressions Precedence : */% first, then +- If not sure, use (…): first performed inside 2 * 6 / – 2 * 3 = – 6 = 2 (integers) 2 * 6.0 / (4 + 5) – 2 * 3 = 12.0/9 – 6 = – 4.67 (reals are here) 2 * 6 / 4 + (5 – 2) * 3 = 12

14 Unifying Type Unifying Type: The type of result when calculations use different types Order for Implicitly Establishing Unifying Type: double float long int short byte

15 Type casting The unifying type can be overridden by explicitly stating a type cast: Place the desired type result in parentheses followed by the variable or constant to be cast (int) 6.0+7=13 Example: int bankbalance=931786; float weeklybudget = (float) bankbalance /4;

16 Boolean expressions: true or false |, || or &, && and !not ==equal to <less than >greater than <=< or == >=> or == Always after arithmetic; If not sure, use parentheses (…): first performed inside

17 Condition int x=2; x+4*2>5true at what x is this false? int x=3; int y=1; x-4 == 1.5*(y+2) can this be true?

18 Precedence table

19 Loop for for(int var=1;var<=st;var++) % no ‘;’ here!!! { do operation depending on var } var++ is var=var+1, not var=var+2; Two types of parentheses: (loop specified) and {body to do} The expression in () consists of three items in this order: –initialising the counting variable once, –variable update, and –stop-condition First, –var is intialised, –stop-condition is tested; if true, block {} is executed, if no, the program proceeds further on, after the block { } –control returns to ( ) After control returns to ( ), –var is updated; –stop-condition is checked; if true, block {} is executed, then control returns to ( ), if no, the program proceeds further on, after the block { }

20 Loop while: less rigid for(init; test; update){ statements } All three in the parentheses refer to a counter that is initialised, updated and tested over reaching the pre-specified threshold Structure of while loop, less rigid – init, test and update are not necessarily based on counter: init; while(test){ statements; update } Similar elements: ( ), { }, initialisation, test condition (not necessarily involving the counter!), and update

21 Example: for (int K = 10; K > 1 ; K--) { //k-- is k=k-1; if (K < 7) { break; } // Stops execution of the loop else System.out.print(“ ” + K); } 1. What this loop does? 2. Can it be rewritten in the while format?

22 Example: answer 1 for (int K = 10; K > 1 ; K--) { if (K < 7) { break; } else { System.out.print(“ ” + K);} } What this loop does? Prints

23 Example: answer 2 int K = 10; while(K >1) { if (K< 7) break; else System.out.print(“ ” + K); K--; }

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

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

26 No { } in for-loop in HelloN Why? A: Because loop covers one next statement y default Let us add { }: where? Is there any difference between before and after “ok”? A: Yes, there is. If after, HW and ok alternate in the out-print.

27 Three branching structures (1) Do under a condition; otherwise do nothing [if… structure] if(BooleanExpr) Statement or if(BooleanExpr) {Statements} (2) Do under a condition; otherwise do differently [if…else… structure] if(BooleanExpr) {Statements1} else {Statements2}

28 Java branching structure (3): (3)Several conditions to do differently [if…else if… … else if… else structure] if(BoolExpr1) Statement1; else if(BoolExpr2) \\and not BoolExpr1 Statement2; else \\ (not BoolExpr1) and (not BoolExpr2) Statement3; Note NO Bool. Exp at else

29 If/else example Ticket’s price is £5, 60+ concession £3, children 12 or less go for free Need a variable for the age, say YourAge, and the price, say Price; The fragment can be as: if (YourAge<=12) Price=0; else if (YourAge<=60) Price=5; else //note NO CONDITION here Price=3;

30 Statements Assignment (followed by ;) Method call (followed by ;) if/ifelse/else (block, no ;) for/while loop (block, no ;) break (followed by ;)

31 This is what was covered tonight Arithmetic expression and precedence Casting Boolean expression Statement Loop for Loop while Choice structure if/elseif/else