You are on page 1of 50

CHAPTER 1 INTRODUCTION TO COMPUTER SYSTEM

Learning Outcome
At the end of this chapter, student should be able to:
Describe the basic of computer component (A1) Differentiate type of programming languages (C1) Compile and execute the sample given. Identify type of error (P3)

What is a Computer?
A computer is a machine that performs computations, logical operations, or more generally, data manipulation according to some prescribed sequence of instructions called a computer program.

The physical components of a computer are termed hardware and the programs software.

The Hardware
The major hardware components:

The central processing unit (CPU) Primary or random access memory (RAM) Secondary or long term memory Input and output devices (I/O devices)

The Central Processing Unit


The CPU does: the computing the processing the bulk of the work Important components of the CPU: arithmetic and logic unit (ALU) control unit (CU) clock

The Central Processing Unit


The ALU performs calculations, billions per second The CU controls or coordinates which calculations the ALU performs The CPU clock determines how frequently the computer hardware executes instructions. Asystemshardwarecomponentsare synchronized with the clock. Every time the clock ticks, another hardware action occurs.

Primary or Random Access Memory


How Data is Stored binary format asequenceof0sand'1scalledbits.
ASCII encoding: aisrepresentedby10000110 bisencodedas01000110 A sequence of eight bits is called a byte.

Where Data is Stored


When the CPU executes a program, the program instructions, along with relevant data, are stored in primary memory.

Primary memory is also known as random access memory (RAM) because data may be retrieved or accessed in random, rather than sequential, order.

Where Data Is Stored


You can conceptualize RAM as a collection of storage cells or boxes, each capable of holding just a single byte of information. A unique number, or memory address, identifies each such storage cell.

Secondary Memory
Long term Permanent storage Secondary memory devices: hard disks tapes CDs flash memory sticks.

Secondary Memory
The programs that you use every day such as word processors, spreadsheets, and games are permanently stored on secondary storage devices. Compared to RAM, secondary memory is, in general, cheaper (per bit), slower, larger, electromechanical rather than electronic, and persistent: secondary memory devices do not lose their values when you turn off the computer.

Input/Output Devices
Standard input devices: keyboards mouses joysticks stylus pens cameras microphones Output devices: monitors printers speakers

Categories of Computers and Computer Software


Computers are classified into two:
A special-purpose computer A general-purpose computer

Special-Purpose Computers
Is a computer designed for a particular function, executing the same stored set of instructions whenever requested. For example
microwave ovens washing machine medical diagnostic equipment

General-Purpose Computers

Is a computer that can be used for solving many different types of problems. Available in many sizes and a wide range of capabilities. Can be classified as follows:
1. Microcomputers a. Laptop computers b. Desktop computers c. Workstations 2. Minicomputers 3. Mainframe computers 4. Supercomputers

Microcomputers

Sometimes referred to as a personal computer (PC), is one that can be placed on a desktop or carried from room to room. The smallest microcomputers are known as laptop computers or notebook computers. Desktop computers are compact microcomputer systems that fit on a desk and are designed for use by individuals. A workstation is the largest type of microcomputer and is generally used in scientific and engineering applications.

Minicomputers
More powerful and more expensive than microcomputers. Are smaller and cheaper compared to mainframes. Also can be server, which is used for managing internal company networks or Web sites. Server computers are specifically optimized to support a computer network enabling users to share files, software, peripheral devices (such as printers), or other network resources.

Mainframe Computer
The largest computer, a powerhouse with massive memory and e extremely rapid processing power. It is used for very large business, scientific or military application where a computer must handle massive amounts of data or many complicated processes.

Supercomputer
Is highly sophisticated and powerful computer that is used for tasks requiring extremely rapid and complex calculations with hundreds of thousands of variable factors. Used in many areas of scientific research, weather prediction, aircraft design, nuclear weapon and so on.

Computer Software

Application Software
Refers to programs that are developed to solve some specific problems. There are two types of application software:

application program to solve special classes of problems Application programs that you can write to solve your own problems.
word processing database programs spreadsheets graphic programs

Examples of application software:


System Software
Refers to programs that make the computer usable and accessible to the developers and programmers of applications software. Examples of system software:
Operating systems Language translator Linker Loader Preprocessors

Programming Languages
Programming Language is an agreed upon format of symbols that allow a programmer to instruct a computer to perform certain predefined tasks. Provide features to support the data processing activities, which include declaring variables, evaluating numeric expressions, assigning values to variables, reading and writing data to devices, looping and making decisions.

a. Machine Languages
Is the natural language of a computer. Does not need to translate and is ready for immediate execution. Machine language instruction is a binary string of 0s and 1s.
010 1 1000 0001 0000 1100 0000 0001 0000

Are machine-dependent - each computer type has its own machine language. Programs written in machine languages are not portable because programs written in for one type of computer cannot be run on another type

Assembly Languages
Consists of English-like abbreviations. Easier to understand.
L 1, GROSSPAY S 1, TAX ST 1, NETPAY

Program written in assembly languages cannot be directly processed by a computer. Must use language translators, called assemblers, to convert them to machine code. Disadvantages:
In general, each assembly language instruction corresponds to one machine language instruction. Therefore, the programs written in them are lengthy.

Because of variations in assembly languages, programs written using them are not portable.

High-Level languages

Instructions are quite English-like, and a single instruction can be written to correspond to many operations at the machine level. For example, the assembly language program can be written in high-level languages as follows:
Netpay = gross pay tax

Are easier to learn than machine or assembly languages. Have to be converted to machine languages before they can be executed using compilers, system software that translates a source program into an almost executable object program

For example:
COBOL developed in the 1960s for business transactions. FORTRAN developed for mathematic calculations. Pascal - is a structured high-level language. C is designed to support only procedure-oriented programming. Popular language for developing system applications such as operating system and compilers. Java is an object-oriented language. C++ - is extension of C programming language that support object oriented programming and procedureoriented approach.

Programs
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.
26

Popular High-Level Languages


Java (We use it in the book) COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code) Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by Microsoft) Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C)
27

Compiling Source Code


A program written in a high-level language is called a source program. Since a computer cannot understand a source program. Program called a compiler is used to translate the source program into a machine language program called an object program. The object program is often then linked with other supporting library code before the object can be executed on the machine.
Source File

Compiler

Object File

Linker

Excutable File

28

Compiling Source Code


You can port a source program to any machine with appropriate compilers. The source program must be recompiled, however, because the object program can only run on a specific machine. Nowadays computers are networked to work together. Java was designed to run object programs on any platform. With Java, you write the program once, and compile the source program into a special type of object code, known as bytecode. The bytecode can then run on any computer with a Java Virtual Machine (a software that interprets Java bytecode).
Java Bytecode Java Virtual Machine Any Computer

29

Operating Systems
The operating system (OS) is a program that manages and controlsacomputersactivities. You are probably using Windows 98, NT, 2000, XP, or ME. Windows is currently the most popular PC operating system. Application programs such as an Internet browser and a word processor cannot run without an operating system.
User

Application Programs

Operating System

Hardware

30

Why Java?
The answer is that Java enables users to deploy applications on the Internet for servers, desktop computers, and small hand-held devices. The future of computing will be profoundly influenced by the Internet, and Java promises to remain a big part of that future.
Java Java

is a general purpose programming language. is the Internet programming language.


31

ExamplesofJavasVersatility
Standalone Applet:

Application: TicTacToe

TicTacToe SelfTest Web site Computing: Cell phones

Servlets: Mobile

32

Java, Web, and Beyond


Java can be used to develop Web applications. Java Applets Java programs that run from a Web Browser Applets use a modern graphical user interface with buttons, text fields etc. to interact with users on the web and process their request. Java Servlets and JavaServer Pages Application on server. Run from a web server to generate dynamic Web pages. Example: self-test website Java can also be used to develop applications for handheld devices such as Palm and cell phones

33

JavasHistory
James Gosling and Sun Microsystems Originally called Oak Java, May 20, 1995, Sun World HotJava
The first Java-enabled Web browser

Early History Website:

http://java.sun.com/features/1998/05/birthday.h tml
34

The Java Language Specification, API, JDK and IDE


The Java language specification is a technical definition of the language that includes the syntax and semantics of the Java programming language. Application Program Interface (API) contains predefined classes and interfaces for developing Java programs. Three editions of the Java API: Java 2 Standard Edition (J2SE), Java 2 Enterprise Edition (J2EE) and Java 2 Micro Edition (J2ME).
35

JDK Versions
JDK 1.02 (1995) JDK 1.1 (1996) major changes Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998) Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000) Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002) Java 2 SDK v 1.5 (a.k.a JDK 1.5, 2004)

36

JDK Editions
Java Development Toolkit (JDK) consists of a set of separate programs for developing and testing Java programs.

Java Standard Edition (J2SE)


J2SE can be used to develop client-side standalone applications or applets.

Java Enterprise Edition (J2EE)


J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages.

Java Micro Edition (J2ME).


J2ME can be used to develop applications for mobile devices such as cell phones.

This book uses J2SE to introduce Java programming.


37

Java IDE Tools


A Java development tool is software that provides an integrated development environment (IDE) for rapidly developing Java programs, such as: Borland JBuilder NetBeans Open Source by Sun Sun ONE Studio by Sun MicroSystems Eclipse Open Source by IBM Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. Just enter source code in one window or open an existing file in a window, then click a button, menu item, or function key to compile and run the program.
38

A Simple Java Program


Example 1.1
//This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

39

Creating, Compiling, and Running Programs


Create/Modify Source Code
Source code (developed by the programmer) Saved on the disk

package chapter1; public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

Source Code

Byte code (generated by the compiler for JVM to read and interpret, not for you to understand)

Compile Source Code i.e., javac Welcome.java


If compilation errors stored on the disk

Method Welcome() 0 aload_0 Method void main(java.lang.String[]) 0 getstatic #2 3 ldc #3 <String "Welcome to Java!"> 5 invokevirtual #4 8 return

Bytecode

Run Byteode i.e., java Welcome

Result

40
If runtime errors or incorrect result

Anatomy of a Java Program


Comments Package Reserved words Modifiers Statements Blocks Classes Methods The main method
41

Comments
In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */.

42

Package
The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. Forte compiles the source code in Welcome.java, generates Welcome.class, and stores Welcome.class in the chapter1 folder.

43

Reserved Words
Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words in Example 1.1 are public, static, and void. Their use will be introduced later in the book.

44

Modifiers
Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs. Modifiers are discussed in Chapter 6, ObjectsandClasses.
45

Statements
A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;).

46

Blocks
A pair of braces in a program forms a block that groups components of a program.

public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

Class block Method block

47

Classes
The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. The mystery of the class will continue to be unveiled throughout this book. For now, though, understand that a program is defined by using one or more classes.

48

Methods
What is System.out.println? It is a method: a collection of statements that performs a sequence of operations to display a message on the console. It can be used even without fully understanding the details of how it works. It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message.
49

main Method
The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. The main method looks like this: public static void main(String[] args) { // Statements; }
50

You might also like