Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Topic 1 - Introduction To Computer and Programming Languages

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

Topic 1 - Introduction To Computer and Programming Languages

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

INTRODUCTION TO

Topic 1
COMPUTER AND
PROGRAMMING
LANGUAGE
1) To learn about the hardware
and software components of
computers
2) To learn about level of
programming languages
3) To learn about the roles of
compilers & interpreters in
OBJECTIVE the translation process
S 4) To understand the activity of
programming
5) To compile and run your first
Java program
6) To recognize 3 types of errors

2
WHAT IS A
COMPUTER?
 An electronic device that stores and
processes data
 Consists of hardware and software.
 Hardware
 the physical, tangible parts of a
computer.
 keyboard, monitor, disks, wires, etc.

 Software
 programs (e.g. Ms Word) and data.
 Intangible parts of the computer.

 Both hardware and software form a


tool that can be used to solve
problems.
 3
Computer System
Organization
Computer System
Organization

Hardware Software
•Central Processing Unit (CPU) •System Software
•Main Memory: Random •Application Software
Access Memory (RAM) •c
•Secondary Storage •B
•Input / Output Devices

4
HARDWAR
E
COMPONE
NTS OF A
COMPUTE
R

5
HARDWARE COMPONENTS
OF A COMPUTER
CPU

• Brain of the computer,


• Handles all instructions that we give to the
computer.
• Most expensive, the more expensive, the faster
is the computer.
• CPU components:
• Control Unit
• Program Counter
• Registers
• Arithmetic Logic Unit
• Accumulator
6
HARDWARE COMPONENTS
OF A COMPUTER

RAM
• Temporary memory.
• Volatile (information stored in it will be lost
when electric power supply is turned off).
• Directly connected to the CPU, using memory
cells unit.

7
HARDWARE COMPONENTS
OF A COMPUTER

Motherboard

adapter cards
processor chip

memory chips

memory slots
Expansion
slots for
8
adapter cards
HARDWARE COMPONENTS
OF A COMPUTER

Secondary Storage
 Provides permanent storage for information.
• Examples of secondary storage:
• Hard disks
• Floppy disks
• CD-ROMs
• USB Flash Drives

9
RAM VS. SECONDARY
STORAGE
RAM / Main Secondary Storage
Memory / Primary / Secondary
Memory Memory
• Volatile • Nonvolatile
• Fast • Slow
• Expensive • Cheap
• Low capacity • Large capacity
• Works directly with • Not connected
the processor directly to the
processor

10
HARDWARE COMPONENTS
OF A COMPUTER

Input and output


 Allow human to interact with the computer

11
CPU AND MAIN MEMORY
Chip that
executes
program
CPU
commands

E.g.
Interact to execute instructions Intel Core i-7-
4960X

Primary storage
area for Main
programs and Memory
data that are in
active use
12
SECONDARY MEMORY
DEVICES
CPU

Secondary memory
devices provide
long-term storage

Information is moved
Main between main memory
Hard Disk Memory and secondary memory
as needed

USB Flash Drive

Hard disks, Floppy disks, USB drives, Writable CDs, 13


Writable DVDs
INPUT / OUTPUT DEVICES
Monitor I/O devices facilitate
CPU user interaction

Mouse

Monitor screen
Keyboard
Joystick Hard Disk
Bar code scanner
Main
Touch screen
Memory
USB Flash Drive

14
THINK
Imagine that you
are using a computer
to write a letter.
 Where is the Microsoft
Word program that you
are running located?

 Where are the


characters you have
typed placed?

15
SOFTWARE
 In contrast to hardware, software is an
abstract, intangible entity.
 Software can be categorized as system or
application software (refer next slide).
 It consists of program and data to be used to
perform certain tasks.
 A program is a sequence of simple steps and
operations, stated in a precise language that
the hardware can interpret.
 The process of programming involve
algorithm design & coding. 16
 System Software
 System programs keep all the
hardware and software running
together smoothly.
 The most important system
software is the operating

SOFTWA 
system (OS).
Controls all machine activities.

RE
 Provides the user interface to
the computer.
 Manages resources such as the
CATEGOR 
CPU, memory & I/O.
E.g: Windows 10, Unix, Linux,
IES Mac OS.
 Application Software
 Generic term for any other kind
of software
 E.g: Ms Word processor, Excel
Spreadsheets, Web browsers,
games

17
 Computers store all information
digitally:
 numbers
 text
DIGITAL 

graphics and images
video
INFORMA 

audio
program instructions
TION  In some way, all information is
digitized - broken down into
pieces and represented as
numbers

18
REPRESENTING TEXT
DIGITALLY
 For example, every character is stored as a
number, including spaces, digits, and
punctuation.
 Corresponding upper and lower case letters are
considered as different characters.

Hi, Heather.

72 105 44 32 72 101 97 116 104 101 114 46


19
American Standard Code for
Computer InterChange (ASCII)
The ASCII data set  128 characters (0 until 127)
Character A in ASCII  01000001

20
p. 4.15 Fig. 4-16 Next
 Once information is
digitized, it is represented
and stored in memory
using the binary number
BINARY system.

NUMBER  A single binary digit (0 or


1) is called a bit.
S  A byte consists of 8 bits.
 Each byte in main memory
resides at a numbered
location called its address.

21
MAIN MEMORY

Addresses 9278
9279 Main memory is
9280 divided into many
9281 memory locations
9282 (or cells)
9283
9284 Each memory cell
9285 has a numeric
9286
address, which
uniquely identifies
it

22
STORING INFORMATION
Each memory cell
stores a set number
of bits (usually 8
bits, or one byte)
9278 01001010 Represents
9279 ‘J’
Represents
01100001
9280 ‘a’
01110110 Represents
9281
9282 01100001 ‘v’
Represents
9283 ‘a’
9284
9285
9286 Large values are
stored in consecutive
memory locations

23
MAIN MEMORY

24
STORAGE CAPACITY
 Every memory device has a storage capacity,
indicating the number of bytes it can hold.
 Capacities are expressed in various units:

Unit Symbol Number of Bytes

kilobyte KB 210 = 1024


megabyte
MB 220 (over 1 million)
gigabyte
terabyte GB 230 (over 1 billion)

TB 240 (over 1 trillion)


25
WHAT IS
PROGRAMMING?
 Computer
programming
 the art and science of
designing and writing
computer programs.

 Computer program

 a sequence of instructions
written in a programming
language to achieve a
task/to solve a problem.
26
 Levels of programming
language levels:
 machine language
(computer directly
understands)
 assembly language
LANGUA (symbolic form, need minor
GE translation)
 high-level language (entire
LEVELS language need to be
translated )

 Each type of CPU has its


own specific machine
language
27
· Machine language
PROGRAM 101101100110 011011010
MING
LANGUAG
· Assembly language
ADDF3 R1,R2,R3
ES
· High-level language
sum = 3+4;

28
 Each type of CPU executes
instructions only in a
particular machine
PROGRAM language.
MING  A program must be translated

LANGUAG into machine language before


it can be executed.
ES  A compiler is a software tool
which translates from high level
language into a specific machine
language.
 An assembler translates from
assembly language into a specific
machine language.

29
Languages Descriptions Examples Translators
Machine Instruction in 0 01110000110000 None
and 1 bits 01

Assembly Instruction in LOAD 3 Assembler


mnemonic code STOR 4
ADD

High-level Similar to sum = 3 + 4; Compiler &


human interpreter
language, e.g.
FORTRAN,
COBOL, Pascal,
C, C++, Java

PROGRAMMING
LANGUAGES 30
THE JAVA PROGRAMMING
LANGUAGE
 Created by Sun
Microsystems, Inc.
 Introduced in 1995
and it's popularity has
grown quickly.
 Rich library
 Platform-
independent("write
once, run anywhere")
or architecture-
neutral
31
 The Java compiler translates
Java source code into a special
representation called
bytecode.

JAVA  Java bytecode is not the


machine language for any
TRANSLA traditional CPU.

TION  Another Java software tool,


called an interpreter or Java
Virtual Machine (JVM),
translates bytecode into
machine language and
executes it.

32
JAVA TRANSLATION
Java source
code (program)

Java Java
compiler bytecode

Bytecode
interpreter

Machine
(Code is executed)
code 33
 After compiling a Java
program into bytecode,
that bytecode can be used
on any computer with a
bytecode interpreter and
without a need to
PORTABILI recompile.
TY  Bytecode can be sent over
the Internet and used
anywhere in the world.
 This makes Java suitable
for Internet applications.

34
 Understand files and
folders/directories
SETTING  Install JDK

UP YOUR  Java SE Download Page:


http://www.oracle.com/tec
COMPUT hnetwork/java/javase/dow
nloads/index.html

ER TO
 Documentation
 Tutorial

USE JAVA  Install jGRASP


 http://www.jgrasp.org/

35
 IDE (Integrated
Development
SETTING Environment)

UP YOUR
 a software application that
can facilitate programmers
to develop program
COMPUT  Write, save, compile &
run program in a single
ER TO environment

USE JAVA
 E.g. jGrasp, Netbeans,
Eclipse, BlueJay

36
JGRASP IDE

37
FILE HELLO.JAVA
public class Hello
{
public static void main(String[] args)
{
// display a greeting in the console window
System.out.println("Hello World!");
}
}

38
 A Java program is made up of class
definitions.
 A class definition must contain a
JAVA 
header and a body.
A class contains zero or more
PROGRA 
methods
A method is a named section of code
M that also has a header & body

ELEMENT
 A method contains program
statements

S  Comments are used to document the


code, will not be interpreted
 Single-line (starts with //)
 Multi-line (enclosed by /* and */)

39
JAVA PROGRAM STRUCTURE
// comments about the class
public class Hello
{
class header

class body

/*Comments can be placed almost


anywhere*/

40
}
JAVA PROGRAM STRUCTURE
// comments about the class
public class MyProgram

{
// comments about the method
public static void main (String[] args)
{

Main method body


} Main method header

41
COMPILING AND RUNNING
 Type program into text editor

 Save: file name must be similar to class


name

 Compile into byte codes


42
 Execute byte codes
OUTPUT OF THE PROGRAM

43
PROCESSING A JAVA
PROGRAM
Hello.java
Hello.class

javac (bytecode) JVM

Class Loader

44
 It is common for
programmer to make
mistake in a program.

ERRORS  Three kinds of errors:


 Syntax errors
 Runtime errors
 Logic errors

45
SYNTAX ERRORS

 Grammatical mistakes in a program.


 The grammatical rules for writing a program
are very strict.
 The compiler catches syntax errors and prints
an error message.
 Example: using a period where a program
expects a semicolon
 System.out.print("Hi, I am Ali"), ;
 System.out.print("Hello);

" 46
SYNTAX
ERROR
47
RUNTIME ERRORS

 Errors that are detected when your program is


running, but not during compilation.
 When the computer detects an error, it
terminates the program and prints an error
message.
 Example: attempting to divide by 0.

total = 90/0;

48
RUNTIME ERRORS

No error

49
LOGIC ERRORS

 Errors that are not detected during


compilation or while running but cause the
program to produce incorrect results.
 Example: an attempt to calculate the total of
groceries that you buy, instead of summing
the values, you subtract the values.

50
LOGIC ERROR

51
Creating a Java
Program…
52

Create/modify source code

Source code

Compile source code


Syntax errors

Byte code

JVM Run byte code


Runtime errors or
Output
incorrect results
 Write this program:
1. Define the class name as
DisplayMessage.
2. Put single line comment about the
class:
This class displays the students’
interest
EXERCISE 3. Put multiple line comment to display
message:
Display a message in the console
window
4. The program will display this message:
I like PROGRAMMING in JAVA very
much!

53
TODAY’S TAKE
AWAY
 Understand what is programming
 Learn about the architecture of
computers
 Learn about level of programming
languages
 Learn about computing
environment and your compiler
 Learn how to compile and run
your first Java program
 Recognize 3 types of errors

54

You might also like