Java Serialization Example

April 27, 2017 Leave a comment

Java provides a method of saving objects to file, called Serialization. In order for an object to be serializable it must implement the interface and you should set a version ID as well as shown below.

class Student implements {

   String name = "";
   Integer age = 0;
   Double gpa = 0.0;

   private static final long serialVersionUID = 1L;

You can save the object to file like this:

        try {
            FileOutputStream fileOut = new FileOutputStream(path);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
        } catch (IOException i) {

And you can load it like this:

        try {
            FileInputStream fileIn = new FileInputStream(path);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            obj = (Student)in.readObject();
        } catch (FileNotFoundException fnf) {
            System.out.println("No serialized file found at " + path + ". Creating new blank object.");
            obj = new Student();
         catch (Exception e) {

No evidence to back idea of learning styles

March 13, 2017 Leave a comment

Richard Stallman on Steve Jobs

March 1, 2017 Leave a comment

“He figured out a way to make computers that are jails for their users and make them so shiny that millions of fools would beg to be jailed.” Richard Stallman.

Is IB Computer Science for me?

January 24, 2017 Leave a comment

Key things to remember:

About 50% of the course is programming, so you will need to enjoy programming. I have given you a short diagnostic challenge below. If you enjoy trying to solve it, then you should do IB Computer Science.

High school computer science is generally NOT a pre-requisite to study computer science at university, so you can do computer science later, even if you don’t do it now. This is not true of other subjects like chemistry and physics.

I don’t set homework outside of reviewing what we’ve done in class and revision for summative assessments. All summative assessments take the form of written tests in the style of the IB Computer Science exam. There are three per semester, including end-of-year and mock examinations. That’s not a lot of tests, but I will expect you to have prepared well.

As with all IB subjects you will have a substantial internally assessed project. In IB Computer Science this takes the form of a software development project in which you must plan, design, code and implement a computer program for a real client.

Do you like programming?

This algorithm prints every item in a list of 100 things.

i = 0
while i < 100:
  print list[i]
  i = i + 1

This algorithm prints every item in the list from back to front.

i = 100
while i > 0:
  print list[i-1]
  i = i - 1

This algorithm prints “Hooray” if it finds the number 7 in the list:

i = 0
while i < 100:
  if list[i] == 7 then:
    output "Hooray"
  i = i + 1

Can you write an algorithm to determine if the list is a palindrome?
(ie it is the same forwards as backwards).

Donate to Wikipedia

January 10, 2017 Leave a comment

I just donated to @Wikipedia. Support free knowledge! #iloveWikipedia

Donate to Wikipedia now

Why is centrifugal force ‘fictitious’?

December 27, 2016 Leave a comment

Centrifugal forces only arise when you treat a non-inertial frame of reference as if it were an inertial frame of reference. Consider what happens if I accelerate past a stationary object and I consider the motion of the object in a frame of reference in which I am at rest. I observe the object accelerate in the other direction. Since the mass of the object is constant, and Newton’s 2nd law gives F = ma, the fact that the object accelerates leads me to conclude that there must some force accelerating it. The same happens if I am in a bus which is accelerating (either by changing speed in the same direction or by changing direction). I witness the stuff, including me, accelerating around the bus but only because I am considering the bus and its contents as at rest in an inertial frame of reference.

Should you teach skills? An excellent case in favour from Geoff Petty

December 6, 2016 Leave a comment