1 / 17

Programming II

Programming II - Part 1 – Object Oriented Programming with Java Sebastian Uchitel www.doc.ic.ac.uk/~su2 Course Structure Lectures Room 308. Monday 14:00 and Friday 10:00. Tutorials Room 344 (and 308 if we need more space) Monday 15:00 Lab

Télécharger la présentation

Programming II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

  5. Part I - Outline • Introduction • Motivation • From Kenya to Java • 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 • How do I create my own classes? • How do I design “good” classes? • Inheritance and Polymorphism • Interfaces and Abstract Classes • Collections • Exceptions © S. Uchitel, 2004

  6. Why Object Oriented Programming? • Programming is about two things • Problem solving • 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... • Functional languages: input and output? acceptance in industry? • Imperative languages do not manage complexity well. More difficult to understand/maintain/extend. © S. Uchitel, 2004

  7. Why learn Java? • Why Java? • Java is an OO programming language. • Widespread in Industry for development of traditional and web-based applications • 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? • C++? Complex (and confusing) mix between OO and imperative programming, memory management, and more... • Smalltalk? Pure? But, low acceptance in Industry, and more... © S. Uchitel, 2004

  8. 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 valuesif (a > b) {return a;} else {return b;} } To tool... © S. Uchitel, 2004

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

  10. 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! • However, in the next 10 lectures you will learn what these bits and pieces are! • Recommendations: • Throw the Kenya compiler away! • Write Java from the very first day! © S. Uchitel, 2004

  11. What’s new: Classes import kenya.io.InputReader; public classBigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); } 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) © S. Uchitel, 2004

  12. What’s new: Objects import kenya.io.InputReader; public classBigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); } 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 © S. Uchitel, 2004

  13. What’s new: Command line parameters import kenya.io.InputReader; public classBigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); } 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 © S. Uchitel, 2004

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

  15. What’s new: Visibility and Encapsulation import kenya.io.InputReader; public classBigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); } 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 © S. Uchitel, 2004

  16. What’s new: Class scope import kenya.io.InputReader; public classBigger { public static void main(String [] args) { System.out.println("Type in your 2 numbers -> "); System.out.println("The winner is " + bigger(InputReader.readInt(), InputReader.readInt())); } 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 © S. Uchitel, 2004

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

More Related