Over a million developers have joined DZone.

Google Dart Hello World Example: A Java-Like Programming Language to Create Web, Android, and iOS Applications

DZone's Guide to

Google Dart Hello World Example: A Java-Like Programming Language to Create Web, Android, and iOS Applications

Read this post to learn more about the Google Dart language and JavaScript for creating web, Android, and iOS applications.

· Java Zone ·
Free Resource

Delivering modern software? Atomist automates your software delivery experience.

Google Dart is a general-purpose programming language from Google that is used to build web applications, advertisements, mobile applications, and the Internet of Things (IoT) devices.  It's most popular application is in the Flutter framework, which is Google's mobile app, SDK, for crafting high-quality native interfaces on iOS and Android in record time. If you haven't tried either of these yet, then it's a good time to try it. Take a look at how much it offers to a programmer and whether it is suitable language to replace JavaScript or not. As a Java Programmer, my first impression of Google Dart is great. It looks quite familiar with Java, my favorite programming language, and this motivates me to write this hello-world example in Google Dart and execute it to see run it and how it works.

Similar to Java, Google Dart also has a class and object. It also has a final keyword, String Class, Object class, extends keyword, and many more. The Google Dart compiler also shows a warning and error like any other structured programming language.

In this Google Dart tutorial, we will see how to write HelloWorld in Google Dart and how to run a Google Dart program using the Google Dartboard Application. This is a browser-based application that allows you to write and run Google Dart programs. This is the easiest and quickest way to get a feel of the Google Dart language before trying it with HTML code

The Google Dart also has compiler and HTML converter that allows you to convert Dart code into JavaScript. We will see about how to convert Google Dart code into JavaScript in next article. For now, let's start with this step-by-step guide to writing the Google Dart HelloWorld example and running it.

Step-by-Step Guide to Write and Run Google Dart Example

Here is a step-by-step guide to writing your first program in the Google Data programming language. It's none other than the class HelloWorld program, which you might have already written for Java, Python, or C++.

1. Open DartPad in Your Browser (https://dartpad.dartlang.org/)

Make sure you use Mozilla Firefox, Google Chrome, or Apple Safari. The Google DartPad application won’t work on Microsoft Internet Explorer, though support is currently underway.

Once you open this link, the Google DartPad application will be open on your browser and the first example it has is "Hello, " as shown in the below screen.

2. Important Points About the Google Dart Structured Programming Language

Now, you have two options: either edit the existing program or write a new program. Before writing the new program, let’s see a few points about the Google Dart language.

1. Like Java, the Google Dart program will start with the main () method.

2. You can declare a variable using "var," a JavaScript style, or use a correct type like String or int in Java Style. For example, below the two lines of code are same.

String text = "NYSE is biggest Stock Market in the world;" var text = "NYSE is biggest Stock Market in the world;"

It depends upon your choice of whether you want to adopt javascript style or Java Style. Since I am a Java programmer, I found Java Style more intuitive and easy to use. 

By the way, var is finally available in Java 10. If you like to write concise code in Java, you can consider using var to declare local variables instead of declaring a full type name. 

3. You can assign an incorrect type to the variable, e.g. in this example assigning "text" as int, your program will run, but the Dart compiler will show a warning related to the incorrect type — int text.

4. Instead of var or a formal type, you can use a final keyword and your program will run successfully.

5. Each statement ends with a semicolon ";" otherwise the compiler will throw the error "Unexpected token "IDENTIFIER expected" or "; expected"

6. For displaying the value of the variable, we need to use interpolation or jsp expression language style "${var}" or else it will complain that it "cannot resolve text."

7. We can display the string as the same as in Java. The print() method is similar to Perl, Java, or any other language. For example:

print("This is String literal");

3. Our First Google Dart Program


main() {

  String tradingSecrets = "High Frequency Trading requires extremely fast computers";

  int latency = 10;

  String message = "Google Dart language";

  print('Hello world in ${message }');

  print("This is String literal just like Java");

  print( '${tradingSecrets}');


Here is "Hello world" in the Google Dart language. This is a String literal, just like Java. This type of high-frequency trading requires extremely fast computers.

4. Running Your Google Dart Program

Just press the Run  button as shown in the above image. It will contact the Dart server and run your program,. Sometimes, you may get an error as "The darn server failed to respond." But, mostly, you see out of your Google Dart program. This is the first Google Dart tutorial there, but there are more to come. This is a good place to start and get a feeling for the Google Dart language. The Google Dartboard application is easy to use and execute Google Dart program, which reduces the learning curve by converting the Google Dart program to JavaScript and then running it into the HTML file, like JavaScript requires little effort, which we will see in next article.

Start automating your delivery right there on your own laptop, today! Get the open source Atomist Software Delivery Machine.

java ,google dart ,apps ,android ,ios ,javascript ,hello world ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}