JAVA programming examples.

Extract.
I got an idea to create this page after reading JAVA mailing list and visiting Java Ranch(formerly on Electric Porkchop). Here you can find different JAVA programs examples, that were created as answers to programming questions. So this can be called a sort of FAQ. Please, feel free to mail me with any JAVA/jdk related questions, I will try to help. But it is better to access mail list at YORKU. For this, send a mail to LISTSERV@YORKU.CA with line "SUB JAVA" in the message body. When providing references to the content on this page, please reference the page itself, and not the individual files or packages.

Italized names mean that this class has static main(String argv[]) method in it.
Bold names mean that this is an interface.

ThreadLocal evaluation
I've had to do some evalaution on Java thread local variables, and alternative ways to store thread local variables, so here the article I put together on thread locals

GetOpt for Java
That's just something I wrote.

getopt.zip This is the class with getopt(3C) implementation in Java. The package contains class itself, class has a selftest, and you can check out the html documentation

Mouse to Keys event.
Q. How to create events manually in JAVA ? For example, if I received left mouse click, I want to generate left key press.
A. You can construct any new event and then send it through Component.processXxxEvent();

Event.java This class shows how to generate left key press on mouse click event

Interrupting threads.
Q. I tried interrupt the thread but no exception was thrown.
A. The most common mistake in thread programming is that one mess with current thread.

Timer.java Class for Thread, that sleeps for a long time and catches InterruptedException
TimeControl.java The main program, creates new thread and interrupt it.

PopUp menu.
Q. How to make PopupMenu appear somewhere inside panel when user clicks the button on this panel ?
A. Example.

PopBut.java This class creates Frame with Button, left click brings the PopUp menu.

Threads and synchronization.
Q. how to use notify() and wait() to have one thread notify the other thread that it is done
A. Example.

ThreadExample.java This class has two threads that can't be run simultaneously

Networking client/server base
Q. I need some examples of client/server programming in JAVA for ....
A. I wrote two applications, that implement the simplest client/server programming. The AWT part is somehow weak, but this is working stuff.

ClientProto.java This application can connect to any host:port and chat to it(sort of telnet)
ServerProto.java This application can bind a local port and open a window on each connect

DATA crypting(UNIX crypt implementation)
That's just a stuff I wrote.

crypt.zip This is class with crypt() (UFC) implementation. The package contains class itself, test program and html documentationUpdated on 4/20/05, tested for JDK 1.4.x

A program that converts integer to roman numbers
Q. How to write a program that converts integers to roman numerals
A. Here is an example

Int2Rom.java This is a class that gets Integer as argument and returns Roman number on output. There is a lot of debug informattion added, comment every System.err to remove it.

Generic executing scheduler
That's just a stuff I wrote.

AtJob.java This is an interface each class that wants to be ran have to implement. The interface promotes public void eventAt(void) method, that would be executed.
AtJobInfo.java This is an internal class that each At job is wrapped with.
AtRunner.java That the engine. To instantiate a new At engine, create an instance of this class. To execute a job in xxx milliseconds, schedule it using registerJob(job, xxx) method. job must implement AtJob interface.

Generic event system
Well, sometimes people need to have their own event system. Using AWT or, for example, beans events isn't actually a good idea, since these event systems are really designed for what they were intended.

API JavaDoc documentation, extracted from the sources.
evs.zip Archive with source files. They contain the javadoc comments. The code is not commented out too much, but quite informative by itself.


This page was visited    times since April, 1999.

Traffic load:

(C) Pawel S. Veselov, 1999-2001, 2005

[Back] Return to my homepage
[Or (better) press "BACK" button on your cool browser ;)]