DOC PREVIEW
UNC-Chapel Hill COMP 401 - LECTURE NOTES

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Storing Primitive Values and VariablesStoring Primitive Values and VariablesStoring Primitive ValuesStoring ObjectsInstance-Specific StructureInstance-Specific StructureStoring Object Values and VariablesAssignment of Object VariablesAssignment of Object VariablesAssignment of Object VariablesSlide 12Extra SlidesStoring Primitive Values and VariablesStoring Primitive Values and VariablesStoring Object Values and VariablesAssignment of Object VariablesAssignment of Object VariablesCOMP 401MEMORY REPRESENTATION OF PRIMITIVE VALUES AND OBJECTSInstructor: Prasun Dewan2STORING PRIMITIVE VALUES AND VARIABLESvariables memory516addressint i = 5;int i525Memory BlockMemory blocks are of the same size32 bits32 bits3STORING PRIMITIVE VALUES AND VARIABLESvariables memory5.58addressdouble d = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80 double e5.54STORING PRIMITIVE VALUESValues and variables of same type take same amount of fixed storage.The storage consists of one or more consecutive memory words that together form a memory block.Values and variables of different types may take different storage.5STORING OBJECTSCan we assign all variables and objects of the same object type the same sized memory block?No: A variable can be assigned instances of different classes.Different instances of the same class can take different amount of space.6INSTANCE-SPECIFIC STRUCTUREnew AnAnotherLine(new APolarPoint (14.01, 0.78), 20, 20)AnAnotherLineAPolarPointintintlocationheightwidthdoubleangleradiusdouble7INSTANCE-SPECIFIC STRUCTUREAnAnotherLineACartesianPointintintlocationheightwidthintxyintnew AnAnotherLine(new ACartesianPoint (10, 10), 20, 20)Structures of instances of same class can be different!8STORING OBJECT VALUES AND VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100public class ACartesianPoint implements Point {int xint y;…}Instance variables stored in memoryPoint p152 8Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks9ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p2568ACartesianPoint@8p2 p110ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p2568ACartesianPoint@8p2 p1p1.setX(100);100p2.getX();  100811ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p256ACartesianPoint@8p2 p1p1.setX(100);100p2.getX();  1008Point p1 = new ACartesianPoint(150,75); ACartesianPoint@7676 [email protected]();  1001213EXTRA SLIDES14STORING PRIMITIVE VALUES AND VARIABLESvariables memory516addressint i = 5;int i52 5Memory BlockMemory blocks are of the same size32 bits32 bits15STORING PRIMITIVE VALUES AND VARIABLESvariables memory5.58addressdouble i = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80 double e5.55.516STORING OBJECT VALUES AND VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100public class ACartesianPoint implements Point {int xint y;…}Instance variables stored in memoryPoint p152 8Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks17ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p256 818ASSIGNMENT OF OBJECT VARIABLESACartesianPoint@8p2


View Full Document

UNC-Chapel Hill COMP 401 - LECTURE NOTES

Documents in this Course
Objects

Objects

36 pages

Recursion

Recursion

45 pages

Load more
Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?