CS 18000 Lecture Notes - Lecture 7: Foreach Loop, Java Syntax, Dynamic Array

21 views3 pages
CS 180 - 2/21/2017
Special Trick: this() in Constructor
Use this(...) to invoke one constructor from another
Java Access Modifiers
Can apply to members: fields and methods
Modifiers control access to members from methods in other classes
This list is from least to most restrictive
Make methods public
Allows anyone to use them
They should be written defensively to “protect” the object internal state
Accessor and Mutator Methods
With fields being private, all access to them from outside the class is via methods
There is no special Java syntax, just naming convention
Accessor: “get” access (read) field in an object
Mutator: “set” mutate (change) field in an object
Generic Classes
Basic idea: A generic class is one that can be parameterized with another class
ArrayList<E> is parameterized with class (or type) E. It can only “hold” elements
ArrayList Class
A class provided in the java.util package
Dynamic array: Automatically grows to accommodate new items
Works with any type of object, but you must specify the type when the ArrayList object
is created
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Use this() to invoke one constructor from another. Modifiers control access to members from methods in other classes. This list is from least to most restrictive. They should be written defensively to protect the object internal state. With fields being private, all access to them from outside the class is via methods. There is no special java syntax, just naming convention. Accessor: get access (read) field in an object. Mutator: set mutate (change) field in an object. Basic idea: a generic class is one that can be parameterized with another class. Arraylist is parameterized with class (or type) e. it can only hold elements. Dynamic array: automatically grows to accommodate new items. Works with any type of object, but you must specify the type when the arraylist object created is. A default method is an instance method defined in an interface whose method header begins with the default keyword.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions