JessLilly.com Jess Lilly's home page
Home
Jess Lilly
Jess' Portfolio
Carin Palsrok-Lilly
Amos
Our journeys
Computer info
Links to our friends
Other Links
Contact info

Stuff I've learned about Java:

All Classes automatically extend Object.

Interfaces are abstract objects.  Interfaces are GOOD.  It is a way of doing multiple inheritance.

Use ==.

I need to use more static initializers.

 

References:
Coordinate pieceGridCoordinate = piece.getGridCoordinate( );

This code will get a reference to the gridCoordinate member of the piece.  The reference is still pointing to the same object!  If you modify it, you are messing with the member data of the piece!  This is what I meant to do:
Coordinate pieceGridCoordinate = new Coordinate( piece.getGridCoordinate( ) );

This is a very interesting issue.  If I used int x and int y simple data types for my gridCoordinate, then this would not happen.  Only Objects pass by reference.  Simple types pass by value.  Doesn't this violate encapsulation?  You can get a reference to my internal data member and then have your way with it.

What if I pass piece.getGridCoordinate() into a method that takes a Coordinate.  I can not be sure that the method will leave my object intact.

This is a big dilemma because I sometimes want to modify the passed in values for the caller.

I think maybe it should be the callers responsibility?? But that will lead to uglier code I think.

Solution: in the code for getGridCoordinate() instead of this: return this.gridCoordinate; do this: return new Coordinate(this.gridCoordinate);  That way you are not returning the member object as a reference, you are returning a copy of the member object.  The calling function can do whatever it wants with this coordinate instance and not mess up the internal member data of the piece.

 

Packages

Packages are a good, but they are a pain.  You can go to these sites to see how to make them work within the APPLET HTML tag: http://www.ibiblio.org/javafaq/course/week5/06.html

http://java.sun.com/docs/books/tutorial/applet/appletsonly/html.html

 

Increase speed and use less memory:

Use inlining for function calls to increase speed.  Isolate functions that take a long time, and see if you can improve them.  Use short, byte, etc. instead of double, int, etc. to make you instances take up less memory.

 

JessLilly.com  Home