UNIVERSITY OF SOUTHERN MINDANAO
Topic Outline
• Introduction to Computers and Logic
• Hardware
• Software
• How computers store data
• Machine Cycle
• How a program works
• Programming Process
• Introduction to Java
CpE 112 – Programming Logic and Design 2
Intended Learning Outcomes
• Define what is computer
• Understand computer components and
operations
• Enumerate and describe different
computers
• Explain how the computer works and how
data is stored and manipulated.
• Describe the steps involved in the
programming process
CpE 112 – Programming Logic and Design 3
What is computer?
- is an electronic device that manipulates information, or
data, typically in binary form, according to instruction
given.
- has the ability to store, retrieve, and process data.
CpE 112 – Programming Logic and Design 4
Uses of Computers
CpE 112 – Programming Logic and Design 5
Uses of Computers
CpE 112 – Programming Logic and Design 6
Uses of Computers
CpE 112 – Programming Logic and Design 7
2 Main Parts of a Computer
• hardware
- is any physical device used in or with your
machine.
- is something you can hold or touch in your
hand.
• software
- is a collection of programming code
installed on your computer's hard drive.
- cannot be held in your hand.
CpE 112 – Programming Logic and Design 8
Hardware
• Input devices
- An input device is any hardware device that sends data to the
computer.
- Without any input devices, a computer would only be a
display device and not allow users to interact with it
CpE 112 – Programming Logic and Design 9
Hardware
• Output devices
- An output device is any piece of computer
hardware equipment used to communicate
the results of data processing carried out by
a computer to the outside world.
CpE 112 – Programming Logic and Design 10
Hardware
• System Unit
- The system unit is the core of a computer system.
- Usually it's a rectangular box placed on or underneath your desk.
- The most important components are:
Central processing unit (CPU)
Random access memory (RAM)
Hard disk – Etc.
- Hardware that is not part of the system unit is sometimes called
peripheral device or device.
CpE 112 – Programming Logic and Design 11
Software
• System Software
- is computer software designed to operate the computer hardware and to
provide and maintain a platform for running application software.
Example:
1. Operating System
- is the program that, after being initially loaded into the computer
by a boot program, manages all of the other application programs in
a computer.
- The application programs make use of the operating system by
making requests for services through a defined application program
interface (API).
- In addition, users can interact directly with the operating system
through a user interface, such as a command-line interface (CLI) or a
graphical UI (GUI).
CpE 112 – Programming Logic and Design 12
Software
• System Software
Example:
2. BIOS
BIOS (basic input/output system) is the program a
personal computer's microprocessor uses to get the
computer system started after you turn it on.
It also manages data flow between the computer's
operating system and attached devices such as the
hard disk, video adapter, keyboard, mouse and printer.
CpE 112 – Programming Logic and Design 13
Software
CpE 112 – Programming Logic and Design 14
Software
CpE 112 – Programming Logic and Design 15
Software
• Application Software
Applications software is capable of dealing with user inputs
and helps the user to complete the task.
It is also called end-user programs or only an app.
Example:
1. Presentation Software
2. Spreadsheet Software
3. Database Software
4. Multimedia Software
5. Simulation Software
6.Word Processing Software
CpE 112 – Programming Logic and Design 16
Basic Computer Operations
CpE 112 – Programming Logic and Design 17
How Computers Store Data?
All data that is stored in a
computer is converted to
sequences of 0s and 1s.
CpE 112 – Programming Logic and Design 18
How Computers Store Data?
CpE 112 – Programming Logic and Design 19
How Computers Store Data?
Determining the value of The bit pattern
10011101
CpE 112 – Programming Logic and Design 20
Storing Numbers
The values of binary
digits as powers by 2
CpE 112 – Programming Logic and Design 21
Storing Numbers
Two bytes used for a large number
CpE 112 – Programming Logic and Design 22
Storing Characters
The letter A is stored in memory as the number 65.
CpE 112 – Programming Logic and Design 23
Storing Characters
CpE 112 – Programming Logic and Design 24
Advanced Numbers Storage
CpE 112 – Programming Logic and Design 25
Other Data Types
CpE 112 – Programming Logic and Design 26
How a Program Works
• A computer’s CPU can only understand instructions that
are written in machine language. Because people find it
very difficult to write entire programs in machine
language, other programming languages have been
invented.
CPU is the most important component in a computer.
CPU is not a brain.
CPU is not smart.
CPU is an electronic device that is designed to do specific
things.
CpE 112 – Programming Logic and Design 27
How a Program Works
• CPU is designed to perform the following operations:
1. Read a piece of data from main memory
2. Adding two numbers
3. Subtracting one number from another number
4. Multiplying two numbers
5. Dividing one number by another number
6. Moving a piece of data from one memory location to
another
7. {{{{{{{{{{{{{{
8. Determining whether one value is equal to another value
CpE 112 – Programming Logic and Design 28
How a Program Works
CpE 112 – Programming Logic and Design 29
Machine Cycle
Machine cycle is the basic operation cycle of a computer processor.
It is the process by which a computer processor retrieves a program instruction from its
memory, determines what actions the instruction requires, and carries out those actions.
This cycle is repeated continuously from bootup to when the computer is shut down.
There are four steps in machine cycle:
Instruction Phase:
• Fetch - get an instruction from Main Memory
• Decode - translate it into computer commands
• [
Execution Phase
• Execute - actually process the command
• Store - write the result to Main Memory
CpE 112 – Programming Logic and Design 30
Machine Cycle
CpE 112 – Programming Logic and Design 31
Machine Cycle
CpE 112 – Programming Logic and Design 32
How a Program Works
CpE 112 – Programming Logic and Design 33
How a Program Works
CpE 112 – Programming Logic and Design 34
How a Program Works
Assembly language is referred to as a low-level language
High-level languages allow you to create powerful and complex programs without knowing how the CPU
works, using words that are easy to understand.
Example:
1. Ada
2. BASIC
3. FORTRAN
4. COBOL
5. Pascal
6. C and C++
7. C#
8. Java
9. JavaScript
10. Python
11. Ruby
12. Visual Basic
CpE 112 – Programming Logic and Design 35
How a Program Works
CpE 112 – Programming Logic and Design 36
How a Program Works
CpE 112 – Programming Logic and Design 37
How a Program Works
CpE 112 – Programming Logic and Design 38
How a Program Works
CpE 112 – Programming Logic and Design 39
Program Development Life Cycle
• Basic steps in trying to solve a
problem on the computer:
1. Problem Definition
2.Problem Analysis
3.Algorithm design and representation
(Pseudocode or flowchart)
4.Coding and debugging
CpE 112 – Programming Logic and Design 40
Program Development Life Cycle
1. Problem Definition
● A clearly defined problem is already half
the solution.
● Computer programming requires us to
define the problem first before we even try
to create a solution.
● Let us now define our example problem:
“Create a program that will determine the
number of times a name occurs in a list.”
CpE 112 – Programming Logic and Design 41
Program Development Life Cycle
• 2. Problem Analysis
● After the problem has been adequately defined, the
simplest and yet the most efficient and effective approach
to solve the problem must be formulated.
● Usually, this step involves breaking up the problem into
smaller and simpler subproblems.
● Example Problem: – Determine the number of times a
name occurs in a list
● Input to the program: – list of names (let's call this
nameList) – name to look for (let's call this keyName)
● Output of the program: – the number of times the name
occurs in a list CpE 112 – Programming Logic and Design 42
Program Development Life Cycle
3. Algorithm Design and representation
● Algorithm – a clear and unambiguous
specification of the steps needed to solve a
problem.
● Pseudocode – is an informal language that
helps programmers develop algorithms
without having to worry about the strict
details of Java language syntax.
CpE 112 – Programming Logic and Design 43
Program Development Life Cycle
• 4. Coding and Debugging
● After constructing the algorithm, it is now
possible to create the source code. Using
the algorithm as basis, the source code can
now be written using the chosen
programming language.
● Debugging – The process of fixing some
errors (bugs) in your program
CpE 112 – Programming Logic and Design 44
Types of Errors
● Compile-time error or syntax errors
– occur if there is a syntax error in the code.
–The compiler will detect the error and the
program won't even compile. At this point,
the programmer is unable to form an
executable program that a user can run until
the error is fixed.
● Runtime Errors
– Compilers aren't perfect and so can't catch all
errors at compile time. This is especially true for
logic errors such as infinite loops. This type of error
is called runtime error.
CpE 112 – Programming Logic and Design 45
Introduction to Java
• Java Background: History
● Java – was created in 1991
– by James Gosling et al. of Sun
Microsystems.
– initially called Oak, in honor of
the tree outside Gosling's window, its
name was changed to Java because
there was already a language called
Oak.
CpE 112 – Programming Logic and Design 46
Java Background: History
● Java – The original motivation for Java
● The need for platform independent language that could
be embedded in various consumer electronic products like
toasters and refrigerators.
– One of the first projects developed using Java
● a personal hand-held remote control
named Star 7.
– At about the same time, the World Wide Web and the
Internet were gaining popularity. Gosling et. al. realized
that Java could be used for Internet programming.
CpE 112 – Programming Logic and Design 47
Java Background: What is Java Technology?
● The Java technology is:
– A programming language
– A development environment
– An application environment
– A deployment environment
CpE 112 – Programming Logic and Design 48
Java Background: What is Java Technology?
● As a programming language
- Java can create all kinds of applications
that you could create using any conventional
programming language.
● As a development environment
- Java technology provides you with a
large suite of tools: – A compiler – An
interpreter – A documentation generator –
A class file packaging tool and so on...
CpE 112 – Programming Logic and Design 49
Java Background: What is Java Technology?
• An Application and Runtime Environment
- Java technology applications are typically general-
purpose programs that run on any machine where the Java
runtime environment (JRE) is installed.
● There are two main deployment environments:
1. The JRE supplied by the Java 2 Software Development Kit
(SDK) contains the complete set of class files for all the Java
technology packages, which includes basic language classes,
GUI component classes, and so on.
2. The other main deployment environment is on your web
browser. Most commercial browsers supply a Java technology
interpreter and runtime environment.
CpE 112 – Programming Logic and Design 50
Java Features:
• Java Virtual Machine (JVM) – an imaginary machine
that is implemented by emulating software on a real
machine – provides the hardware platform
specifications to which you compile all Java
technology code
• Bytecode – a special machine language that can be
understood by the Java Virtual Machine (JVM) –
independent of any particular computer hardware, so
any computer with a Java interpreter can execute the
compiled Java program, no matter what type of
computer the program was compiled on
CpE 112 – Programming Logic and Design 51
Java Features:
• Garbage collection thread – responsible for
freeing any memory that can be freed. This
happens automatically during the lifetime of the
Java program. – programmer is freed from the
burden of having to deallocate that memory
themselves
CpE 112 – Programming Logic and Design 52
Java Features:
• Code security is attained in Java through the implementation of its Java
Runtime Environment (JRE).
• JRE – runs code compiled for a JVM and performs class loading (through the
class loader), code verification (through the bytecode verifier) and finally
code execution
• Class Loader – responsible for loading all classes needed for the Java program
– adds security by separating the namespaces for the classes of the local file
system from those that are imported from network sources – After loading
all the classes, the memory layout of the executable is then determined. This
adds protection against unauthorized access to restricted areas of the code
since the memory layout is determined during runtime
• Bytecode verifier – tests the format of the code fragments and checks the
code fragments for illegal code that can violate access rights to objects
CpE 112 – Programming Logic and Design 53
Phases of a Java Program
● The following figure describes the process of
compiling and executing a Java program
CpE 112 – Programming Logic and Design 54
Phases of a Java Program
CpE 112 – Programming Logic and Design 55
Summary
• Introduction to Computers and Logic
- What is computer?
- Uses and Parts
• Hardware
- Input devices, Output devices, System Unit
• Software
--System, Programming, Application
• How computers store data
- Storing Numbers, Storing Characters
• Machine Cycle
- Instruction Phase, Execution Phase
• How a program works
• Programming Process
• Introduction to Java
- History
- What is Java Technology?
- Java Features
- Phases of a Java Program
CpE 112 – Programming Logic and Design 56
References
• Farell, J. 2009. Java Programming Concepts
and Application
• JEDI Compilation
• Gaddis, T. 2013. Starting out with
>>>Programming Logic and Design. 3rd
Edition
• Deitel, H.M & Deitel P.J. 2005. Java How to
Program. 6th Edition
CpE 112 – Programming Logic and Design 57