Course Code Cookbook


Here you'll find fragments of code for doing lots of different jobs; some from the course, some just of general interest. Feel free to send anything you think would be useful to Andy.


Core language principles

Casting to superclasses and interfaces
Code for the basic singleton pattern


IO

Code for making a directory in the user's home space.
Code for getting the directory packaged code is running from.
Code for getting the name at the end of a filepath.


GUI Elements

Help with Gridbags.
Progress bar code.
jFileChooser that only shows/allows selection of directories.


ArcGIS and Java

HelloWorld for the ArcMap status line.
Code for running a tool, model, or script from within an Arc AddIn.
Code for adding a toolbox and generating a tool within it for use.
Code for getting a Layer by name and the ITable from it.
Code for getting a sorted version of a table.
Code for making and using a DockableWindow addin.
Code showing how to communicate between addins.
Code to set up a Dockable Window with a scrollbar.


SQL

Code for basic SQL using JDBC and derby.
Code for setting the derby home directory.


R

Code to show basic java communication with R using rJava.


Modelling

Genetic Algorithm used to solve the Travelling Salesman problem.
Monte Carlo sampling code.
Simulated Annealing sampling code.