Home Writing Samples Coding Samples

Coding Samples

Coding projects for coursework and self-study since 2004 (courses taken at San Jose State University, College of San Mateo, Notre Dame de Namur University, and Golden Gate University).

Code Listings


[Self-Study] (2019, 2020)

  • NeedlesHaystackTest.java, a Java console-based test application that finds words in a given textfile, is my personal stretch exercise that expands on a Google-provided code snippet (part of a technical writing test). The code snippet comprised a single method, findNeedles(). The test required simply marking up findNeedles() as if one were writing code comments, asking questions, and making suggestions for improvements to a Google engineer. See About the findNeedles method for details. To refresh java and javadoc knowledge, I implemented additional methods and improved findNeedles() in this sample.

    The screenshot shows a sample run of the working application. Users can specify from 1 to 5 different words f0r their search and enter the path to the textfile target of the search. The application then searches the text for the words, keeps track of how many of each word are found, and displays the results in the console.

       > NeedlesHaystackTest.class | NeedlesHaystackTest.java | javadoc
       > See also the Python adaptation of this project.

[CIS-255] Object-oriented programming methods using Java College of San Mateo (2005).

  • StudentRecords is an application that processes Student records contained in a simple flat-file [student.dat]. StudentRecords adds each student record to the student.dat file (appends to the end of the file) in the format "lastName:firstName:studentID:gpa". Clicking the Display All Student Records button initiates the process of opening the student.dat file and determining the number of records in the file, and then creating an array of student references of that size; populating the array with Student object instances; and then sorting the array so that the results are in alphabetical order. The application incorporates try-catch exception handling; file i/o; and sorting algorithms [using a QuickSort routine provided by Prof. Green, modified to handle String comparisons rather than integer values]; in a graphical user interface:

    StudentRecords application--Adding a new student record   StudentRecords after clicking Add button   StudentRecords after clicking Display All

    Adding a new student   After clicking the Add button, the field entries are validated, and if everything is okay, the student record is added to the student.dat file; the details of the student record are displayed in the output [above, center]. Clicking the Display All Student Records button outputs all sorted records in the output. [above, right]
  • ScreenSaver application emulates a screensaver by drawing 100 random filled shapes (lines, triangles, spheres). This application uses the Java2D API. Classes from previous projects [the MyShape interface, plus the MyLine, MyTriangle, and MySphere classes] were modified for this project.
  • MyShapeTest applet that demonstrates polymorphism by using an array of superclass references to instantiate subclass objects.
  • ShapeTest applet that instantiates three different arrays of shapes (MyLine, MyTriangle, MyCircle). This project exercises aggregation (also known as "composition", which defines a "has-a" relationship) as well as inheritance ("is-a"). MyLine is the superclass in a simple inheritance hierarchy that includes MyTriangle and MyCircle. MyLine defines two points (using the Point class) and then draws a line between the two points. MyTriangle extends MyLine and adds a new point object to define the third point in the triangle. MyCircle extends MyLine and adds a private member (radius); MyCircle uses only one point from MyLine. The ShapeTest.java class is the driver applet that instantiates three arrays comprising four objects each (MyLine[], MyTriangle[], MyCircle[]) using Math.random to generate the data necessary for the constructors. Colors for the lines are also generated using Math.random().
  • Complex is an abstract data type that represents a complex number and performs basic math operations (add, subtract, multiply, divide) on a complex number. The ComplexTest.java is a driver application that instantiates two Complex objects and then performs calculations using the two objects.
  • Morse Code, a Java application that generates Morse code from a basic input line (just letters a-z and digits 0-9).
  • Sieve of Eratosthenes, an applet that generates all the prime numbers between 2 and 999. Here's the source code listing.
  • Pig Latin application (must compile and run using javac, that is, not an applet). This Java class accepts user input (a single word, a phrase, or a complete sentence) and converts to 'pig latin,' according to simplified rules: 1) words starting with vowels have 'way' added to them; and all other words have their first letter moved to the end, with 'ay' tacked on after that. The PigLatin.java class extends JFrame and uses an anonymous inner class to handle event processing (that is, it listens on the text input component and then invokes the algorithm that converts the words). Key elements of this program: Using StringTokenizer class, passing it a new string of delimiters, calling a separate method (printLatinWord()) that actually performs the conversion. Uses Swing components.
  • Airline Reservation system, an applet that assigns seats in a 10-seat airplane based on user input (a 1 for first class, a 2 for economy). Seats 1-5 are first class, seats 6-10 are economy class. When one or the other class seating is full, offer the user a seat on the alternate class (if a seat is available). If the user doesn't want the seat in the alternative seat class, display a message saying "next flight leaves in 3 hours." Use an array of booleans for the seating chart. Here's the [code listing]. Uses Swing components.

[CS277] XML Processing and Web Services. Notre Dame de Namur University (2004). Foundation class for now-defunct MA in Computer Science program launched by NDNU in the Fall of 2004. Code samples below include both client and server-side Java (Servlets and JSPs), WSDL, SOAP, and so on (not running due to lack of Tomcat or other java server by hosting provider).

Addressbook Manager (Final Project): Complete application to manage XML-based address book (AddressBook.xml) file. Developed user interface to add, delete, search, and edit contacts in the AddressBook.xml file. Implemented as JavaServer Pages (JSPs), deployed to Apache Tomcat. More...

Code listings:

Other Java web service code samples:

  • Click here for larger screenshotWeb service that calculates compound interest payment amounts and total cost over the life of a loan, and a simple Java console based client that calls the Web service. This Web service has been deployed on a Tomcat 5 install running Axis. Here's the web-services deployment descriptor file for the project, the WSDL that was generated by Axis/Tomcat after deploying to the server. Screenshot shows the client program executing and obtaining response from the Web service.
  • Write a Java program that uses the SAX parser to parse the AddressBook.xml, search for an printout one of the contacts from the AddressBook.xml. This was a real pain, no question, and seemed like more trouble than it was worth. I've a feeling JAXB might have been a better choice, but I'm still trying to get a handle on JAXB.
  • Write a simple Newspaper.xml file based on this XML Schema (newspaper.xsd), and a Java program (Newspaper.java) that gets a headline that matches the name of the author entered at the command line.
  • Write a Java program [ContactPrintout.java] that finds a contact in the AddressBook [note that when you click on the link to display the addressbook.xml, you're getting the results as filtered by the XML Stylesheet] and displays all the data about that contact. Uses the DOM interfaces. This program has two versions:
    • the ContactPrintout.java version is very simple. It finds the contact's last name, then first name, then backs up the tree to find the Contact node for that contact, then sends to a recursive method the other complexElements of the XML (PrimaryInfo, HomeAddress, HomePhones, and so on (see the AddressBook.xsd for details)).
    • ContactReport.java is an alternative approach, which spends a lot of time extracting just the information of interest, without the element names, and prints out in a more 'narrative' style the particulars of the found contact. I think the way I'm working with the data in this latter program would have been better suited to JAXB—I'll try that later, after I've finished creating the SAX version of this program.
  • Create an XML Schema, XML document, and XSLT stylesheet for an AddressBook. Using XPath expressions to find only certain nodes.
  • Create DTDs to be used for XML addressbook. Two primary approaches:

[CIS-101] Fundamental Java Programming. Golden Gate University (2004). Projects listed are applications (console based) originally created using JDK 1.4.1 but recompiled with JDK 7 (Feb 2014). Blackjack (~900 lines of code) and TuitionCalculator (~300 lines) were final projects.


Developing database-backed web applications using PHP and MySQL. CIS-380 in the internet programming sequence, College of San Mateo (2009).


[Self-Study] (2020) needles_haystack.py, a python console application that adapts and expands on Google-provided java method. Python seems much better suited to this type of simple coding problem. Initially, I wrote just one long script but then refactored to break into a couple of functions. Another stretch goal for this project was to get some exposure to Sphinx as a documentation generation tool.

The screenshot shows a sample run of the working application. Users can specify from 1 to 5 different words f0r their search and enter the path to the textfile target of the search. The application then searches the text for the words, keeps track of how many of each word are found, and displays the results in the console.

   > needles_haystack.py | Sphinx-generated doc
   > See also the Java origins of this project.

[LING165] Introduction to Natural Language Processing. San Jose State University (2013). Some final projects from the course:

  • POS (part of speech) tagging using HMM (Hidden Markov Model) > code  |  screenshot
  • Naïve Bayes classifier and word-sense disambiguation > code  |  screenshot
  • Script to summarize word frequency > code  |  screenshot
  • Spelling correction using Levenshtein (minimal-edit) distance > code  |  screenshot

Web Programming

AJAX (Asynchronous JavaScript and XML). CIS-112 in the internet programming sequence, College of San Mateo (2009). Javascript coding plus using various libraries and APIs from Google. (Yahoo! libraries no longer supported).

Last updated 6 June 2020