Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

DART Programming Language Summary, Summaries of Programming Languages

Contains important Definition, Points, and Programmes of Important Topics in Dart Programming Language for revision.

Typology: Summaries

2020/2021

Uploaded on 01/16/2022

ayush-kadbe
ayush-kadbe 🇮🇳

1 document

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DART Programming Language Summary
Dart is a Object Oriented Language, its upports features like Classes, interfaces,
etc. Dart is created by Google Inc.
Important Definition: -
//Class: is blueprint for objects.
//Fields: are any variable defined in class. Fields represent Data applied to objects.
//Setters and Getters allows the program to initialize the retrive the data of fields.
//Constructors allocates memory for the object of the class.
//Functions: Functions are actions that objects can perform. They at some times are
called Methods.
//Method is a action that an object can perform.
//Instance of Class i.e use new key word followed by class name.
syntax: var ObjName = new ClassName(argument);
//Attributes and Functions can be accessed USING Object with dotnotation
followed by attribute/function name .
Syntax: ObjName.fieldName;
Syntax: ObjName.functionName();
//Constructors are special Funtions of Class that are responsible for initializing
fields in the class.
//Metadata is data about a data
//Symbols are constants/objects which can be used to show metadata of a
library/class
IMPORTANT TOPICS: -
//Dart Constructors Syntax:
ClassName(ParamList){
//construtor body
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download DART Programming Language Summary and more Summaries Programming Languages in PDF only on Docsity!

DART Programming Language Summary Dart is a Object Oriented Language, its upports features like Classes, interfaces, etc. Dart is created by Google Inc. Important Definition: - //Class: is blueprint for objects. //Fields: are any variable defined in class. Fields represent Data applied to objects. //Setters and Getters allows the program to initialize the retrive the data of fields. //Constructors allocates memory for the object of the class. //Functions: Functions are actions that objects can perform. They at some times are called Methods. //Method is a action that an object can perform. //Instance of Class i.e use new key word followed by class name. syntax: var ObjName = new ClassName(argument); //Attributes and Functions can be accessed USING Object with dotnotation followed by attribute/function name. Syntax: ObjName.fieldName; Syntax: ObjName.functionName(); //Constructors are special Funtions of Class that are responsible for initializing fields in the class. //Metadata is data about a data //Symbols are constants/objects which can be used to show metadata of a library/class IMPORTANT TOPICS: - //Dart Constructors Syntax: ClassName(ParamList){ //construtor body

//Other Object is used to put the value of Parameter in the Constructor. E.G. void main(){ //Object to put value in the parameter. Car myCar = new Car("Enn"); } //Other class class Car{ //Constructor Car(String engine){ print(engine); //Constructor body. } } ================================================== //Empty Constructors can also be created without Parameters & Objects are also created to call those constructors without the Value for Parameter. void main(){ //Object for calling that constructorl Car myCar = new Car(); } class Car{ //Empty Constructor Car(){ print("This is an empty constructor, ENGINE); } } //Named Constructors used to enable class dfeine multiple Constructors. //You can have 1 UnNamed Constructor while Have many Named Constructor =================================================== Multiple Constructors: //LETS DEFINE MULTIPLE CONSTRUCTORS IN A CLASS

//class class Car{ String engine; Car(String engine){ this.engine = engine; print(engine); } } ==================================================== Getters and Setters: - Getters AND Setters: Initialize and Retrive Values of Class Fields which are Present in Constructors 1Default Getter and Setter is present, which can be Overridden by explicitly Defining a new Getter/Setter Getter: Get Keyword, No Parameter, Return a Value Setter: Set Keyword, One Parameter, Not Return Value Syntax: ReturnType get identifier{ } set identifier{ } //You have to create a getter to get var value/return var; //Datatype is used for getting //Gettter no parameter //Return a value //You have to create a setter to set this.variable = variable; //Void is used to setting //Setter 1 parameter //Set a value

void main(){ Student s1 = new Student(); print(s1.studName); print(s1.studAge); } class Student{ //Two variables or Data to get and set String name; int age; //Create a setter; void set studName(name){ this.name = name; } //Create a getter String get studName{ return name; } //Create a setter for int var void set studAge(age){ if(age <= 5){ print("Age should be greater than 5"); }else{ this.age = age; } } //Create getter to return age; int get studAge{ return age; } }

class Student{ //method 1 void test1(){ print("Test 1 will be held on Monday."); } //Method 2 void test2(){ print("Test 2 will be held on Wednesday"); } } ===================================== DART Collections: - Dart doesnt support ARRAYS, DART COLLECTIONS can be used to replicate data like Arrays. LIST------------------ void main(){ List myGoal = new List(); myGoal.add("Dart"); myGoal.add("Flutter"); myGoal.add("C lang"); myGoal.add("PHP"); /print the list like array print(myGoal); /iterating accross the list i.e writing againg and again for(String type in myGoal){ print(type); } Size or length print(myGoal.length); yGoal.remove("PHP"); print("The updated list"); print(myGoal);

//Syntax to print List/set in forms of Each Object in new Line for(Datatype objName in ListName){ print(objName); } SET -------------------------------- Set represents a collection of Object in which each Object can occur only once. Sytax: Identifier = new Set(); Identifier = new Set.from(Iterable); Iterables are a list of values to add to a set. //Vertical print of set for(var obj in Identifier){ print(obj); } ===================================== Advanced Dart Collections: - HashMap HashSet LinkedList Queue HashMap: HashMap is hash Table based on implementation of Maps, which does not have a particular order

  • datatype Identifier = new HashMap(); import 'dart:collection'; main() { var accounts = new HashMap(); accounts['dept']='HR'; accounts['name']='Tom';

print("Default implementation :${numberSet.runtimeType}"); for(var no in numberSet){ print(no); } } ========================================== Map: - var Identifier = new Map(); Identifier[‘key’] = ‘value’; ========================================== Queue: A queue is a collection that can be manupulated at both ends. It can add a element at start as well as end Queue Identifier = new Queue(); Identifier.add[]=’’; Identifier .addAll(); Identifier.addFirst(); Identifier .addLast(); ========================================== ITERATOR COLLECTIONSD: Iterator class enable easy collection traversal Each collection has an Iterator Property This property return a Iterator that points to a Object in the Collection Syntax : Iterator obj = IdentifierName.iterator; Current property of iterator shows where iterator is pointing currentl IteratorObj.current ========================================== GENERICS: - Dart Collections are Heterogenous, which can hold values of Various types,

Dart Collections can be made Homogenous using type-safety implementations Syntax: CollectionName identifier = new CollectionName(); ========================================== PACKAGES: - package manager for dart is pub Each dart application has a pubspec.yaml file which contains dependencies to other libraries and metadata of application like name, version,author, description ========================================== EXCEPTIONS: - each exceptions is a subtype of Exception Class there are try/on/catch blocks try Block: Embeds the code that might possibly result in a exceptions on Block: Used when exception type needs to be specified catch Block: used when the hander needs the Exception Object finally Block: Finally Block includes code that should be executed irrespecitve of an exception’s occurrence. The optional finally block executes unconditionally after try/on/catch block try { // code that might throw an exception } on Exception1 { // code for handling exception } catch Exception2 { // code for handling exception } many on/catch blocks can be created to handle multiple exceptions. try { // code that might throw an exception }

//VariableName(parameter) oper(23,345); oper = Sub; oper(4,4); oper = Div; oper(34,34); oper=Mul; oper(54, 98); } //Defing a typedef typedef manyOperations(int fn, int sn); Add(int fn, int sn){ print("ADD: ${fn + sn}"); } Sub(int fn, int sn){ print("SUB: ${fn - sn}"); } Div(int fn, int sn){ print("DIV: ${fn/sn}"); } Mul(int fn, int sn){ print("Mul: ${fn/sn}"); } Calculator(int fn, int sn, manyOperation oper){ print("Inside calculator"); oper(24,34); } //Passing typedef as parameter to a function void main(){

//Passing typedef as a parameter to a function Calculator(23, 43, Add); Calculator(43, 98, Sub); Calculator(98,21,Div); Calculator(76,45,Mul); } //Defing a typedef typedef manyOperations(int fn, int sn); Add(int fn, int sn){ print("ADD: ${fn + sn}"); } Sub(int fn, int sn){ print("SUB: ${fn - sn}"); } Div(int fn, int sn){ print("DIV: ${fn/sn}"); } Mul(int fn, int sn){ print("Mul: ${fn/sn}"); } Calculator(int fn, int sn, manyOperation oper){ print("Inside calculator"); oper(24,34); } ========================================== Concurrency: - Help in doing many parallel processes at same time. Dart:isolate package ==========================================

void main(){ //Stdout //Stdin stdout.write("Enter your name: "); var name = stdin.readLineSync(); print("Hi, $name!"); }

  1. Celsius to Fahrenheit Converter import 'dart:io'; void main() { print("Enter the temperature in Celsius: "); double C = double.parse(stdin.readLineSync()); double F = ((9/5)*C)-32; print(F); } ==========================================