Tuesday, February 10, 2009

Instances and Classes

There's a new ppt in the Handout folder called ICS4M_03_InstanceClass.ppt. It deals with instance and class variables and instance and class methods. You can look at pp 184 and 184 of your text for some clarification. As always Google is you r friend for a quick and dirty take on what these concepts mean. Try something like "java instance variabl" or "java instance vs class variable"

We worked on the two Review exercises on page 185 in class and I asked those who were here to complete them at home if they didn't get it done in class.

With respec to instance and class variables remember this:

Instance variables are created with objects when the objects are instantiated. You should understand them as part of the object itself. That means that there's one copy of the instance variable for every object that gets created.

Class variables are part of the class itself. This means that there's just one for the whole class and all objects instantiated from the class use that same variable.

How do we tell the difference between an instance and a class variable? A class variable is declared using the keyword static.

Monday, February 9, 2009

Live Streaming Test

Sir Wilfred Laurier HS in the board has purchased and configured a live streaming video server which they want to makde available board-wide. Before they go ahead, however, they want to do some load testing. Consequently, they're asking as many people as possible within the board to connect to the server for a test between 9.30 AM and 10.00 AM this morning.

We'll connect and let this run in the background. Go to: http://web.swil.ocdsb.ca/Streaming_Test.html

Wednesday, February 4, 2009

JCreator Runtime Woes

Ok. So we had some problems getting some main application code to run in JCreator today. My bad. I'd blithely assumed that JCreator would see our main() method in whatever file it was in and automagically run the right thing. Ah....not so much.

Here's the basic task (revised).

  1. Create a new Basic Java Application called Circle and enter the text that's on page 181 in the text.
  2. Keep the existing main() method template that's automatically filled in for you. The code you add will be under public class Circle { but outside the main() method declaration (public static void main(String[] args){ blah blah blah }
  3. Declare a new Circle object in main()
  4. Print out it's radius
  5. Change it's radius
  6. Print out the radius again.
If you create the main() method in another file you need to tell JCreator that Circle.java no longer is supposed to contain your main() method.
  1. Create a new File by going to the Filemenu and selecting New and then File.
  2. The File Wizard dialog box pops up. Under Java Classes, select Main Class.
  3. Give your Main Class file a name.
  4. Add in your code to declare the new circle object and change and display its radius, etc.
  5. Go to the Project menu
  6. Select Project Settings
  7. The Project Settings dialog box pops up. Select your new Main Class file from the Run drop down list and click OK. (You've just told Java that this is the file it's supposed to use to run your project.)
If you haven't done this or something like it (there's more than one way to skin this (and most) cats) you will get the error a bunch of you saw today:
java.lang.NosuchMethodError: main
Exception in thread "main"
Process completed.

If you see this then you almost certainly need to tell JCreator where to look for the main()( method...Or you haven't specified one and are trying to run it.