Welcome

Welcome to my blog.


I will be updating this blog with lecture notes and miscellaneous information for:

CSE 1030 : Winter Term
Prof. A. Eckford, Section-Z: MWF at 10:30 in R S137



Feel free to leave me a message or send me an e-mail at producap@yorku.ca.

Here is a link for MyMail, Hotmail, G-mail, and PRISM login.

On that note, you must have a PRISM account in order to write the lab tests.

If you have not created a PRISM account yet (e.g., if you received transfer credit for 1020), see the lab monitor in CSEB 1006 as soon as possible.

I will also leave the blog open to comments, etc. much like the CSE forums.

Thanks for visiting.

Phil.

Tuesday, January 15, 2008

CSE Lecture 11/JAN/2008

Java Packages

Ref: http://java.sun.com/docs/books/tutorial/java/package

You can assemble classes into packages, bundling related classes into one unit (one name space).

Creating a Package

e.g. a package named MyPackage
- create a directory called MyPackage/
- all classes intended for the package go in the directory
- First line of the java file for all classes in package: package MyPackage;

Using a Package

- Within the package, you use the usual simple names e.g. just Class A.
- Outside of the package we must use qualified names: e.g. MyPackage.Class A or import members of the package then use simple names.

To import, the first line of the program would be:

import MyPackage.Class A;
import MyPackage.Class B;
or
import MyPackage.*;

Then use simple names.

Arguments vs. Parameters

Parameter: the variable input by a method.
e.g. public static double areaOfCircle (double radius)

double y = 0;
double x = 1;
y = MyUtility.areaOfCircle(x);

The value of x should be unchanged after this operation. This is known as "passing by value". Within the method, a local copy of x is made.

That's the end of the story for non-object types.

The primitive types are not objects.

Object types:

Variable name (the value of the variable) is the location in memory where the object is stored: i.e. a pointer in some sense.

See Rectangle API in document e.g. Rectangle f = new Rectangle (3,4);

Knowing f gives access to f.width and f.height (via the Rectangle API);

"Passing by value" - a method is not allowed to change the value of the parameter in the calling method. Therefore a method cannot change the address of an object parameter.

A method, however, can change the contents of that memory address (if allowed by that API).

e.g. public static void twice(Rectangle x)
//intended to double width and height

Rectangle r = new Rectangle (3,4);
twice(r); //twice is allowed to change the value of r.width and r.height via the API.
//twice is not allowed to substitute r for a different object.

No comments: