Lecture3 2024
Lecture3 2024
SCIENCE
CSI141
PROGRAMMING
h t t p : / / ho r st m a n n . c o m / b j l o / i n d e x . ht m l PRINCIPLES
Programming Principles T ALLMAN NKGAU
L ECTURE 3
CHAPTER 1.2 – 1.6
‣ Programming process
‣ Programming environment
‣ First Java program
http://horstmann.com/bjlo/index.html
L EARNING OUTCOMES
At the end of the lecture, you should be able
to:
logic, run-time)
program
‣ Programming process
‣ Programming environment
‣ First Java program
h t t p : / / ho r st m a n n . c o m / b j l o / i n d e x . ht m l
REVIEW - POP QUIZ
❑ The algorithm
MYSTERY(n)
Input: An integer n > 0
Output: You find out!
b ← 0
while n > 0 do //read as “while n is greater than 0 do”
d ← n % 10 // remainder when dividing by 10
b ← b + d
n ← n / 10 // integer division
return b
Called block of
statements
Page 5
Programming process
❑ Systematic steps involved in solving a computational programming
problem. Start
Define
Problem
Program Bugs
Analysis/
Maintenance
Algorithm Design
Bugs
Coding
Page 6
Programming process
❑ Defining the problem
・ State the problem concisely
・ A lot of software systems fail due to vague problem definition.
・ Usually specified by Management and/or Systems Analyst.
・ In this course, the lecturers will specify the problem.
Page 7
…Programming process
❑ Coding
・ Implement your algorithm using an appropriate language
・ Fix all compile-time errors (like syntax errors, class not found, etc.)
・ Properly document your source code (so others have no difficulty
understanding your code)
❑ Usage & Maintenance
・ Use the program / Execute the program
・ Fix all run-time errors (like logical errors, etc.)
・ If requirements change, adapt the program
Page 8
Java programming process
Page 9
Java Compilation
HelloWorld.class
javac java
HelloWorld.java
Java Compilation
javac HelloWorld.java
Compiler 1
(IBM)
Editor
Compiler 2
Java Source Code File (Sun) Java Bytecode
(HelloWorld.java) (HelloWorld.class)
Compiler 3
(Apple)
Machine Instructions
Output Data
(Execution)
Programming errors
❑ Syntax Error
・ It is a grammatical mistake in a program – breaking grammar rules.
・ The compiler is used to check for syntax errors.
❑ Logic Error
・ It is an error introduced by using faulty logic in a program.
・ Program produces incorrect results.
❑ Run-time Error
・ An error issued by the computer when a program is executed.
・ Program usually crashes with some sort of an error message.
Page 12
‣ Anatomy of a computer
‣ Data representation
‣ Programming process
‣ Programming environment
‣ First Java program
h t t p : / / ho r st m a n n . c o m / b j l o / i n d e x . ht m l
Programming Environment - JDK
Page 14
Programming Environment - vscode
❑ Code Editor
・ This is software that allows us to type in our source code (our Java
programs)
・ Source code is plain text (so really any text editor will do)
・ For this course we will be using Visual Studio Code
– https://code.visualstudio.com/
– Its totally free!
– Can be used both on Windows and Linux operating systems
Page 15
Visual Studio Code (vscode) - Code
Editor
Page 16
Programming Environment
Page 17
CMDER – Terminal (CLI)
Page 18
Programming Environment
Page 19
CLI crash course
❑ We will create the following directory/folder structure
• Z: is the drive letter
• CSI141-2024 is a folder
files
Directory = Folder
directories
Page 20
1. Launch CMDER
Represents
Current directory
Represents the
parent directory
This
means
directory
Page 22
3. Create CSI141-2024 directory
Creating directory.
Notice no visual
feedback!
Listing the
files/directory
shows that our
directory was
created
Page 23
4. Change into the directory CSI141-2024
Page 24
5. List the files/directories inside CSI141-2024
• We only have
the . and ..
directories.
• In fact, every
directory has
them!
Page 25
6. Create lab1 directory and its files
Create file
MyFirstProgram.java
List the files in current
directory – lab1
Page 26
‣ Anatomy of a computer
‣ Data representation
‣ Programming process
‣ Programming environment
‣ First Java program
h t t p : / / ho r st m a n n . c o m / b j l o / i n d e x . ht m l
Our first Java program
Java class name
λ
Review exercise - CLI
Create the following folder structure.
import java.net.URI;
Import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
}
Summary
Page 32