Skip to content

Classes and Objects

Introduction
  • When designing a class, think about objects that will be created from that class type.
  • Ask yourself and think about:
    1. Things the object knows - attributes
    2. Things the object does - Methods
  • A class is a blueprint for an object
  • The Dot (.) operator
    • Gives you access to an object's state and behavior
Quick get out of MAIN
  • As long as you are in main, you are not in ObjectVille
  • In a true Object Oriented application, you need objects talking with objects
    • unlike the static main creating and testing objects.
  • The Two uses of Main
    1. to test your real class
      1. to launch/start your Java Application
Heap, Globals
  • Heap
    • Every object created goes to Heap
    • Java Heap is called Garbage-collectible Heap
  • Globals
    • There is no concept of Global variables and methods in Java
    • But, marking a method as public static, makes it behave like global
    • Similarly, marking variable as public, static and final does the job
  • JARs
    • Java Archive Files based on pkzip format
      • a .jar file can hold the classes together and a simple text file formatted as something called a manifest, that defines which class in the main() method should be run
  • IMPs
    • Java is Pass By Value
    • The compiler defaults in similar number types
    • It defaults to
      • Double, so for Float you have to specify using something like a 'f' float a = 3.45f
      • Int, so for Long you have to specify using something like a 'L'
How do the objects Behave?