Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Similar documents
C H A P T E R 1. Introduction to Computers and Programming

What did we talk about last time? Examples switch statements

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

CHAPTER 1 Introduction to Computers and Java

Chapter 1: Introduction to Computers and Programming

Introduction. Arizona State University 1

Chapter 1: Why Program? Computers and Programming. Why Program?

COMP Computer Basics. Yi Hong May 13, 2015

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Programming with Java

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Computer Components. Software{ User Programs. Operating System. Hardware

The Programming Process Summer 2010 Margaret Reid-Miller

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

CC411: Introduction To Microprocessors

Introduction to Computers and Java

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

Introduction to Software Development (ISD) David Weston and Igor Razgon

Darrell Bethea May 25, 2011

Chapter Two. Hardware Basics: Inside the Box

Introduction to Computers and Java

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Computer Components. Software{ User Programs. Operating System. Hardware

Variables, Constants, and Data Types

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

B.V. Patel Institute of BMC & IT, UTU 2014

Chapter 1 Introduction to Computers and Programming

PROGRAMMING FUNDAMENTALS

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

CMSC 104 -Lecture 2 John Y. Park, adapted by C Grasso

Computer Programming-1 CSC 111. Chapter 1 : Introduction

COMP 202 Java in one week

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Computational Expression

Introduction to Computers and Java

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS 231 Data Structures and Algorithms, Fall 2016

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

Course Outline. Introduction to java

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Introduction to Computers and Java

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings

Electricity: Voltage. Gate: A signal enters the gate at a certain voltage. The gate performs operations on it, and sends it out was a new signal.

Lecture Set 2: Starting Java

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Lecture Set 2: Starting Java

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CHAPTER 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING. 1 Muhalim Mohamed Amin Faculty of

Midterms Save the Dates!

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

2 rd class Department of Programming. OOP with Java Programming

Section 2.2 Your First Program in Java: Printing a Line of Text

Intermediate Programming & Design (C++) Notation

Java Bytecode (binary file)

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Full file at

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Chapter 1 Computer and Programming. By Zerihun Alemayehu

Introduction to Computers and Java

Class List. Java Must Have. Class Goals. Class Goals. Schedule

Fundamentals of Programming (Python) Basic Concepts. Ali Taheri Sharif University of Technology Spring 2018

SCSP Programming Technique C

Chapter. Let's explore some other fundamental programming concepts

Chapter 1 INTRODUCTION

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

CST112 Variables Page 1

15/09/15. Introduction to Computers & The Internet. Contents. Computer hardware and software. Input and output devices CPU. Memory.

Primitive Data, Variables, and Expressions; Simple Conditional Execution

BASICS.

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

Oct Decision Structures cont d

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Components of a Computer System

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

AP Computer Science A: Java Programming

Zheng-Liang Lu Java Programming 45 / 79

Introduction to Programming Using Java (98-388)

AN INTRODUCTION TO THE COMPUTER

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Transcription:

. Chapter 1 Introduction to Computers and Programming www.raparinweb.com M hiwa ahmad aziz 1

Ch 1 - Introduction to Computers and Programming Hardware Terminology Main Memory Auxiliary Memory Drives Writing Algorithms Using Pseudo code Programming Language Code The Compilation Process for Non-Java Programs Object Code Portability Java Virtual Machine The Compilation Process for Java Programs History of Java 2

Hardware Terminology Computer system = all of the components shown below. 3

Hardware Terminology I/O = input and output devices Input examples: keyboard, mouse, scanner. Output examples: monitor (screen), printer. CPU = the computer's "brain." Synonyms: central processing unit processor microprocessor popular CPUs: Intel Core 2 Quad Intel Core i7 AMD Phenom II AMD Athlon 64 4

Main Memory When a computer performs calculations, it often needs to save intermediate results. It saves those intermediate results in the main memory storage area. Main memory is often called RAM (Random Access Memory). Memory contains storage boxes, and each storage box contains a piece of information. For example, if a program stores the word Emu, it uses six storage boxes: one for the first half of E, one for the second half of E, one for the first half of m, one for the second half of m, etc. 5

Main Memory Each of the eight storage boxes used to store Emu is a byte. Computers don't understand the alphabet. They only understand 0 s and 1 s. So computers map each alphabet character to a series of sixteen 0's and 1's. For example, the letter E is 00000000 01000101. So in storing the letter E, main memory actually stores 00000000 01000101. Each of the 0's and 1's is called a bit. And each of the eight-bit groupings is a byte. The capacity (size) of memory is described in terms of number of bytes. RAM capacities in a typical computer range from 1 GB (gigabyte) to 8 GB. RAM is volatile data is lost when power is turned off. Address 50,000 50,001 50,002 50,003 50,004 50,005 Memory Contents E m u 6

Vocabulary Hardware - the "machinery" - computer equipment - the CPU, the monitor, the keyboard, the mouse, the external speakers, the scanner, the printer, etc. The physical, touchable parts of a computer system. Software - the program instructions that make the computer do something, such as word processing, database management, games, etc. Your Java programs will be your software. Program - a listing of instructions (code) for the computer to follow written in some programming language. For this course, these instructions will be written in the language of Java. Network - a hardware and software data communication system. Usually a group of computers that are linked to share memory and programs. Control Unit - the unit inside of the CPU which "directs the traffic" - makes decisions. It performs the functions of fetch, decode, execute, and store. Machine Language - the lowest level of computer languages where instructions are given by numeric code. High Level Language - a computer language which is easily read by humans - the code consists of English-like words where each statement corresponds to several machine language instructions. 7

Vocabulary Compiler - converts the source code of a program to machine language placing the result in an object code file. Interpreter - converts a program one line at a time into machine language. Bit - the representation of a 1 or 0 designating power ON or power OFF. A binary digit. Byte - 8 bits. Kilobyte - approximately 1000 bytes (1024 bytes). Megabyte - approximately 1,000,000 bytes (1,048,576 bytes). Gigabyte - approximately a billion bytes (1,073,741,824 bytes). Format/Initialize - to prepare a storage device (diskette or hard disk) for receiving information for a system. The storage device is said to be formatted (into areas called sectors and tracks) when its space has been divided and organized into areas that can be quickly controlled by the system for storage and access. 8

The Mechanics of Creating a Java Program Java Program: a set of instructions for the computer to follow. The source code. Data: data for the Java program. Java Compiler: translates the program from Java to a language that the computer can understand. Compilers differ by make of machine and operating systems. Byte Code Program: the compiler translates Java into a language called byte-code. Byte code is the machine language for a hypothetical computer called the Java Virtual Machine. Byte Code Interpreter: the interpreter translates each instruction of byte code into instructions that the computer in use can execute. Machine Language: is the language the computer in use understands. 9

Writing Algorithms Using Pseudocode A program is a set of instructions that can be used to solve a problem. The first step in writing a program is writing a draft of your program where your focus is on the basic logic, not the specific details. The draft should include instructions that are coherent and logically correct, but there's no need to worry about missing minor steps or misspelling words. Such a draft program is referred to as an algorithm. For example, a Scrambled eggs recipe is an algorithm. Algorithms are written with pseudo code similar to regular programming code except that precise syntax (words, grammar, punctuation) isn't required. Example: Write an algorithm that finds the average miles per hour value for a given car trip. Sample input starting location = 100 ending location = 200 x=vt starting time = 2:00 ending time = 4:00 10

Programming Language Code A programming language is a language that uses specially defined words, grammar, and punctuation that a computer understands. Some of the more popular programming languages are VisualBasic, C++, and Java. Example: Write Java code that finds the average miles per hour value for a given car trip. Initially, programming language code might be harder for you to understand than pseudo code. But after you gain experience with a programming language, you may become so comfortable with it that you're able to skip the algorithm pseudo code step and start coding with the programming language directly. However, for larger programs, I recommend that you do not skip the algorithm pseudo code step. Why? 11

The Compilation Process for Non-Java Programs After writing a program, you'll normally want to have a computer perform the tasks specified by the program. Getting that to work is normally a twostep process: 1) Perform a compile command, 2) Perform a run command. When you perform a compile command, you tell the computer to translate the program's programming language instructions to a binary format (all 0's and 1's). When you perform a run command, you tell the computer to read the binary-format instructions and perform the tasks specified by them. The computer contains a special program called a compiler that's in charge of the compilation process. If you submit programming language instructions to a compiler, the compiler translates them into binary-format instructions. More formally, if you submit source code to a compiler, the compiler compiles the source code and produces object code as the result. Source code is the formal term for programming language instructions. Object code is the formal term for binary-format instructions. 12

The Compilation Process for Non-Java Programs source code (programming language instructions) Programmers write this. Compilers compile source code into object code. object code (binary instructions) Computers run this. 13

The Compilation Process for Java Programs Java source code bytecode object code Java compilers compile source code into bytecode. When a Java program is run, the JVM translates bytecode to object code. 14

Java language features Features instructions Sensitive to Big and small letters for example while is keywords but WHILE is not keywords Each command end with ;. the maximum length of an instruction is 255 characters. Each command can be written in a few lines. Each line can be written in several commands. Description of the * / and / * are placed or after the / / is written 15

Variable and Data types in Java A variable is a named memory location which temporarily stores data that can change while the program is running. Variables of different types occupy different amounts of memory space and are described as having different sizes. Variable Value will change over time For naming From combined Letters a to z or A to Z, Underlined, Numbers. The first character can t be a number and may not use reserved words. Acceptable names count test sum s_1 Unacceptable names 1test high!there grade.1.pcx 16

Java reserved keywords The Java programming language has total of 50 reserved keywords which have special meaning for the compiler and cannot be used as variable names. Following is a list of Java keywords in alphabetical order, click on an individual keyword to see its description and usage example. 17

Variable and Data types in Java Of the eight primitive data types in Java, the four most commonly used are:double, int, boolean, and char. When you learn about objects, you will discuss the differences between primitives and objects. 18

19

Integer and Double This type is numerical value Boolean This type is tow value true and false Boolean type is used for comparison Char For saving the character like 'a', 'b',..., 'y', 'z' is used String For saving Names such as Names of the students: Ali Array An array a collection of data that have the same type. Object Can have every type in java 20

Define the variables Data Type Variable name int a, b; float x, y; char z; There are many ways to give Value for a variable When defining int x=12, y=8; char ch1= a, ch2= b ; float m=11.5; After defining with (=) int s, n ; float f1; s=n=0; f1=13.28; 21

constants are value that there are in program But unlike variables do not change. Variables are defined as constants But before that type placed keyword final placed. final float final boolean final int Invalid instructions pi=3.14; debug = true; id= 12345; pi=3.1445; id=1265; constants debug=false; 22

Operators Operators are symbols that do Certain acts Such as +, * Arithmetic Operators + - * / % ++ -- Int x, y =10; x = y++ ; Int x, y =10 ; x= ++y ; Int m,x =10, y=15 ; m= ++x + y++ ; Relational operators < <= ==!= >= > Logic operators (Boolean) &&! x y X && y X y! x F F F F T F T F T T T F F T F T T T T F Combinatorial operator -= += *= /= %= x + = y => x = x + y 23

Priority operators in general Operator ( ) Highest Priority ++ - -.!. * /. %. + -. < > <= >=. = =!=. &&..?. = += - = / =... lowest Priority 24

Operand with the smaller type converted to the Operand is Greater type. Short s ; Int i ; Float f ; Double d ; Result = (s / i) + (f * d) + (f i) Conversion of type Int x = 10; Float y, m = 3.14 Y = (float) x ; X = (int) m ; int double float but Missing some numbers. double 25

Consider these examples: 26

Sample A small program public class (class name) Declaration class } { } { public static void main(string[] args ) instaction program...... declaration methood main Public class first { public static void main ( String[] args) { System.out.println( java is a powerful program ); System.out.print( let s go to learn java programing ); } } 27