Recap: Objects and Names - PowerPoint PPT Presentation

1 / 3
About This Presentation
Title:

Recap: Objects and Names

Description:

We use names (also called variables) to refer to objects. buttonUserPressed homeURL mobyDick ... Objects are always given label names. Dog familyDog = myPet; ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 4
Provided by: davidmutch8
Category:
Tags: dog | names | objects | recap

less

Transcript and Presenter's Notes

Title: Recap: Objects and Names


1
Recap Objects and Names
  • There are two types of things in Java
  • Objects
  • the button that the user just pressed
  • the URL of your home page
  • Primitive-type things
  • The integer that represents the number of times
    you have visited Alaska
  • The character that represents your middle initial
  • There are 8 primitive types, all of which begin
    with a lower-case letter
  • The most commonly used are int, double, char and
    boolean
  • Less common are long, short, byte and float
  • We use names (also called variables) to refer to
    objects
  • buttonUserPressed homeURL mobyDick
  • and to primitive-type things
  • numberOfTimesVisitedAlaska
  • middleInitial

2
What can you do with names?
  • Java is a strongly typed language every name
    must have a type. The type of an object helps
    the compiler
  • (and programmer) tell what kinds of thing the
    object can do
  • write more efficient code

The type name pattern appears often in Java
  • Declare the type of the name
  • JButton buttonUserPressed
  • char middleInitial
  • Give (assign) a value to the thing to which the
    name refers
  • buttonUserPressed new JButton(press me)
  • yourMiddleInitial C
  • Refer to the thing to which the name refers, in
    an expression
  • buttonUserPressed.isEnabled()
  • numberOfTimesVisitedAlaska
  • System.out.println(yourMiddleInitial)

These dot notation references are where the power
of an OOP language lies!
3
Object-type versus primitive-type
  • An object-type name is justa label stuck onto an
    object.
  • Objects are always given label names.
  • Dog familyDog myPet
  • A primitive-type name is like a dial it refers
    to its value, rather than merely being a label
    stuck onto that value
  • Primitive types (int, double, char, boolean and a
    few others) always have primitive-type names
    associated with them.
  • int count 9 char grade
  • boolean isSleepy true

Questions?
Write a Comment
User Comments (0)
About PowerShow.com