0% found this document useful (0 votes)
17 views

1.2 - Computer Organisation & Programming Languages2024S1

Uploaded by

Md. Obaydullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

1.2 - Computer Organisation & Programming Languages2024S1

Uploaded by

Md. Obaydullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

XPD124 Programming Fundamentals

1.2 Computer Organisation &


Programming Languages

class and object Increasing…


method …complexity
control structure …size
statement …sophistication
What those levels mean

class and object ‘wrap up’ data and actions

method ‘wrap up’ code for reuse

control structure make decisions, repeat actions

statement do something
Hardware and Software
Programs and data

Software • a program is a series of instructions


• data is what the program instructs
the computer to manipulate
(numbers, words etc.)

Hardware Physical, tangible parts of a computer


(keyboard, screen, wires, chips)

Application Application Application

A computer requires both


Operating System hardware and software

Hardware
Software Categories

GUI • some of our programs


will have a GUI

• generic term for any


GUI Application other kind of software
• we will write applications

Operating System
• controls all machine activities
• user interface to the computer
• manages resources such as the
CPU and memory
Hardware – CPU and Main Memory

Chip that executes


program commands
Central Processing Unit

CPU interacts with


main memory
Primary storage area for
programs and data that Main
are in active use Memory
Hardware – Secondary Memory Devices

Information is moved
between main memory
and secondary memory
as needed
Central Processing Unit

Hard disk/SSD
Main
Memory Removable
storage
Secondary memory
devices provide
long-term storage
Typical Hardware Configuration

Screen

CPU

Keyboard
I/O (Input Output)
devices for
communication
with CPU Hard disk/SSD
Main
Memory Removable
storage
The Central Processing Unit
• A CPU is also called a microprocessor
• It continuously follows the fetch-decode-execute
cycle:
Retrieve an instruction from
Fetch main memory

Execute Decode
Carry out the instruction; Determine what the
access and modify data if instruction is
instructed to
Memory

9278 Main memory is divided into many


9279 memory locations (or cells)
9280
9281
9282
9283
Each cell has a unique numerical address
9284
9285
9286

Java does not provide direct access to memory addresses


Storing information

9278 Each memory cell stores a set number


9279 00101010
of bits (a multiple of 8 bits [or 1 byte])
9280
9281
9282
Large values are
9283 stored in consecutive
9284 memory locations
9285
9286

Java does not provide direct access to memory addresses


Storing information
In a program, memory locations
are given names (identifiers)

9278
9279 00101010 personAge
9280 personAge is called a variable
9281
9282
9283
9284
9285
9286

Java uses identifiers to refer to blocks of memory


Storing information
In a program, variables are given a type

9278
9279 00101010 byte personAge
9280 personAge is a variable of type ‘byte’
9281 It can represent integer values from
9282 –128 to 127
9283
9284
9285
9286

Java uses type names to interpret the value of a block of memory


Why Java (or equivalent)?

High-level languages:
Python
SQL
Java
C

assembly language
machine code
Why Java (or equivalent)?
movq $4, %rax
movq $1, %rbx
movq $string, %rcx
movq length, %rdx
int $0x80
movq %rax, %rbx
return syscall exit status
movq $1, %rax
int $0x80

Things can be easier


What is programming?

Designing a sequence of simple steps that can be


used by a computer to solve some problem

It is not instructing a machine to manipulate bits


stored in memory*

*Of course, it really is that, but that’s just how the program’s execution is
realised in a physical machine
What is a language?

Correct Syntax
a cat
• valid words and sat on under
symbols mat dog the
• valid ways of arranging
them the cat sat on the mat

Correct semantics
• what the arrangement
of symbols means
the mat sat on the cat
What is a programming language?
Syntax personCase
class void { }
• valid words and symbols public +-*/
• valid identifiers (new personAge main
‘words’)
• valid ways of arranging byte personAge = 25;
them
Semantics
• what the arrangement of 00011001
symbols means
personAge
A basic Java program

You only have choice over the pieces indicated


Everything else must appear exactly as below

public class Jabber


{

public static void main(String [ ] args)


{

System.out.println("'Twas brillig and the slithy toves");

}
}
A basic Java program
Identifiers: author-given names for types (class names) and variables
• Jabber is a name we chose (so is args)
• String, System, out, println, main chosen by Java library authors
• main is a special name: program execution always starts here

public class Jabber


{

public static void main( String[[ ] args)


main(String
{

System .ou .println ("'Twas brillig and the slithy toves");


System.out.println(“’Twas toves”);
t
}
}
Java Translation and Execution
Java
source
code

MyProgram.java Java >javac MyProgram.java


compiler

Java
bytecode
Java
virtual >java MyProgram
MyProgram.class
machine

Executable
/executing machine
code
(Simplified) Program Development

Edit program source


• Any text editor will do: Notepad,
DrJava, vim, emacs
syntax semantic
errors and
javac Compile program run-time
errors
Execute program; check
java behaviour/results
What should you do now?

Familiarise
Do Task 1PP
yourself with
Hello World
the MyLO site

You might also like