You are on page 1of 61

Introduction to Programming

Dr. Riham Abdel Kader


Spring17
What Is This Course About?

www.bau.edu.lb
Course Information

CMPS 241: Introduction to Programming


Instructor: Riham Abdel Kader
Office: B115
email: r.abdelkader@bau.edu.lb
TA: Salma Ghali & Ali Ghosn
Textbook: Java How to Program by
Dietel & Dietel, 9th Edition

www.bau.edu.lb
Course Objective

Understand the fundamentals and


principles of programming
Introduce the concepts of structured
programming and good programming
techniques
Provide an introduction to algorithms
and to the Java language.

www.bau.edu.lb
Database System Concepts - 6th Edition
Goal

Learn enough Java to do


something useful

www.bau.edu.lb
Grading

Programming lab and assignments


(30%)
Midterm (30%)
Final Exam (40%)
As set by BAU regulations, students
who miss more than one-fifth of the
sessions will be required to withdraw
from the course with a grade of WF.

www.bau.edu.lb
Why Study Programming?

www.bau.edu.lb
What Is
Computer Science?
Computer Science is NOT the study of
computers.
A lot of work in CS is done with pen and
paper!
Computer Science is no more about
computers than astronomy is about
telescopes, biology is about microscopes,
or chemistry is about test tubes.
Computer Science is about programming
and the study of algorithms.
www.bau.edu.lb
Why Computer Science?

Computer scientists are needed in


every type of industry
Every industry uses computers.
Problems in science, engineering,
health care, and so many other areas
can be solved by computers.
It's up to the computer scientist to figure
out how, and design the software to
apply the solution.

www.bau.edu.lb
Why Computer Science?

The digital age needs computer


scientists
Like it or not you're living in the Digital
Age. Computer programmes have all
but infiltrated every aspect of our
lives.
Computer scientists theorise, design,
develop, and apply the software and
hardware for the programmes we use
day in day out sounds pretty
important to us.
www.bau.edu.lb
Why Computer Science?

Can easily find a job


Computer Scientist can easily find a
job after graduating.
Many of our BAU students are
finding a job before even finishing
their studies.
Internships during CMPS study -
collaboration between BAU and 4
software companies.

www.bau.edu.lb
Why Computer Science?

Computer scientists earn good money


Computer scientists are in demand and
their salaries reflect this.
Recent graduates with zero experience
earn at least 800$/month in Lebanon.
Recent graduates with internship
experience can earn 1200$/month in
Lebanon.
Salaries increase quickly, can reach after
4 years of experience 3000$/month.
www.bau.edu.lb
What Will You Learn
in This Course?

www.bau.edu.lb
Chapter 1

Computer: Software
and Hardware

www.bau.edu.lb
A simplified view of a
The Computer
computer system
Memory

Central
Processing Unit
(CPU)

Input/Output
(IO) Devices

www.bau.edu.lb
A simplified view of a
computer system

Monitor
Central
Processing
Unit
Keyboard

Hard Disk
Main
Memory
External Disk

www.bau.edu.lb
Chapter 2

Problem Analysis

www.bau.edu.lb
Hardware Devices

Understand requirements:
The given data
The required results
The processing that is required in
the problem
A list of solution alternatives

www.bau.edu.lb
The Interactivity Chart
for the Payroll Problem

www.bau.edu.lb
Flowchart Symbols

www.bau.edu.lb
Software
Development Cycle

Analysis
Design
Development
Implementation
Maintenance and review

www.bau.edu.lb
Chapter 3

Java programming

www.bau.edu.lb
Java Programming

Variable declarations
Primitive data types in Java (Integers,
Characters, Floating Points)
Input / Output
Output formatting
Escape Sequences

www.bau.edu.lb
Chapter 4

Arithmetic and
logic operations

www.bau.edu.lb
Operators and Their
Computer Symbols

www.bau.edu.lb
Definitions of the
Logical Operators

www.bau.edu.lb
Hierarchy of Operations

www.bau.edu.lb
Evaluating a
Mathematical Expression

www.bau.edu.lb
Chapter 5

Branching and conditional


branching
if statement
if/else statements
Nested if statements

www.bau.edu.lb
Flowchart Diagram of
the Decision Structure

www.bau.edu.lb
Chapter 6

Introduction to Loop using


flowchart
Loop for
Loop while
Loop do/while

www.bau.edu.lb
Flowchart Diagram of
While/While End

www.bau.edu.lb
Chapter 7

Arrays: 1D-array applied on


integer elements

www.bau.edu.lb
One-Dimensional Array

www.bau.edu.lb
Chapter 8

Arrays: 1D- array applied on


specific applications

www.bau.edu.lb
Chapter 9

Arrays: sorting

www.bau.edu.lb
Computer: Software and
Hardware

www.bau.edu.lb
Course Objective

Explain in general terms what


computers do.
List several examples of input and
output devices.
What are softwares and algorithms?

www.bau.edu.lb
Database System Concepts - 6th Edition
What Computers Do

www.bau.edu.lb
Basic Functions of a
Computer
Four basic operations:
Receive input: Accept information from
outside world
Process information: Perform arithmetic
or logical operations on information
Produce output: Communicate
information to outside world
Store information: Store and retrieve
information from memory and storage
devices

www.bau.edu.lb
Basic Components of a
What ComputersComputer
Do (cont.)
Hardware components
Hardware components
Input devices (mouse,
Input devices
keyboard, scanner)
Output
Output devices
devices
(monitor, printer, (CPU)
Microprocessor
speaker)
Memory and storage
Microprocessor(CPU)
devices
Memory andstorage
Primary storage
devices
Secondary storage
Peripherals
Primary storage
Secondary storage
Copyright 2012 Pearson Education, Inc. publishing as Prentice Hall 5

www.bau.edu.lb
Input Devices

www.bau.edu.lb
Input: From Person to
Processor

User sees only input and output or I/O.


Mouse: Designed to move pointer around
screen
Wireless mice: Use Bluetooth or other
wireless frequencies
Keyboard: Standard or wireless

www.bau.edu.lb
Other Types
ard of Keyboard
Ergonomic keyboards:
evice Keys are at angles; easy on arms and
hands
o manual typewriters
To address possible medical problems
o computer through
Folding keyboards
Used with palm-sized computers

5 www.bau.edu.lb
Pointing Devices
Touchpad: A flat panel, sensitive to light
pressure
Trackpoint and trackball: Used to control
pointer
Game controllers, graphics tablets,
touch screens: Used for inputting

Trackball Joystick Spaceball

www.bau.edu.lb
Multi-Touch Input
Devices
e multi-finger or multi-hand gestures to
Use multi-finger
omplish complex tasksto accomplish
quickly complex tasks
quickly
uch-sensitive screen, touch tablet, or trackpad can
Touch-sensitive screen, touch tablet, or
ognize position,
trackpad can pressure, and movement
recognize position, pressure,ofand
more
n one finger orofhand
movement moreat a time
than one finger or hand at a
time.
st known example is
Best known example is
ples Apples
iPhoneiPhone
d recognizes one- and
o- fingered movements
www.bau.edu.lb
Output Devices

www.bau.edu.lb
Output: From Pulses
to People
Output devices convert computers internal
bit patterns into a form humans can
understand.
Output produced through two main devices:
Display screens for immediate visual
output
Printers for permanent paper output

www.bau.edu.lb
Screen Output
Screen = Display = Monitor
Display size measured length of diagonal
line across screen
Images composed of tiny dots called
pixels.
Resolution: The number of pixels
displayed on the screen, measured in dots
per inch (dpi)
The higher the resolution, the closer
together the dots

www.bau.edu.lb
Output You Can Hear

Sound card in the PC enables it to:


Play music and other sound through
speakers or headphones
Accept microphone input

Headsets are particularly useful for


telephone and teleconferencing
applications

www.bau.edu.lb
Data in a PC

www.bau.edu.lb
A Bit About Bits

Bit: From Binary digit


Smallest unit of
information computer
can process
Can have one of two
values: 0 or 1
Byte
Collection of 8 bits

www.bau.edu.lb
Bits as Numbers
Decimal Binary

Denotes all numbers with 0 0000


combinations of 0s and 1s 1 0001
2 0010
Decimal numbers
3 0011
automatically converted to
4 0100
binary and vice versa
5 0101
Binary number processing is 6 0110
completely hidden from user 7 0111
8 1000
9 1001

www.bau.edu.lb
Bits, Bytes, and
Buzzwords
Byte = 8 bits or one character in ASCII
Kilobyte (KB, K) 1,000 bytes
Megabyte (meg, MB) 1,000 KB or
1 million bytes
Gigabyte (gig, GB) 1,000 MB or
1 billion bytes
Terabyte (TB) 1 million MB or
1 trillion bytes
Petabyte (PB) 1 quadrillion bytes

www.bau.edu.lb
Software

www.bau.edu.lb
Software

Example of software??

www.bau.edu.lb
Algorithms

Algorithm: a set
of step-by-step
instructions
written in a
natural
language, e.g.,
English.
Just like a
recipe but for
computers!!
www.bau.edu.lb
Copyright 2012 Pearson Education, Inc. publishing as Prentice Hall
Example Algorithm

1. Define x to be equal to 10
2. Define y to be equal to 20
3. Compute the sum of x and y
4. Give output to user

www.bau.edu.lb
Creating Programs

The steps are translated into the


vocabulary of a programming
language.
A programming language is a high-
level language
C++, Java, and Visual Basic

www.bau.edu.lb
Software

HIGH LEVEL ASSEMBLY MACHINE


C++ and Java
z=x+y MOV AL, X 0010 1001 0001
MOV AH, Y 0010 1100 0010
ADD AL, AH 0100 0001 0010
MOV Z, AL 0010 0010 1011

www.bau.edu.lb
Example Program

int x = 10;
int y = 20;
int z = x + y;
print(z);

www.bau.edu.lb

You might also like