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

Basics of Programming

A computer program is a set of instructions that helps perform tasks to produce desired outputs from given inputs. Programming concepts include algorithms, source code, compilers, data types, variables, conditionals, arrays, loops, functions, and classes. Programming languages can be low-level like machine language or assembly, or high-level like C, C++, Java, and Python. The basic operations in any programming environment are input, output, arithmetic operations, conditionals, and looping. C programming was created for systems programming and remains widely used today. The phases of a C program are editing code, preprocessing, compiling, and linking.

Uploaded by

ssssmailnat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Basics of Programming

A computer program is a set of instructions that helps perform tasks to produce desired outputs from given inputs. Programming concepts include algorithms, source code, compilers, data types, variables, conditionals, arrays, loops, functions, and classes. Programming languages can be low-level like machine language or assembly, or high-level like C, C++, Java, and Python. The basic operations in any programming environment are input, output, arithmetic operations, conditionals, and looping. C programming was created for systems programming and remains widely used today. The phases of a C program are editing code, preprocessing, compiling, and linking.

Uploaded by

ssssmailnat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Basics of Programming

Contents
• What is Computer Programming
• Programming Concepts
• Types Of Computer Programming Languages
• Basic Operations of a Programming Environment
• Introduction to C Language
• Different Phases in programming
What is Computer Programming?
• Computer Programming is a set of instructions, that helps the
developer to perform certain tasks that return the desired output for
the valid inputs.

Given below is a Mathematical Expression.

• Z = X + Y, where X, Y, and Z are the variables in a programming language.


• If X = 550 and Y = 450, the value of X and Y are the input values that are called
literals.
• We ask the computer to calculate the value of X+Y, which results in Z, i.e. the
expected output.
Contd..
Basic Programming Concepts
#1) Algorithm: It is a set of steps or instruction statements to be followed to
accomplish specific tasks. A developer can design his algorithm to achieve
the desired output.
For Example, a recipe to cook a dessert. The algorithm describes the steps to be
followed for completing a specific task, but it does not say how to achieve any of the
steps.

#2) Source code: Source code is the actual text that is used to construct the
program using the language of choice.
For Example, it is mandatory to have the main method in Java and the text used is as
shown below.

public static void main(String arg[]) {


//Steps to be performed
}
Contd..
#3) Compiler: Compiler is a software program that helps in converting the
source code into binary code or byte code, also called machine language,
that is easy for a computer to understand, and can be further executed using
an interpreter to run the program.

#4) Data Type: Data used in the applications can be of a different type, it can
be a whole number (integer), floating-point (decimal point numbers),
characters or objects. For Example, double currency = 45.86, where double is
a data type used for storing numbers with decimal points.

#5) Variable: Variable is a space holder for the value stored in the memory
and this value can be used in the application. For Example, int age = 25,
where age is a variable.
Contd..
#6) Conditionals: Knowledge of how to use a certain condition, such that a set of
code should execute only if a certain condition is true. In case of a false condition,
the program should exit and should not continue the code further.

#7) Array: Array is the variable that stores elements of a similar data type.
Knowledge of using an array in coding/programming will be a great benefit.

#8) Loop: Loop is used to execute the series of code until the condition is true. For
Example, in Java, loops can be used as for loop, do-while, while loop or enhanced
for loop.
Contd..
#9) Function: Functions or methods are used to accomplish a task in programming,
a function can take parameters and process them to get the desired output.
Functions are used to reuse them whenever required at any place repeatedly.

#10) Class: Class is like a template that contains state and behavior, which
corresponding to programming is field and method. In Object-Oriented languages
like Java, everything revolves around Class and Object.
Essentials of a Programming Language
• Just like any other language we use to communicate with others, a
programming language is a special language or a set of instructions to
communicate with computers.
• Each programming language has a set of rules (like English has
grammar) to follow and it is used to implement the algorithm to
produce the desired output.
Types of Computer Programming Languages
Computer Programming language can be divided into two types
1. Low-level Language
2. High-level Language
#1) Low-level Language
• Hardware dependent
• Difficult to understand
Low-level Language can be further divided into two categories,
• Machine Language: Machine dependent, difficult to modify or program, For
Example, every CPU has its machine language. The code written in machine
language is the instructions that the processors use.
• Assembly Language: Each computer’s microprocessor that is responsible for
arithmetic, logical and control activities needs instructions for accomplishing such
tasks and these instructions are in assembly language. The use of assembly
language is in device drivers, low-level embedded systems, and real-time
systems.
Machine Language
• The representation of a computer program which is actually read and understood
by the computer.
• A program in machine code consists of a sequence of machine instructions.
• Instructions:
• Machine instructions are in binary code
• Instructions specify operations and memory cells involved in the operation
Example:

Operation Address

0010 0000 0000 0100

0100 0000 0000 0101

0011 0000 0000 0110


The Multiplication Program in Machine Language
Assembly Language
• A symbolic representation of the machine language of a specific processor.
• Is converted to machine code by an assembler.
• Usually, each line of assembly code produces one machine instruction (One-to-
one correspondence).
• Programming in assembly language is slow and error-prone but is more efficient in
terms of hardware performance.
• Mnemonic representation of the instructions and data

Example:
Load Price
Add Tax
Store Cost
High-level language
• A programming language which use statements consisting of English-like
keywords such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language instructions (one-to-
many correspondence).
• Much easier to program than in assembly language.
• Data are referenced using descriptive names
• Operations can be described using familiar symbols
• Example:
Cost := Price + Tax
Contd..
#2) High-level Language
• Independent of hardware
• Their codes are very simple and developers can read, write and debug as they are
similar to English like statements.
High-level Language can be further divided into three categories.
1. Procedural Language: Code in the procedural language is a sequential
step by step procedure, that gives information like what to do and how
to do. Languages such as Fortran, Cobol, Basic, C, and Pascal are a few
examples of procedural language.
2. Non-procedural Language: Code in non-procedural language specify
what to do, but does not specify how to do. SQL, Prolog, LISP are a few
examples of non-procedural language.
3. Object-oriented Language: Use of objects in the programming language,
where the code is used to manipulate the data. C++, Java, Ruby, and
Python are a few examples of Object-oriented language.
Basic Operations of a Programming Environment
Five basic elements or operations of programming are listed below:
• Input: Data can be input using the keyboard, touch screen, text editor, etc. For Example,
to book a flight, the user can enter his login credentials and then select a departure date
and return date, the number of seats, starting place and destination place, Name of
Airlines, etc, from desktop, laptop or mobile device.
• Output: Once authenticated, and upon receiving the request to book the tickets with the
mandatory inputs, a confirmation of booking for the selected date and destination will
be displayed on the screen, and a copy of the tickets and invoice information is sent to
the user’s registered email id and mobile number.
• Arithmetic: In case of flight booking, update of the number of seats booked and those
seats need some mathematical calculations, further name of the passenger, no. of seats
reserved, date of journey, journey start date, and starting place, destination place, etc.
should be filled into the airlines server database system.
• Conditional: It is required to test if a condition is satisfied or not, based on the condition,
the program may execute the function with parameters else it will not get executed.
• Looping: It is required to repeat /perform the task until the condition holds. Types of
loops can be While loop, Do-while loop, For loop.
C - Orientation
• Created in 1972 to write operating systems (Unix in particular)
• By Dennis Ritchie
• Bell Labs
• Evolved from B
• Can be portable to other hardware (with careful design – use
Plauger’s The Standard C Library book)
• Built for performance and memory management – operating
systems, embedded systems, real-time systems, communication
systems
C - Standardization
• 1989 - ANSI and ISO -> Standard C
• 1999 - C99
• 2011 - C11
Later Languages
• 1979 - C++ by Bjarne Stroustrap also at Bell
• Object orientation
• 1991 - Java by Sun
• Partial compile to java bytecode: virtual machine code
• Write once, run anywhere
• Memory manager – garbage collection
• Many JVMs written in C / C++

• 1991 - Python by Guido van Rossum


Program
makes input
#include <stdio.h>
and output available
to us
header
int main(void)
{
printf("This is my first C program.\n");
return(0);
}

open and close braces mark statements


the beginning and end
Contd..

printf("This is my first C program.\n");


return(0);

Prints the message


This is my first C program.

Ends the program Ends the line


C Program Phases
• Editor - Used for coding by programmer
• Compiling
• Preprocess – expand the programmer’s code
• Compiler – create machine code for each file
• Linker – links with libraries and all compiled objects to make
executable file
• Running the executable file:
• Loader – puts the program in memory to run it
• CPU – runs the program instructions
Compiler
• The compiler is the translator program software.
• This software can translate into its equivalent machine language
program.
• The compiler compiles a set of machine language instructions for
every program in a high-level language.
Linker
• The linker is used for the large programs in which we can create some
modules for the different task.
• When we call the module, the whole job is to link to that module and
program is processed.
• We can use a linker for the huge software, storing all the lines of
program code in a single source file.
Interpreter
• The interpreter is the high-level language translator.
• It takes one statement of the high-level language program and translates it into
machine level language instruction.
• Interpreter immediately executes the resulting machine language instruction.
• The compiler translates the entire source program into an object program, but
the interpreter translates line by line.
Top Computer Programming Languages
Programming Language Popularity Practical Applications of Languages

Java 1 Desktop GUI application (AWT or Swing api), Applets, online shopping
sites, internet banking, jar files for secured file handling, enterprise
applications, mobile applications, gaming software.

C 2 Operating Systems, Embedded systems, Database management


systems, Compiler, gaming and animation.

Python 3 Machine learning, Artificial Intelligence, Data analysis, face detection


and image recognition Software.

C++ 4 Banking and trading enterprise software, virtual machines and


compilers.
Visual Basic .NET 5 Windows services, controls, control libraries, Web applications,
Web services.

C# 6 Desktop applications like a file explorer, Microsoft office


applications like Word, Excel , Web browsers, Adobe Photoshop.

JavaScript 7 Client side and server side validations, DOM handling,


developing web elements using jQuery (JS library).

PHP 8 Static and dynamic websites and applications, Server side


scripting.

SQL 9 Querying database, CRUD operations in database programming,


creating a stored procedure, triggers, database management.

Objective – C 10 Apple’s OS X, iOS operating system and APIs, Cocoa and Cocoa
Touch.

You might also like