Course Info

#Programming Fundamentals 1

This is an introductory Programming module and assumes no prior knowledge of programming.

In this module, we will introduce you to the Java programming language through the Processing Development Environment (PDE) and then IntelliJ.

First, we will work through non-complex problems that will introduce you to the basic constructs of programming languages i.e. Sequence, Selection and Loops. You will also learn to use variables, different data types, manipulate the data, logical operators and methods. This will be done using processing.org

Then, using IntelliJ, we will progress to more complex problems that will briefly introduce you to object-oriented programming and data structures. You will do a deeper dive into both of these areas in the semester 2 module, Programming Fundamentals 2.

Primitive Data Types

In Java, there are:

  • four whole number data types: byte, short, int, long.

  • two decimal number data types: float (default in Processing) and double (default in Java apps).

  • a single character data type: char.

  • a true/false data type: boolean.

Using the int data type

Create a new Sketchbook in your PDE and save it using the following naming convention: labXX_stepYY, where XX is the number of the lab and YY is the number of the step.

Enter the following code: Using int data type to set the coordinates of three lines Run the code. Your window should now have three blue lines similar to the screen shot below: Three blue linesUpdate the code using a, b and c variables to generate new lines:

Using int data type to set the coordinates of more lines

Run the code. Your window should now have three new blue lines similar to the screen shot below:

Six blue lines

A syntax error

Update the code by changing int to Int (uppercase I). Run your code again. What happened? Can you explain what happened? Ask your lecturer to explain it if you are not sure.

Change Int back to int.

Another syntax error

Update the code by changing the amount assigned to variable a from 70 to 70.56.

Run your code again. What happened? Can you explain what happened? Ask your lecturer to explain it if you are not sure.

Change 70.56 back to 70.

Save and close the sketchbook.