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

Chapter - 1 (Introduction To Dart)

The document introduces Dart programming language by discussing how to set up the development environment, writing the "Hello World" program, exploring variables and data types, and working with operators and expressions. It explains that Dart is an object-oriented language developed by Google to build efficient apps for multiple platforms. It also provides steps to install Dart SDK, choose an IDE, and create a new project to write the first program. Finally, it demonstrates the use of basic data types like int, double, String, bool and operators.

Uploaded by

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

Chapter - 1 (Introduction To Dart)

The document introduces Dart programming language by discussing how to set up the development environment, writing the "Hello World" program, exploring variables and data types, and working with operators and expressions. It explains that Dart is an object-oriented language developed by Google to build efficient apps for multiple platforms. It also provides steps to install Dart SDK, choose an IDE, and create a new project to write the first program. Finally, it demonstrates the use of basic data types like int, double, String, bool and operators.

Uploaded by

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

Chapter 1: Introduction to Dart

1.1 Overview of Dart programming language: Dart is a modern, object-oriented programming


language developed by Google. It is designed to be efficient, expressive, and versatile, allowing
developers to build high-performance applications for a variety of platforms. Dart is known for
its strong typing system, which helps catch errors at compile-time, and its focus on simplicity
and productivity.
1.2 Setting up the development environment: To start programming in Dart, you need to set up
your development environment. Follow these steps:
Step 1: Install Dart SDK:
 Visit the official Dart website: https://dart.dev/
 Choose the installation package suitable for your operating system (Windows, macOS,
or Linux).
 Download and run the installer to install the Dart SDK on your machine.
Step 2: Verify the installation:
 Open a terminal or command prompt and type dart --version.
 If the Dart SDK is installed correctly, you should see the version information displayed.
Step 3: Choose an IDE (Integrated Development Environment):
 There are several popular IDEs that support Dart development, such as Visual Studio
Code, IntelliJ IDEA, and Android Studio.
 Choose the IDE that suits your preferences and install it on your machine.
 Install the Dart plugin or extension for your chosen IDE to enable Dart development
support.
1.3 Hello, World! Your first Dart program: Now that you have your development environment
set up, let's write your first Dart program.
Step 1: Create a new Dart project:
 Open your IDE and create a new Dart project.
 Give your project a name and choose a location to save it.
Step 2: Write the "Hello, World!" program:
 Open the main.dart file within your project.
 Remove any existing code and replace it with the following Dart code:

codewithzee
void main() {

print("Hello, World!");

}
In this program, the main() function is the entry point of the program. It prints the "Hello,
World!" message to the console using the print() function.
1.4 Variables and data types: Variables are used to store data in a program. Dart is a statically
typed language, which means that variables have a declared type. Let's explore variables and
data types in Dart. Variables in Dart are associated with specific data types, which define the
kind of data that can be stored in a variable. Dart has built-in data types for representing
various kinds of information. Let's explore some commonly used data types in Dart:
 int: Represents integer values (whole numbers) such as 1, 2, -10, etc.
 double: Represents floating-point values (numbers with decimal places) such as 3.14, -
0.5, etc.
 String: Represents a sequence of characters, such as "Hello", "Dart", "123", etc. Strings
are enclosed in double or single quotation marks.
 bool: Represents boolean values, which can be either true or false. Boolean values are
used to represent logical states or conditions.
 dynamic: Represents a type that is not known at compile-time. The dynamic type allows
you to store values of any type in a variable, but it sacrifices static type checking.
 var: A type inference mechanism in Dart that automatically determines the type of a
variable based on its initial value. The var type allows you to omit the explicit type
declaration.
Here's an example that demonstrates the use of different data types:

void main() {
int age = 25;
double height = 1.75;
String name = "John Doe";
bool isStudent = true;

print("Name: $name"); // Output: Name: John Doe


print("Age: $age"); // Output: Age: 25
print("Height: $height"); // Output: Height: 1.75
print("Is Student: $isStudent"); // Output: Is Student: true
}

codewithzee
In this example, we declare variables age with the int type, height with the double type, name
with the String type, and isStudent with the bool type. We assign values to these variables, and
then we use the print() function to display the values on the console.
It's important to choose the appropriate data type for your variables to ensure correct
representation and manipulation of data in your programs. Dart provides a rich set of data
types to handle different kinds of information.
1.5 Operators and expressions: Operators are used to perform operations on variables and
values. Dart provides various operators for arithmetic, assignment, comparison, and logical
operations.

void main() {
int a = 10;
int b = 5;

// Arithmetic operators
int sum = a + b;
int difference = a - b;
int product = a * b;
double quotient = a / b;
int remainder = a % b;

// Assignment operators
int x = 10;
x += 5; // Equivalent to x = x + 5

// Comparison operators
bool isEqual = a == b;
bool isNotEqual = a != b;
bool isGreater = a > b;
bool isLess = a < b;
bool isGreaterOrEqual = a >= b;
bool isLessOrEqual = a <= b;

// Logical operators
bool logicalAnd = (a > 0) && (b < 10);
bool logicalOr = (a > 0) || (b < 10);
bool logicalNot = !(a > 0);

print("Sum: $sum");
print("Difference: $difference");

codewithzee
print("Product: $product");
print("Quotient: $quotient");
print("Remainder: $remainder");
print("Is Equal: $isEqual");
print("Is Not Equal: $isNotEqual");
print("Is Greater: $isGreater");
print("Is Less: $isLess");
print("Is Greater or Equal: $isGreaterOrEqual");
print("Is Less or Equal: $isLessOrEqual");
print("Logical AND: $logicalAnd");
print("Logical OR: $logicalOr");
print("Logical NOT: $logicalNot");
}

In this program, we perform arithmetic operations using the +, -, *, /, and % operators. We also
demonstrate assignment operators (+=) to modify variable values. Additionally, we use
comparison operators (==, !=, >, <, >=, <=) and logical operators (&&, ||, !) to perform
comparisons and logical operations.
Congratulations! You have successfully completed chapter 1 of the Dart programming course.
In this chapter, you learned about the Dart programming language, set up your development
environment, wrote your first Dart program, explored variables and data types, and worked
with operators and expressions.

codewithzee

You might also like