- Forward


Static Attributes and Methods
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

static Attributes
Back SMYC Forward
  • Definition:
    • Attributes that belong to a class rather than instances of a class
  • Implication:
    • They can be used without instantiating an object
  • Common Uses:
    • Constants, flags, special values, etc...
static Methods
Back SMYC Forward
  • Definition:
    • Methods that belong to a class rather than instances of a class
  • Implication:
    • They can be used without instantiating an object
  • Common Uses:
    • Utilities, mathematical functions
Utility Class
Back SMYC Forward
  • Definition:
    • A class that contains only static members
  • Examples:
    • The Math class
Some Useful static Attributes
Back SMYC Forward
  • In the Integer Class:
    • MIN_VALUE
    • MAX_VALUE
  • In the Double Class:
    • NEGATIVE_INFINITY
    • POSITIVE_INFINITY
    • MIN_VALUE
    • MAX_VALUE
  • In the Math Class:
    • E (base of the natural log)
    • PI
Some Useful static Methods
Back SMYC Forward
  • In the System Class:
    • currentTimeMillis()
    • exit()
  • In the Math Class:
    • abs()
    • sin()
    • cos()
    • tan()
    • log()
    • pow()
    • sqrt()
More Useful static Methods
Back SMYC Forward
  • In the Integer Class:
    • parseInt()
    • toString()
  • In the Double Class:
    • parseDouble()
    • toString()
Some Things You Can Now Think About
Back SMYC Forward
  • main():
    • Why is main() static?
  • System.in and System.out:
    • What are they?
    • What "kind of thing" is printf()?
There's Always More to Learn
Back -