notes3 - • Java primitives (data types like int) are...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Java primitives (data types like int ) are passed "by value". Objects are passed "by reference". e.g. class Foo { } Foo myfoo = new Foo(); //myfoo is a ref. to an object Foo newfoo = myfoo; //another ref to the object pointed //to by ref myfoo A reference is like a pointer to that object and this reference can be passed to a method. Then the receiving ref var will get a copy of the ref passed. Now two refs will point to this same object and can be used to alter the original object. e.g. mymethod(myfoo); Strings (and arrays) are objects in Java. Thus they are ref types. e.g. String s = "This is indeed "; The ' + ' symbol is the overloaded operator in Java and is used to concatenate strings. e.g. String s = s + "funny"; String objects have a length method. E.g. int len = s.length(); The type of an expression is known at compile-time in Java. Control statements include: if ( . . ) { } else { . .} while (…) { …. . } switch (….) { case intexpr: statement1; break; default: statement2; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java does not allow pointer manipulation. So no *, and & operators. The expression null can be assigned to any reference type. It
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/29/2011 for the course CNT 6707 taught by Professor Ahuja during the Spring '11 term at UNF.

Page1 / 6

notes3 - • Java primitives (data types like int) are...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online