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

Programming Languages(1)(2)(2)

Uploaded by

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

Programming Languages(1)(2)(2)

Uploaded by

pranav.garg1006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Programming Languages

Introduction to Computational Thinking 2


Lesson Outcomes

At the end of this lesson, you should be able to:


• Distinguish between the low-level machine-language and high-level
programming language

• Describe the two ways of translating high-level language program code to


machine-language instructions

• State the main features of high-level programming languages: C, C++, Java,


Python

Introduction to Computational Thinking 3


Programming Language

Programming is the process of


• implementing a representation of the solution for the computer to execute
• taking an algorithm and encoding it using certain programming language

Programming language
• a medium through which programmer may give instructions to a computer

A programming language
• must support certain control constructs and data types needed to implement algorithms

• Sequential processing • Numbers such as integer and


real (floating point)
Examples • Decision-making selection
• Characters and Strings
• Iteration for repetitive execution

Introduction to Computational Thinking 4


Types of Programming Language

The computer has its own language.

• machine-language that is specific to the type of


computer processor

• consists of a set of machine instructions and


data objects that are encoded in ‘0’ and ‘1’
binary format

• error-prone for human to code a program


directly using the computer’s machine codes

Introduction to Computational Thinking 5


Types of Programming Language (Cont’d)

High-level programming languages that are more user-friendly are hence invented.

• provide abstraction from the internal operating detail of the computer

• enable the programmers to focus on solving the problem

• make the process of developing the algorithm simpler

C
Most programs used in modern computers

• coded in high-level programming languages, such as


C, Java, Python, etc.

Introduction to Computational Thinking 6


Program Translations

translated into instruct the


High-level low-level computer to perform
is first which then
program code machine-language the necessary
instructions operations

Two approaches for program translation:

• interpretation

• compilation

Introduction to Computational Thinking 7


Program Translations: Interpretation Approach

Interpretation approach

• uses a program known as interpreter

• reads one high-level code statement at a time

- immediately translates and executes the statement before processing the next one

• examples: Python, R, and JavaScript

Introduction to Computational Thinking 8


Program Translation: Compilation Approach

Compilation approach
• uses a program called compiler
• reads and translates the entire high-level language program
(source) code into its equivalent machine-language instructions in an
executable file
• the resulting machine-language instructions can then be
executed directly on the computer when the program is launched
• examples: C and C++

It is also possible to use the combination of both translation techniques

• example: Java

Introduction to Computational Thinking 9


Interpreter vs. Compiler

Interpreter
Compiler
• very portable across different
computing platforms • program runs very fast AFTER
compilation
• produces results almost
immediately • smaller in code size after compilation
• easy to debug • must compile the entire program
before execution
• program executes more slowly
• needs to be re-compiled if to be used
• useful for implementing dynamic, on different computing platforms
interactive features, such as
those used on web pages • used in large and sophisticated
software applications when speed is
of the utmost importance

Introduction to Computational Thinking 10


Programming Language: C

C
C language THE
• originally developed to help implement the Unix operating system
• allow for direct access of, and manipulation of, the underlying computer’s
hardware PROGRAMMING
LANGUAGE
It is a compiled language
• the program code (i.e. source code) needs to be Examples of applications
compiled first, before it can be executed
• embedded systems development
Most suitable for applications • operating systems
• direct access to the computer’s hardware implementations
• fast real-time response • device drivers that control the
hardware inside the computer

Introduction to Computational Thinking 11


Programming Language: C++

C++ language
• an extension to the C language
• with additional support for Object-Oriented Programming (OOP)

In OOP
Examples of
• programs are designed based on objects that contain attributes
Applications
and behaviors
• programming is then focused on how the objects interact with • Video games
one another • Graphic User
- without the need to know the internal code detail of the object Interface (GUI)
based applications
C++ is a compiled language
• Latest operating
• used for applications that need high performance and are based systems design and
on object oriented software design principles implementation

Introduction to Computational Thinking 12


Programming Language: Python

Python language
• a relatively easy-to-learn programming language
• targeted for general purpose programming for applications that do
not need direct access to the computer’s hardware Examples of
Applications
It is an interpreted language
• Data science
• program code is hence portable across different computing platforms
• Web developments
Python interpreter converts and executes the Python program
statement one-by-one to the corresponding machine instructions
• provides instant feedback to the user at runtime
• very helpful for learning to program

Introduction to Computational Thinking 13


Programming Language: Java

Java language
• highly portable, general purpose language with Object-Oriented (OO)
methodological support

Designed to run as an interpreted language on a Java Virtual Machine (JVM) Examples of


• portable across different types of machines and devices Applications
• no direct access to the computer’s hardware • Mobile Apps
for Android
Combination of compiler and interpreter, as well as Just-in-time (JIT) compiler phones
• the source code (with file extension .java) is first compiled to Java bytecode
• Game
(with file extension .class)
development
• Java bytecode instruction is then interpreted by the JVM interpreter during
execution
• JVM may call the JIT compiler to compile some of the bytecode instructions at
runtime before they are executed, achieving better performance

Introduction to Computational Thinking 14


Programming Language: Examples of Source Code

Source Code of a C Program Source Code of a Java Program


#include <stdio.h> public class HelloWorld {
int main() public static void main( String[] args ) {
{ System.out.println("Hello, World!");
printf("Hello, World!"); System.exit( 0 ); //success
return 0; //success
C }
THE

} PROGRAMMING }
LANGUAGE

Source Code of a C++ Program Source Code of a Python Program


#include <iostream> print('Hello, World!')
int main()
{
std::count << "Hello, World!";
return 0;
}

Introduction to Computational Thinking 15


Programming Language for Internet

Webpage: a text document transferred over the internet and be displayed in a web browser,
such as Chrome, Safari, Firefox, and Internet Explorer (IE)

A web browser reads the webpage and composes it into visible or audible page(s).

Introduction to Computational Thinking 16


Programming Language for Internet (Cont’d)

The content of a webpage is commonly described by using the language HTML (Hypertext Markup
Language)

• a content-markup language uses symbols and phrases

• instructs the web browser to structure information for display or process

Introduction to Computational Thinking 17


Programming Language for Internet (Cont’d)

A webpage can be made to appear dynamic and interactive by adding scripts in language, such as
JavaScript.

Example: to prompt for user’s name in the webpage

Introduction to Computational Thinking 18


Programming Language for Internet (Cont’d)

PHP (PHP: Hypertext Pre-processor) is another script language

• dynamically generates html webpage before it is sent to the browser

• Example: contents that need to be composed based on user’s request

Introduction to Computational Thinking 19


Programming Language: Others

R language • an interpreted language


• used for statistical computing, such as data analysis
• provides extensive graphic plotting functions
- useful for displaying data trends

MATLAB • commonly used for developing science and engineering computation applications
language • an interpreted language used primarily for numerical computing
• supports many functions and libraries, such as matrix manipulation, plotting, and
visualization of data
Examples of types of computation:
• audio, video, and image related signal processing
• control systems

Introduction to Computational Thinking 20


Summary

Low-level machine-language executed directly by the computer


Two levels
can be High-level programming language that needs to be first
separated into translated to the machine-language for execution

Programming Classifications
Language Compiled language: Interpreted language:
C, C++ Python, JavaScript, R
Two ways of
translations Combination of both: Each language
Java provides different
Interpreter Compiler features that are
suitable for
translates and executes first translates the entire program’s statements into the different
each program’s statements corresponding machine instructions, before the requirements
one-by-one during run time computer is used to execute the machine instructions

Introduction to Computational Thinking 21


References for Images

No. Slide No. Image Reference


Monitor screen [Online Image]. Retrieved June 20, 2018 from
1 3
https://pixabay.com/en/monitor-screen-computer-speaker-2455524/.

Python logo [Online Image]. Retrieved June 20, 2018 from


2 6, 13, 15
https://www.python.org/static/community_logos/python-logo-master-v3-TM.png.

Java log [Online Image]. Retrieved June 20, 2018 from


3 6, 14, 15 http://www.oracle.com/us/technologies/java/java-licensing-logo-guidelines-
1908204.pdf.

By Annakoppad - Own work, CC BY-SA 4.0,retrieved June 20, 2018 from


4 8
https://commons.wikimedia.org/w/index.php?curid=48721101.

By Trewyy - Own work, CC BY-SA 3.0,retrieved June 20, 2018 from


5 8
https://commons.wikimedia.org/w/index.php?curid=18694958.

Introduction to Computational Thinking 22


References for Images

No. Slide No. Image Reference


Devcpp5110 [Online Image]. Retrieved June 20, 2018 from
6 9
https://pixabay.com/en/amd-cpu-processor-microprocessor-1310766/.

By Jeremy Kratz - https://github.com/isocpp/logos, Copyrighted free use, retrieved


7 10, 15
June 20, 2018 from https://commons.wikimedia.org/w/index.php?curid=62851110.

By W3C, CC BY 3.0, retrieved June 20, 2018 from


8 17
https://commons.wikimedia.org/w/index.php?curid=12736763.

Php Logo [Online Image]. Retrieved June 20, 2018 from


9 19
http://php.net/images/logos/new-php-logo.png.

Introduction to Computational Thinking 23

You might also like