0% found this document useful (0 votes)
30 views

Week1 - Introduction To Computer and Programming Language

This document provides an introduction to computer programming and programming languages. It discusses the goals of understanding programming, computer architecture, and programming language levels. It defines programming and computers, describing their basic hardware and software components. It explains how programs are executed by computers, stored in memory, and translated between machine language, assembly language, and high-level languages like Java. It also describes common programming errors and sets up the reader to write and run a simple Java program.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Week1 - Introduction To Computer and Programming Language

This document provides an introduction to computer programming and programming languages. It discusses the goals of understanding programming, computer architecture, and programming language levels. It defines programming and computers, describing their basic hardware and software components. It explains how programs are executed by computers, stored in memory, and translated between machine language, assembly language, and high-level languages like Java. It also describes common programming errors and sets up the reader to write and run a simple Java program.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

INTRODUCTION TO

COMPUTER AND
PROGRAMMING
LANGUAGE

WEEK 1
GOALS
 To understand the activity of programming
 To learn about the architecture 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
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.
WHAT IS A COMPUTER?
Hardware
– the physical, tangible parts of a computer
– keyboard, monitor, disks, wires, chips, etc.

Software
– programs and data
– a program is a series of instructions

 A computer requires both hardware and software


 Each is essentially useless without the other
COMPUTER
ORGANIZATION
Computer System Organization

Hardware Software
•CPU •System Programs
•Main Memory (RAM) •Application Programs
•Secondary Storage
•I/O Device
CPU
Brain of the computer, most expensive,
the faster computer.
CPU components– control unit, program
counter, register instruction, arithmetic
logic unit, accumulator.
RAM
Temporary memory, volatile, directly
connected to the CPU, using memory
cells unit.
SECONDARY STORAGE
Provides permanent storage for
information.
Examples of secondary storage:
 Hard disks
 Floppy disks
 Zip disks
 CD-ROMs
 Tapes.
RAM VS. SECONDARY
STORAGE
Primary memory Secondary Storage
 volatile  Nonvolatile
 Fast  Slow
 Expensive  Cheap
 Low capacity  Large capacity
 Works directly with the  Not connected directly to
processor the processor
INPUT DEVICES
OUTPUT DEVICES
This Photo by Unknown Author is licensed under CC BY-SA
 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.
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 software
 word processors, Spreadsheets, Web
browsers, games
Computers store all information digitally:
 numbers
 text
 graphics and images
 video
 audio
 program instructions

In some way, all information is digitized -


broken down into pieces and represented
as numbers
For example, every character is stored as a
number, including spaces, digits, and
punctuation
Corresponding upper- and lower-case letters
are separate characters
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.
STORAGE
CAPACITY
Every memory device has a
storage capacity, indicating
the number of bytes it can
hold
Capacities are expressed in
various units:
PROGRAMMING
LANGUAGES
Levels of programming language:
 machine language
 assembly language
 high-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
Machine language
101101100110 011011010

Assembly language
iload intRate
bipush 100
if_icmpgt intError

High-level language
if (intRate > 100) . . .
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
Language Description Examples Translator
Machine Instruction in 0 and 1 0111000011000001 None
bits

Assembly Instruction in LOAD 3 assembler


mnemonic code STOR 4
ADD

High-level Similar to human sum = 4 + 3; Compiler & interpreter


language, FORTRAN,
COBOL, Pascal, C, C+
+, Java…
PROGRAM ERRORS
It is common for programmer to make mistake in a program.
Three kinds of errors:
 Syntax errors
 Runtime errors
 Logic errors
SYNTAX ERRORS
Grammatical mistakes in a program
 The 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);
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
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
Eg.
 System.out.print("Hello");
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
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
SETTING UP YOUR
COMPUTER TO USE JAVA
Understand files and folders/directories
Install JDK
 Java SE Download Page
- http://www.oracle.com/technetwork/java/javase/downloads/index.html
Download JDK (ver 5.0 or above))
Documentation
API specification
Tutorial

Install jGRASP IDE


 http://www.jgrasp.org/
 (download ver 2.0 or above)
 Other IDE Netbeans, Eclipse, BlueJay
Processing a Java Program
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.

You might also like