Dart Programming Language (Variables, Data Types)

Hello, today we will give a general introduction to the Dart programming language.

Dart is an open source programming language developed by Google.

. . .

Features:

  • Development can be done on web, server, Android,IOS and IOT(Internet of Things) devices using Dart language.
  • It’s a object-oriented Laguage. So everything is an object(including null) that inherits form Object class.
  • Variables are defined with different data types according to the data.
  • Each program must contain a main function “main()”.

. . .

Advantages of Dart:

  • It’s flexible, easy to learn, has a syntax similar to C, C#, Java languages.
  • With its “Hot Reload” feature, it allows to see the changes in the application instantly.
  • With “Async-await”, it provides an asynchronous working environment when an asynchronous structure is needed.
  • With the AOT(Ahead Ot Time) compiler(unlike JIT(Just In Time)) it provides performance because it precompiles the source code and translates it quickly into machine language.
  • It performs fast compilation process for the web with dart2js, a JavaScript compiler.

. . .

Variables and Data Types:

The first thing to do to perform an operation is to store that data. When you want to do the operation, it is necessary to recall the data from the memory. The recall job here is called “Variable”. In other words, the definitions we have made to keep the data we process in the programming language in the memory of the computer.

There are a few important points to consider when defining variables:

  • Only English characters are used, spaces are not used,
  • The definition does not start with numbers,
  • The same name cannot be defined more then once in the same blog (class, function, etc.)
  • Program language terms(if, else, while etc.) cannot be used.

. . .

Let’s examine the data types in order:

1. var: It’s the definition used when we do not know or need to specify the variable type.

 var name = "name"; 
 var number = 2;

2. int: It’s the definition that takes integer expressions between 263   and 263 -1 , where they are kept.

int x = 5;
int counter = 10;

3. double: It is the type of variable in which decimal numbers are expressed.

 double x = 5;   // 5 is actually 5.0. 
 double y = 5.2;

4. String: It is the type of variable in which text expressions are kept.

 String name = "Hello word!"; 

Some important points about strings are as follows:

=>>> Used with “” or ‘’.

 String name1 = "Hello"; 
 String name2 = 'Hello'; 

=>>> “+” Sign is used in the concatenation of strings.

 String text1 = "Hello";
 String text2 = ' Word!';
 String texts = text1 + text2;  
 print(texts);

=>>> Proper names are separated by “‘ “or” \ “. (\ = ALT +? Or OPTION +?)

  String text1 = "Emral's files";
  String text2 = 'Emral\s files';
  String text3 = "Emral\s files"; //  INCORRECT!!
  String text4 = 'Emral's files'; //  INCORRECT!!

=>>> The value of a variable is used in a String with “$ {}”.

  int num = 5;
  String x = "five";
  String text = "Emral's files number: ${num} (${x})";
  print(text);    //  =>>> Emral's files number: 5 (five)

5. bool:  Are variables where decision expressions are kept where the result is “true” or “false”.

  bool selection = true;
  print(selection);     // =>>> true
 
  bool example = 5<2;
  print(example);       // =>>> false

6. dynamic: It is the type of variable that can take any value (String, int, double, bool), which is used when the type of a variable is desired to be changed during execution.

  dynamic exampleString="İlkDeğer";
  dynamic exampleInt=5;
  dynamic exampleList=[10];
  print(exampleList.toString());  // =>>> [10]

We can sample the types of variables we have learned so far as in the diagram below.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.