Computer Fundamentals and Introduction to Programming · Prerequisites
Prerequisites for Computer Fundamentals and Introduction to Programming
The course does not expect any programming experience. This page collects the everyday computer skills and school mathematics on which the 21 presentations in the 12 chapters rest. Each topic card says what you should know, in which presentations it is used, and has two short self-check questions. The details open with the Details and self-check button, and clicking a question shows its answer.
The essential core. Typing accurately and being able to find your files, the four operations with integer quotient and remainder (/ and %), percentages and averages, using letters in place of numbers, and/or/not, and following steps in order. Java itself is taught from scratch in Chapter 5. If something here is missing, a short review in the first weeks is enough.
Terms. The terms used in the slides are collected in the course glossary.
Computer use basics
Keyboard and mouse, careful typing, files and folders, the web and email, installing software. Chapters 1–3 build on these, and the Java labs take them for granted.
Keyboard, mouse and shortcuts
You should be able to select, copy, move and undo quickly with the keyboard. The Windows and Office presentations introduce many more shortcuts on top of these.
Chapters Chapter 1.2 · Computer Hardware Chapter 2.2 · The Windows Operating System Chapter 3.1 · Microsoft Word Chapter 3.2 · Microsoft Excel Chapter 3.3 · Microsoft PowerPoint
- Mouse: a single click selects, a double click opens, and a right click opens the context menu. Dragging moves an item; holding Ctrl while dragging copies it.
- Selecting text: Shift with the arrow keys extends the selection. Ctrl + A selects everything, and a double click selects a single word.
- Basic shortcuts: Ctrl + C (copy), Ctrl + X (cut), Ctrl + V (paste), Ctrl + Z (undo), Ctrl + Y (redo), Ctrl + S (save), Ctrl + F (find).
- Window and system shortcuts used in Chapter 2: Win + E (File Explorer), Win + D (show the desktop), Alt + Tab (switch between windows), Win + Shift + S (capture a region of the screen).
Test yourself
With a paragraph selected, you press Ctrl + X and then Ctrl + V somewhere else. What happens to the paragraph?
It moves. Cut removes the paragraph from its old place, and paste inserts it in the new one. With Ctrl + C the paragraph would have been copied instead.
A sentence was deleted by accident. Which shortcut brings it back?
Ctrl + Z (undo).
Accurate typing and special characters
Java is unforgiving: a single wrong capital letter or a missing semicolon stops compilation. Code must be typed letter for letter, including symbols that can be awkward to type on your keyboard layout.
Chapters Chapter 2.2 · The Windows Operating System Chapter 5 · Getting Started with Java Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals Chapter 11 · Strings
- Java is case-sensitive:
System,systemandSYSTEMare three different names, and only the first one is defined. - Symbols typed every day:
; { } ( ) [ ] " ' + - * / % = < > ! & |. - On a US keyboard the braces and brackets are on the keys next to P (
{ }are Shift +[ ]). Many other layouts need AltGr for them, for example AltGr + 7 and AltGr + 0 for{and}on several European layouts. Switching between keyboard layouts (Win + Space) is explained in the Windows presentation. - Look-alike characters must not be confused: the digit 0 and the letter O, the digit 1 and the letter l, the straight quote
"and the curly quotes “ ” that Word inserts. Java does not accept curly quotes. - Letter case depends on the locale: the Turkish dotted and dotless i can cause trouble in identifiers and string comparisons (Chapter 11, “Turkish Characters and Locale”).
Test yourself
Does Java accept the line system.out.println("Hi");?
No. The class name is System with a capital S. javac takes the lowercase name system to be a package and reports package system does not exist.
On a US keyboard, how are { and } typed?
With Shift + [ and Shift + ].
Files, folders, paths and extensions
Programs are files that live in folders. You need to know where a file is saved, its full name including the extension, and how to read a path such as C:\Course\Week1\Hello.java.
Chapters Chapter 1.2 · Computer Hardware Chapter 2.1 · Software and Operating Systems Chapter 2.2 · The Windows Operating System Chapter 3.1 · Microsoft Word Chapter 5 · Getting Started with Java
- A path lists the folders from the drive (the root) down to the file: drive
C:, foldersCourseandWeek1, fileHello.java. - The extension is the part of the name after the last dot and shows the type of the file:
.docx,.xlsx,.pptx,.pdf,.txt,.java(source code),.class(compiled bytecode). To make extensions visible, turn on the “File name extensions” option in File Explorer. - A relative path starts from the current folder:
.is the current folder and..is its parent folder. - A Java rule (Chapter 5): the file that contains
public class Hellomust be named exactlyHello.java. - Keeping the coursework in a separate folder for each week or chapter makes things easier. Saving everything to the Desktop or Downloads creates clutter.
Test yourself
What is the extension of the file at C:\Users\Ann\Documents\homework\Hello.java, and in which folder is it?
The extension is .java. The file is in the homework folder, whose parent folder is Documents.
If the current folder is C:\Course\Week1, where does the relative path ..\picture.png point?
To the file C:\Course\picture.png. .. goes up one level, to the folder C:\Course.
Web browser, search and email
Throughout the course you download material, search for error messages, and submit assignments by email or through a learning platform. Chapter 1 also explains how web addresses (URLs), the Domain Name System (DNS) and email work behind the scenes.
Chapters Chapter 1.1 · Basic Concepts Chapter 1.4 · The Internet Chapter 1.5 · Computation and Computational Thinking Chapter 11 · Strings
- A URL is read from left to right: first the protocol (
https), then the domain name (www.example.edu), and last the path on the server (/announcements). - For an effective search, type the error message in quotation marks exactly as shown, add the name of the language (“java”), and give priority to the official documentation.
- An email address consists of a user name,
@and a domain name. A good email has a clear subject, the attachment is checked before sending, and the reply goes to the right person. - Safe habits: a separate, strong password for each account, multi-factor authentication, and caution with unexpected links and attachments (phishing).
- Chapter 11 splits an email address into user name and domain name with
indexOf('@')andsubstring. Knowing the structure of an address beforehand is therefore useful.
Test yourself
In the address https://www.example.edu/en/announcements, which part is the domain name?
www.example.edu. https is the protocol, and /en/announcements is the path.
In the address ann.lee@students.example.edu, what are the parts before and after the @ sign?
The part before is the user name (ann.lee), and the part after is the domain name (students.example.edu).
Installing and updating software
Before the programming chapters, a JDK (Java Development Kit) and an editor must be installed. To do this, the installer is downloaded from the official source, run, and the installed version is checked.
Chapters Chapter 2.1 · Software and Operating Systems Chapter 2.2 · The Windows Operating System Chapter 5 · Getting Started with Java
- Programs should be downloaded only from the maker's own site or an official store. Stay away from “free download” sites and cracked software.
- You need to know your system: the Settings → System → About screen shows the Windows version and whether the system is 64-bit.
- After installation, verify it: open the program (or a terminal) and look at the version it reports.
- Keep the operating system and the browser up to date. Remove programs through Settings → Apps, not by deleting their folders.
Test yourself
In Windows 11, where can you see whether the system is 64-bit?
On the Settings → System → About screen, in the “System type” row.
Why is it wrong to uninstall a program by deleting its folder inside C:\Program Files?
Its shortcuts, registry entries and settings are left behind, and the system still thinks the program is installed. The right way is to use Settings → Apps or the program's own uninstaller.
Arithmetic and numbers
Operator precedence, integers and decimal numbers, quotient and remainder, percentages and averages, powers and number bases, unit prefixes and logarithms.
Arithmetic and operator precedence
Excel formulas and Java expressions follow the rules learned at school: parentheses first, then multiplication and division, and addition and subtraction last. Operations of the same precedence are performed from left to right.
Chapters Chapter 3.2 · Microsoft Excel Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals
- Order of precedence: ( ) → exponentiation (
^in Excel; Java has no power operator, soMath.powis used) →* / %→+ -. - Operations at the same level are done from left to right:
12 / 3 * 2is (12 / 3) · 2 = 8, not 12 / 6. - When in doubt, add parentheses. Parentheses cost nothing and show your intent clearly.
- Unary minus and comparisons also appear in the precedence table. Chapter 3 (Excel) and Chapter 6 (Java) give both tables.
Example (Chapter 6). In Java, the expression "Result: " + 2 + 3 is evaluated from left to right and gives the text Result: 23. "Result: " + (2 + 3), on the other hand, gives Result: 5.
Test yourself
What are 2 + 3 * 4 and (2 + 3) * 4?
14 and 20.
Calculated from left to right, what is 10 - 4 - 3?
(10 − 4) − 3 = 3. The result is not 10 − 1 = 9.
Integers and decimal numbers
A computer stores integers and decimal numbers differently. It matters which type of number a calculation is done with: the result of 5 / 2 is 2 in Java but 2.5 on a calculator.
Chapters Chapter 1.3 · Computers Chapter 3.2 · Microsoft Excel Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals
- Integers (…, −2, −1, 0, 1, 2, …) are stored exactly. Java's
inttype holds values up to 2,147,483,647. - Decimal numbers are stored approximately (Chapter 1, “Why Isn't 0.1 Exact?”). In Java,
0.1 + 0.2prints0.30000000000000004. - Rounding and truncation are different: 3.99 rounded to the nearest integer is 4, but truncated (dropping the fractional part) it is 3. In Java,
(int) 3.99truncates and gives 3. - Notation: many countries write 3,14 with a comma, and spreadsheets set to those regional settings do too. In Java source code, a period is always used:
3.14.
Test yourself
What are 5 / 2 and 5.0 / 2 in Java?
2 and 2.5. In the first, both operands are integers, so only the whole part of the result is kept.
What do 7.5 and 7.49 become when rounded to the nearest integer and when truncated?
Rounded: 8 and 7. Truncated: 7 and 7.
Division with quotient and remainder
Division with a remainder, learned in primary school (17 ÷ 5 = 3, remainder 2), is the most-used mathematics in the course: / gives the quotient and % gives the remainder.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.1 · Algorithms Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals Chapter 8 · Loops Chapter 9 · Methods Chapter 12 · Recursion
- For positive integers, a = b · q + r and 0 ≤ r < b. In Java you write
q = a / bandr = a % b. - Odd or even: if
n % 2 == 0, n is even (Chapter 7 “Odd or Even?”, Chapter 9isEven()). - Digits:
n % 10gives the last digit, andn / 10drops it. Repeating these two steps counts or adds up the digits (Chapter 8, Chapter 9, Chapter 12). - Unit conversion: from seconds to hours, minutes and seconds (Chapter 6 “Seconds to Hours”).
- Divisibility: if
a % b == 0, b divides a exactly (prime numbers, greatest common divisor, leap years). - In Java the sign of the remainder is the same as the sign of the dividend:
-7 % 3is −1 (Chapter 6).
Test yourself
With integers, what are 17 / 5 and 17 % 5?
3 and 2, because 17 = 5 · 3 + 2.
Using / and %, how many hours, minutes and seconds is 3725 seconds?
3725 / 3600 = 1 hour, remainder 125. 125 / 60 = 2 minutes, 125 % 60 = 5 seconds. The result is 1 hour 2 minutes 5 seconds.
Percentages and averages
Grade sheets in Excel, methods that compute an average temperature, and array statistics rest on percentages, plain averages and weighted averages.
Chapters Chapter 3.2 · Microsoft Excel Chapter 6 · Variables, Data Types and Operators Chapter 9 · Methods Chapter 10 · Arrays
- p% of x is x · p / 100. A p% increase multiplies the value by (1 + p/100), and a p% decrease by (1 − p/100).
- Average (arithmetic mean) = total ÷ count. In Excel you write
=AVERAGE(B2:B10). In Java a loop first adds up, then divides. Usedoubleso that the fractional part is not lost. - Weighted average: for a course grade where the midterm counts 40% and the final 60%, the grade is 0.4 · midterm + 0.6 · final.
- Chapter 10 finds the elements above the average, and the smallest and largest values, in an array.
Test yourself
Midterm 70 (weight 40%), final 85 (weight 60%). What is the course grade?
0.4 · 70 + 0.6 · 85 = 28 + 51 = 79.
If a $250 price gets a 20% discount, what is the new price? What is the average of 4, 8 and 9?
250 · 0.8 = $200. (4 + 8 + 9) / 3 = 21 / 3 = 7.
Powers and place value
The value of a digit depends on the place it occupies (ones, tens, hundreds = 10⁰, 10¹, 10²). The same idea, with powers of 2, explains binary numbers. Computing powers is also a classic example for loops and recursion.
Chapters Chapter 1.1 · Basic Concepts Chapter 1.3 · Computers Chapter 3.2 · Microsoft Excel Chapter 8 · Loops Chapter 12 · Recursion
- aⁿ is a multiplied by itself n times. a⁰ = 1, a¹ = a and aᵐ · aⁿ = aᵐ⁺ⁿ.
- Place value: 307 = 3 · 10² + 0 · 10¹ + 7 · 10⁰.
- Powers of 2 worth knowing: 2⁰ = 1, 2¹ = 2, 2⁴ = 16, 2⁸ = 256, 2¹⁰ = 1024.
- In Excel you write
=2^10. In Java, ^ is not exponentiation but the XOR operation. For powers useMath.pow(2, 10)or a loop (Chapter 8 “Exponentiation”, Chapter 12 “Fast Power”).
Test yourself
What are 2¹⁰ and 5⁰?
1024 and 1.
Starting with x = 1, if x is doubled 4 times, what is x?
2⁴ = 16.
Number bases, bits and bytes
All data is stored as bits. You need to convert small numbers between decimal and binary, work out storage sizes in bytes, and see why a fixed number of bits limits the range of values.
Chapters Chapter 1.1 · Basic Concepts Chapter 1.2 · Computer Hardware Chapter 1.3 · Computers Chapter 6 · Variables, Data Types and Operators Chapter 8 · Loops
- In binary the place values go 1, 2, 4, 8, 16, …: 1011₂ = 8 + 0 + 2 + 1 = 11.
- To convert from decimal to binary, divide the number by 2 repeatedly and read the remainders from bottom to top (Chapter 1, Chapter 8 “Decimal to Binary”).
- n bits give 2ⁿ different values: 8 bits = 1 byte = 256 values (0–255 unsigned).
- Units: in the decimal (SI) notation that disk makers use, 1 KB = 1000 B, while in binary (IEC) notation 1 KiB = 1024 B. The table in Chapter 1 writes 1 KB = 1,024 B, and the units based on 1024 are called KiB, MiB and GiB.
- Network speeds are given in bits per second: 100 Mbit/s is 12.5 MB/s.
- A fixed-width value overflows: adding 1 to the 8-bit value 255 needs a ninth bit. Java's
intwraps around after 2,147,483,647 (Chapter 6 “Overflow”).
Test yourself
What is 1011₂ in decimal, and how is 13 written in binary?
1011₂ = 11. 13 = 8 + 4 + 1 = 1101₂.
About how many GiB does Windows show for a disk sold as 500 GB (500 · 10⁹ bytes)?
500 · 10⁹ / 2³⁰ ≈ 465.7 GiB.
Units of measurement and prefixes
In hardware, networking and operating systems, very large and very small numbers are written with prefixed units: 3 GHz is 3 billion cycles per second, and 5 ms is five thousandths of a second. You need to know which power of 10 each prefix stands for, and to be able to go from a frequency to a duration.
Chapters Chapter 1.2 · Computer Hardware Chapter 1.3 · Computers Chapter 1.4 · The Internet Chapter 2.1 · Software and Operating Systems
- Prefixes that enlarge: kilo (k) = 10³, mega (M) = 10⁶, giga (G) = 10⁹, tera (T) = 10¹². Prefixes that shrink: milli (m) = 10⁻³, micro (µ) = 10⁻⁶, nano (n) = 10⁻⁹.
- A negative exponent means division: 10⁻³ = 1/1000. 1 s = 1000 ms = 1,000,000 µs = 10⁹ ns.
- Hertz (Hz) is the number of repetitions per second. The duration of one cycle is the inverse of the frequency: on a 3 GHz processor, 1 ÷ (3 × 10⁹) s ≈ 0.33 ns.
- Keep the units the same in calculations: a 100 Mbit/s line carries 12.5 MB per second, so a 500 MB file downloads in 500 ÷ 12.5 = 40 s at best. If bits and bytes are confused, the result is off by a factor of 8.
- Bandwidth is the amount of bits carried per second; latency (ping) is the time for the first bit to reach the other end, measured in ms. One can be high without the other being good.
Test yourself
How long does one clock cycle take on a 2 GHz processor, in ns?
1 ÷ (2 × 10⁹) s = 0.5 × 10⁻⁹ s = 0.5 ns.
How many milliseconds is 0.25 s? How many seconds is 20 ms?
250 ms and 0.02 s.
Logarithm (log₂)
log₂ n tells you which power of 2 equals n: since 2¹⁰ = 1024, log₂ 1024 = 10. The same number also gives how many times n can be halved until it reaches 1. The number of bits needed to encode a set of values, and the number of rounds of a binary search, are found this way.
Chapters Chapter 1.1 · Basic Concepts Chapter 4.1 · Algorithms Chapter 4.1 · Algorithms Chapter 10 · Arrays Chapter 12 · Recursion
- It is the inverse of the exponent: if 2ᵏ = n then log₂ n = k. log₂ 1 = 0, log₂ 8 = 3, log₂ 1024 = 10.
- For numbers that are not exact powers, the result falls between two integers: since 2⁵ = 32 < 58 < 64 = 2⁶, log₂ 58 ≈ 5.86. The number of bits needed to encode N different values is this value rounded up: 6 bits for 58 values.
- In a sorted array of n elements, binary search halves the range in every round and finishes in at most ⌊log₂ n⌋ + 1 rounds. For a million elements, that bound is 20 rounds.
- O(log n) and O(n log n) in big-O notation describe this slow growth: when n grows a thousandfold, log₂ n grows by only about 10, because 2¹⁰ ≈ 1000.
Test yourself
What is log₂ 64? In a sorted array of 64 elements, in at most how many rounds does binary search finish?
Since 2⁶ = 64, log₂ 64 = 6. The search finishes in at most ⌊log₂ 64⌋ + 1 = 7 rounds.
At least how many bits are needed to give each of 40 students a distinct binary number?
6 bits. 5 bits give 2⁵ = 32 different values, which is not enough; 6 bits give 64 values.
Algebra, logic and functions
Letters standing in for numbers, simple formulas, inequalities, and/or/not, and the function as a rule that turns input into output.
Variables and basic algebra
In algebra, a letter holds the place of a number. In programming, a variable is a named box whose contents can change. Substituting values for the letters in an expression is exactly what the computer does.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.3 · Introduction to Programming Chapter 4.2 · Flowcharts Chapter 6 · Variables, Data Types and Operators Chapter 8 · Loops
- Substitution: for a = 3 and b = 4, a² + b² = 9 + 16 = 25.
- In Java,
=is not equality but assignment:x = x + 1means “compute x + 1 and write the result back into x”. It is not a false equation. Equality is tested with==. - Swapping two values needs a temporary variable:
t = a; a = b; b = t;(Chapter 6 “Swapping”, Chapter 9 “swap Pitfall”). - Counters and accumulators (Chapter 4 flowcharts, Chapter 8):
count = count + 1,total = total + x.
Test yourself
With x = 5, if x = x + 1; runs first and then x = x * 2;, what is x?
(5 + 1) · 2 = 12.
With a = 3 and b = 5, after t = a; a = b; b = t; runs, what are a and b?
a = 5 and b = 3; the values have traded places.
Everyday formulas
Many first programs turn a school formula into code: the area and circumference of a circle, converting Celsius to Fahrenheit, the roots of a quadratic equation, absolute value.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.3 · Introduction to Programming Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals Chapter 9 · Methods
- Circle: area πr², circumference 2πr (Chapter 6 “Area and Circumference of a Circle”,
Math.PI). - Temperature: F = C · 9/5 + 32 and C = (F − 32) · 5/9 (Chapter 6, Chapter 9 “Temperature Methods”).
- The quadratic equation ax² + bx + c = 0: the discriminant is Δ = b² − 4ac. If Δ > 0 there are two real roots, if Δ = 0 there is one, and if Δ < 0 there are no real roots. The roots are found with (−b ± √Δ) / 2a (Chapter 7).
- The absolute value |x| equals x if x ≥ 0, otherwise −x (Chapter 7 “Absolute Value”). The quantity under a square root cannot be negative (Chapter 1 “Square Root, Step by Step”).
Test yourself
How many degrees Fahrenheit is 25 °C?
25 · 9/5 + 32 = 45 + 32 = 77 °F.
For x² − 5x + 6 = 0, what are Δ and the roots?
Δ = 25 − 24 = 1. The roots are (5 ± 1)/2, that is, 3 and 2.
Inequalities and ranges
Conditions such as “10 < x < 20”, “grade ≥ 50” or “index from 0 to n − 1” are inequalities. Whether an endpoint is included is the source of many off-by-one errors.
Chapters Chapter 3.2 · Microsoft Excel Chapter 4.1 · Algorithms Chapter 4.2 · Flowcharts Chapter 7 · Conditionals Chapter 8 · Loops Chapter 10 · Arrays
- A strict inequality (<, >) leaves the endpoint out, while a non-strict one (≤, ≥) includes it. In Java, ≤ is written
<=and ≠ is written!=. - A two-sided inequality is two conditions joined by “and”: 10 < x < 20 becomes
x > 10 && x < 20. In Java you cannot write10 < x < 20. - Counting the integers in a range: from a to b (both included) there are b − a + 1 numbers.
- Loops:
for (int i = 0; i < 5; i++)runs 5 times (i = 0..4), while withi <= 5it runs 6 times (Chapter 8 “Off-by-One Errors”). An array of length n has indices 0 … n − 1 (Chapter 10).
Test yourself
How many integers satisfy 10 < x < 20? How many satisfy 10 ≤ x ≤ 20?
9 (11 … 19) and 11 (10 … 20).
How many times does the loop for (int i = 0; i < 5; i++) run? How many times if it is i <= 5?
5 times and 6 times.
Logic: and, or, not
Every decision in a program is a statement that is true or false, and it is often combined with and, or, not. This logic appears in logic gates (Chapter 1), in Excel's AND/OR/NOT functions (Chapter 3) and in Java's &&, || and ! operators.
Chapters Chapter 1.1 · Basic Concepts Chapter 1.3 · Computers Chapter 3.2 · Microsoft Excel Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals Chapter 8 · Loops
- A and B is true only if both are true. A or B is true if at least one is true. Not A reverses the value of A.
- A truth table lists all the cases: with two inputs there are 4 rows.
- De Morgan: not (A and B) = (not A) or (not B); not (A or B) = (not A) and (not B) (Chapter 7).
- The “or” of logic is inclusive: true or true is true. The exclusive or (XOR), meaning “one or the other but not both”, is a separate operation.
- The leap-year rule (Chapter 7): divisible by 4 and (not divisible by 100 or divisible by 400).
Test yourself
With x = 15, what are the values of x > 10 && x < 20 and !(x > 10)?
true and false.
According to the leap-year rule, are 1900 and 2000 leap years?
1900 is divisible by 100 but not by 400, so it is not a leap year. 2000 is divisible by 400, so it is a leap year.
Functions as input → output
A function in mathematics takes inputs and gives a single output: f(x) = 2x + 3. Excel functions (=SUM(…)) and Java methods work the same way: arguments go in, a value comes back.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 3.2 · Microsoft Excel Chapter 4.3 · Introduction to Programming Chapter 9 · Methods Chapter 12 · Recursion
- f(x) = 2x + 3 means “given x, return 2x + 3”, and f(4) = 11. The name of the input does not matter: f(t) = 2t + 3 is the same function.
- Functions with several inputs: max(a, b), gcd(a, b), and in Excel
=MAX(B2:B10). - Composition: when computing f(f(1)), the inner call is evaluated first. Chapter 9 follows nested calls step by step on the call stack.
- A Java method has a parameter list (the inputs), a return type (the type of the output) and a body.
voidmethods do not return a value.
Test yourself
If f(x) = 2x + 3, what are f(4) and f(f(1))?
f(4) = 11. Since f(1) = 5, f(f(1)) = f(5) = 13.
In Excel, cells B2:B4 contain 3, 9 and 4. What do =MAX(B2:B4) and =SUM(B2:B4) return?
9 (the largest value) and 16 (the sum).
Sequences, divisibility and recursion
Sums such as 1 + 2 + … + n, prime numbers and the greatest common divisor, factorial and Fibonacci, counting layouts of rows and columns and positions. These are the standard examples of the presentations on loops, methods, arrays and recursion.
Number sequences and sums
Adding up a sequence of numbers term by term is the first job of every loop (Chapter 4 flowchart “Example: Sum from 1 to n”, Chapter 8, Chapter 10, Chapter 12). Knowing the closed-form formulas lets you check the answer a program gives.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.2 · Flowcharts Chapter 8 · Loops Chapter 10 · Arrays Chapter 12 · Recursion
- 1 + 2 + … + n = n(n + 1)/2 (Gauss). For example, 1 + 2 + … + 100 = 5050.
- Arithmetic sequence: starts at a and increases by d (2, 4, 6, …). Geometric sequence: starts at a and is multiplied by r at each step (1, 2, 4, 8, …).
- A running sum starts at 0 (the identity element of addition), and a running product starts at 1.
- The digit sum of 4827 is 4 + 8 + 2 + 7 = 21 (Chapter 8 “Sum of Digits”, with the recursive version in Chapter 12).
Test yourself
What are the sums 1 + 2 + … + 100 and 2 + 4 + … + 20?
100 · 101 / 2 = 5050. 2 · (1 + … + 10) = 2 · 55 = 110.
With s = 0, if s = s + i · i is done for i = 1, 2, 3, 4, what is s at the end?
1 + 4 + 9 + 16 = 30.
Divisibility, primes and GCD
Primality testing, perfect numbers, GCD/LCM and the sieve of Eratosthenes are standard examples in the presentations on algorithms, loops, methods, arrays and recursion.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.1 · Algorithms Chapter 8 · Loops Chapter 9 · Methods Chapter 10 · Arrays Chapter 12 · Recursion
- If n % d == 0, d divides n. A prime number has exactly two divisors: 1 and itself. 1 is not prime, and 2 is the only even prime.
- To find out whether n is prime, it is enough to try the divisors up to √n (Chapter 4, Chapter 8, Chapter 9
isPrime()). - Euclid's algorithm: apply gcd(a, b) = gcd(b, a % b) until the remainder is 0 (Chapter 1, Chapter 9
gcd(), Chapter 12). Then lcm(a, b) = a · b / gcd(a, b). - A perfect number equals the sum of its divisors other than itself: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14 (Chapter 8).
Test yourself
Is 91 prime?
No: 91 = 7 · 13.
Using Euclid's algorithm, what are gcd(48, 18) and then lcm(48, 18)?
48 % 18 = 12, 18 % 12 = 6, 12 % 6 = 0 → gcd = 6. lcm = 48 · 18 / 6 = 144.
Factorial, Fibonacci and recursive definitions
Some sequences are defined by referring to earlier terms: n! = n · (n − 1)! with 0! = 1, and each Fibonacci number is the sum of the two before it. The recursive methods in Chapter 12 are written in exactly this way.
Chapters Chapter 4.1 · Algorithms Chapter 8 · Loops Chapter 12 · Recursion
- Since n! = 1 · 2 · … · n, 5! = 120. The recursive definition is n! = n · (n − 1)!, and the base case is 0! = 1 (1! = 1 also holds).
- Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, … Each term is the sum of the two terms before it.
- Every recursive definition must have a base case that stops it. Without a base case the computation never ends (Chapter 12
StackOverflowError). - These numbers grow quickly: 13! = 6,227,020,800 does not fit in an
int(the largest value is 2,147,483,647). Chapter 12 therefore useslongand discusses overflow.
Test yourself
Given that 5! = 120, what is 6! by the rule n! = n · (n − 1)!?
6! = 6 · 120 = 720.
What Fibonacci number comes after 5, 8, 13?
8 + 13 = 21.
Counting, row-column layouts and positions
Nested loops, star patterns, multiplication tables, two-dimensional arrays and string indices all rest on the same two skills: counting the cells in rows and columns, and numbering positions from 0.
Chapters Chapter 3.2 · Microsoft Excel Chapter 4.2 · Flowcharts Chapter 8 · Loops Chapter 10 · Arrays Chapter 11 · Strings
- A table with r rows and c columns has r · c cells. A nested loop whose outer loop takes r steps and inner loop takes c steps runs r · c times.
- Triangle patterns: a triangle whose rows have 1, 2, …, n stars has 1 + 2 + … + n stars in total (Chapter 8 “Growing Triangle”).
- Java counts positions from 0: an array or string of length n has indices 0 … n − 1, and the last one is n − 1 (Chapter 10, Chapter 11).
- Excel cell references (B3 = column B, row 3) and a multiplication table built with mixed references (Chapter 3) rest on the same row-column thinking.
Test yourself
The rows of a star triangle have 1, 2, 3, 4, 5 stars. How many stars are there in total?
1 + 2 + 3 + 4 + 5 = 15.
The word “PROGRAM” has 7 letters. If positions are numbered from 0, what is the last position, and which letter is at position 2?
The last position is 6. At position 2 is O (P = 0, R = 1, O = 2).
Reading and problem-solving skills
Following instructions literally, tracking values step by step, testing with carefully chosen inputs, and reading technical English.
Following step-by-step instructions
An algorithm is a recipe that must be carried out literally and in order, “without guessing what was meant”. Reading flowcharts and pseudocode is the bridge from everyday instructions to Java.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.3 · Introduction to Programming Chapter 4.1 · Algorithms Chapter 4.2 · Flowcharts
- Each step is carried out in order and exactly as stated. A loop says “go back and repeat”, and a decision says “take only one of the branches”.
- Flowchart symbols (Chapter 4): oval = start/end, parallelogram = input/output, rectangle = process, diamond = decision, arrows = order.
- There are three building blocks: sequence, selection (if) and repetition (loop) (Chapter 1, Chapter 7).
- A good instruction is clear and ends in a finite number of steps. Chapter 4 lists the properties of a good algorithm.
Test yourself
Steps: (1) x ← 1. (2) Repeat 4 times: x ← x · 2. (3) Print x. What is printed on the screen?
16.
Which shape represents a decision in a flowchart, and how many arrows leave it?
A diamond. Two arrows leave it (yes/no, true/false).
Tracing with a table of values
Every presentation has “Step by Step” slides that show the values of the variables after each step. You should be able to keep such a table on paper too: a column for each variable and a row for each step.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.1 · Algorithms Chapter 4.2 · Flowcharts Chapter 8 · Loops Chapter 9 · Methods Chapter 12 · Recursion
- The variable names go in the column headings. Each time a value changes, a new row is added, and no step is skipped.
- The loop condition is checked before every round. The final check that ends the loop counts too.
- The table is compared with the program's output. The first row where the two differ shows where the bug is.
- Chapter 9 and Chapter 12 carry tracing over to the call stack: each method call gets its own row (frame).
Test yourself
a = 10, b = 3, k = 0. As long as a ≥ b, do a ← a − b and k ← k + 1. What are a and k at the end?
a = 1, k = 3 (rows: 7/1, 4/2, 1/3). This is the result 10 / 3 = 3 and 10 % 3 = 1 obtained by repeated subtraction.
In the previous question, how many times is the condition a ≥ b checked?
4 times: it is true three times and false once (when a = 1).
Breaking a problem into parts and testing
Before writing code, the problem is split into inputs, steps and outputs. After the code is written, it is tested both with ordinary inputs and with the boundary values at which programs most often go wrong.
Chapters Chapter 1.5 · Computation and Computational Thinking Chapter 4.3 · Introduction to Programming Chapter 4.1 · Algorithms Chapter 4.2 · Flowcharts Chapter 8 · Loops Chapter 9 · Methods
- The four elements of computational thinking (Chapter 1): decomposition, pattern recognition, abstraction and algorithm design.
- Before code is written, the input and output are fixed with an example (Chapter 1 “Algorithm Design and Testing”, Chapter 9 “Contract First”).
- Test cases: an ordinary value, the boundary values on either side of every condition, and special values such as 0, 1, negative numbers and empty input.
- Change only one thing at a time and run the program again. Inputs that exposed a bug are kept as permanent tests.
Test yourself
The rule is “passes if the grade is ≥ 50”. Which two inputs test the boundary?
49 (fails) and 50 (passes).
Which four years could test all branches of the leap-year rule together?
For example 2023 (not divisible by 4), 2024 (divisible by 4, not by 100), 1900 (divisible by 100, not by 400), 2000 (divisible by 400).
Technical English and error messages
Java's keywords, method names and all the messages from the compiler and the runtime environment are in English. Reading these messages carefully (what, where, which line) is the fastest way to fix a program.
Chapters Chapter 5 · Getting Started with Java Chapter 6 · Variables, Data Types and Operators Chapter 7 · Conditionals Chapter 8 · Loops Chapter 9 · Methods Chapter 10 · Arrays Chapter 11 · Strings Chapter 12 · Recursion
- Keywords are ordinary English words with a precise meaning:
if,else,while(“as long as”),for,return(“give back”),break,new,void,static. - javac messages give the file, the line, a short explanation and a caret (^) marking the place of the error:
Hello.java:5: error: ';' expected. - Common messages:
cannot find symbol(a misspelled or undeclared name),incompatible types,missing return statement. - Runtime messages are exceptions:
ArithmeticException: / by zero,ArrayIndexOutOfBoundsException,StackOverflowError. - Fix the first error first, because later messages are often a consequence of it (Chapter 5 “Common Compile Errors”).
Test yourself
javac gives the message error: ';' expected. What should you look at?
At the end of the statement shown (often the line before the caret). A semicolon is missing there.
What does the message error: cannot find symbol … symbol: variable totl usually mean?
The name totl is not defined. It is most likely a typo (for example for total), or the variable is used outside its scope.
Tools and setup
A JDK and an editor or IDE, a few terminal commands, and an office suite.
A JDK and an editor or IDE
From Chapter 5 on, Java programs are written, compiled and run on your own computer. For this, install a current JDK and either a plain editor or an IDE (for example Eclipse, IntelliJ IDEA or VS Code with a Java extension).
Chapters Chapter 4.3 · Introduction to Programming Chapter 5 · Getting Started with Java
- Install the JDK, not just the JRE (Java Runtime Environment). The messages in Chapter 5 were produced with JDK 21. Check the installation with
javac -versionandjava -version. - Source code is a plain-text file with the extension
.java. Word documents cannot be compiled. - The workflow is as follows: write
Hello.java→ the commandjavac Hello.javaproduces the fileHello.class(bytecode) → the commandjava Helloruns it on the Java Virtual Machine (JVM). - An IDE does these steps with one button and underlines errors as you type. You should still do these steps by hand at least once.
- Save files as UTF-8 so that non-ASCII characters in strings are not garbled (
javac -encoding UTF-8, Chapter 5).
Test yourself
With which command is Hello.java compiled, with which is the program run, and which file does compilation create?
It is compiled with javac Hello.java and run with java Hello. Compilation creates the file Hello.class.
The file is named Homework1.java but contains public class Hello. What happens?
javac rejects the file: a public class must be defined in a file bearing its own name (Hello.java).
Using the terminal (at the most basic level)
A few commands are enough: seeing where you are, listing files, changing folders, and running javac/java. Chapter 2 introduces these commands for Windows (cmd) and for Linux/macOS.
Chapters Chapter 2.1 · Software and Operating Systems Chapter 2.2 · The Windows Operating System Chapter 5 · Getting Started with Java
- Opening a terminal: Start → “cmd” (Command Prompt) or Windows Terminal. If you type
cmdin File Explorer's address bar, the terminal opens in that folder. - Windows cmd:
cd(show or change the folder),dir(list),mkdir(new folder). Linux/macOS:pwd,ls,cd,mkdir. cd ..goes up to the parent folder. Paths that contain spaces are written in quotation marks:cd "C:\Course Notes".- Commands run in the current folder: if you are in the wrong folder,
javac Hello.javagives a “file not found” error. delandrmdelete files permanently (they do not send them to the Recycle Bin). Check the command before pressing Enter.
Test yourself
If you are in the folder C:\Course\Week1 and type cd .., which folder do you move to?
To the folder C:\Course.
What is the Windows command that lists the files in the current folder, and what is the Linux/macOS equivalent?
dir and ls.
Office software
Chapter 3 is taught with the English-language interface of Microsoft Word, Excel and PowerPoint. The university's Microsoft 365 account or a free alternative such as LibreOffice is enough to follow the course.
Chapters Chapter 1.1 · Basic Concepts Chapter 3.1 · Microsoft Word Chapter 3.2 · Microsoft Excel Chapter 3.3 · Microsoft PowerPoint
- You should know how to open and save files (choosing the folder and format with “Save As”), print, and export as PDF.
- Formats:
.docx(Word),.xlsx(Excel),.pptx(PowerPoint). Free suites can also open and save these files. - Excel function names and argument separators depend on the language and regional settings of the installation. English Excel writes
=IF(B2>=50,"Pass","Fail")with commas; some regional settings use semicolons instead. - Basic Excel vocabulary: cell (B3), range (B2:B10), formula (starts with =), relative and absolute reference (
$A$1).
Test yourself
What is the Excel formula that adds the cells from A1 to A10?
=SUM(A1:A10).
Which extensions do Word, Excel and PowerPoint use by default?
.docx, .xlsx and .pptx.
No prerequisite matches the search or filters.
Presentation map
The topics each presentation rests on. Accurate typing matters in all the programming chapters.
© Sercan Külcü · Computer Fundamentals and Introduction to Programming