introduction to computer and java
DESCRIPTION
chapter 1TRANSCRIPT
![Page 1: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/1.jpg)
AN OVERVIEW OF COMPUTERS &
PROGRAMMING LANGUAGES
AN OVERVIEW OF COMPUTERS &
PROGRAMMING LANGUAGES
![Page 2: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/2.jpg)
GOALS To understand the activity of programming
To learn about the components of computers
To learn about level of programming languages
To become familiar with your computing
environment and your compiler
To compile and run your first Java program
To recognize 3 types of errors
![Page 3: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/3.jpg)
What is Programming?
Computer programming the art and science of designing and writing
computer programs.
Computer program a sequences of instructions written in a
programming language to achieve a task/to solve a problem.
![Page 4: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/4.jpg)
What is a computer? Hardware
the physical, tangible parts of a computerkeyboard, monitor, disks, wires, chips, etc.
Softwareprograms and dataa program is a series of instructions
A computer requires both hardware and software
Each is essentially useless without the other
![Page 5: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/5.jpg)
Computer System Organization
Hardware•CPU•Main Memory (RAM)•Secondary Storage•I/O Device
Software•System Programs•Application Programs
Computer Organization
![Page 6: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/6.jpg)
Hardware Components of a Computer
![Page 7: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/7.jpg)
Hardware Components of a Computer – motherboard
processor chipadapter cards
memory chips
memory slots
motherboard
Expansionslots for adapter cards
![Page 8: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/8.jpg)
Hardware Components of a Computer
CPU Brain of the computer, most expensive, the faster computer.CPU components– control unit, program counter, register instruction, arithmetic logic unit, accumulator.
RAMTemporary memory, volatile, directly connected to the CPU, using memory cells unit.
![Page 9: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/9.jpg)
SECONDARY STORAGE
•Provides permanent storage for information.•Examples of secondary storage:
•Hard disks•Floppy disks•Zip disks•CD-ROMs•Tapes.
Hardware Components of a Computer
![Page 10: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/10.jpg)
RAM vs Secondary Storage Primary memory
volatileFast Expensive Low capacity Works directly with the processor
Secondary StorageNonvolatileSlow Cheap Large capacity Not connected directly to the processor
![Page 11: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/11.jpg)
INPUT DEVICES
Sheet-fed
Hardware Components of a Computer
![Page 12: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/12.jpg)
OUTPUT DEVICES
Hardware Components of a Computer
![Page 13: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/13.jpg)
CPU and Main Memory
CentralProcessing
Unit
MainMemory
Chip that executes program commands
Eg.Intel Pentium 4Sun ultraSPARC III
Primary storage area for
programs and data that are in
active use
Synonymous with RAM
![Page 14: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/14.jpg)
Secondary Memory Devices
CentralProcessing
Unit
MainMemory
Floppy Disk
Hard Disk
Secondary memorydevices providelong-term storage
Information is movedbetween main memoryand secondary memoryas needed
Hard disksFloppy disksUSB drivesWritable CDsWritable DVDsTapes
![Page 15: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/15.jpg)
Input / Output Devices
CentralProcessing
Unit
MainMemory
Floppy Disk
Hard Disk
Monitor
Keyboard
I/O devices facilitateuser interaction
Monitor screenKeyboardMouseJoystickBar code scannerTouch screen
![Page 16: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/16.jpg)
Software
In contrast to hardware, software is an abstract, intangible entity.
Software can be categorized as system or application software (refer next slide)
It consists of program and data to be used to perform certain tasks
A program is a sequence of simple steps and operations, stated in a precise language that the hardware can interpret
The process of programming involve algorithm design & coding.
![Page 17: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/17.jpg)
Software Categories System Software
Systems programs keep all the hardware and software running together smoothly
The most important system software is the operating system (OS) controls all machine activities provides the user interface to the computer manages resources such as the CPU, memory & I/O Windows XP, Unix, Linux, Mac OS
Application Software generic term for any other kind of softwares word processors, Spreadsheets, Web browsers, games
![Page 18: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/18.jpg)
Algorithm
Algorithm refers to the strategy to solve a problemIt is a clear step by step sequence of instructions that describes how to accomplish a certain task.2 ways can be used to represent algorithm:a) pseudocode
- using english-like-phrases to describe the algorithmb) flowchart
-using diagrams that employ the symbol to describe the algorithm.
![Page 19: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/19.jpg)
Coding
Algorithm need to be translated into computer language so that it can be executedCoding refers to the process of expressing algorithm in a programming languageThe product of coding is a program.The act of carrying out the instructions contained in a program is called program execution
A computer program is stored internally as a series of binary numbers known as the machine language of the computer
![Page 20: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/20.jpg)
Digital Information Computers store all information digitally:
numberstextgraphics and imagesvideoaudioprogram instructions
In some way, all information is digitized - broken down into pieces and represented as numbers
![Page 21: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/21.jpg)
Representing Text Digitally For example, every character is stored as a
number, including spaces, digits, and punctuation
Corresponding upper and lower case letters are separate characters
H i , H e a t h e r .
72 105 44 32 72 101 97 116 104 101 114 46
![Page 22: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/22.jpg)
p. 4.15 Fig. 4-16 Next
The ASCII data set 128 characters (0 until 127) Character A in ASCII 01000001
American Standard Code for Computer InterChange (ASCII)
![Page 23: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/23.jpg)
Binary Numbers Once information is digitized, it is represented
and stored in memory using the binary number system
A single binary digit (0 or 1) is called a bit A byte consists of 8 bits. Each byte in main memory resides at a
numbered location called its address.
![Page 24: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/24.jpg)
Memory
24
Main memory is divided into many memory locations (or cells)
927892799280928192829283928492859286
Each memory cell has a numeric address, which uniquely identifies it
![Page 25: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/25.jpg)
Storing Information
25
927892799280928192829283928492859286
Large values arestored in consecutivememory locations
1001101010011010Each memory cell stores a set number of bits (usually 8 bits, or one byte)
![Page 26: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/26.jpg)
Main Memory
![Page 27: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/27.jpg)
Storage Capacity Every memory device has a storage capacity,
indicating the number of bytes it can hold
Capacities are expressed in various units:
27
KB 210 = 1024
MB 220 (over 1 million)
GB 230 (over 1 billion)
TB 240 (over 1 trillion)
Unit Symbol Number of Bytes
kilobyte
megabyte
gigabyte
terabyte
![Page 28: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/28.jpg)
Language Levels Levels of programming language levels:
machine languageassembly languagehigh-level language
Each type of CPU has its own specific machine language
The other levels were created to make it easier for a human being to read and write programs
28
![Page 29: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/29.jpg)
Programming Languages
Machine language101101100110 011011010
Assembly languageiload intRatebipush 100if_icmpgt intError
High-level languageif (intRate > 100) . . .
![Page 30: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/30.jpg)
Programming Languages Each type of CPU executes instructions only in a
particular machine language
A program must be translated into machine language before it can be executed
A compiler is a software tool which translates from high level language into a specific machine language
An assembler translates from assembly language into a specific machine language
30
![Page 31: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/31.jpg)
Language Description Examples Translator
Machine Instruction in 0 and 1 bits
0111000011000001
None
Assembly Instruction in mnemonic code
LOAD 3
STOR 4
ADD
assembler
High-level Similar to human language, FORTRAN, COBOL, Pascal, C, C++, Java…
sum = 4 + 3; Compiler & interpreter
Programming Languages
![Page 32: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/32.jpg)
The Java Programming Language
Created by Sun Microsystems, Inc. introduced in 1995 and it's popularity has
grown quickly since Rich library Platform-independent ("write once, run
anywhere") or architecture-neutral
![Page 33: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/33.jpg)
Java Translation
The Java compiler translates Java source code into a special representation called bytecode
Java bytecode is not the machine language for any traditional CPU
Another Java software tool, called an interpreter (or Java Virtual Machine (JVM)) , translates bytecode into machine language and executes it
33
![Page 34: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/34.jpg)
Java Translation
34
Java sourcecode (program)
Machinecode
Javabytecode
Bytecodeinterpreter
Javacompiler
![Page 35: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/35.jpg)
Portability After compiling a Java program into byte-code, that
byte-code can be used on any computer with a byte-code interpreter and without a need to recompile.
Byte-code can be sent over the Internet and used anywhere in the world.
This makes Java suitable for Internet applications.
![Page 36: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/36.jpg)
Becoming Familiar with your Computer to use Java
Understand files and folders/directories Locate the Java compiler/ Install J2SE Set path & Java class path Write a simple program (later) Save your work Compile & run Use Dos Command Prompt or IDE
![Page 37: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/37.jpg)
A DOS Command Window
![Page 38: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/38.jpg)
An Integrated Development Environment
![Page 39: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/39.jpg)
File Hello.java1 public class Hello
2 {
3 public static void main(String[] args)
4 {
5 // display a greeting in the console window
6 System.out.println("Hello, World!");
7 }
8 }
![Page 40: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/40.jpg)
Java Program Elements A Java program is made up of class definitions. A class definition must contains a header and a
body. A class contains zero or more methods A method is a named section of code that also has
a header & bodyA method contains program statements
Single-line (starts with //) and multi-line (enclosed by /* and */) comments are used to document the code
![Page 41: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/41.jpg)
Java Program Structure
41
public class Hello{
}
// comments about the class
class header
class body
//Comments can be placed almost anywhere
![Page 42: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/42.jpg)
Java Program Structure
42
public class MyProgram{
}
// comments about the class
public static void main (String[] args){
}
// comments about the method
method headermethod body
![Page 43: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/43.jpg)
Compiling and Running
Type program into text editor Save (file name must be similar to class name) Open Dos Window Change directory to saved file directory Compile into byte codesjavac Hello.java
Execute byte codesjava Hello
![Page 44: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/44.jpg)
Hello.java
javac
Hello.class
java
Class Loader
Processing a Java Program
![Page 45: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/45.jpg)
Class Loader A Java program typically consists of several pieces
called classes. Each class may have a separate author and each is
compiled (translated into byte-code) separately. A class loader (called a linker in other programming
languages) automatically connects the classes together and loads the compiled code (bytecode) into main memory.
![Page 46: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/46.jpg)
JVM
Create/modify source code
Source code
Compile source code
Byte code
Run byte code
Output
Syntax errors
Runtime errors or
incorrect results
Creating a Java Program…
![Page 47: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/47.jpg)
Errors
It is common for programmer to make mistake in a program.
Three kinds of errorsSyntax errorsRuntime errorsLogic errors
![Page 48: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/48.jpg)
Syntax Errors
Grammatical mistakes in a programThe grammatical rules for writing a program are very
strict
The compiler catches syntax errors and prints an error message.
Example: using a period where a program expects a semicolon System.out.print("..."),System.out.print("Hello);
![Page 49: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/49.jpg)
Runtime Errors
Errors that are detected when your program is running, but not during compilation
When the computer detects an error, it terminates the program and prints an error message.
Example: attempting to divide by 0
![Page 50: Introduction To Computer and Java](https://reader036.vdocuments.us/reader036/viewer/2022062307/555c3f0cd8b42a0b038b4cfe/html5/thumbnails/50.jpg)
Logic Errors
Errors that are not detected during compilation or while running, but which cause the program to produce incorrect results
Example: an attempt to calculate a Fahrenheit temperature from a Celsius temperature by multiplying by 9/5 and adding 23 instead of 32
E.gSystem.out.print("Hell");