Object Oriented Software Development Naufal F. Setiawan School of - - PowerPoint PPT Presentation

object oriented software development
SMART_READER_LITE
LIVE PREVIEW

Object Oriented Software Development Naufal F. Setiawan School of - - PowerPoint PPT Presentation

Object Oriented Software Development Object Oriented Software Development Naufal F. Setiawan School of Computing and Information Systems University of Melbourne Workshop 3 ( Most images from Wikimedia Commons) Object Oriented Software


slide-1
SLIDE 1

Object Oriented Software Development

Object Oriented Software Development

Naufal F. Setiawan School of Computing and Information Systems University of Melbourne Workshop 3 (Most images from Wikimedia Commons)

slide-2
SLIDE 2

Object Oriented Software Development

Question 1: Java Input/Output

By the end of this tutorial you will have an IDE. So we can do IO with Scanner instead of Grok’s heavily flawed Input class. Now, which next method in the Scanner class consumes the newline character? Answer

slide-3
SLIDE 3

Object Oriented Software Development

Scanner.nextLine()

1 large latte with an extra shot\n and a banana bread\n plus 3 almond croissants\n returned consumed

slide-4
SLIDE 4

Object Oriented Software Development

Scanner.next()

1 large latte with an extra shot\n and a banana bread\n plus 3 almond croissants\n returned consumed

slide-5
SLIDE 5

Object Oriented Software Development

Question 1: Java Input/Output

How much IO do we need to know for the exam and projects?

slide-6
SLIDE 6

Object Oriented Software Development

You will not be asked to write IO in the exam

Python IO C++ IO Java IO

slide-7
SLIDE 7

Object Oriented Software Development

Arrays

What are arrays and how do we initialize them? Answer

slide-8
SLIDE 8

Object Oriented Software Development

Arrays

What are arrays? Answer Arrays are fixed-size collections of references. How do we initialize them? Answer Type[] name = new Type[size]; int[] bigArray = new int[20];

slide-9
SLIDE 9

Object Oriented Software Development

Arrays are objects...

This means any variable containing arrays will be stored as references. marchPaydays happyDays [0] = 13 [1] = 27 Code int[] marchPaydays = { 13, 27 }; int[] happyDays = marchPaydays;

slide-10
SLIDE 10

Object Oriented Software Development

Arrays are objects...

So if you make changes to the array... marchPaydays happyDays [0] = 13 [1] = 30 Code marchPaydays[2] = 30; System.out.println(happyDays[2]) // outputs '30', not '27'

slide-11
SLIDE 11

Object Oriented Software Development

Arrays of Objects

Each element of the array is a reference. rhcp[0] rhcp[1] rhcp[2] rhcp[3] Example Pig[] redHotChilliPeppa = { new Pig(), new Pig(), new Pig(), new Pig() };

slide-12
SLIDE 12

Object Oriented Software Development

Arrays of Objects

Remember though, variables store arrays as references as well. Example Person[] uniStaff; Person[] uniStudents; Person naufal = new Person("Naufal") uniStaff[133307] = naufal; uniStudents[84XXXX] = naufal;

slide-13
SLIDE 13

Object Oriented Software Development

Arrays of Objects

naufal staff student [133307] [8XXXXX]

slide-14
SLIDE 14

Object Oriented Software Development

Getting Started with Eclipse

In the interest of fairness, SWEN20003 will officially support the Eclipse IDE (as other IDEs are not available on the lab computers). Eclipse Installation (Windows / Mac) You need to download: JDK8 (from Oracle’s website). Eclipse (or your favorite) IDE. Linux users (if any) are suggested to install openjdk8 and eclipse using their favorite package manager. You know what you’re doing.

slide-15
SLIDE 15

Object Oriented Software Development

Kahoot Answers: Explanations

Code int[] array1 = {12, 7, 0, 36, 11}; int[] array2 = array1; Arrays.sort(array1); System.out.println(array2[0]); array1 and array2 refers to the same array, if we sort one of

  • them. Then the other one is also sorted!
slide-16
SLIDE 16

Object Oriented Software Development

Kahoot Answers: Explanations

Code String[] bestSubjects = {"SWEN20003", "COMP20007", "COMP30026", null, null, null}; System.out.println(bestSubjects.length); The length trap! array.length refers to the full maximum size

  • f an array. (Answer = 5).
slide-17
SLIDE 17

Object Oriented Software Development

Kahoot Answers: Explanations

Code String[] bestSubjects = {"COMP10001", "COMP20007", "COMP30026", null, "SWEN20003"}; for (int i = 0; i < bestSubjects.length; ++i) { if (bestSubjects[i].equals("SWEN20003")) { System.out.println("big mood"); } } We see that bestSubjects[3] == null. We will get a NullPointerException because we tried to call null.equals("SWEN30006"). That will crash Java as null does not have an equals method.