2012-02-26

Java - Getting Started

 

// *** Both object and object2 refer to this one object!
SampleObject object = new SampleObject();
SampleObject object2 = object;


// object.getSampleName doesn't change!
SampleUtil.tryReferanceData(object.getSampleName);

public class SampleUtil{
 
 public static void tryReferanceData(String inputy) {
  inputy = "tryReferanceData";
 }
}


// method parameters & fields...
public void setCurrency(Double currency)
{
 // The parameter visitor is the same name as the field visitor. 
 currency = currency;  
 // correct this
 this.currency = currency;
}


// *** the java naming convention recommends package names be all lovercase
// *** prodected access can seem child class or  other class in the same package.
// *** A static fiels or method can be accessed without any instances of the class existing.
// *** Created objects' static fields reference only one memory location.
public class Employee {
 public String name;
 public static int moneyAmount; // Created all objects reference this static fields!
 //.....
 public static int getMoneyAmount() {
  return moneyAmount;
 }
}

// *** the java naming convention recommends package names be all lovercase
// *** prodected access can seem child class or  other class in the same package.
// *** A static fiels or method can be accessed without any instances of the class existing.
// *** Created objects' static fields reference only one memory location.
public class Employee {
 public String name;
 public static int moneyAmount; // Created all objects reference this static fields!
 //.....
 public static int getMoneyAmount() {
  return moneyAmount;
 }
}