Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE110 Lecture 24

CSE110 Lecture 24

Principles of Programming with Java
References
(202006)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

June 22, 2017
Tweet

Transcript

  1. CSE110 Principles of Programming with Java Lecture 24: References Javier

    Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com Office Hours: By appointment
  2. References

  3. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 3 Assignment

    | Primitive Types • The act of assignment takes a copy of a value and stores it in a variable • For primitive types:
  4. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 4 References

    • An object reference variable holds the memory address of an object • Rather than dealing with arbitrary addresses, we often depict a reference graphically as a “pointer” to an object • For object references, assignment copies the memory location: jane john jane john
  5. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 5 Assignment

    | References
  6. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 6 Arrays

  7. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 7 Assignment

    | References
  8. Arrays of Objects

  9. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 9 Arrays

    of Objects • The elements of an array can be object references. • Suppose that we have the Student class Student[] list = new Student[5]; //The following causes NullPointerException int id = list[0].getID(); //We need to instantiate each object first: list[0] = new Student(“Bob”); list[1] = new Student(“Mary”); list[2] = new Student(“Peter”); // ... // OR we can use the Initializer: Student[] list = {new Student(“Bob”), new Student(“Mary”), new Student(“Peter”) };
  10. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 10 Arrays

    of Objects
  11. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 11 Arrays

    of Objects
  12. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 12 Reference

    Chapter 6
  13. CSE110 - Principles of Programming Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2020

    Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.