girlcoderuk











I have been reading a lot of blogs all about why you should not use TDD and why it is a bad idea. I would like to put forward my viewpoint on the arguments.

Premise: TDD restricts your design abilities.
If you believe this then you do not get TDD or Agile development. Early in your Agile life you should have been to a sprint planning meeting, writing cards and then ripping them up… TDD is the same, if you get down the path and find it going the wrong way. Rip it up, start again. That goes for TDD tests as well as code. Software is an organic construct TDD is designed to keep it tame and not a huge lumbering beast destroying your city. If the design changes it makes sense to change the test as well.

Premise: We have legacy code which do not have tests.
Well you are in a bad way, however that is not the end of the world. Each time you get a bug, write a test to prove when the bug is gone. Not only does this prove that the bug is gone it also prevents regression and the bug reappearing in the future. As the bugs get squashed you get new tests and the coverage of the legacy code improves. This follows one of the other agile methods which is when you touch a piece of code you always leave it in a better state than when you found it, if you are working under the hood of the ecommerce module and you see a nasty if then else mess clean it up, if you see repeated code extract it. Over time your code is cleaner and you can then add tests around any new code until you have more coverage.

Premise: it takes longer to write tests before why can’t I add them after?
You are working in a business. There is never time for code cleanup, you will never get the chance to add the tests after. If you write the tests up front using BDD style naming you can also show the results to the business owner who can see you have produced their request and can prove it. Simple to sign off and any smart head of business will start to push other devs to follow your lead as they know that your code is fit for purpose.

Premise: Sometimes the design changes after you have started meaning changing the tests
What’s wrong with that? Isn’t that the idea for Agile development, tests are never immutable, sure you need to be sure that a change to a test is justified (you have added new functionality or made a new field mandatory breaking older tests that now need updating)
It’s more a way of making you think about the change you are doing, and the design you are using. Is it fit for purpose?

These are just my views and I am sure that everyone has different feelings about TDD and Agile development. As with most Agile methodologies it is a guideline not a rule,



This article is designed to fill a gaping hole in the Examples for Spring / Hibernate configuration and that is for Standalone Applications.

Usually all the demonstrations are for Web applications or J2EE applications, so this one is for a simple Command Line Application. I use Intellij Idea and Maven but i hope it works as easily if you are using Netbeans or Eclipse.

Ok Lets start out Easily:

Create a new Maven Project with no Archetype

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.theresajayne.standaloneexample</groupId>
<artifactId>standaloneExample</artifactId>
<version>1.0-SNAPSHOT</version>
</project>

Idea will have created the pom file but nothing else do under src/main/java add a package for your system (mine is com.github.theresajayne/standaloneexample) and create a main class under there to match your project name

package com.github.theresajayne.standaloneexample;

public class StandaloneExample {
}

now lets return to the pom file, We need to add the Spring, Hibernate and MySQL libraries to the project and then rebuild to make it download all the dependencies. This is a simple copy/paste task so my complete pom file is below.

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.theresajayne.standaloneexample</groupId>
<artifactId>standaloneExample</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<spring.version>3.2.3.RELEASE</spring.version>
<hibernate.version>4.2.2.Final</hibernate.version>
</properties>

<dependencies>
<!– Spring –>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!– Hibernate –>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!– Others –>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>

</dependencies>

</project>

Now we have the project building lets add some configuration files.

under src/main/resources we need to make the spring configuration  file. So create spring-config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=”http://www.springframework.org/schema/context” xmlns:tx=”http://www.springframework.org/schema/tx”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd “>
<context:annotation-config/>
<context:component-scan base-package=”com.github.theresajayne.standaloneexample”/>

<!– JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with
username root and root as password. Change below if it’s not the case –>
<bean id=”myDataSource” class=”org.apache.commons.dbcp.BasicDataSource” destroy-method=”close”>
<property name=”driverClassName” value=”com.mysql.jdbc.Driver”/>
<property name=”url” value=”jdbc:mysql://localhost:3306/standalone”/>
<property name=”username” value=”root”/>
<property name=”password” value=”root”/>
<property name=”validationQuery” value=”SELECT 1″/>
</bean>

<!– Hibernate Session Factory –>
<bean id=”mySessionFactory” class=”org.springframework.orm.hibernate4.LocalSessionFactoryBean”>
<property name=”dataSource” ref=”myDataSource”/>
<property name=”packagesToScan”>
<array>
<value>com.github.theresajayne.standaloneexample</value>
</array>
</property>
<property name=”hibernateProperties”>
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>

<!– Hibernate Transaction Manager –>
<bean id=”transactionManager” class=”org.springframework.orm.hibernate4.HibernateTransactionManager”>
<property name=”sessionFactory” ref=”mySessionFactory”/>
</bean>

<!– Activates annotation based transaction management –>
<tx:annotation-driven transaction-manager=”transactionManager”/>

</beans>

This now is all we need on configuration boilerplate code as the rest is all done via annotations.

Now back to the Main class of the application. We start off the file looking like this

package com.github.theresajayne.standaloneexample;

public class StandaloneExample {

public static void main(final String[] args) throws Exception {

}
}

First we need to annotate the whole class with @Component This as you will see will allow us to create the main class using Spring, next we add the main code providing us with the following

package com.github.theresajayne.standaloneexample;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class StandaloneExample {

public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext(“spring-config.xml”);
StandaloneExample standalone = ctx.getBean(StandaloneExample.class);
standalone.startStandalone();
}
}

If you are using an IDE you will see the startStandalone() method is currently Red meaning that it is not there, so if you can use your ide tools to create it.

Next we will create the Dao and allow it to create a table in the preexisting standalone schema in the database (if you have not created the schema then you will need to.

Under the standaloneexample package create a new package called model.beans, then create StandaloneVO inside. Annotate the class as @Entity and @Table(name=”standalone”) within the class add and id with the @Id and @GeneratedValue annotations then add any other fields you wish on your object.remember to make them private with public getters and setters.

package com.github.theresajayne.standaloneexample.model.beans;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name=”standalone”)
public class StandaloneVO {

@Id
@GeneratedValue
private long id;
private String name;
private double amount;
private Date created;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getAmount() {
return amount;
}

public void setAmount(double amount) {
this.amount = amount;
}

public Date getCreated() {
return created;
}

public void setCreated(Date created) {
this.created = created;
}
}

Now add a new package under model called dao, DAO means Data Access Object and these are the methods to execute the CRUD methods (Create Read Update and Delete) , normally you would also have a service layer which would take the VO (value objects) and change them to DTO’s or FBs (Data Transfer Objects or FormBeans) This is a good approach to seperate Database Objects from transient data movement objects so you do not inadvertently alter a record you only wanted to modify on the front end. but as this is an example we will go straight to the DAO layer.

First create an interface StandaloneDao

package com.github.theresajayne.standaloneexample.model.dao;

import com.github.theresajayne.standaloneexample.model.beans.StandaloneVO;

import java.util.List;

public interface StandaloneDao {
public List<StandaloneVO> findAll();

void save(StandaloneVO standaloneVO);
}

Now create the Implementation of the Dao usually called StandaloneDaoImpl

package com.github.theresajayne.standaloneexample.model.dao;

import com.github.theresajayne.standaloneexample.model.beans.StandaloneVO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class StandaloneDaoImpl implements StandaloneDao {

@Autowired
private SessionFactory sessionFactory;

@Override
public List<StandaloneVO> findAll() {
Session session = sessionFactory.getCurrentSession();
return (List<StandaloneVO>)session.createQuery(“from StandaloneVO”).list();
}

@Override
public void save(StandaloneVO standaloneVO) {
Session session = sessionFactory.getCurrentSession();
session.save(standaloneVO);
}
}

Now lets do something with our code….

private void startStandalone() {
StandaloneVO standaloneVO = new StandaloneVO();
standaloneVO.setName(“Test1″);
standaloneVO.setAmount(239.32);
standaloneVO.setCreated(new Date());
standaloneDao.save(standaloneVO);
List<StandaloneVO> result = standaloneDao.findAll();
for(StandaloneVO vo : result)
{
System.out.println(vo.getId()+”:”+vo.getName()+”:”+vo.getAmount()+”:”+vo.getCreated());
}

}

Now each time you run the code there will be a new line to the output….

1:Test1:239.32:2013-07-14 13:22:11.0
2:Test1:239.32:2013-07-14 13:22:21.0

Process finished with exit code 0

Hopefully this article has helped to make setting up Spring and Hibernate easy for Stand Alone Applications.

Source code is available from http://www.github.com/theresajayne/standaloneexample



{November 22, 2012}   Raspberry PI – A first look

I finally decided to get myself a Raspberry PI, I have a spare HDMI cable, Keyboard and mouse and A few spare Mini USB phone chargers.

I got mine from ModMyPi.com which offers a PI plus case for only £35.99  So I ordered a PI, Said it was out of stock but had a backorder button saying 3-10 days. But then that evening at about 4pm The status of my order went to “Shipped”.

The next day nothing arrived except a few bills, So I went out to Tesco and purchased 3 SD Cards, 2 x 8GB and 1 x 32 GB. Once I got them home, I downloaded 3 images and blew them to the cards ready for use.

RISC OS

RISC OS is a computer operating system designed in Cambridge, England by Acorn. First released in 1987, its origins can be traced back to the original team that developed the ARM microprocessor. RISC OS is owned by Castle Technology, and maintained by RISC OS Open. This version is made available free of charge to Raspberry Pi users.

Arch Linux ARM

Arch Linux ARM is based on Arch Linux, which aims for simplicity and full control to the end user. Note that this distribution may not be suitable for beginners. The latest version of this image uses the hard-float ABI, and boots to a command prompt in around ten seconds.

Soft-float Debian “wheezy”

If you’re just starting out, this is the image recommended that you use. It’s a reference root filesystem from Alex and Dom, based on the Raspbian optimised version of Debian, and containing LXDE, Midori, development tools and example source code for multimedia functions, but uses the slower soft-float ABI. It is only intended for use with software such as the Oracle JVM which does not yet support the hard-float ABI used by Raspbian

I chose the Soft-float as I am a Java developer and want to do stuff using that rather than the Python or other languages available.

 

Now we wait to see what happens when it arrives…..

Ok its just arrived, in the small box were the case and the PI itself. nicely packaged in an anti static wrap.

2012-11-22 14.07.232012-11-22 14.12.52

Plugged it in.. Within seconds RISC OS Pi came up on the screen, then before i could take a photo, POP, and the screen went blank. Repower Same thing. something isnt right.

I am using a 2A Kobo psu which is more than the 750ma needed so it shouldn’t be that, so Next, i have an old Sony Bravia HD Ready TV, maybe the HDMI has a problem so I will switch to the phono lead for the video.

 

Will post again when i have a solution….



{August 5, 2012}   Agile BDD/TDD

Lots of people have a strange view about TDD/BDD programming methodology. People tend to write code then write a test for it, this usually doesn’t test fully the code as you are writing the test to match your code.

So for proper Agile Development we start with a test.

[Test]
public void i_should_be_able_to_instantiate_an_organisation()
{
    IOrganisation organisation = Substitute.For<IOrganisation>();
    organisation.IsInstanceOf<IOrganisation>();
}

At This point [Test] IOrganisation and Substitute.For<> are all underlined in red, So this is a failing Test,

So we use NuGet to add Nunit, NSubstitute and Chaining Assertions for Nunit, Then we use Resharper to Alt-Enter on IOrganisation to create a new Interface.

Running the tests now, Pass with a Green Bar.

So, We refactor, Test again and Save the output checking it into source control.

Why Refactor?

Well we want to move the newly created IOrganisation Interface to its own class, or even project.

Once this is done, we write another test.

[Test]
public void I_should_be_able_to_retrieve_the_number_of_salons_in_the_organisation()
{
    IOrganisation organisation = Substitute.For<IOrganisation>();
    organisation.GetSalonCount();
    organisation.Received().GetSalonCount();
}

This one forces the IOrganisation to have a GetSalonCount() method so we add it, then once Green Bar on the test, we Refactor if needed

then Save and check in.

TDD and Agile development means you can do many check ins to your repository per day, the reason is that we can roll back to any previous version easily and every checkin also is guaranteed to run as all test pass before a checkin.

Using this methodology we can write working software quickly knowing that all changes we do result in a passing test and nothing previously written has been broken,

Ron Jeffries has written a good book that covers this method of development, http://my.safaribooksonline.com/book/programming/csharp/0735619492 and I would recommend you try it if you can, and Safari Books online will provide access to it if you cannot find a paper version



Recently an Analyst report Called Agile a Scam, Says it’s an easy out for Lazy Developers, This is a strange concept to me, an Agile Proponent.

The crux of the argument is that It is for Lazy Developers who don’t want to spend weeks planning and months documenting.

If that is what makes a developer Lazy, then I guess I am also a Lazy developer. However what is also evident is that part of the argument against Agile is that it is a waste of money, and just a way to sell training courses in Agile for lots of money.

POPPYCOCK!!!

The Agile Manifesto (http://agilemanifesto.org) States the following

We are uncovering better ways of developing
software by doing it and helping others do it.
Through this work we have come to value:

Individuals and interactions over processes and tools
Working software over comprehensive documentation
Customer collaboration over contract negotiation
Responding to change over following a plan

That is, while there is value in the items on
the right, we value the items on the left more

 

What this means is that we value good cleanly written maintainable software. We are professionals, we care about the software we write. Someone out there in the internet once said “Write your code as if the next person to maintain it knows where you live and has a gun”  This is a very good idea to hold in mind. David Eddings in the first book of The Belgariad, had Garion ask Durnik why he was spending so much time and effort, smoothing a strut for the undercarriage of a waggon when it would never be seen by anyone, and Durnik replied that he would know it was there, and he would see the waggon every day, he had pride in his work. Well so do we.

Non Agile companies have usually laid out as follows

Managers at the top,

Analysts/ Architects under them – these are the top brass and the only people who have spoken to the customer and are the bible according to how the software will look,

Senior Developers – They control the flow of information to the lower developers so that no developer is doing more than the Senior thinks they can do

Junior Developers – otherwise known as Code Monkeys or Code Jockeys, spend all day writing code they don’t like or own.

Now Any company that follows the above schema is heading for failure, they will produce a software package that looks as the Architect imagined it but has no relation to what the customer actually wanted. Months of planning and development wasted.

So Why Agile?

Ok so here we go with the same company that has moved to Agile

Customers are level with

Managers who are supporting and assisting the

Senior developers who are level with the

Junior Developers who all have an input to how the program is written and have ownership of the project so that it can move forward faster and with less errors and problems.

 

Agile, is also a part of the XP (eXtreme Programing) methodology, XP has 2 forms, True XP/Pair Programming – Developer Led, and Sprint/Scrum – Manager Led. And usually uses a Card wall to track the progress of each iteration or Sprint. But we come back to the Crux, Agile is for the lazy programmer. 

Hmmmm, that was a little harsh.. Rather than sit there and just type what you have been told to type (the code monkey above) an Agile developer has to think about the card, design tests that will test the required functionality, Code said tests then write the code to make the tests pass, Also at the same time understanding what they are supposed to be producing, and as the customer is accessible as they are in the same meetings and in an ideal world working in the same office. They can be asked how things are supposed to be if the specification is not as clear as it should be. So instances where a Message box could be Green or Blue, and the Architect says Green when the customer needs Blue as Blue is the new corporate colours, are gone. Now the customer explains why it needs to be Blue  and by the way due to regulations in the management of toxic Widgets the danger message has to be polkadot pink with a puce background…. The domain knowledge provided by the customer being on site means fewer mistakes are made, and as with an agile release regime it means that the customer gets to see the results every 2 weeks or similar time scales, meaning that any problems are caught sooner and delays resolved earlier.

Where it may seem to the old style of company that Agile is for the lazy developer is that rather than design the whole product in one foul swoop, it is designed in small manageable chunks which will mean that more code can be reused and tweaked without breaking the existing functionality. The other issue for the Old Style of company is that now the developers are doing the same job as the Architect why should we have an architect. But of course the Architect is fighting to keep his position and who has the loudest voice the Architect or the Junior Developer who actually has some good ideas on how to improve the software and can show how the design the architect came up with cannot work properly in a million years… Yes the junior developer either quits or breaks to become a non thinking developer.

Developers have never liked Documenting code, the code is easy to understand, the method names are useful, why should they document it – doesn’t the architect’s design document it? Documentation of code is a waste of time and effort, if code is not easy to understand then it needs to be rewritten and simplified until it is.  Planning, instead of waiting for months without any code being written as the architect designs the holy grail of software, just for it to end up a plastic cup… The developers design the software based on the actual functionality needed from the software and so doesn’t have any useless functionality or “undocumented features”

Lets consider that we are professional developers and we all have brains, so lets all use them and not treat a software company as if it was an Army and break the wills of those who if allowed would be able to produce elegant beautiful software that works.



Most people i speak to on the IRC chats have no idea what Spring is, all they know is that it is a Java J2EE programming framework.

I will today try to simplify the situation Spring in essence is mainly a configurable Dependency Injection (DI) framework, this means that you can initialise objects without actually knowing how to,

example:

public Class Service {
    private ModelObject modelObject;

    public Service(ModelObject modelObject)  {
        this.modelObject = modelObject;
    }

   public void useModelObject() {
     ....
    }
}

    This works by passing in the predefined ModelObject when the class is instantiated, so there is a config file in XML which details how to declare each object so the framework can pass it in. This means you invert the dependency

    model so that if the “ModelObject” was actually declared as an Interface it would be able to take ANY class passed in on the configuration that implemented the declared interface.

    This leads nicely to the SOLID programming principle where D means Dependency Inversion principle.

      

    SOLID is an excellent way to make sure your new Class is good OO design.

    1. Single Responsibility Principle – Every object should have a single responsibility, and that responsibility should be encapsulated by the class

    2. Open/Closed Principle – When you get a request for a new feature you should be able to add this without changing any old code by using subclases and new implmentations

    3. Liskov Substitution Principle – This means that you should be able to use any subclass in the same place the parent class is used (it honours the method signatures of the parent)

    4. Interface Segregation Principle – avoid getting your classes included into other classes, if you break this one it is considered bad design

    5. Dependency Inversion Principle – Decouple your software modules, to achieve that you need to isolate dependencies for code reusage

      Anyway back to Spring, so we have all our objects declared in the config as well as all the database configuration and the database drivers etc. This means that we have a lot of independent classes which are

      sat all on their own and so is easy to test using unit tests. (this is a good thing) This is the main power of Spring, you can drop out and drop in classes and change them by just changing the configuration file.

        

      A project i worked on used Spring to add security so that even if anyone tried to access data they shouldn’t then it still protected them, by having the Domain (Model) objects behind an assembler which checks which information is

      allowed to be passed to the Domain Transfer Object (DTO), so if you are admin you can see the person’s email addresses but if not then they don’t even come out of the database so the information is just not there rather than being hidden.

        

      This of course stops nasty hackers from siphoning off your users details and selling them to fraudsters as has happened with Sony, Amazon, SipGate and many other companies around the globe.



      {January 23, 2012}   Why you should not use Skype

      Skype, The wonderful Internet phone service. What could possibly be wrong, its secure, it works and sounds great.

      The problem is not the service offered, more how it is implemented.

      Way back at the start of the internet some companies developed software to facilitate peer to peer fileshare, eDonkey, and Kazaa were two of the big players, RIAA then went after the software developers so Kazaa to divert the wrath of the courts developed Skype to use the same technology as the file sharing network.

       

      Back to the present…..

      Skype is now huge, everyone uses it, this is good as it now means that the technology used by it is working as good as ever or even better as there are so many people using it.

      So what is so wrong with the image here, Well Sarah User is a housewife who uses Skype to keep in touch with family in other countries, she pays the low broadband fee and gets 1GB of bandwidth per month and then she has slowed down internet and surcharges for using too much data. She leaves Skype running so that family and friends can call her without having to pay fees.

      But underneath the covers a nasty situation is brewing, as part of the Skype network, Sarah’s internet line is being used to send other people’s phone calls as they bounce calls between logged in users.

      On top of that to prevent drop outs they also use 3 streams for each call discarding the slower packets when they arrive. 

      image

      The Skype Network

       

      Sarah now has run out of bandwidth for the month and is paying for other peoples calls.

       

      VOIP on the other hand is a direct connection protocol, First of all the phones log into the VOIP provider’s registration server, and when a call is set up it is direct between all users and not via anyone else so you are not losing your internet connection to any other users.

      image

      VOIP provider

       

      There are many VOIP services out there and you can even get adapters that you can plug your normal house phone into and redirect all your calls through the internet.

      Some providers are

      3CX  and VoIP Unlimited

       

      You can even if you are interested get a FREE VoIP server called Asterisk, this can with the right hardware in the system interface with ISDN lines or normal phone lines,

      as well as a built in answerphone and IVR (the system where you get a message like “Press 1 for sales, press 2 for accounts, press 3 to be redirected to the legal department”)



      {January 20, 2012}   Generic toString() for Java

      I found myself needing to retroactively add a toString() method to about 300 classes so that the AOP logging could track the data being passed in to DAOs etc.

      So what to do? Spend a day or two trying to shoehorn this into the system class by class ? or work out a way to use one method in all classes?

      Obviously wanting more time for blogging , shopping for shoes and doing my make-up  I chose the latter.

      So I need to get a toString() that works. the default one for Object prints the class name and the instance id

      uk.co.myorg.model.AuditLog@56f967c6

      This doesn’t help so we had to move cleverer. either go through a whole class doing a StringBuilder with lines like

      result.append(this.getName());

      result.append(“\n”);

      this was the long way around, so I decided to delve into reflection and do it in a clever way.

          @Override
      public String toString() {
      StringBuilder result = new StringBuilder();
      try {
      result.append(this.getClass().getName());
      result.append(“\n————————————\n”);
      Class c = this.getClass();
      Field fieldList[] = c.getDeclaredFields();
      for(Field entry: fieldList) {
      result.append(entry.getName());
      result.append(“:”);
      result.append(entry.get(this));
      result.append(“\n”);
      }
      } catch (Exception e) {

      }
      return result.toString();
      }

      Now this is nice and compact, and does what it says on the tin.

      I now need to have an abstract class that every single class i use extends, oh well not much work saved but a nice concept.



      {January 19, 2012}   Wireless Internet

      Several years ago I wrote an article to post in the Reading Chamber of Commerce magazine but for some reason they did not publish, So i will attempt to recreate the article here and update it for current information.

      Everyone has heard of Wi-Fi,  Motorway services provide it for free, but what are the risks with it. Back in 1997 I took my laptop with a pcmcia wireless network card ran up a piece of software called stumblr and drove round the IDR (Inner Distribution Road) in Reading heading out down Queens Road and back in by Kings Road (the legal/financial area)

      In all I found 64 wireless hotspots, 32 of them strangely enough were wide open and unprotected by any security at all.

      At the time every company was getting wifi for their employees to use in the office on their laptops, but no-one was securing the connection with WEP (Wireless Encryption Protocol)

      As many know, this has since been cracked and even WPA-2 one of the latest encryption methods is crackable in minutes by even a mobile smartphone. It at least deters the opportunist.

      People have a problem understanding how Wireless works, they are connected to WiFi but they still cannot get onto the internet, take for instance Wired connections they will plug in the cable and if it doesn’t work they will look at the network configuration or the router to determine what is not working, With wifi, they keep figuratively plugging and unplugging the cable by disconnecting and reconnecting the WiFi.

      The WiFi connection you set up with the WPA key is the same as the Cable you plug into your PC. After that you have what is called the TCP/IP protocol  this is what allows you to connect out to the internet, but at its core the internet is machines connected together using an internet address called IPV4  you may recognise it as numbers like 192.168.1.2

      but how do you connect to sites like http://www.google.com, We use a system called DNS (Domain Name Services) which is like a large Telephone Book allowing you to look up http://www.google.com and get its phone number (IP address).

      There are small ranges allocated for non-routable connections and they are seperated into classes, don’t worry about those they just detail how many digits at the start do not change.

      Class A: 10.x.x.x

      Class B: 172.16.0.0 – 172.32.255.255

      Class C: 192.168.x.x

      Well most WiFi systems automatically allocate anyone connecting with an address to allow them to access the internet, To start securing the network you need to stop this happening, TURN OFF DHCP – this is the mechanism used to automatically issue internet addresses, or if you need this on because you have a large network, you could also lock the WiFi to only allow connections from certain machines, whilst this can cause more administration to the IT team it will make the network more secure.

      How does this work? Well every network card ever created has an allocated “MAC” address (Media Access Control)  This is a series of digits which uniquely identify any piece of hardware, and most modern routers allow what is called Mac locking meaning if you don’t have the correct network card you cannot connect,  Interestingly enough the new IPV6 which is already starting to replace the old IPV4 due to us running out of addresses on the IPV4 network almost is a mac address and I have seen where some providers are allocating the IPV6 address based on the Mac Address of the connected hardware.

      If you exclusively use Mac Locking then you can actually have your WiFi without a password as unless they are on the list they can’t come in.

      Further to that all WiFi routers also Broadcast their Ident so you can see the name of the hotspot, You can also turn this off, so unless you know its name you cannot manually connect.

      added to that, all routers need to have their default password and name changed and if possible change the ip address it uses.

      A hacker will start looking for the router address to be able to try and gain access to the rest of the network by looking for 192.168.1.1 or 192.168.1.254 as this is where they usually reside. Change the default address say go for 192.168.4.20 for the router, so its completely out of the normal addressing range. All of this will help you to secure your network and deter hackers from stealing your ideas and installing nasty software in your connection

      So The Suggestions are

      • MAC lock the router
      • Use WPA-2 or better security on the router
      • Change the router password and default ip address
      • Switch off the WiFi Beacon

      All of these steps will increase your security in the office, and also at home, many people will implement security at the office that is second to none but they will still have a completely open Netgear router on default IP and password at home,

      A last thought, A hacker logs into your network, downloads child porn, plants it on your computer then calls the police. What would that mean to you?



      {January 18, 2012}   Hello world!

      Welcome to my little corner of the internet, I thought after so many years reading other people’s blogs, and getting advice on programming problems and such

      I should start my own blog to detail my technical stuff and maybe discuss life in general.

       

      So welcome to what I hope doesn’t end up like other attempts in the past which have dwindled off after about 2 weeks.



      et cetera