Introduction
[Part 1 of 11]


Welcome to the course! 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 materials (like this), where you can download and listen again to lectures, and practicals. As you work through the course, more options will become available to you. You can find out how each part of the course fits into the broader picture by clicking the [Part 1 of 11] or equivalent at the top of the page. This links to a page that describes how the course holds together and what to expect later in the course. This is where you can also find the lecture powerpoints and handouts, if you want them -- though all the information will be on these pages as well, with additional info that will help you get your head around it.

These 'lecture' materials are for you to work through to revisit topics you're unsure of. There are a set of quiz questions for each one which will help you to think through issues, and there's also usually a summary of the key concepts (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 between lectures: they will help.

 

Ready? Great! Then we'll get started!

Screenshot: Progress paths

First up, the slides to the left and below repeat the introductory lecture given, including all the spoken info.

 

Note that the slides have sound, so you may like to use headphones/speakers. The tracks play all the way through once started, so to repeat the sound track associated with a slide, let it finish, then zip back to the last side and forward again.

 


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.


In each case, if you feel you need to revisit the lecture, 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...

 


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.


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");

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 material' 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 part's set:

[Key ideas from this part]