Data Structures in the Java Class Libraries Analysis Using Reflection

For our module “Data Structures and Algorithms”, I had an assignment to find something interesting in the Java class libraries, and analyse it using Java reflection. This assignment was very challenging, and the results had to be presented in a special report format, but I was very happy with my end result of 88%.

This was my first time using reflection in any language, and I was very interested to see the Java language looking and collecting statistics from its own classes etc. Finding something “interesting” in the Java class libraries came as a bit of a challenge – as I wasn’t sure what to aim for.

Preview of Paper

I started off thinking about Data Structures – something we had learnt a lot about in this module. There is a definite noticeable difference between the speeds of different data structures in Java (especially with large data sets), and this caused me to hypothesise that maybe there would be a relation between the code complexity and the speed of the data structure. In my report I investigated this by building a Java program to collect statistics about the classes, classes referred to by those classes etc and print the results out to the terminal or to a CSV (comma seperated value) file.

You can find my paper here if you are interested, and if anyone was truly interested in the code, I am quite happy to give advice on that too where possible.

Matt

LINKS Conference

This weekend, the St John LINKS conference was held here in Aberystwyth, which involved all of the LINKS units in Wales (us, Cardiff and Swansea) meeting up for some talks on things such as Fundraising, Volunteering and operations. We also did some training, looking at how neck braces and box splints work, as well as receiving training to qualify us to be an AED (Automated External Defibrillator) Operator.

AED and CPR on Annie Doll

AED and CPR on Annie Doll

Another valuable part of the weekend involved learning about what can happen in a major incident – where one emergency service may not be able to cope without incurring side effects to its service, and more people are called in to help.

Major Incident Simulation

Major Incident Simulation

In this session, we learnt about how the command structure works between the Police, Ambulance and Fire service, as well as getting to look at some of the equipment they use including: A fast blow-up casualty tent [Red tent in right of picture above], various stretchers and some very noise cancelling headphones.

Looking at the equipment

Looking at the equipment

Inbetween receiving the invaluable training for AEDs and major trauma, we were able to get to know the LINKS members that had travelled from Cardiff and Swansea, and learnt that both units were relatively new, and will hopefully continue to grow and carry on their current success. We enjoyed some fantastic lunches in TaMed Da, and went out for a Thai meal with them on Saturday night.

Lunch with Aber, Swansea and Cardiff LINKS

Lunch with Aber, Swansea and Cardiff LINKS

Overall, a very interesting weekend, I now have to just take and pass the AED exam to receive that qualification, and look at the London St John District division, a group recommended to me by one of our trainers – as I hope to continue my St John work whilst on my year in industry in London.

Matt

Aber LINKS Website – URL Redirecting From “/news.php” to “/news” With .htaccess

Had an Idea – well I have always wanted to be able to type www.aber-links.co.uk/contact rather than /contact.php to get to the contact page – and the only idea I had myself was creating a directory called /contact with an index.php file in there, either that or a redirection to the actual /contact.php. I thought surely there must be a better way, and after a little searching online and reading – I found a way.

If you have a site, in the root directory (or /public_html) there should be a file called “.htaccess”. This file is a configuration file for web servers, so you can give it some rules. For example, mine has a line:

ErrorDocument 404 /notfound.php

This redirects the user to the page “notfound.php” if they get a 404 error (page not found). To redirect the user from an input like “www.aber-links.co.uk/news” to the /news.php page, you need the following lines:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.php [L]

If your site is .html files, change the .php to .html or .htm – whatever you use.

news URL example

I read this article to learn about what to put: http://www.webmasterworld.com/apache/3715021.htm

Matt

Aber LINKS Website – Colouring Nav Links

To let the user know which page they are on, I wanted the corresponding link in the nav bar to be different to indicate that they were on that page. Until now, I thought the only way would be having a separate nav bar for each page, each with one link as a certain style.

A few days ago, I had an idea – can PHP determine what page it is on (almost like Java’s Reflection). It turns out yes, yes it can! I was talking to a colleague and they had just implemented what I had been thinking about, and a short time later, it is all done and working. I first tried underlining the current nav location with a large orange line, and then colouring the background grey – but neither looked too good. I had the idea of making the background white with black text so that it looked like the top tab of the current page. This wasn’t easy to implement as I was trying to style an anchor that did not want to change it’s colour. In the end I chose to surround each nav item with a div – “highDiv” or “lowDiv” depending on if they were on that page that link points to or not.

Example of highlighted nav item

The vital code for each of my nav items is:

<li><div <?php if(basename(strtolower($_SERVER['SCRIPT_NAME'])) == ‘index.php’) {echo ” id=\”highDiv\”";} else  {echo ” id=\”lowDiv\”";} ?>><a href=”index.php”>Home</a></div></li>

Explanation:

Each nav item is a list item, and inside that thre is a div – the id of which is controlled by PHP. The PHP asks if the SCRIPT_NAME (page name) is equal to ‘index.php’ (for the “Home” link), and if so, it will give the div the id “highDiv” – which colours the background white and the text black. If that statement is false, it will give it the id of “lowDiv” – just normal.

I have a feeling this could be streamlined by using an array of pages (replace the index.php with pageArray[i] in a big for loop) and an array of link texts [to replace "Home" etc]. I assume this is what people do for big sites that have changing link menus.

Hope this helps!

Matt

Aber LINKS Website – Font Size and Google Search Box

I am currently doing a User Centred Design and Human Computer Interaction module at university, for which the assignment requires us to create a website that is user friendly and conforms to many design standards. These standards have been created to ensure that a website is as accessible as possible to all users, especially catering for disabled users. We are allowed to use websites that we have already created for this assignment, so I had the choice of using my personal site, the Aber LINKS site, or my CS25010 games website. I chose to use the Aber LINKS site, as it would benefit most from the improvements researched and implemented in this assignment, as well as giving the marker something physically real to mark full of real data with a real purpose, rather than junk data.

The first thing I did was make a bar at the top of the page for the accessibility options, and the search bar. I may move the search bar to the right end of the nav bar later on.

The Google search bar took a bit of fiddling and 3-4 different implementations before I found one that worked. This one is quite simple, and takes only the code pasted below to take your search term and search Google for that term within your site.

<form id="searchForm" method="get" action="http://www.google.com/search">

<table border="0" cellpadding="0">
	<tr>
		<td>
		<input type="text" name="q" size="25"
		 maxlength="255" value="Search Site.." onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>
		<input id="searchButton" type="submit" value="Search" />
		</td>
	</tr>
	<tr>
		<td align="center" style="font-size:75%">
			<input type="hidden"  name="sitesearch" value="aber-links.co.uk" checked="checked" />
		</td>
	</tr>
</table>
</form>

This code makes a search box with a default  value that is cleared by JavaScript if the text box is clicked or focused (e.g by tabbing to it) on.

 

Font Size

Although not essential for our assignment, I thought it would be relevant to include a facility to allow users to change the size of the main text, to allow them to read text easier if they have sight or other problems.

I learnt about most of the information and code here.

I swapped out the hyperlink text for a “+” and “-” image that I created in Fireworks, and the following code calls the JavaScript to tell it to decrease or increase the font size:

<a href="javascript:changeFontSize(1)"><img src="images/fontPlus.png" alt="Increase Font Size" /></a>
<a href="javascript:changeFontSize(-1)"><img src="images/fontMinus.png" alt="Decrease Font Size" /></a>

The JavaScript called will then add or subtract one from the current paragraph size value:

<script type="text/javascript">
<!--
function changeFontSize(inc)
{
  var p = document.getElementsByTagName('p');
  for(n=0; n<p.length; n++) {
    if(p[n].style.fontSize) {
       var size = parseInt(p[n].style.fontSize.replace("px", ""));
    } else {
       var size = 20;
    }
    p[n].style.fontSize = size+inc + 'px';
   }
}
-->
</script>

And that’s about it. A bit of styling later, and all is looking well. The font changes size when the buttons are clicked, allowing the user to select a size suitable for them, without destroying the overall layout of the page.

Matt