Java - ExamplesJ/ - TABLE OF CONTENTS
Dec. 24, 2020


This directory contains a collection of programs and writeups that will be of interest (and aid) to students studying Java and Java programming.

KEY:  Files of particular interest to:
           'C'  students taking CSCI 211 - Programming Language Concepts
           'J'   students taking CSCI 311 - Java Programming
           'D'  students taking CSCI ??? - Data Structures & Algorithms
           '-'   students in general

FILE or DIRECTORY/

KEY

DESCRIPTION

index.html

-

This file

Abs.java

C

Demonstrate use of an abstract class and inheritance

AbsClsVsIfx.rtf

-

The difference between an abstract class and an interface

AbsExt.java

C

Extending an abstract class, one containing concrete methods

AddEmUp/

C

Designing for command-line and GUI use; MVC

ADTList/

D

Implementations of ADT List and ADT ArrayList

ADTQueue/

D

Implementation of ADT Queue

ADTStack/

D

Implementations of ADTStack and ADT ArrayStack

AnimationDemo/

D

Animation using sprites, threads, gif files

AnimatorApplet/

J

Template showing how to do simple animation

AppletComm/

-

How an applet can communicate with other running applets

ArrayExample/

C

Using an array; using Math.random; using printf()

ArrayListDemo.java

C

Demonstrate ArrayList methods

AssignmentZero.java

-

Java source for Homework Assignment Zero for all Java courses

Async.java

-

Responding to events using asynchronous (threaded) semantics

AudioItem/

C

Playing sound in Java1.1 & Java 2, .AU and .WAV clips, Adapters

AUSounds/

-

A collection of sound clips in .AU format

Authors/

C

How to "half-simulate" a dialog in an applet

AutoBoxing.java

C

Demonstrate automatic boxing and unboxing of primitives/wrappers

AutoPolygons/

C

Demonstrate creating polygons, Random, timer, animation, resizing

BankData.txt

J

Data for CSCI 311 homework assignment J6

Batch/

C

How to run a Batch script from Java

Beep.java

C

How to play the PC's 'beep' sound

BinarySearch.java

-

The Binary Search algorithm in Java

BinSrchFlwchrt.ppt

C

Binary Search Structured Flowchart: in both C/C++ and Java

Black/

C

Show how to display a full-screen black window using AWT

BlowStack/

C

Demonstrate 'blowing the stack' -, applet and application

ButtonPos.java

C

How to position and size a button using absolute coordinates

Callback/

C

Simple callback; demo how access/information is passed

Calc.zip

D

Bary's solution for CSCI??? homework assignment D2 -, Calculator

CenterDesktop.java

C

Initially display a JFrame at the center of the Windows desktop

clean.bat

-

A Windows (DOS) "batch file" used by the makefile

ClientServer/

J

Client/Server using sockets

Clock/

-

(Digital) Clock thread example

Clock2/

-

(Analog) Clock thread example

Clock3/

-

(Analog) Clock thread example, run as application or applet

CMBubble/

-

Drawing using an off-screen buffer; createImage

Cmplx/

-

Complex numbers example

CodeConv/

C

Coding Conventions (style), most recent version (view-ready HTML)

CodeConventions.pdf

-

Coding Conventions (style),  most recent version (in PDF format)

CodeConventions2.pdf

-

iCarnegie's 2-page quick summary of the Sun Java Coding Conventions

Coding.pdf

-

Coding Conventions (style), an older opinion (in PDF format)

Colors/

C

How to use predefined and user-defined colors

Colors.java

C

Using JButtons, inner classes, Enter key, Java named colors

CompileJava/

-

A Java application that compiles Java programs

Components/

-

Applet illustrating how to use various Components

CompoundSort.java

C

Compound sort - sorting on both a primary and secondary field

ConsoleIO/

-

Show how to read data from the keyboard, also from a file

CountDown.java

C

How to use sleep() and beep()

CountFlips/

C

Simple programmer-defined class

CycleThru.java

C

Demonstrate Enumeration and Iteration

DemoHeirarchy.java

C

Demonstrate inheritance, upcasting, downcasting, abstract class

Direction/

C

Demonstrate how to listen for the cursor keys

DitherTest/

D

How to use the image buffering routines for fast screen updates

DnD.java

C

Drag and Drop Between a TextField and a TextArea

DocumentModalDialog.java

D

Modal Dialogs in Swing

Doodle/

C

Doodle example from L&L, using MouseMotion and MouseListener

DoodleIC/

C

Doodle example from L&L, using inner classes

DoodleIC2/

C

Doodle example from L&L, showing Canvas, Panels, Layout Managers 

Dots/

C

Demonstrate how to set up and use a "callback" handle

DoubleBuffering/

C

Using double-buffering to avoid flicker

Dual/

C

Running the same program both as an applet and an application

DualModal.java

D

Modal and non-modal dialogs in Swing

Enum/

C

Show how to use enum (enumerated types)

Except.java

C

Demonstrate Exceptions and Exception Handling

Execute.java

-

How to execute an operating system command

Execute2.java

-

How to execute an operating system command (> Java 1.5)

ExeJar/

-

How to create an "executable JAR file"

ExtendImplement.rtf

C

Extending classes, implementing interfaces, abstract classes

ExtendInnerClass.java

-

How to extend an inner class

Fibonacci.java

-

Traditional and memorized recursive Fibonacci calculations

Figure4/

-

Show how to draw simple shapes and control color, also show time

FileCopy/

C

Show how to read/write flat ASCII files, one line at a time (Scanner)

FileIO/

-

How to read/write from files, how to use StreamTokenizer

FileNIO.java

-

How to read/write from files using the nio api

Fireworks/

-

Fireworks - use of threads for animation

FishPlus/

C

Helpful hint for Skyline - Homework Assignment F2

FormatNumbers.java

C

How to format numbers for output

GifImages/

C

Displaying GIF images on a Canvas

Grids/

-

Setting up a visual layout, layout managers & absolute positioning

GridLayoutDemo.java

C

Demonstrate using GridLayout

HelloWorld.java

C

Java source for Homework Assignment Zero (application)

HelloJavaWorld/

C

Java source for Homework Assignment Zero (applet)

HT.java

C

Show how to use a Hashtable (and Enumeration)

ImportStatic/

-

Show use of import static and packages

Interf/

-

A tiny example showing how to set up and use interfaces

JBlack/

C

Show how to display a full-screen black window using Swing

JButtonDemo/

C

A tiny Swing example - applet & application - like TwoButtons/Dual

JColorChooserDemo.java

C

Using the Java Color Chooser dialog

JComboBoxDemo/

C

Swing application showing JComboBox and anonymous inner class

JFontSlider.java

-

Swing application showing use of a Slider to control font size

JLabelArray/

C

Swing applet showing an array of JLabels

JLists.java

C

Singly-linked, simple, forward-directed Lists application

JMenusDemo/

C

A tiny Swing example showing how to set up Menus

Jotpad.zip

C

Bary's solution for CSCI211 homework assignment F7, Jotpad

JTableDemo/

D

Create and fill a JTable using MySQL

JTextFieldDemo/

C

A tiny Swing example showing how to set up a JTextField

JukeBox/

C

Using a Swing Combo Box, playing sounds in Swing

KeywordOrder

C

Preferred order of appearance of Java keywords (reserved words)

KochSnowflake/

C

Swing applet demonstrating recursion

LayoutDemos/

C

How to use the layout managers

LeftRightMouse/

C

How to detect the left, middle, right mouse button

LifeData.txt

D

Data for CSCI ???homework assignment D3

MakeDirectory.java

-

How to create a directory (folder)

makefile

-

A "makefile" for compiling and running Java programs

Marquee/

-

A "marquee" applet using threads based on ScrollText

MasterSlave/

C

Demo "master-slave" relationship (help for Blobs)

MatMult.java

C

Demonstrate 2-D arrays and matrix multiplication

MaxThreads/

-

Multiple threads and synchronization example using a mutex

MazeSearch/

C

Demonstrate recursion and how to search a simple maze

MenusDemo/

C

How to set up menus and dialogs using AWT, including FileDialog

MinThreads/

-

Multiple threads and critical section example

Moire/

-

Graphics - Moire pattern - and threads

MostDivisors.java

-

Find integer with most divisors

MouseFollow.java

C

How to follow the mouse, change the cursor

MouseMove.java

-

How to move the mouse under "Robot" control

MyApps/

C

AWT & Swing versions of RealJ's default (simple GUI) application

MyApps/MyApp.java

C

Anonymous inner class for windowClosing

Newline.java

-

How to handle end-of-line (newline) environment independently (LS)

OuterClass.java

-

Passing handles to inner and outer classes

PackageDemo/

-

How to declare and use your own Packages

Palindromic.java

J

Main class for CSCI 311 homework assignment J2

Parameters.java

-

How to extract parameters from an Applet's HTML

Perms.java

C

A highly recursive way to print the permutations of a string

Picture/

C

How to rotate and display a picture (.jpg)

PlayASound/

C

How to play sounds and use radio buttons

Plot.java

-

How to plot data as points

PlotLines.java

-

Expansion of the Plot.java example, using lines and a timer

PlowDataFINAL.txt

D

Data for CSCI ??? homework assignment L5

Poly.zip

D

Bary's solution for CSCI??? homework assignment D1, Poly

PolyData.txt

D

Data for CSCI ??? homework assignment D1

PolyMain.java

D

Main program /driver for CSCI ??? assignment D1

Polys/

C

Demonstrate polylines, polygons and animation in time

PPGame/

D

Ping-Pong Game - thread synchronization using wait and notifyAll

PressMe/

C

A simple GUI showing a button and a color panel

Primes/

C

Calculating prime numbers; number theory; residue sieve

ProducerConsumerSync/

J

Synchronized Producer-Consumer example

Property.java

-

Show what's in the System's "properties"

PWriter.java

C

How to create and write a file using a PrintWriter

QueueClass/

-

A Queue class, since Java doesn't have one

Quotes/

C

Swing push buttons, radio buttons and check boxes

RailData.txt

J

Data for CSCI 311 homework assignment J3

RandomRange

C

How to calculate a random int in a given range

RanPolygons/

C

Random Polygons in random colors; using Random and random()

RealPolymorphism.rtf

-

Is polymorphism used in the "real world?"

Rebound/

C

How to do simple timer-based animation

Rebound2/

C

Extension of Rebound for two animated images

Redir/

C

How to redirect stdin and stdout for input/output

Redirect2/

-

Another stdin/stdout/stderr redirection example

Redirection.rtf

-

Using Redirection, capturing output (Java/C++)

RobotDemo/

C

Driving the JVM -- move the cursor/mouse, etc.

RSAData.txt

D

Data for CSCI ??? homework assignment D2

RubberLines/

C

How to "rubberband," both w/wo inner classes

Scale/

-

How to scale (resize) a GIF or JPG image

ScanConsoleApp.java

C

Demonstrate how to use the Scanner Class

ScreenSize.java

-

Determine current screen size in pixels

ScrollText/

-

Scrolling text thread application

ScrollingHelloWorld/

-

Scrolling text thread/notify applet

SendMail.java

-

Tiny SMTP send Email application

Serialize.java

-

Demonstrate serialization and deserialization

ShowLabels/

C

Using Swing JLabel and image icons

SimpleApGraphics

-

The simplest application with graphics

SimpleApplet/

C

The all-time simplest possible Applet

SimpleJApplet/

C

The all-time simplest possible JApplet

SimpleJApplet2/

C

The all-time simplest possible JApplet; uses ContentPane

SimpleSounds/

C

A simple sound-playing applet

SimpleThread/

-

A simple multiple free-running thread example

Sine/

-

Animation of the trigonometric sine function (using threads)

SingleListenerHandler/

F

Using a single Listener and Handler for a bunch of Buttons

Singleton.java

-

How to create a Singleton object

SlideShow/

C

Applet for a "slide show," also shows how to run a Jar applet

SlideShowJS/

-

JavaScript slide shows (w/wo fading between images)

Sockets/

-

Using sockets for Client-Server Internet communications

Sorts.java

C

Selection sort and insertion sort examples

SoundApplet/

-

Sun's SoundApplet tutorial example, modified slightly

SoupTest/

D

Producer and Consumer Threads example, wait and notify

SplashTest/

C

Show how to set up and use a "splash screen"

SplashWindow3/

C

Earlier technique for setting up and using a "splash screen"

StackQueue.java

-

Show how to use a Java Stack

StandardMenus.java

C

Setting up standard menus, shortcut keys (accelerator keys)

StripExtension.java

-

Yields filename sans extension/suffix

SubMenusDemo/

C

How to set up sub-menus, how to set up a key listener

SwingVsAWT.rtf

C

The architectural differences between Swing and AWT

TableDemo.java

D

Filling a JFrame in Swing

TableSortDemo.java

D

Sorting columns in a JFrame

TextClock.java

C

Creates a digital clock; uses anonymous class and Timer

TicTacToe/

J

Source code and other files for CSCI 311 homework assignment J4

TimeAnimation.java

C

Example of 'time animation' using sleep() - Help for HW #6 - Sorts

TimeAnimationT.java

C

Example of 'time animation' a Timer - Help for HW #6 - Sorts

Timepiece Taxonomy/

-

A taxonomy of "timepieces" -- like watches & clocks...

Towers.java

-

A solution to the "Towers of Hanoi" puzzle

TreeData.txt

D

Data for CSCI ??? homework assignment D4

Treemap.java

C

Show how to use a TreeMap

TreeOfDoubles.java

-

Show how to use the Java 2 TreeSet Collection

Triangles/

C

Animation in time using triangles, polygons, timer

TwoButtons/

C

A tiny applet showing two buttons, inner classes

TwoDArrays/

C

Using 2D arrays, rectangular and triangular

TwoPolygons/

C

Show the two ways to create Polygons; draw a PolyLine

TwoScreens.java

D

How to "ping-pong" between two screens, passing data

TxtArea/

C

How to use a TextArea, Menus, Accelerator Keys

UniversalDemo.java

C

Creating a universally accessible method

UseAVector/

C

Show how to use a Vector

UsingRealJ.pdf

C

How to use the RealJ Integrated Development Environment

V2A/

C

How to copy information from a Vector to a pair of arrays

VarArgsArrayExample.java

C

Using a variable length parameter list with 2D arrays

VarArgsInts.java

C

Using a variable length parameter list with ints

VarArgsOverloads.java

C

Using overloads with a variable length parameter list

VMSpec2ed.zip

-

Java Virtual Machine Specification, 2nd Edition, in HTML format

WhatClass.java

J

Find what class called your method

WhoAmI.java

J

Get a computer's current IP address

Notes:  "/" indicates a subdirectory containing several files
            L&L = Lewis & Loftus, 'Java Software Solutions' textbook

File:       http://Snow.SierraNevada.edu/~csci/ExamplesJ/index.html
Mirror:   http://www.csci-snc.com/ExamplesJ/index.html

Back to top

Last updated: Dec. 24,2020 – 15:00