DOC PREVIEW
UNC-Chapel Hill COMP 14 - Primitive Values vs Objects

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 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 17 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 17 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 17 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 17 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 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Primitive Values Vs ObjectsWrapper ClassesOther Wrapper ClassesStoring Primitive Values/VariablesStoring Objects Values/VariablesStructured ObjectsSlide 7InheritanceSlide 9Assignment of Object VariablesSlide 11Slide 12Slide 13== for ObjectsSlide 15== Vs Equal for Strings== Vs equals() for ObjectsPrimitive Values Vs Objects•Wrapper Classes•Memory Representation of Primitive Values Vs Objects–Pointers•Equal Vs ==•Sharing of Objects•Garbage Collectionvector.elementAt(3)5new Integer(5)Wrapper ClassesAStringDatabaseAStringHistoryStringObjectintbooleanchar doublewrapper class“Joe Doe”.toString()5.toString()Vector vector = new Vector()vector.addElement(“Joe Doe”)vector.addElement(5)vector.addElement(new Integer(5))(new Integer(5)).toString()vector.elementAt(3).intValue()NumberIntegerDoublewrapper classOther Wrapper Classes•Double–public Double(double value)–public double doubleValue()•Boolean–public Boolean(boolean value)–public boolean booleanValue()•Character–public Character(char value)–public char charValue()•Float, Short, LongStoring Primitive Values/Variables55.55.548double d52int i80double e8 5.5 5.55165int i = 5;memory addressdouble d = 5.5;same sizesame, double sizedouble e = d;Storing Objects Values/Variables1685.5Double@8860Integer I516Integer@1648Double DInteger I = new Integer(5)Double D = new Double(5.5)memory addressdifferent sizesvariables same sizeStructured Objectspublic class APoint implements Point {int x, y; public APoint (int initX, int initY) { x = initX; y = initY;}public int getX() {return x};public void setX(int newVal) {x = newVal;}public int getY() {return y};public void setY(int newVal) {y = newVal;}}Structured Objects16805.5Double@8860Integer I516Integer@1696Point p5010080APoint@8048Double Dpublic class APoint implements Point { // instance vars int x, y; //methods …}Point p = new APoint(50, 100)Inheritancepublic class ABoundedPoint extends APoint { APoint upperLeftCorner, lowerRightCorner; public ABoundedPoint (int initX, int initY, Point initUpperLeftCorner, Point initLowerRightCorner) { super(initX, initY); upperLeftCorner = initUpperLeftCorner; lowerRightCorner = initLowerRightCorner; } …}}Superclass ConstructorInheritancepublic class APoint implements Point { int x, y; …}new ABoundedPoint(75, 75, new APoint(50,50), new APoint(100,100) )8165050APoint@8848ABoundedPoint@4810016APoint@161007575public class ABoundedPoint extends APoint { Point upperLeftCorner ; Point lowerRightCorner; …}Assignment of Object VariablesPoint p1 = new APoint(50, 50); Point p2 = p1;5050APoint@88816Point p1848Point p2P1 [email protected](100);Assignment of Object VariablesPoint p1 = new APoint(50, 50); Point p2 = p1;10050APoint@88168Point p1848Point p2p1.setX(100);p2.getX() 100 P1 P2APoint@8p1 = new APoint(200,200);Assignment of Object Variables10050200APoint@86420016488Point p1APoint@648 Point p264Point p2 = p1;p1 = new APoint(200,200);p2.getX() 100 p1.setX(100);p2.getX() 100 Point p1 = new APoint(50, 50); P1 P2APoint@64 APoint@8p2 = p1;Assignment of Object Variables10050200APoint@86420016488Point p1APoint@6464 Point p264Point p2 = p1;p1 = new APoint(200,200);p2.getX() 100 p2 = p1;p2.getX() 200 p1.setX(100);p2.getX() 100 Point p1 = new APoint(50, 50); P1 P2APoint@64 APoint@8 Garbage collected== for Objects200200200APoint@86420016488Point p1APoint@648 Point p264Point p2 = new APoint(200, 200)Point p1 = new APoint(200, 200); P1 P2APoint@64 APoint@8p2 == p2  false Same physical object?== for Objects200200APoint@8816488Point p18 Point p2Point p2 = p1;Point p1 = new APoint(200, 200); p2 == p2  true P1 P2APoint@8== Vs Equal for StringsJoe DoeJoe DoeString@86416488String s1String@648 String s264String s2 = “Joe Doe”String s1 = “Joe Doe”; S1 S2String@64 String@8s1 == s2  false s1.equals(s2)  true== Vs equals() for Objects200200200APoint@86420016488Point p1APoint@648 Point p264Point p2 = new APoint(200, 200)Point p1 = new APoint(200, 200); p2 == p2  false public boolean equals(Point otherPoint) { return x == otherPoint.getX() && y == otherPoint.getY();}p1.equals(p2) 


View Full Document

UNC-Chapel Hill COMP 14 - Primitive Values vs Objects

Download Primitive Values vs Objects
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 Primitive Values vs Objects 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 Primitive Values vs Objects 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?