Classes and Objects
Introduction¶
- When designing a class, think about objects that will be created from that class type.
- Ask yourself and think about:
- Things the object knows - attributes
- 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
- to test your real class
- to launch/start your Java Application
- to test your real class
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
- Java Archive Files based on pkzip format
- 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'