Docsity

Understanding References, Packages, and Javadoc in Java: A Comprehensive Guide, Slides of Java Programming

Partial preview of the text

Download Understanding References, Packages, and Javadoc in Java: A Comprehensive Guide and more Slides Java Programming in PDF only on Docsity!

References, packages

and javadoc

“pointers” are “references”

memory locations Docsity.com

Announcements

HW 2 solutions on moodle

Matryoshka doll

(See: MemoryEater.java)

References - null

If a variable references null, then you will crash your program if you use the reference

For example:

String x = null; int y = x.length();

References - leaking

If data is private, then it can only be changed through methods, right?

Classes are stored as references... If you give out its reference, then it can be changed (See: NextInLine.java and Counter.java) Docsity.com

References - leaking

If you want to not leak your private classes, make a copy of that class and give that out instead

This would not have been a problem if couter did not have a setCounter(x) method

(Remember if you cannot change the data, the class is called immutable, like String)

Packages

Java files in a packages are grouped together and you can see and use classes in the same package

javadoc and importing

javadoc gives descriptions of how classes, methods, etc. should be used

(See: SampleJavadoc.java)

To import other packages and/or JARs (other people's Java code) in NetBeans, simply right click on the “Libraries” in the package