02.Dart Programming
02.Dart Programming
Dart Programming
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, inspired by other programming languages such as
Java, JavaScript, C#, and is Strongly Typed.
Since Dart is a compiled language so you cannot execute your code
directly; instead, the compiler parses it and transfer it into machine
code.
It supports most of the common concepts of programming languages
like classes, interfaces, functions, unlike other programming languages.
Dart language does not support arrays directly. It supports collection,
which is used to replicate the data structure such as arrays, generics,
and optional typing.
1. void main() {
2. for (int i = 0; i < 5; i++) {
3. print('hello ${i + 1}');
4. }
5. }
Data Type
Dart is a Strongly Typed programming language.
It means, each value you use in your programming language has a type
either string or number and must be known when the code is compiled.
The most common basic data types used in the Dart programming
language.
Simple Examples
Example 3:
void main() {
int num1 = 10; //declaring number1
int num2 = 3; //declaring number2
// Calculation
int sum = num1 + num2;
int diff = num1 - num2;
int mul = num1 * num2;
double div = num1 / num2;
// It is double because it outputs number with decimal.
Output:
The sum is 13
The diff is 7
The mul is 30
The div is 3.3333333333333335
Example 4:
// Main function
void main() {
// Creating a list
var myList = [121, 12, 33, 14, 3];
Output:
Smallest value in the list : 3
Largest value in the list : 121