Example homework 3 html validator htmlvalidator

This preview shows 6 out of 11 pages.

Example: Homework 3 (HTML Validator) HtmlValidator  stores a reference to a  Queue the  Queue  stores many references to  HtmlTag  objects each  HtmlTag  object stores a reference to its element  String private Queue<HtmlTag> tags; ... HtmlValidator bac k ... ... ... front Queue private String element; ... HtmlTag private String element; ... HtmlTag l m t h String y d o b String
Image of page 6

Subscribe to view the full document.

7 Null references null  :  A value that does not refer to any object. The elements of an array of objects are initialized to  null . String[] words = new String[5]; not the same as the empty string  ""  or the string  "null" Why does Java have  null  ?  What is it used for? index 0 1 2 3 4 value null null null null null words
Image of page 7
8 Null references Unset reference fields of an object are initialized to  null . public class Student { String name; int id; } Student timmy = new Student(); name null timmy id 0
Image of page 8

Subscribe to view the full document.

9 Things you  can  do w/  null store  null  in a variable or an array element String s = null; words[2] = null; print a  null  reference System.out.println(timmy.name); // null ask whether a variable or array element is  null if (timmy.name == null) { ... // true pass  null  as a parameter to a method some methods don't like  null  parameters and throw exceptions return  null  from a method  (often to indicate failure) return null;
Image of page 9
10 Dereferencing dereference : To access data or methods of an object. Done with the dot notation, such as  s.length() When you use a  .  after an object variable, Java goes to the  memory for that object and looks up the field/method requested.
Image of page 10

Subscribe to view the full document.

Image of page 11
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern