1
Computer
Programming
Dr: Marwa AL Enany
Course Objectives 2
To Introduces students to computer
programming. To develop a good
programming style
To develop basic skills of designing
To develop coding, debugging, and
programs documentation.
3
Chapter 1
Principles of
Programming
Objectives 4
To understand computer basics, programs, and operating systems.
To describe the relationship between Java and the World Wide Web.
To write a simple Java program.
To explain the basic syntax of a Java program. To create,
compile, and run Java programs.
To become familiar with Java programming style and
documentation.
To explain the differences between syntax errors, runtime errors, and
logic errors.
What is a Computer?
5
A computer consists of a CPU, memory, hard
disk, floppy disk, monitor, printer, and
communication devices.
Bus
Storage Communication Input Output
Devices Memory CPU Devices Devices Devices
e.g., Disk, CD, e.g., Modem, e.g., Keyboard, e.g., Monitor,
and Tape and NIC Mouse Printer
Programs 6
Computer programs, known as software, are
instructions to the computer.
You tell a computer what to do through programs.
Without programs, a computer is an empty machine.
Computers do not understand human languages, so
you need to use computer languages to communicate
with them.
Programs are written using programming
languages.
Programming Languages
7
Machine Language
Assembly Language
High-Level Language
Programming Languages
8
Machine Language Assembly Language High-Level Language
Machine language is a set of primitive instructions built into
every computer.
The instructions are in the form of binary code, so you have
to enter binary codes for various instructions.
Program with native machine language is a tedious process.
Moreover the programs are highly difficult to read and
modify.
For example, to add two numbers, you might write an
instruction in binary like this:
1101101010011010 Computer
Programming, Dr.
M. Badawy
Programming Languages
9
Machine Language Assembly Language High-Level Language
Assembly languages were developed to make programming
easy.
Since the computer cannot understand assembly language,
however, a program called assembler is used to convert
assembly language programs into machine code.
For example, to add two numbers, you might write an
instruction in assembly code like this:
ADD 2, 3, Result
Programming Languages
10
Machine Language Assembly Language High-Level Language
The high-level languages are English-like and easy to
learn and program.
For example, the following is a high-level language
statement that computes the area of a circle with
radius 5:
area = 5 * 5 * 3.1415;
11
https://spectrum.ieee.org/top-programming-languages-2021
Popular High-Level Languages
12
Interpreting/Compiling Source Code 13
A program written in a high-level
language is called a source program or
source code.
Because a computer cannot understand
a source program, a source program
must be translated into machine code for
execution.
The translation can be done using another
programming tool called an interpreter or a
compiler.
Interpreting Source Code 14
An interpreter reads one statement from the source code,
translates it to the machine code or virtual machine code, and
then executes it right away, as shown in the following figure.
High-level Source File
… Output
area = 5 * 5 * 3.1415; Interpreter
...
Note that a statement from the source code may be
translated into several machine instructions.
Compiling Source Code 15
A compiler translates the entire source code into a
machine-code file, and the machine-code file is then
executed, as shown in the following figure.
High-level Source File Machine-code File
… … Output
area = 5 * 5 * 3.1415; Compiler 0101100011011100 Executor
... 1111100011000100
…
Operating Systems 16
The operating system (OS) is a
program that manages and User
controls a computer’s activities.
The popular operating systems for
Application Programs
general-purpose computers are
Microsoft Windows, Mac OS, and
Linux. Operating System
Application programs, such as a
Web browser or a word processor,
cannot run unless an operating Hardware
system is installed and running on
the computer.
Software Development Process 17
Computer
Programmin
g, Dr. M.
13-Nov-21 Badawy
Requirement Specification 18
Seek to understand the problem
Requirement
Specification and document in detail what the
software system needs to do. This
System phase involves close interaction
Analysis between users and designers.
System
Design
Implementation
Testing
In the real world, problems are not well
defined. You need to study a problem carefully Deployment
to identify its requirements. This phase
involves close interaction between users and
Computer
Maintenance
developers. Programmin
g, Dr. M.
13-Nov-21 Badawy
System Analysis 19
Requirement Seek to analyze the business process
Specification
in terms of data flow, and to identify
System the system’s input and output.
Analysis
System
Design
Implementation
Testing
When you do analysis, it helps to Deployment
identify what the output is first, and
then figure out what input data you Computer
Maintenance
Programmin
need in order to produce the output. g, Dr. M.
13-Nov-21 Badawy
System Design 20
Is to design a process for obtaining
Requirement
Specification the output from the input.
System
Analysis
System
Design
Implementation
Testing
Decompose the problem into
Deployment
components and design strategies for
implementing each component You can
view each component as a subsystem that Computer
Maintenance
performs a specific function of the system. Programmin
g, Dr. M.
13-Nov-21 Badawy
Implementation 21
Requirement The process of translating the system
Specification design into programs. Separate
programs are written for each
System
Analysis component and put to work together.
System
Design
Implementation
Testing
This phase requires the use of a
programming language like Java. Deployment
The implementation involves coding, Computer
Maintenance
self-testing, and debugging. Programmin
g, Dr. M.
13-Nov-21 Badawy
Testing 22
Ensures that the code meets
Requirement
Specification the requirements specification
and weeds out bugs.
System
Analysis
System
Design
Implementation
Testing
An independent team of software Deployment
engineers not involved in the design
and implementation of the project Maintenance
Computer
usually conducts such testing. Programmin
g, Dr. M.
13-Nov-21 Badawy
Deployment 23
Requirement
Specification Deployment makes the project
available for use.
System
Analysis
System
Design
Implementation
Testing
Deployment
For a Java applet, this means installing it
on a Web server; for a Java application, Maintenance
Computer
installing it on the client's computer. Programmin
g, Dr. M.
13-Nov-21 Badawy
Maintenance 24
Requirement
Maintenance is concerned with
Specification changing and improving the product.
System
Analysis
System
Design
Implementation
Testing
Deployment
This requires periodic upgrades of the
product to fix newly discovered bugs and Maintenance
Computer
incorporate changes. Programmin
g, Dr. M.
13-Nov-21 Badawy
Java Programming language
Java is popular high-level, class-based object oriented
programming language originally developed by Sun
Microsystems and released in 1995.
Java runs on a variety of platforms, such as Windows, Mac OS,
and the various versions of UNIX.
Java is used to develop numerous types of software
applications like Mobile apps, Web apps, Desktop apps, Games
and much more.
Java Applications
• Mobile applications (specially Android apps)
• Desktop applications
• Web applications
• Web servers and application servers
• Games
• Database connection
• And much, much more!
Java Applications
There are many other good reasons which makes Java as the
first choice of any programmer:
• Java is Open Source which means its available free of cost.
• Java is simple and so easy to learn
• Java is much in demand and ensures high salary
• Java has a large vibrant community
• Java has powerful development tools
• Java is platform independent
Java Terminology
1. Java Virtual Machine(JVM):
• Writing a program is done by a java programmer like you and me.
• The compilation is done by the JAVAC compiler which is a primary
Java compiler included in the Java development kit (JDK). It takes
the Java program as input and generates bytecode as output.
• In the Running phase of a program, JVM executes the bytecode
generated by the compiler.
• Every Operating System has a different JVM but the output they
produce after the execution of bytecode is the same across all the
operating systems. This is why Java is known as a platform-
independent language.