Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

1 Introduction

Introduction to Programming 1 1
Objectives
At the end of the lesson, the student should be able to:


Identify the different components of a computer

Know about programming languages and their categories

Understand the program development life cycle and apply
it in problem solving

Introduction to Programming 1 2
Introduction
Computer Programming –written to instruct program to carry out specific task to solve
specific problem.
Algorithm-step by step procedure that accomplishes desired task
Programming-activity of communicating algorithms to computer.


Computer
– a machine that performs a variety of tasks according to specific
instructions


Two major components:
– Hardware

tangible part of the computer

composed of electronic and mechanical parts
– Software

intangible part of a computer

consists of data and the computer programs

Introduction to Programming 1 3
Basic Components of a
Computer : Hardware

CPU
– Central processing unit
– The processor is the “brain” of the computer
– It does the fundamental computing within the system
– Examples: Pentium, Athlon and SPARC.

Introduction to Programming 1 4
Basic Components of a
Computer : Hardware

Memory
– where data and instructions needed by the CPU to do its appointed
tasks can be found
– 2 Types:

Main Memory

Secondary Memory

Introduction to Programming 1 5
Basic Components of a
Computer : Hardware

Main Memory
– used to hold programs and data, that the processor is actively
working with.
– not used for long-term storage
– sometimes called the RAM (Random Access Memory).
– considered as volatile storage – means once the computer is turned
off, all information residing in the main memory is erased

Introduction to Programming 1 6
Basic Components of a
Computer : Hardware

Secondary Memory
– used to hold programs and data for long term use.
– Examples of secondary memory are hard disks and cd-rom.
– considered as non-volatile storage

Introduction to Programming 1 7
Basic Components of a
Computer : Hardware

Comparison between main memory and secondary memory

Introduction to Programming 1 8
Basic Components of a
Computer : Hardware

Input and Output Devices
– allows a computer system to interact with the outside world by
moving data into and out of the system
– Examples:

input devices: keyboards, mice and microphones

output devices: monitors, printers and speakers

Introduction to Programming 1 9
Basic Components of a
Computer : Software

Software
– a program that a computer uses in order to function
– kept on some hardware device like a hard disk, but it itself is
intangible
– data that the computer uses can be anything that a program needs


Programs
– act like instructions for the processor.

Introduction to Programming 1 10
Basic Components of a
Computer : Software

Some Types of Computer Programs
– Systems Programs
– Application Programs
– Compilers

Introduction to Programming 1 11
Basic Components of a
Computer : Software

Systems Programs
– Programs that are needed to keep all the hardware and software
systems running together smoothly
– Examples: Operating Systems like Linux, Windows, Unix, Solaris,
MacOS

Introduction to Programming 1 12
Basic Components of a
Computer : Software

Application Programs
– Programs that people use to get their work done
– Examples: Word Processor, Game programs, Spreadsheets

Introduction to Programming 1 13
Basic Components of a
Computer : Software

Compilers
– Translates computer programs to machine language
– Machine language

Language that your computer understands.

Introduction to Programming 1 14
Programming Languages

Programming Language
– a standardized communication technique for expressing instructions
to a computer
– Like human languages, each language has its own syntax and
grammar
– There are different types of programming languages that can be
used to create programs, but regardless of what language you use,
these instructions are translated into machine language that can be
understood by computers.

Introduction to Programming 1 15
Categories of Programming
Languages

High-level Programming Languages
–a programming language that is more user-friendly, to some extent
platform-independent, and abstract from low-level computer
processor operations such as memory accesses
– A programming statement may be translated into one or several
machine instructions by a compiler.
– Examples: Java, C, C++, Basic, Fortran

Introduction to Programming 1 16
Categories of Programming
Languages

Low-level Assembly Language
– Assembly languages are similar to machine languages, but they are
much easier to program because they allow a programmer to
substitute names for numbers
– Assemblylanguages are available for each CPU family, and each
assembly instruction is translated into one machine instruction by an
assembler program

Introduction to Programming 1 17
Program Development Life
Cycle

Basic steps in trying to solve a problem on the computer:

1. Problem Definition
2. Problem Analysis
3. Algorithm design and representation
(Pseudocode or flowchart)
4. Coding and debugging


Debugging
– The process of fixing some errors (bugs) in your program
Types of Errors

Compile-time error or syntax errors
– occur if there is a syntax error in the code.
– The compiler will detect the error and the program won't even
compile. At this point, the programmer is unable to form an
executable program that a user can run until the error is fixed.


Runtime Errors
– Compilers aren't perfect and so can't catch all errors at compile time.
This is especially true for logic errors such as infinite loops. This type
of error is called runtime error.
20
21
public class Hello
{
/**
* My first java program
*/
public static void main(String[] args) {
//prints the string "Hello world" on screen
System.out.println("Hello world!");
}
}

1. public class Hello- indicates the name of the class which is Hello. In Java, all code should be placed inside a class
declaration. We do this by using the class keyword. In addition, the class uses an access specifier public, which
indicates that our class in accessible to other classes from other packages (packages are a collection of classes). We
will be covering packages and access specifiers later.
Class identifier-hello

2. {- indicates the start of a block

3. The next three lines indicates a Java comment


A comment is indicated by the delimiters “/*” and “*/”. Anything within these delimiters are ignored by the Java compiler, and are
treated as comments.

1. public static void main(String[] args) {- indicates the name of one method in Hello which is the main method. The main method is
the starting point of a Java program. All programs except Applets written in Java start with the main method.(method modifier)

2. The next line is also a Java comment,


//prints the string "Hello world" on screen

3. System.out.println("Hello world!");- prints the text “Hello World!” on screen. The command System.out.println(), prints the
text enclosed by quotation on the screen.

The last two lines which contains the two curly braces is used to close the main method
and class respectively.
Statement-piece of programming action which must be terminated by a semi-colon(;).
Ex. System.out.print("Hello");

Block – a group of programming statement enclosed with brackets({})


Case Sensitivity-Java is case sensitive meaning a variable add is different from variable Add.
Program- is a sequence of instruction that is executed one after another usually in sequential manner.
Variables-use to store values
-called variable as you can change the value
-has name,type and value
Ex. int num1=1;
*note
-each statement is terminated with semi-colon.
-In multiple variable declaration, names are separated with commas.
-the symbol (=) is an assignment operator and used for assigning value to a variable.

22

You might also like