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

Session 1 Intro and Data Types

The document provides an introduction to programming, specifically focusing on the Dart programming language, its data types, and key concepts such as algorithms and variables. It explains programming as a sequence of instructions for computers, the importance of programming languages, and the structure of Dart, including its core libraries and syntax. Additionally, it covers various data types supported by Dart, including numbers, strings, booleans, lists, and maps, along with variable declaration and constant keywords.

Uploaded by

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

Session 1 Intro and Data Types

The document provides an introduction to programming, specifically focusing on the Dart programming language, its data types, and key concepts such as algorithms and variables. It explains programming as a sequence of instructions for computers, the importance of programming languages, and the structure of Dart, including its core libraries and syntax. Additionally, it covers various data types supported by Dart, including numbers, strings, booleans, lists, and maps, along with variable declaration and constant keywords.

Uploaded by

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

Session 1

Main topics:
• Intro to programming
• Intro to dart language
• Data types in Dart
Intro to programming
- What is Programming?
In a simple answer, “Programming is the act of instructing
computers to carry out tasks.” It is often referred to as coding.
So then, what is a computer program? A computer program is a
sequence of instructions that the computer executes.
Computer in the definition above is any device that is capable of
processing code. This could be smartphones, ATMs,
Conditioners, Traffic lights, Servers to name a few.

- The Natural Language of the Computer


Machines have their natural language like humans do. Computers
do not understand the human language.
The natural language of computers is the binary code (1 and
0)
These represent two states: on (1) and off (0).
That is the natural language of electronic equipment. It would be
hectic for us as humans to communicate with the computer in
binary.
To communicate with machines who speak binary, we do so in a
language that’s closer to our own natural language. Such as
English, French, Swahili or Arabic. Programming languages are
close to our natural languages. But they are more structured and
must be thoroughly learned.
- What is Programming Language?
A programming language is a vocabulary and set of
grammatical rules for instructing a computer or computing
device to perform specific tasks.
The term programming language usually refers to high-level
languages, such as C, C++, Dart, Java, JavaScript, PHP, Swift...
Each language has a unique set of keywords (words that it
understands) and a special syntax for organizing program
instructions.

- So, the two important terms that we have used in the above
definition are:
• Sequence of instructions
• Computer Programming Language

To understand these terms, consider a situation when someone


asks you about how to go to a nearby KFC. What exactly do you do
to tell him the way to go to KFC?
You will use Human Language to tell the way to go to KFC,
something as follows ->
First go straight, after half kilometer, take left from the red light and
then drive around one kilometer and you will find KFC at the right.
Here, you have used English Language to give several steps to be
taken to reach KFC. If they are followed in the following sequence,
then you will reach KFC -
1. Go straight
2. Drive half kilometer
3. Take left
4. Drive around one kilometer
5. Search for KFC at your right side

Now, try to map the situation with a computer program. The above
sequence of instructions is actually a Human Program written in
English Language, which instructs on how to reach KFC from a
given starting point. This same sequence could have been given in
Spanish, German, Arabic, or any other human language, provided
the person seeking direction knows any of these languages.
Now, let's go back and try to understand a computer program,
which is a sequence of instructions written in a Computer
Language to perform a specified task by the computer. Following is
a simple program written in Dart programming Language --
The above computer program instructs the computer to print
"Hello,World!" on the computer screen.
A computer program is also called a computer software, which
can range from two lines to millions of lines of instructions.
Computer program instructions are also called program source
code and computer programming is also called program coding.
A computer without a computer program is just a dump box; it is
programs that make computers active.

- Algorithm
From programming point of view, an algorithm is a step-by-step
procedure to resolve any problem.
An algorithm is an effective method expressed as a finite set of
well-defined instructions.
Thus, a computer programmer lists down all the steps required to
resolve a problem before writing the actual code. Following is a
simple example of an algorithm to find out the largest number
from a given list of numbers
- In general, programming is nothing but a way to create
solutions to the problems we face in this world.
- What is Dart?
Dart is an open-source, general-purpose, object-oriented
programming language with C-style syntax developed by Google
in 2011. The purpose of Dart programming is to create a frontend
user interfaces for the web and mobile apps.
It is under active development, compiled to native machine code
for building mobile apps.
- Let’s dive in, after install dart on your machine refer to this
instructions, we can go through some fundamentals:

- dart:core library contains built-in types, collections, and other


core functionality for every Dart program.
- dart:core library automatically imports to every Dart
program.
- Dart is a single thread programming language like
'JavaScript'
- Dart source file extension is .dart
- Every Dart statement ends with a semicolon ;
- main() is the entry point of a Dart program. Every app or
program must have a top-level main function.
- Programming Sentence?
Any programming sentence - In Dart - has three main parts

Data Type Name = Value;

Ex:
Data Types
The Dart language supports the following types:

• Numbers (1, 2,… - 1.2, 468.654 - (-156) - 65489984984)


• Strings (‘Mohammed’ – ‘A’ – “‫)”اهال‬
• Booleans (true, false)
• Lists ( [1,2,3,4,5] )
• Maps ( <Name – Khaled>, <Age, 26>
Numbers
Numbers in Dart are used to represent numeric literals. The
Number Dart come in two flavors:-
• Integer − Integer values represent non-fractional values, i.e.,
numeric values without a decimal point. For example, the value
"10" is an integer. Integer literals are represented using
the int keyword.

• Double − Dart also supports fractional numeric values i.e. values


with decimal points. The Double data type in Dart represents a 64-bit
(double-precision) floating-point number. For example, the value
"10.10". The keyword double is used to represent floating point
literals.
Strings
Strings represent a sequence of characters. For instance, if you were to
store some data like name, address etc. the string data type should be
used.
The keyword String is used to represent string literals. String values are
embedded in either single or double quotes.
Boolean
The Boolean data type represents Boolean values true and false.
Dart uses the bool keyword to represent a Boolean value.
List and Map
The data types list and map are used to represent a collection of objects.
A List is an ordered group of objects. The List data type in Dart is
synonymous to the concept of an array in other programming languages.
The Map data type represents a set of values as key-value pairs.
Lists

Map
The Dynamic Type
Dart is an optionally typed language. If the type of a variable is not explicitly
specified, the variable’s type is dynamic.
Variables
A variable is “a named space in the memory” that stores values. In other
words, it acts a container for values in a program. Variable names are
called identifiers. Following are the naming rules for an identifier:
• Identifiers cannot be keywords.
• Identifiers can contain alphabets and numbers.
• Identifiers cannot contain spaces and special characters, except the
underscore (_) and the dollar ($) sign.
• Variable names cannot begin with a number.

Type Syntax
A variable must be declared before it is used.
Dart uses the var keyword to achieve the same. The syntax for
declaring a variable is as given below:
var name = 'Abdallah';
All variables in dart store a reference to the value rather than containing
the value. The variable called name contains a reference to a String object
with a value of 'Abdallah'.

Dart supports type-checking by prefixing the variable name with the data
type. Type-checking ensures that a variable holds only data specific to
a data type.
The syntax for the same is given below:
String name = 'Abdallah';
int num = 10;
Consider the following example:

All uninitialized variables have an initial value of null. This is


because Dart considers all values as objects. The following
example illustrates the same:
The dynamic keyword
Variables declared without a static type are implicitly declared as dynamic.
Variables can be also declared using the dynamic keyword in place of the
var keyword.

Final and Const


The final and const keyword are used to declare constants. Dart prevents
modifying the values of a variable declared using the final or const
keyword. These keywords can be used in conjunction with the variable’s
data type or instead of the var keyword.
The const keyword is used to represent a compile-time constant.
Variables declared using the const keyword are implicitly final.
Note: Only const variables can be used to compute a
compile time constant. Compile-time constants are
constants whose values will be determined at compile time

Thanks, Good Luck!

You might also like