Java

Vars:

Names prefixed by letter, underscore,  dollarsign

Primitive = basic var

 

  • boolean (true/false)
  • char: unsigned 16 bits
  • byte: signed 8 bits
  • short: signed 16 bits
  • int: signed 32 bits
  • long: signed 64bits
  • float: 32 bits
  • double: 64 bits
When assiging a constant float value to var assign as:
v = 32.5f to cast constant as a float as Java asumes double
Complex:
  • String
    • String title;
    • title = "xxx";
  • Arrays (are objects as well)
    • int[] nums // declares num are an array of ints (as a type)
    • nums = new int[7]  // creates the new array
    • int[] nums = new int[7] // combine both the above
Uninitialised vars
Local (as opposed to instance) vars must be initialised or you get a compiler error

Reference = link to an object
  • like a pointer so you are passing the address of the object around not the object
  • eg: dog myDog = new Dog();


Objects
Uninitialised vars
Instance vars always have a default value:
  • integers: 0
  • float: 0.0
  • boolean: false
  • references: null
Methods
void bark(intNoOfBarks) {
  xxxx;
}
A method uses parameters, a caller passes arguments
Methods can return values
int bark(intNoOfBarks) {
  xxxx;
  return xxx;
}
Getters /Setters (Acessors/Mutators)
Mark all instance vars privaye and associated geters/seters public