// DrJava saved history v2 // this is reconstructed version of key class events - original was not saved correctly /** Today we examine what */ /* a variable is. */ /* It is really a reference */ /* to an object we create */ /* in memory. */ Student faisal; faisal Student maria; Student faye; /* we do not have a student yet - only a variable that can refer to a Student object */ maria faye /* Now create a student (in memory) and assign its position in memory to the variable */ /* we have created. */ faisal = new Student("Mike", "K."); /* faisal now refers to the student that we created in memory using the "new" word */ faisal.getName() maria = new Student("Mohamed", "H."); maria.getName() /* maria now refers to the student that we created in memory using the "new" word */ faye = new Student("Azadeh", "E."); faye.getName() /* So if I assign maria to faye, what happens? */ faye = maria; faye.getName() /* faye now refers to the same student that maria refers to */ /* if I change maria to refer to faisal, will faye change too? */ maria.getName() maria = faisal; maria.getName() faye.getName() /* no, faye is still referring to the student at the location in memory that we assigned it */ /* however, maria has changed, and is now referring to the student in memory that was */ /* referred to by faisal */ /* how do we declare a reference variable that refers to an Integer i?*/ Integer i; /* how do we make i refer to a value of 5? */ i = new Integer(5); /* note that Integer is not the same as int */ /* have a look at the API documentation under the Java Links on the course webpage*/ /* select the java.lang package on the upper left hand side */ /* You can see that there are several classes with names like primitives but they are capitalized */ /* These are actually pre-written classes that extend the things you can do with a primitive */ /* Things like converting a string to an integer, or getting the max and min value of an Integer, Real, Double, etc. */