Thu, Dec 1, 2022
Read in 2 minutes
In this post we will take a look at what Dart language is with a simple code example.
Dart is a modern, object-oriented programming language developed by Google. It was designed to be fast, efficient, and easy to use for building web, mobile, and server applications. Dart is a statically-typed language, which means that the type of a variable is known at compile-time, and it supports both Just-in-Time (JIT) and Ahead-of-Time (AOT) compilation.
Here is a simple example of Dart code that prints “Hello, World!” to the console:
void main() {
print('Hello, World!');
}
Let’s break down the code:
void
indicates that the main()
function does not return any value.main()
is the entry point of the Dart program, which is where the program starts executing.print('Hello, World!');
is a built-in function that prints the string “Hello, World!” to the console.Dart also supports a variety of programming concepts, such as classes, interfaces, mixins, and more. Here is an example of a simple Dart class:
class Person {
String name;
int age;
Person(this.name, this.age);
void sayHello() {
print('Hello, my name is $name and I am $age years old.');
}
}
void main() {
var person = Person('Alice', 30);
person.sayHello();
}
In this example, we define a class called Person
that has two properties: name
and age
. We also define a constructor that takes two arguments and assigns them to the corresponding properties. Finally, we define a method called sayHello()
that prints a greeting message to the console.
In the main()
function, we create an instance of the Person
class and call the sayHello()
method on it, which prints the greeting message to the console.
Overall, Dart is a powerful and versatile programming language that is suitable for a wide range of applications. Its clean syntax and strong typing make it easy to read a