Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming II - Part 1 – Object Oriented Programming with Java Sebastian Uchitel www.doc.ic.ac.uk/~su2.

Similar presentations


Presentation on theme: "Programming II - Part 1 – Object Oriented Programming with Java Sebastian Uchitel www.doc.ic.ac.uk/~su2."— Presentation transcript:

1 Programming II - Part 1 – Object Oriented Programming with Java Sebastian Uchitel www.doc.ic.ac.uk/~su2

2 2 © S. Uchitel, 2004 Course Structure Lectures Lectures  Room 308.  Monday 14:00 and Friday 10:00. Tutorials Tutorials  Room 344 (and 308 if we need more space)  Monday 15:00 Lab Lab  4 labs dedicated to topics covered in Programming II.  Week 2 (unassessed), and weeks 3, 5, and 6. Assessment Assessment  2 assessed assignments (one for each part of the course)  2h exam, 3 questions out of 4

3 3 © S. Uchitel, 2004 Part I - Aims 1. Learn concepts and fundamentals of the Object Oriented paradigm. 2. Apply in a real programming language (Java) these concepts and fundamentals 3. Learn Java 4. Practice problem solving using Java and OO principles.

4 4 © S. Uchitel, 2004 Part I - Textbooks Java Software Solutions – Foundations of Program Design (3 rd ed.), Lewis and Loftus, Addison Wesley. Java Software Solutions – Foundations of Program Design (3 rd ed.), Lewis and Loftus, Addison Wesley. Thinking in Java (3 rd ed.), Bruce Eckel, Prentice Hall. Freely available at http://www.mindview.net/Books/TIJ/ Thinking in Java (3 rd ed.), Bruce Eckel, Prentice Hall. Freely available at http://www.mindview.net/Books/TIJ/http://www.mindview.net/Books/TIJ/ Java Documentation: Java Documentation:  http://java.sun.com/docs/books/tutorial/ http://java.sun.com/docs/books/tutorial/  http://java.sun.com/j2se/1.4.2/docs/api/ http://java.sun.com/j2se/1.4.2/docs/api/

5 5 © S. Uchitel, 2004 Part I - Outline Introduction Introduction  Motivation  From Kenya to Java Objects and Classes: A User’s Perspective Objects and Classes: A User’s Perspective  What are they?  How do I create objects from classes, and how do I use them?  Where do I get classes from in the first place? Objects and Classes: A Developers Perspective Objects and Classes: A Developers Perspective  How do I create my own classes?  How do I design “good” classes? Inheritance and Polymorphism Inheritance and Polymorphism Interfaces and Abstract Classes Interfaces and Abstract Classes Collections Collections Exceptions Exceptions

6 6 © S. Uchitel, 2004 Why Object Oriented Programming? Programming is about two things Programming is about two things  Problem solving  Managing complexity OO Programming provides conceptual framework and programming constructs for managing complexity OO Programming provides conceptual framework and programming constructs for managing complexity In principle with imperative and functional languages you can implement anything but... In principle with imperative and functional languages you can implement anything but...  Functional languages: input and output? acceptance in industry?  Imperative languages do not manage complexity well. More difficult to understand/maintain/extend.

7 7 © S. Uchitel, 2004 Why learn Java? Why Java? Why Java?  Java is an OO programming language.  Widespread in Industry for development of traditional and web-based applications Why not Kenya? Why not Kenya?  Kenya is not an OO programming language.  Developed at Imperial for educational purposes.  Outside Imperial College VERY few people know it.  Not used in Industry Why not other OO programming languages? Why not other OO programming languages?  C++? Complex (and confusing) mix between OO and imperative programming, memory management, and more...  Smalltalk? Pure? But, low acceptance in Industry, and more...

8 8 © S. Uchitel, 2004 From Kenya... void main() { // Requests two numbers and prints the larger println("Type in your 2 numbers -> "); println("The winner is " + bigger(readInt(), readInt())); } int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} } To tool...

9 9 © S. Uchitel, 2004... to Java import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }}

10 10 © S. Uchitel, 2004 From Kenya to Java By adding the bits and pieces of the previous slide, you can now write Java programs for all the Kenya programs you did in the previous term! By adding the bits and pieces of the previous slide, you can now write Java programs for all the Kenya programs you did in the previous term! However, in the next 10 lectures you will learn what these bits and pieces are! However, in the next 10 lectures you will learn what these bits and pieces are! Recommendations: Recommendations:  Throw the Kenya compiler away!  Write Java from the very first day!

11 11 © S. Uchitel, 2004 What’s new: Classes import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Classes (In Java, nearly everything appears within one) within one)

12 12 © S. Uchitel, 2004 What’s new: Objects import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Objects, object methods and calls

13 13 © S. Uchitel, 2004 What’s new: Command line parameters import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Command line parameters

14 14 © S. Uchitel, 2004 What’s new: Packages import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Packages

15 15 © S. Uchitel, 2004 What’s new: Visibility and Encapsulation import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Visibility & Encapsulation

16 16 © S. Uchitel, 2004 What’s new: Class scope import kenya.io.InputReader; public class Bigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); bigger(InputReader.readInt(), InputReader.readInt()));} static int bigger(int a, int b){ static int bigger(int a, int b){ //post: returns the larger of the 2 values if (a > b) {return a;} else {return b;} }} Class scope

17 17 © S. Uchitel, 2004 What’s new: Much more! Inheritance Inheritance Polymorphism Polymorphism Dynamic Binding Dynamic Binding Casting Casting Overloading Overloading Constructors Constructors Abstract Classes Abstract Classes Interfaces Interfaces and much more! and much more!


Download ppt "Programming II - Part 1 – Object Oriented Programming with Java Sebastian Uchitel www.doc.ic.ac.uk/~su2."

Similar presentations


Ads by Google