SOFTWARE AND PROGRAMMING 1 Lecture 23.03.11 TODAY: Python and Java Instructor: Prof. Boris Mirkin web-site

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

SOFTWARE AND PROGRAMMING 1 Lecture 3: Ticketing machine: Constructor, method, menu Instructor: Prof. Boris Mirkin web-site
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Principles of Object-Oriented Software Development The language Java.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Defining Classes and Methods Chapter 4.1. Key Features of Objects An object has identity (it acts as a single whole). An object has state (it has various.
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
“Introduction to Programming With Java”
Hello AP Computer Science!. What are some of the things that you have used computers for?
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Fundamentals of Software Development 1Slide 1 Recap: “From scratch” projects Today’s software engineering is almost NEVER “from scratch”Today’s software.
Welcome to the Lecture Series on “Introduction to Programming With Java”
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Lecture # 5 Methods and Classes. What is a Method 2 A method is a set of code which is referred to by name and can be called (invoked) at any point in.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
“Introduction to Programming With Java”
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
CIT 590 Intro to Programming First lecture on Java.
An Introduction to Python Blake Brogdon. What is Python?  Python is an interpreted, interactive, object-oriented programming language. (from python.org)
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
02 Variables1November Variables CE : Fundamental Programming Techniques.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
SOFTWARE AND PROGRAMMING 1 In-class open-book TEST1 on 6/02 Lab SH131: (from ) Ms Mihaela Cocea Room London Knowledge Lab Emerald.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
Classes - Intermediate
SOFTWARE AND PROGRAMMING 1 Lecture 4: Ticketing machine details: Constructor, method, static/instance variables Instructor: Prof. Boris Mirkin
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Programming – Lecture 15 Going Beyond the ACM Library.
1 Text File Input and Output. Objectives You will be able to Write text files from your Java programs. Read text files in your Java programs. 2.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
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.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
10/16/07.
SOFTWARE AND PROGRAMMING 1
GC211 Data Structure Lecture 1 Sara Alhajjam.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Chapter No. : 1 Introduction to Java.
Java Course Review.
Learning about Programming Languages
Learning about Programming Languages
Java Language Basics.
Java so far Week 7.
slides created by Ethan Apter
Introduction to Java Brief history of Java Sample Java Program
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
The keyboard is the standard input device.
Python Basics with Jupyter Notebook
More on iterations using
Lecture 1 Review of 1301/1321 CSE /26/2018.
Presentation transcript:

SOFTWARE AND PROGRAMMING 1 Lecture TODAY: Python and Java Instructor: Prof. Boris Mirkin web-site Revision lecture 11 May: Java main concepts andpast exam questions

2 In-class Test 2 results Marks improved for those with 20 or greater Distribution –34 or less9 – – –75 or more7 _____________________________ –Total36 PLS – DO COME to SP1 Exam 31 May, even if your expected mark is low: Head count is done over exams only, and our HEFCE funding depends on that

3 Java/Python: Some history Java: SUN Microsystem’s creation supported by Netscape (currently, Mozilla) web browser – 1996, 2004 Python: one dedicated man’s development, Van Rossum (Netherlands, USA) – 1994, 2000, 2008

4 Python and Java: Similarities - Object oriented -Typed variables -Static/non-static -Default constructors -User defined types -Assignments -Arithmetic operations -Expressions -If/elseif/else branching -Header-body method/function structure -Local variables -String/array entries indexed from 0,1,…

5 Python and Java: Differences JavaPython Compiler/InterpreterInterpreter Interactive regime Lower level, e.g.Higher level, e.g. System.out.println(); print() Class cannot changeStructuring by using ; and {}ident / line

6 Python and Java: Differences JavaPython Loop for : formalLoop for : informal Type: explicitType: implicit class – alwaysonly for user-defined types Work within main methodNo main method Array & List & Collections (list, set, map) Collections (tuple,set, dictionary)

7 Python and Java: Differences JavaHW.java class HW{ public static void main(String[] args){ System.out.println(“Hello world”);} } Python HW.py >>>print(“Hello world”) * Java’s System.out.print(“Hello world”);} is Python’s print(“Hello world”),

8 Python and Java: Differences STRINGS: Python is much richer, e.g. >>>s=‘Hello, world’ >>>s.find(‘l’) 2 >>>ns=s.replace(‘o’,’X’) >>>print ns ‘HellX, wXrld’ >>>s.split() [‘Hello,’, ‘world’] >>>s.split(‘l’) [‘He’, ‘o, wor’, ‘d’]

9 Python and Java: Differences Input from keyboard Java: Scanner class called, Instance created and its method used to feed in Python: input anything (or raw input for all inputs treated as strings) print(“Please enter a number’) R=input() print(“You entered ”, R)

10 Python and Java: Differences For loop Task: print numbers from 1 to 10 Java for( int count=1;count<11;count++) System.out.println(count); Python for count in range(1,11) print(count)

11 Python and Java: Differences For loop in array/list Task: print contents of array/list demoar Java for( int count=0;count<demoar.length;count++) System.out.println(“Current item ”+demoar[count]); Python demoar=[‘life’, 5, 6, ‘and’, ‘other’, 333] for count in demoar print(“Current item %s” % count)

12 Python and Java: Differences METHOD/Function Java: a special structure output_type o_name(typed parameters) { BODY }//, e.g. int square(int x){ return x*x;} Python: an object (flexibility!) def o_name(typed parameters): BODY #, e.g. def square(x): return x*x

13 Python and Java: Differences Class and instances Java: class Pet{ BODY } Pet p1=new Pet(); Pet p2=new Pet(); // two instances Python: class Pet: BODY p1=Pet() p2=Pet()

14 Python and Java: Differences Constructor Java: method class_name no_output_type class Pet{ int v1; String v2; Pet(int a, String B){ v1=a; v2=B;} } Pet p1=new Pet(5, “HaHa”); Pet p2=new Pet(3, “AhAh”);

15 Python and Java: Differences Constructor Python: method __init__() class Pet: int v1; String v2; def __init(self, int a, String B){ self.v1=a self.v2=B # ‘self’ in Python, as ‘this’ in Java, refers to the # instance being created p1= Pet(5, “HaHa”); p2= Pet(3, “AhAh”);

16 Python and Java: Differences Handling files in Python: Downloading a file import urllib urllib.urlretrieve( “nonimportant.pdf”) File input F=open(‘test.txt’, ‘r’) for line in F: print line[0] F.close

17 Python and Java: Differences Handling files in Python: File output F=open(‘want.txt’, ‘w’) #or, F=open(‘want.txt’, ‘a’) for appending for line in F: F.write line F.close