Java’s Two Kinds of Types
Reading
- Read this code about primitive types.
- Then read this code about object types.
- Remember to run the code for yourself, see what it does, and try experimenting with it. Here are the instructions. (Note that you only have to clone the code once for this reading, even though it has two parts: both files come together, in the same repository.)
Supplemental reading (not required, but if you’re curious and hungry for more, or you’d like some more traditional reading to supplement the code):
Important concepts
- primitive types
- operators
- limits of int types, overflow
- boolean value
- primitive types vs object types
- method, method call, receiver
- comparison operators (
==
) vs. comparison methods (.equals
) for strings
Things to consider (exercises for yourself, not to turn in)
- Ponder the puzzles at the end of PrimitiveTypes.java. What questions do you have?
-
What
might
the AST for this code from the reading look like?mascot.repeat(3)
What about this?
(mascot + "!").repeat(3)
What about this?
mascot.substring(0, 2).repeat(100)
We haven’t covered this in class yet, or in the readings. Just take a guess! What do you think might make sense? Think about it before class.
- What other little experiments can you try on this code?
Your response
What was particularly interesting, confusing, or exciting to you in this reading?