Using tomcat role based security in JSP"s or servlets

By dave on March 22, 2015

Following on from Setting up role based security in tomcat we now look at accessing the realm security information from code. Although tomcat takes care of authenticating users at the right time, there are still times when we need to programatically access the credential information. For example the following snippet from userProfile.jsp is a mixed mode page In that anyone can view the page, but some users with manager role see more information.

Using Java"s XMLStreamReader PULL XML Parser

By dave on February 17, 2014

In this entry I show how to use the inbuilt Java XMLStreamReader PULL parser class to read an XML file. The XML stream libraries are PULL based XML parsers that do not load the whole document into a memory structure, so therefore are more suited to large volumes of XML. Below is an example XML file for a zoo, it contains Animal data types that have both attributes and data. It is kept simple for the sake of example.

Groovychart Bar chart with fixed colour

By dave on November 30, 2013

In this article I show an example of creating a bar chart with a fixed colour. This was missing from the groovychart example set, and will get included into the next build. If you are unfamiliar with groovy chart then here is an introduction to Groovychart We simply tell the plot’s renderer to use the StandardBarPainter. This turns off the gradient paint that is used by default. Also this example shows one way of using multiple colours in the bars, its probably not the only way and as recommended elsewhere, I suggest the JFreeChart book for anyone intending serious usage of the library.

Using Semaphore and CyclicBarrier in Java applications

By dave on November 10, 2013

In this example I show an usage of two more concurrent classes CyclicBarrier and Semaphore; which are both provided in the core Java library. There's a wealth of concurrency classes built directly into the JVM that can really simplify multi-threaded development. CyclicBarrrier to make threads wait for alignment. In the example below, I use a cyclic barrier to make several threads wait for alignment. This is a common example where we have many threads and need to wait for all threads to reach a barrier before proceeding:

BlockingQueue producer consumer example

By dave on November 1, 2013

In this BlockingQueue example we show how to write a very simple producer - consumer with a blocking queue. This example generates SimpleAddition objects that require an addition of two numbers to be performed on the consumer thread. In this case the two values to be added are generated using java.util.Random's nextInt call. They are stored on the queue as a SimpleAddition transfer object and picked up for processing on the consumer thread.

Impressed with Fedora 19 Linux

By dave on October 26, 2013

After 10 years of service, my old linux box finally gave up so I bought a basic tower to run Linux on. I've got to say that Fedora 19 was very easy to install and get working. Just as with Windows 8, I think the new Gnome 3 interface is an improvement once one is accustomed. Although I did tweak a few things with the tweak tool.  These days, I use a setup of Win7/64 running on a macmini (you read that right - I run windows on my macmini).

NIO File operations in Java 7

By dave on October 23, 2013

Hot on the heals of the last article, interested in what other goodies may be in the new file IO package, and wanting to try the new catch block, I cooked up another example. In this example, I create a Path object for an example directory, into which I then create a file and write some text into the file. Some things of note here: We do not need to concern ourselves with closing the writer objects as they are opened in the new auto-close section.

Watching files in Java 7 with WatchService

By dave on October 23, 2013

In this article I show how to watch files and directories for additions/changes/deletions using the new file system support in Java 7. Finally, after years of native solutions, it is now possible to listen for file changes without resorting to OS specific solutions. In the code below, first we use the new file system support class Paths to get a Path object that represents our particular directory. We then create a watching service, that we will use to listen for changes and finally we register our path (directory) with the watcher for files that are created.

What a great summer we had in England

By dave on September 27, 2013

Over here in England we've had the best summer in some years. During a recent week holiday in Devon, we could as well have been in the French Riviera the temperatures were so high. I stumbled across a town called Lynton in the Exmoor region on the way back, and what scenery there - the valley of rocks is certainly worth a visit! In the town centre there was a small record shop, I don't know the name, but I managed to get half and hour in there to pick up a few records.

Technological advances and AVR chips

By dave on May 19, 2013

Just recently I stopped to think about AVR's. There's something astounding about a chip that costs a couple of pounds and yet has a fully implemented processor, memory, flash, serial IO, ADC and reprogrammable ROM. Just think that's basically almost as powerful as an old 8 bit computer from the 80's in an 8 pin DIP package. To put that in some perspective, the old 8 bits had countless support chips and their power requirements would be well in excess of any of the ATTINY range of Atmel's chips.

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.