Welcome to the course!
[Part 1]


Welcome! This introductory page will help you understand the course and get you up and running with the basics of computer programming.

The course is designed to teach the basics of computer programming. The examples used are taken from spatial analysis and modelling, so will hopefully be of use to anyone wanting to do scientific programming that analyses real-world systems: social scientists, ecologists, economists, etc.


The course is a mix of online lecture material pages (like this) and practicals. You can find out how each part of the course fits into the broader picture by clicking the [Part 1] or equivalent at the top of the page. This links to an outline page that describes how the course holds together and what to expect later in the course. In addition to the 'core' lectures, as you'll see on the homepage there are also some additional lectures and materials that you might find useful/interesting.

The lecture materials pages are for you to work though. There are a set of quiz questions for each set of slides which will help you to think through issues, and there's also usually a summary of the key concepts at the bottom of each page (you can also reach these directly via the outline page).

However, the key to learning any language is to practice, so most sets of lecture materials come with small example projects for you to do that will also help you think through issues. Try and do these as you read through the lectures: they will help. There is also a more extensive list of additional short practice pieces linked from the homepage right sticky-note -- again, you don't *have* to do these, but they will help.

Finally each set of slides comes with a practical you can do (the right-hand path on the homepage). Try to do the practicals at each stage (as shown by the red arrows). They build up to a full application; specifically we'll be building up an agent-based model (we'll come on to what these are in the second practical). However, even if you aren't interested in agent-based models, the code will be more generally useful for any spatial analysis or modelling application.

 

Ready? Great! Then we'll get started!

Screenshot: Progress paths

Work through materials in a zig-zag.


Powerpoint and audio

First up, the slides to the left start the introductory lecture.

 

Note that the slides have sound, so you should use headphones/speakers. To re-start a track, just go back to the last slide and then forward again. If you can't use the audio tracks, there is a powerpoint copy of the slides below the embedded slides to the left, and these have complete notes in their note panels.

If you read the slides embedded within this page, and you struggle to read the slides at all, you can always go back to the first slide and click on the link to see them fullscreen.

 


Quiz: Here's your first quiz. There are three or four quizzes per lecture. They are designed to explore issues you'll need to get your head around, so think them through in detail rather than choosing any old answers until you get the right one. Nevertheless, if you do get a right answer, but you're still not 100% sure why, don't worry -- an explanation will appear as well.

Note that if you go to any links off this page the quizzes will reset, so open all links in new tabs if you don't want to do quizzes over again. To open a link in a new tab, click it with the rotary wheel button in the centre of your mouse, or right click it and select the appropriate option.

Drag the right answers into the underlined area to answer.

The code shown on slide 6 (in the above slides) ________________________________________

  1. prints the circumference of a circle.
  2. prints the radius of a circle.
  3. initiates the self destruction sequence for the whole world. Oh noes!!

Correct! One of the key things when coding is to use names that make it obvious what the code does, both for your sake when you come back to code, but also so it is nice and clear for others who might want to look at it.


For each set of slides, work through the slides first -->

Then, if you want to follow up some of the themes, there's further info to the side of them, as there is for these slides, below. Skim-read these sections at least, because occasionally there's important stuff to do, but with most of it you can either read the linked material in your own time, or ignore it, as you like. We'll let you know if it's important.

-----------------------------------

Further info:

Becoming a programmer isn't just about knowing how to code, there's a whole culture and history to engage with as well. Part of being a programmer is being able to talk to other programmers in a language they understand so you can work productively together.

With that in mind, this course will also introduce some key ideas in computing more generally. We'll also link to information you can follow up and read in your own time. For example, here's some links on computing you might like to explore...

Powerpoint and audio

 


Quiz: A standard (non-Java) compiler converts code from ________________________________________

  1. human readable text to machine readable binary.
  2. human readable text to a running program.
  3. human readable text to a list of things to do with its own binary functions.

Correct! But remember that the Java compiler compiles to bytecode, not binary files in the same sense.


Powerpoint and audio

Further info:

Formally, we might distinguish between 'Design Time' (which, in java, is when we write the program), 'Compile Time' (which is when the compiler checks our syntax and rearranges our code for optimum efficiency), and 'Run Time' (which is when our code is running, and 'runtime' issues can arise, like the user typing "two" instead of "2" when asked to enter a number). We'll come back to this division when we look at debugging, and how we cope with problems in our code.

 

If you want to see what the "add three numbers" algorithm looks like as code, here's the java code version.

 

If you're interested in Open Source Software, you can find out more information on the Open Source Initiative website. Licenses we've used in the past include the GNU General Public License (GPL) and the Artistic License. You may also be interested in the Creative Commons licenses, which tend to be used for non-software projects.

 

Finally, it is worth mentioning that a popular forum for help with tricky coding issues is Stack Overflow; but note that if you are doing this course for credit you should take note of our Plagiarism and Collaboration page.

 


Quiz: The correct order of doing things for a java programmer is: ________________________________________

  1. write; debug; debug; debug; cry.
  2. write; compiler; debug; interpreter.
  3. write; interpreter, debug, compiler.

Correct! The crying is an entirely optional part of the development process.


So, let's get coding!

Without further a-do, let's move on to learning the core language so we can get some coding done in our first practical! The first thing we need to understand is the fundamental structural unit of a Object Orientated Programming Language: the class. Moreover, we need to know how to build one of these mavellous structures such that the Java Runtime Environment knows that it is a computer program that should be run. These issues are covered in the next set of slides.


Further info:

Blocks: it is worth noting that blocks are always used with some kind of statement, so you'd actually never see this kind of thing:

public class HelloWorld {
   {
      System.out.println("Hello World");
   }
}

The example of the 'main' block in the slides is more usual, where a block is preceeded by some kind of statement or declaration, in the case of 'main' a declaration that the block is the main block.

public class HelloWorld {
   public static void main (String args[]) {
      System.out.println("Hello World");
   }
}

Note also that you can break lines anywhere except between quote marks, so this is ok:

System.out.println(
   "Hello World");

But this isn't:

System.out.println("Hello
   World");

You'd have to do this:

System.out.println("Hello " +
   "World");

Powerpoint and audio

Other than inside quote marks, Java ignores spaces and line breaks; it only demands that at the end of each command there is a semi-colon, and at the end of each block, there's a closing bracket.

 


Quiz:

To make a java application that runs you need ________________________________________

  1. at least one class with a main block.
  2. at least one class with a block.
  3. every class to have a main block.
  4. every class to have a block.

Correct! For an application, at least one class must have a main block - this is the class passed to the interpreter. You can have more than one class with a main block, and choose which to run, but it is unusual.


Towards the end of each of these lecture pages you'll find a summary of the key take-home concepts and code-structures from each set of material, along with some new examples. You can also reach these from the course outline. Here's this introductory part's set:

[Key ideas from this part]

 

Once you're familiar with the material on each page, return to the homepage for the next set of materials.
[homepage]