Sample Java

The sample code below is written using only those language features that are known at the time the code is discussed. Much of the code could be improved, using more advanced Java language features. In some cases, multiple solutions are given to show how a more advanced Java language feature can be used to improve a solution.

Paint a checker board and view it in a JFrame
Approximating Pi via a Monte Carlo method
AnimatedJPanel.java (rotating cube)
Solar System
Cellular Automaton - Life
Chat client - example of GUI design
A recursive bijective map, T: N —> rooted, unoriented trees (view as String)
A recursive bijective map, β: Z+ —> rooted, unoriented trees (view as Image)
Solar system animation with multithreaded recording and animated playback
Thread-safe blocking queue—written before generics & java.util.concurrent package
Networking: A simple stream-socket client-server chat application.
A database hello, world! example
A database hello, world! example using JdbcRowSet
A PreparedStatement example of a range query (Mandelbrot set)
JUnit test of a stack
JUnit: Simple unit test of PositiveIntegerTree.java
Graphics: {draw | fill}Arc
Graphics: {draw | fill}Polygon
Reading from & writing to a text file.
Illustrating recursively defined methods.
Generic Clases & Methods

Laboratory Assignment Solutions

  1. Classes: HeartRates class
  2. Exceptions:
  3. Strings: Morse Encoding
  4. Recursion: GCD - instrumented to illustrate recursion
  5. Generic class: Pair
  6. JUnit

Programming Assignment & Solutions

AssignmentSolution
Visualize an n-clique
A Graphical Virtual Machine
Zap 'em! An animated Game
SuperZap 'em! A Modestly Enhanced Zap 'em Game
GALA: GVM Assembly Language

 cappello@cs.ucsb.edu © Copyright 2014 Peter Cappello                                           2014.06.04