King Fahd University of Petroleum & Minerals Dhahran, Saudi Arabia
King Fahd University of Petroleum & Minerals College of Computer Science & Engineering
description
Transcript of King Fahd University of Petroleum & Minerals College of Computer Science & Engineering
![Page 1: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/1.jpg)
King Fahd University of Petroleum & MineralsCollege of Computer Science & Engineering
Information & Computer Science Department
Lecture 1 : Introduction
ICS102 - Introduction to computing
![Page 2: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/2.jpg)
ICS102: Intro To Comp2
Components of a Personal Computer
Questions :
- what are the input devices ?
- what are the output devices ?
![Page 3: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/3.jpg)
ICS102: Intro To Comp3
A motherboard, provides the electrical connections by which the other components of the system communicate and hosts the central processing unit as well as other subsystems and devices.
Motherboard
![Page 4: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/4.jpg)
ICS102: Intro To Comp4
Motherboard example : Acer E360
![Page 5: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/5.jpg)
ICS102: Intro To Comp5
CPU (Central Processing Unit)
The Central Processing Unit (CPU) or processor is the portion of a computer system that carries out the instructions of a computer program and is the primary element carrying out the computer's functions.
In an addition operation, the arithmetic logic unit (ALU) will be connected to a set of inputs and a set of outputs. The inputs provide the numbers to be added, and the outputs will contain the final sum.
Example: (3 + 2) = 5
3
2
5
![Page 6: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/6.jpg)
ICS102: Intro To Comp6
• CPU memory
– Registers
– Cache
• Main memory (RAM):
– Data has to be in main memory so that CPU can access it
– Volatile: lost when program exits; computer shuts off
• Hard Disk, CD, etc.
– Persistent
– This is where you keep the data for long-term storage
Memory
Memory refers to computer components, devices, and recording media that hold digital data used for computing for some interval of time.
There are mainly three types of memory :
![Page 7: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/7.jpg)
ICS102: Intro To Comp7
Main Memory…
10021003
1004
1005
CellAddress
Memory is divided intoMany memory locations (cells)
Each memory cell has a numeric address, which uniquely identifies it
Each cell contains a datavalue, e.g. 22
![Page 8: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/8.jpg)
ICS102: Intro To Comp8
Main Memory…
![Page 9: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/9.jpg)
ICS102: Intro To Comp9
The word “Hello.” stored in 6 memory cells
Main Memory…
![Page 10: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/10.jpg)
ICS102: Intro To Comp10
Memory units : Bits and Bytes
• Bit -- most basic unit of memory
– 1 or 0, on or off
• 1 Byte = 8 bits
• In a computer, data values are stored as a sequence of bits
2
7
1004
1005
00000010
00000111
1004
1005
![Page 11: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/11.jpg)
ICS102: Intro To Comp11
Program / CPU / Memory Interaction
• Example:
– Input read a number from keyboard
– Add 1 to it
– Output it on screen
KeyboardRAM
11 CPU
RAM
2 Monitor1 2 2
![Page 12: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/12.jpg)
What is programming?
![Page 13: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/13.jpg)
ICS102: Intro To Comp13
What is a program?
• A (software) program is a list of instructions intended to a computer
• The list must be ordered correctly
• A program has inputs and outputs
• Each instruction tells the computer to do something (an action, a calculation, a comparison)
![Page 14: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/14.jpg)
ICS102: Intro To Comp14
Program Execution
• A program tells the CPU how to manipulate and/or move information
• Programming is about processing information
– Take some input, manipulate it in some way, and produce a particular output
ManipulationInputs Outputs
Program
![Page 15: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/15.jpg)
ICS102: Intro To Comp15
Example 1 : Recipe for Scrambled Eggs
• Ingredients (Inputs) : two eggs, tablespoon of oil, salt
• Instructions (program):
– Add oil to pan
– Heat pan on stove
– Crack eggs into pan
– Add salt
– Mix until light and flakey
• Output: scrambled eggs
![Page 16: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/16.jpg)
ICS102: Intro To Comp16
Example 2 : Currency Exchange
• Input:– Amount– Source Currency– Desired Currency
• Instructions– Look up in table current exchange rate for the selected
currencies– Calculate result as amount * exchange rate
• Output: result
Task : convert an amount of money in some currency (e.g. US Dollars) to another one (e.g. Saudi Riyals).
![Page 17: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/17.jpg)
ICS102: Intro To Comp17
Programming language
• A programming language is the language used to write programs
• A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements
• A programming language has a syntax and semantics
• There are several types of languages (functional, Object-Oriented, etc.)
• In this course we focus on Java programming language.
![Page 18: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/18.jpg)
ICS102: Intro To Comp18
Java
• Java is a programming language originally developed by James Gosling at Sun Microsystems
• It was first released in 1995.
• The language derives much of its syntax from C and C++.
• But has a simpler object model and fewer low-level facilities than C and C++.
![Page 19: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/19.jpg)
ICS102: Intro To Comp19
Why Java?
Currently, Java is the most popular language in the world !
![Page 20: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/20.jpg)
ICS102: Intro To Comp20
Why Java?
1. Simple
• Get started quickly
2. Concise
• Write less code
3. Object-oriented
• Better quality code
4. Portable
• Architecture neutral (write once run anywhere)
5. Secure
• More appropriate for Internet
![Page 21: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/21.jpg)
ICS102: Intro To Comp21
Portability of Java
Classical model:
Java model:
![Page 22: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/22.jpg)
ICS102: Intro To Comp22
Portability of Java
Write once, run anywhere: Because applications written in the Java programming language are compiled into machine-independent bytecodes, they run consistently on any Java platform.
![Page 23: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/23.jpg)
ICS102: Intro To Comp23
A Java Program
• A Java program consists of one or more classes
• A Java class consists of one or more methods
• A Java method consists of one or more statements
A Java Program
Javaclasses
JavaMethods
![Page 24: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/24.jpg)
ICS102: Intro To Comp24
A Java Program
• A Java program resides in one or more files.
• The file name of a Java program has extension .java.
• One of the classes of a Java program is called the driver class.
• The name of the driver class must be the same as the name of its Java file. (Java is case sensitive. So EX1 is different from ex1.)
• The diver class must contain a method called main. The execution of Java program starts from the main method of the driver class.
![Page 25: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/25.jpg)
ICS102: Intro To Comp25
Example of a Java Program
![Page 26: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/26.jpg)
ICS102: Intro To Comp26
Example of a Java Program
Class nameMain method
Instruction
Class body
![Page 27: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/27.jpg)
ICS102: Intro To Comp27
Example of a Java Program
Also notice:
Curly braces } {
![Page 28: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/28.jpg)
ICS102: Intro To Comp28
Example of a Java Program
Also notice:
Parentheses ( )
Curly braces } {
![Page 29: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/29.jpg)
ICS102: Intro To Comp29
Example of a Java Program
Also notice:
Parentheses ( )
Curly braces } { Square brackets] [
![Page 30: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/30.jpg)
ICS102: Intro To Comp30
Example of a Java Program
Also notice:
A pair of braces } { define a block
![Page 31: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/31.jpg)
ICS102: Intro To Comp31
Compiling and running a program
• Type in your program
• Save the program
– Store all your files in one directory for now
– Give the program the same name as the class
• Compile the program
– this produces a .class file
– Translates the program into something the computer can understand and execute (Java bytecode)
• Run the program
• Observe the result and adjust the program if necessary
![Page 32: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/32.jpg)
ICS102: Intro To Comp32
Edit
Text Editor
Public class/*
Adventure.java
Public class Adven/* This program is an Arit*/
public static void main /* Program statements g System.out.print(“Wel }}
![Page 33: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/33.jpg)
ICS102: Intro To Comp33
Compile - With Errors
Adventure.java
Public class Adven/* This program is an Arit*/
public static void main /* Program statements g System.print(“Welcome }}
Compiler
Errors and Warnings-------------------Error : The method print(String) is undefined forType System
![Page 34: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/34.jpg)
ICS102: Intro To Comp34
Compile - Success
Adventure.java
Public class Adven/* This program is an Arit*/
public static void main /* Program statements g System.out.print(“Wel }}
Compiler
Adventure.class
00101101000101110110110100010111011101010001011101110101101000101110111010110100010111011101011010001011101110101101000101110111000101110111010110100010111011100101110111010110100010111011100101110111010110100010111011100101110111010110100010111011100101110111010110100010111011100101110
![Page 35: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/35.jpg)
ICS102: Intro To Comp35
Run Program
Welcome to the ArithmThe date is Monday SepWhat is your name?FredWell Fred, after a dayThe cube appears to beYou find a Green door,The door closes behindThere is a feel of mat
Adventure
Fred
1
![Page 36: King Fahd University of Petroleum & Minerals College of Computer Science & Engineering](https://reader036.fdocuments.in/reader036/viewer/2022070416/5681503f550346895dbe3d2f/html5/thumbnails/36.jpg)
End