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

Week 9

Programming Languages

Uploaded by

Saravanan V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Week 9

Programming Languages

Uploaded by

Saravanan V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

Information Technology Fundamentals

Week 8
CS 1101

1
Introduction to
Programming Languages

2
Programmers (or coders) are individuals who work
with one or more programming languages to write
code that is used as the basis for the applications
that you use on your computing device.
Program Sequence
A program is just a sequence of instructions for your
computer to perform.
 For example, you might want to add two user-entered
numbers together and display the sum on the screen.
 In plain English, the program might look something like
this:
1) Clear the current display.
2) Ask the user for the first number and store that number for
subsequent use.
3) Ask the user for the second number and store that number for
subsequent use.
4) Retrieve the two stored numbers and add them together.
5) Display the result.
Cont.
 In designing a program, we have to consider how input, processing, and output are all
clearly defined.
1) Clear the current display.
2) Output to the screen the instructions for the operation.
3) Ask the user for the first number.
4) Verify that the entered value is a number:
a) If it is, proceed.
b) If it is not, remind the user what the valid range is and prompt again.
5) Store that number for subsequent use.
6) Ask the user for the second number.
7) Verify that the entered value is a number:
a) If it is, proceed.
b) If it is not, remind the user what the valid range is and prompt again.
8) Store that number for subsequent use.
9) Retrieve the two stored numbers and add them together.
10) Display the result.
Using a Flow Chart
 As this restatement of the
program is getting
significantly more complex,
it might help to visualize it.
 You could view the sequence
as a graphical flow chart to
help understand the
processes.
Features of Programming Code
■ The main routine calls some subroutines. Each routine is completed by an
"End Routine" statement. This means (for example) when the program reaches
the last step of the main routine, it closes rather than flowing through to try to
execute the first subroutine.
■ When a subroutine completes, it can return to the point in the main
routine from where it was called, and the main routine continues execution.
Note that when we use structures such as this, we have to be very careful not
to create infinite loops in the code by mistake.
■ There is a conditional statement (IF) that means part of the code only
executes when certain conditions are true or false.
■ There are variables to store data input by the user.
Features of Programming Code
■ There are functions (such as "sum" and "write") that we can assume are provided as
features of the programming language. We don't need to code how to add two numbers
together or write output to the display screen.
■ There is a user interface that the program interacts with (prompting for input and
displaying output).
■ It contains comments, preceded by the ' character. Comments are part of the programming
code that are not executed by the computer but that help the developer read and maintain
the code.
Programming Languages

Having created the logic behind your program, you


must then code it using the appropriate
programming language.
It’s important to consider what programming
language to use.
The choice that you make will be determined by
many factors, including:
■ What type of program you are writing.
■ How experienced you are as a programmer.
■ What type(s) of device(s) your users will be using.
Programming Languages
There are many programming languages to choose
from, but the most popular are:
■ Java
■ Python
■ JavaScript
■ C++
■ C#
■ PHP
■ GO
■ Ruby
Programming Languages
Programming languages can also be divided into a
number of broad categories:
◦ Compiled.
◦ Interpreted
◦ Query languages.
Compiled Programming Languages
 When you write a program using a compiled programming language, you must transform
the code to an executable binary before it can run.
 Compiling converts the source code that you wrote to machine code.
 Machine code is the instructions converted to strings of ones and zeros for the CPU to
process.
 A compiled program generally runs quickly (compared to interpreted code).
 However, a compiled program tends to be platform (CPU) specific; to run on other
platforms, you must recompile the source code for the new platform.
 The following languages are compiled:
■ C++
■ C#
■ COBOL
■ PASCAL
Interpreted Programming
Languages
 When you write code with an interpreted language, you do not need to
compile the program.
 It runs within the context of an interpreter, which converts the code into
machine code at runtime.
 This means that the program probably runs more slowly but also means it is
likely that you can run the program on any platform for which you have an
interpreter.
 Examples of interpreted languages include scripting languages, such as
JavaScript, Perl, and Python.
Query Languages
Query Languages: Code written in a query
language, such as Structured Query Language
(SQL), is designed to retrieve specific records from a
dataset.
The code does not need to be compiled
Assembly Language
 An assembly language represents machine code in human-readable text.
 An assembly language is typically specific to a particular hardware
architecture.
 This is in contrast to compiled, interpreted, and query languages which you
can use to write code that can be run on a number of platforms, assuming
you have an appropriate compiler or interpreter.
 Even though it is in humanreadable text, assembly code is very difficult to
follow and is only really used by specialists trying to solve a very particular
problem with an application.
 You would not choose an assembly language to start your new development
project.
Markup Languages
A markup language is not a programming language but a
means of making data in a document accessible to a
program.
 A markup language, such as the HyperText Markup Language
(HTML) or eXtensible Markup Language (XML), defines a
series of nested tags that describe the structure and/or
meaning of the tag contents.
Markup Languages
 The tags tell a client application (such as a browser) how to structure the document:
◦ html—this top-level parent element identifies the type of document. All the other tags
are nested within this one.
◦ body—indicates the main part of the content as a page to show to the client. HTML files
can also have head sections, which would not be shown as part of the page display.
◦ h1—indicates that the content is a heading level.
◦ p—indicates the content is a paragraph-level block.
◦ a—indicates that the content links to another resource. In the example, this is an email
address, but it could be another section of the page or another file or a page on another
web server.

Note that each tag has a start and close element.


Programming Concepts
Inorder to write a program using a particular
programming language, you must first understand
the structure and syntax of the language.
Most programming languages share similarities in
their structure and syntax, but it is important to use
the specific syntax correctly as any errors will cause
the code not to compile or run.
Programming Concepts- Identifiers
An identifier is used in a program to access a
program element, such as a stored value, class,
method, or interface.
For example, you might assign the identifier
FirstName to a stored value that contains a user’s
first name.
In essence, an identifier is a label for something
within your program.
If your identifier stores data, then it will be either a
variable or a constant.
Variables
A variable contains a value that can change during
the execution of the program. This value might be a
text string, a number, or any other data type.
For example, the following pseudocode declares our
FirstName variable to store a string value with an
initial value Andy, then sets it to a value from a data
store:
Constants
A constant is a specific identifier that contains a
value that cannot be changed within the program.
For example, you might want to store the numerical
value for the screen dimensions or resolution.
Programming Concepts- Containers
 Container can be used as a term for a special type of identifier that can reference multiple
values (or elements).
 One example of a container construct is a simple array. For example, say that you want your
program to store a list of user names who have logged on to the computer in the last 24
hours.
 You would declare the array with the data type of the values it will contain and the number
of elements or "rows" that the array can contain:
declare Logons(9) as string Note: Elements in the array are counted from
zero so the Logons(9) array contains up to 10
elements.

 The following pseudocode would add a value to the first element in the array:
Logons(0) = find LastLoggedOnUser and get FirstName
Programming Concepts- Containers
 In the previous example, the array has a single dimension.
 Arrays can also be multidimensional, which you can visualize as like a table with multiple
columns.
 Note that all the elements must be the same data type.
 For example, the following code creates a two-dimensional array: declare Logons(9,1) as
string
 The following pseudocode would populate the first "row" in the array, with the first name
going into the first column and the logon time into the second:
Logons(0,0) = find LastLoggedOnUser and get FirstName
Logons(0,1) = find LastLoggedOnUser and get Time

 One of the limitations of the array container type is that it cannot be resized. Most
programming languages support container types called vectors that can grow or shrink in
size as elements are added or removed.
Programming Concepts- Branches
 Your program runs from the start to the end unless you instruct it to
deviate from this path.
 One way of doing so is to create a branch; this is an instruction to your
computer to execute a different sequence of instructions.
 You use branches to control the flow within your program.
 For example, you might create a branch based on a condition. We saw
this in our earlier example when we verified a number had been entered
correctly. If it had, then something happened, and if it had not, then
something else happened. This is a conditional branch.
 For example, in the following pseudocode, the value of a variable called
DisplayNumber is compared to 25. If DisplayNumber is greater than 25,
then a variable called Count is incremented by 1. If DisplayNumber is less
than 25, no action occurs and the variable Count remains the same.
If DisplayNumber > 25 Then
Count = Count+1
End If
Programming Concepts- Loops
 Loops are similar to branches in as much as they deviate from the initial program path according to
some sort of logic condition.
 However, with a loop, you instruct your computer to perform, or repeat, a task until a condition is
met.
 For example, you might create a loop that continues until a certain amount of time has elapsed or
until a counter reaches a certain level. Then, a predetermined action might occur, depending upon
what you want. In the following example, the program loops around until the value of i is 5.
 Then the program proceeds to the next statement.
For i = 1 to 5
print i
Next
 As well as "For" structures, loops can also be implemented by "While" statements:
Do While i <= 100
i=i+1
print i
Loop
Programming Concepts- Operators
 Looping and branching structures depend on logical tests to determine whether to continue the loop
or the branch to follow.
 A logical test is one that resolves to a TRUE or FALSE value. You need to be familiar with basic
comparison operators:
■ == is equal to (returns TRUE if both conditions are the same).
■ != is not equal to.
■ < less than.
■ > greater than.
■ <= and >= less than or equal to and greater than or equal to.
 You might also want to test more than one condition at the same time. The logical operators are as
follows:
■ AND—if both conditions are TRUE, then the whole statement is TRUE.
■ OR—if either condition is TRUE, then the whole statement is TRUE.
■ XOR—if either condition is TRUE but not both, then the whole statement is TRUE.
 You can also use the negation operator NOT to reverse the truth value of any statement.
Programming Concepts- Procedures and
Functions
 Both procedures and functions enable you to create segments of code that you will reuse.
 In our earlier example, we used a function to check that the user had entered a number.
 The key difference, in programming terms, between a procedure and a function is that the latter can return a value
to whatever called it, whereas a procedure cannot.
 For example, the following is a procedure:
Verify subroutine {
verify user input is number
if FALSE, call Display Instructions subroutine
return
}
 Whereas, the following is a function:
Verify function {
IsNumber = verify user input is number
return IsNumber
}
 In the function, the value of IsNumber, which will either be TRUE or FALSE, is returned to the main program for
some further processing.
Programming Concepts- Comments
 As noted above, it is important to use comments in code to assist with maintaining it.
 A comment line is ignored by the compiler or interpreter.
 A comment line is indicated by a special delimiter, such as double forward slash (//), hash
(#), or apostrophe (').
Object-Oriented Programming
Object-Oriented Programming
• A class serves as a prototype, or template, for individual
objects in the class.
• Classes contain properties that are the attributes or characteristics that
objects can hold as fields or private variables that other programs cannot
change or access directly. Properties can be used as another way to access a
field publicly.
• Classes also contain methods (also known as procedures, functions, routines,
or subroutines) that are the behaviors or operations that the object can
perform.
• For example, a method takes input, generates output, and manipulates data.
• Methods are used to make changes to attributes.
• Objects are the specific models built from the class
templates. These objects work with each other to make
the computer program function.
Object-Oriented Programming
 Objects can have :
◦ attributes (fields)
◦ properties
◦ methods
Attributes
Attributes are values and data types that define the object.
The attributes are stored within the object as fields or private
variables.
Other programs cannot access or change the fields directly. They
must call a particular method (see below) to do that.
Methods
 Methods define what you can do to an object.
 For example, a Customer object might have a ChangeAddress method.
 When another part of the program calls the ChangeAddress method, it also passes a string
(hopefully containing a well-formatted address) to the object because that is what the
method expects.
 The object's code receives this string, checks that it can be used as a valid address, and
updates its Address field.
 The object might then have another method (PrintAddress) allowing another part of the
program to find out what the current value of the Address field is.
Properties
Properties represent an alternative way of accessing a field
publicly.
Using a method might be regarded as quite a "heavyweight"
means of doing this, so properties allow external code to ask the
object to show or change the value of one of its fields.
Scripting Languages
We learned earlier that some of the interpreted
programming languages are scripting languages.
You can also make a distinction between the general
purpose interpreted scripted languages, such as
JavaScript or Perl and scripting languages, such as
Windows Command Prompt, Windows PowerShell, or
Linux Bash.
These languages support the automation and
configuration of a particular operating system.
Scripting Languages
A script is a smaller piece of code than a program.
 A script is generally targeted at completing a specific task,
whether that task is based within a web-based application or is
used by a network administrator to perform a repetitive
administrative task.
 While a program usually provides some sort of unique
functionality, anything a script does could usually be
performed manually by a user.
 Writing scripts is a good place to learn the basics about
programming.
 They are usually simpler to learn, require no compiling, and are
well documented on the Internet, should you require guidance
or samples.
Batch Files
Batch files are a collection of command-line
instructions that you store in a .CMD file.
You can run the file by calling its name from the
command line, or double-clicking the file in File
Explorer.
Generally, batch file scripts run from end to end and
are limited in terms of branching and user input.
Batch Files
VBScript
VBScript is a scripting language based on Microsoft’s
Visual Basic programming language.
It provides similar functionality to JavaScript. VBScript
is often used by network administrators to perform
repetitive administrative tasks.
With VBScript, you can run your scripts from either
the command line or from the Windows graphical
interface. Scripts that you write must be run within a
host environment.
Windows 10 provides Internet Explorer, IIS, and
Windows Script Host (WSH) for this purpose.
VBScript
Application Platforms and Deliver
Application Platforms and Delivery
Once you have written and tested your code, you
need to package it as an executable or script for
deployment to the hosts that will run the software.
There are many different ways of packaging and
deploying software applications.
Single-platform Software
Some software applications are written to run under
a particular operating system (and sometimes a
particular version or set of versions of an OS).
The software is written using a development
environment suitable for that OS.
The developer writes the application in program
code using a particular programming language.
 When the application is compiled, it gets converted
to machine code that can run (or execute) in the
target OS environment.
Single-platform Software
This development model can be referred to as
single-platform software.
Because this model produces software that is
optimized for a particular platform, it can perform
better and be simpler to check for errors than
crossplatform software.
The drawback is that "porting" the software to a
different platform (from Windows OS to Android for
instance) can be very difficult.
Single-platform Software
Cross-platform Software
 Software written for PCs and laptops ("desktop"
applications) is being supplemented with software written
for touch-based mobile devices and operating systems.
 These are often referred to as apps. There is usually plenty
of interoperability between desktop and mobile platforms.
 For example, you could create a document in Microsoft
Word on a PC and send it to someone to view on their
smartphone.
Cross-platform Software
 Another trend is for applications to be accessed over the web, often
using a "cloud" deployment model.
 When software is run from a web server as a web application, it can
usually support a wide range of different types of client operating
systems and devices. Usually the only client required is a compatible web
browser.
 This sort of cross-platform development is complicated by the different
hardware interfaces for different computing devices.
 The interfaces supported by keyboard and mouse input devices for PCs
and laptops do not always work well with the touchscreens used by
smartphones.
Cross-platform Software
 The wide range of display sizes, orientations, and resolutions are another
factor making cross-platform design challenging.
 There can be performance problems when software is written for a
"platform independent" environment, such as a Java virtual machine, rather
than code run natively by the OS.
 Compatibility issues can also affect web applications as different browser
vendors can make slightly different interpretations of open standards that
result in applications not working correctly in particular browsers or browser
versions
Application Delivery Methods
 A traditional PC-type software application is installed locally to the
computer's hard drive.
 When launched it executes within the computer's memory and is processed
by the local CPU.
 Any data files manipulated by the application can also be stored on the local
disk, though usually in a user folder rather than the application folder.
 For security reasons ordinary users should not be able to modify application
folders.
 A locally installed application such as this does not need network access to
run, though obviously the network has to be present if the application
makes use of network features.
Application Delivery Methods
 For some enterprises, this locally installed model presents performance and
security issues.
 Another option is for the application to be installed to a network server and
executed on that server.
 Client workstations access the application using a remote terminal or
viewer.
 The most successful example of this kind of application virtualization model
is Citrix XenApp.
 Locating the application and its data files on a server is easier to secure and
easier to backup. This model also does not require that client hosts be able
to access the Internet.
 The drawback is that if there is no local network connection or the local
network is heavily congested, users will not be able to use the application.
Integrated Development
Environments
 IDE stands for integrated development environment,
which is a set of programming tools that work together to
make a programmer's job easier.
 It's important to remember that an IDE can make it easier
to spot mistakes,
• Most IDEs include the following components:
 Text or code editor
 Project windows for convenience
 Compiler
 Debugger
 Language-specific features
IDE Example
Application Programming Interface
The term API stands for application programming
interface.
Programmers use APIs to connect or communicate
with databases, operating systems, and other
services.
APIs define both protocols and tools for
programmers to build applications.
A web APIs is a specific type of API that governs the
access points of a web server that receives requests
and sends responses.
How Do APIs Work?
Who Uses APIs?
 Ifyou want to build an app for a particular operating
system, such as Windows or macOS, that operating
system will already have a large number of APIs that
you can draw from in order to make things easier.
 For example, let's say you're building an app and
want it to be able to take a photo using the phone's
camera. That isn't something you need to code from
scratch.
 The operating system should already have an API for
this function which you can insert into your app and
save yourself a great deal of time and effort.
Questions?

You might also like