More Java

This is a collection of odds and ends.

Getter and Setter methods. The way to provide "outsiders" with access to a private class field is to use getter's and setters. For example the Device class has a private field called viewNormal. To provide access one should add a routine (aka member function) like

	public Vector3f getViewNormal() { return viewNormal; }

In this case there is no need for other classes to change viewNormal. (Well at least in the context of project1.) But it there was one could add a setter method like:

	public void setViewNormal(Vector3f vN) { viewNormal = vN; }
This method fails to keep the viewNormal normalized so a more realistic setter method might be
	public void setViewNormal(Vector3f vN) {
		viewNormal = vN;
		fixView();
	}

jdb the Java Debugger We went over a jdb session. The first step is to compile the program with debuuging turned on. This is done via the -g flag, so one can recompile for debugging by

	rm *.class
	javac -g *.java
Be careful to remove class files and not java source files.

Here is the output of a jdb session on Device.java

jar files are the best way to distribute java programs. Jar files are like zip files or compressed tar files. Surpose you want to turn in project 1, the way to do this is with a single jar file. Do these steps.

  1. Create a manifest.mf file containing
    Manifest-Version: 1.0
    Main-Class: Device
     
    
  2. Create the jar file with the command
    jar cmf manifest.mf yourname.jar *.class *.java ReadMe
    
  3. Test it via (This only uses the class files, but I want the src too.)
    java -jar yourname.jar
    

The options to jar are much like the options to tar. In particular, jar tf foo.jar will list the table of contents of the jar file and jar xf foo.jar will extract all the files from the jar file.

How to print your plot

How to mail a jar file