INF101: Object-Oriented Programming
Total Page:16
File Type:pdf, Size:1020Kb
INF101: Object-Oriented Programming Lecture 1: Introduction Welcome to INF101! • Today: – Practical course information: who, what, where? – Introduction to Object-Oriented Programming About myself • From the Netherlands • Lecture language options: • Dårlig norsk! • Goed Nederlands! • English • I do understand Norwegian, so feel free to speak/write Norwegian to me if you prefer this! INF101 Teaching Team Responsible Adjunct Teaching Teaching lecturer: lecturer: assistant: assistant: Noeska Smit Jan Byška Albin Yngve S. Severinson Kristiansen INF101 Teaching Team: Gruppeledere • Brigt Arve Toppe • Eirin Sognnes Håvardstun • Rikke Aas • Fromsa Hera • Jens Christian Tiemann • Jarle Wallevik Hetland • Daniel Berge • Sjur Finne • Jakob Kallestad • Karl Henrik Elg Barlinn • Tobias Eilertsen INF101 Content • Follow-up course to INF100 • Object-oriented Programming in Java INF101 Topics • Object-oriented Programming • Abstraction • Git • Testing, interfaces, types • Generic classes • Inheritance, class invariance, abstract classes • Recursion, searching, sorting • Exception handling and data streams • Immutable objects INF101 Pensum • All lectures • All weekly assignments and two compulsory assignments • All material that will be handed out • No concrete book, but recommended reading in the ‘Digital litteraturliste’ on Mitt UiB. • https://retting.ii.uib.no/inf101/inf101.v19/wikis/pensumoversikt Course Set-Up: A typical week • Mo. and Tu. 12:15-14:00: Lecture • Weekly assignments: practical lab-work in groups • Some Fri.: 12:15-14:00: Repetition • Schedule: https://tp.uio.no/uib/timeplan/?id=INF101&type=course &week=04&ar=2019 Typical location - Realfagbygget ‘Bygningen regnes som et av de beste eksempel på brutalistisk arkitektur i Bergen’ Some exceptions: • This week, the lectures are Monday and Friday in Egget • No group hours yet! Practical group hours Groups • Pick any group you like: first come, first serve (max. 20 students per group) • 12 groups initially (but we will merge them based on attendance numbers) in 5 timeslots • Within a time-slot, please fill out the leftmost groups first Left-most groups first When full, try the next Weekly assignments • Single-player/Do-It-Yourself individual hand-ins • GitLab system that will automatically check your results and give feedback • Ask your knowledgeable group leaders for help Compulsory Semester Assignments • Two bigger assignments/projects where you get more time • Count for the final grade Code nights • We plan to organize two ‘kodekvelder’ for some extra time to work on the semester assignments Repetition hours • Some Fridays: repetition hours from 14:15 – 16:00 at the Realfagbygget Auditorium 1. • Will be announced as they occur Exam • Digital exam in Inspera • 23.05.2019, 09:00-14:00 (5 hours) How to reach us • Lab group hours • Facebook group: INF101v19 • Mitt UiB discussion platform Pro Tips (1) • Our ordliste No-En: https://retting.ii.uib.no/inf101/inf101.v19/wikis/ordliste • Online library UiB - free access to books, for example: https://ebookcentral-proquest-com.pva.uib.no/lib/bergen- ebooks/reader.action?docID=540877&query=head+first+design Pro Tips (2) Pro Tips (3) • A lot of work, much of it practical • Semester assignments are extensive, start early • Be active, and have fun! ☺ Questions? Intro to Object- Oriented Programming What is Object-Oriented Programming (OOP) • “the premise that all programs are essentially computer-based simulations of real-world objects or abstract concepts” For example: flight-simulator programs, business programs, computer games FFIFA Fortnite Some history • What was the first object-oriented programming language? • Where and when was it developed? Simula, developed in Oslo in the 1960s! The programming language had the most impact on me was Simula. It was the first object-oriented language. Really lovely. https://www.electronicdesign.com/embedded-revolution/c-what-did-you-use So what are objects? • Entities that have certain basic characteristics: – Type – Identity – State – Behavior Type • What kind of object it is Identity • Every occurrence of an object (instance) can be distinguished from other occurrences State • Combination of values for all attributes of an object (which are determined by type) Behavior • What the object can do Quote James Whitcomb Riley (1849–1916): “When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.” Exercise: Analyze a Text In the game Super Mario Bros., the nice Type? character Mario sets off on an adventure to save the sassy Princess Peach Toadstool State? from the mean King Bowser Koopa. Peach Behavior? wears a golden crown, and Mario wears a red hat. Bowser wears a green shell. Mario can jump and run to make his way to Bowser. You lose the game when Mario or Peach dies, and win if Bowser dies. Exercise: Analyze a Text In the game Super Mario Bros., the nice Type? character Mario sets off on an adventure to save the sassy Princess Peach Toadstool State? from the mean King Bowser Koopa. Peach Behavior? wears a golden crown, and Mario wears a red hat. Bowser wears a green shell. Mario can jump and run to make his way to Bowser. You lose the game when Mario or Peach dies, and win if Bowser dies. Exercise: Analyze a Text In the game Super Mario Bros., the nice Type? character Mario sets off on an adventure to save the sassy Princess Peach Toadstool State? from the mean King Bowser Koopa. Peach Behavior? wears a golden crown, and Mario wears a red hat. Bowser wears a green shell. Mario can jump and run to make his way to Bowser. You lose the game when Mario or Peach dies, and win if Bowser dies. Exercise: Analyze a Text In the game Super Mario Bros., the nice Type? character Mario sets off on an adventure to save the sassy Princess Peach Toadstool State? from the mean King Bowser Koopa. Peach Behavior? wears a golden crown, and Mario wears a red hat. Bowser wears a green shell. Mario can jump and run to make his way to Bowser. You lose the game when Mario or Peach dies, and win if Bowser dies. Break Great, so we have objects • Entities that have certain basic characteristics: – Type – Identity – State – Behavior How does this come back in Java? • Type: class • Identity: memory location • State: class variables (fields) • Behavior: methods Type in Java • What kind of object it is • Types are defined by classes • When you create an object from a type, this object is of type ‘class’ Type Example ducka and duckb are of type Duck • the identity of this first Duck object (that is, its address in memory) is assigned to the variable ducka Identity in Java • Every occurrence of an object (instance) can be distinguished from other occurrences • All stored in different memory locations • If you compare objects (equality operator ==), Java checks if they refer to the same object instance, if yes: two variables or expressions are considered equal. Identity Example – what gets printed? Identity Example – the result State in Java • Combination of values for all attributes of an object (which are determined by type) • The attributes of a class are determined by class variables, aka fields • These can change over time (unlike identity) • Some are public, some are private State Example Behavior in Java • What the object can do • Like state, depends on type (class), but not different for every instance • Services the object can provide to other objects • Defined in methods Behavior Example Class in Unified Modeling Language (UML) Wrap-up Objects • Type: class -> What is it? • Identity: memory location –> Which object is it? • State: class variables (fields) -> What properties does it have? • Behavior: methods -> What can it do? Questions But wait, there’s more… Four main concepts in OOP • Encapsulation • Abstraction • Inheritance • Polymorphism Encapsulation • Bundling properties and methods of objects in classes Abstraction • Interface concept: Set of methods and fields that the class makes public for other objects to access • How it does what it does: hidden in private properties and methods – Reduces complexity – We can change it later without affecting other classes Inheritance • Eliminate redundant code by inheriting properties and methods from a superclass • New class that derives from superclass is subclass • Subclass automatically gets all fields and methods from superclass • Implements ‘is-a-type-of’ relationships Polymorphism • Many Forms • Get rid of long if/else, switch/case by specifying specific methods in subclasses Benefits • Encapsulation: reduce complexity + increase reusability • Abstraction: reduce complexity + isolate impact of change • Inheritance: eliminate redundant code • Polymorphism: refactor long if/else cases More details on all of this in the rest of the course! Questions What can you do? • Join the MittUiB course page and Facebook group • Go to https://retting.ii.uib.no/inf101/inf101.v19/wikis/oppsett and follow the installation instructions for Java and Eclipse to be ready for the first practical assignment next week • Have a look at Object-oriented Programming in 7 minutes | Mosh https://www.youtube.com/watch?v=pTB0EiLXUC8 What’s next? • Next lecture Friday, same time same place! • Topic: Java vs. Python image source: https://stackify.com/java-vs-python/ (Coffee vs. Snake) Thanks!.