DEV Community

SameX
SameX

Posted on

The World of HarmonyOS Programming: Basic Concepts of HarmonyOS and ArkTS

This article aims to deeply explore the technical details of the Huawei HarmonyOS Next system (up to API 12 as of now), and is summarized based on actual development practices. It mainly serves as a vehicle for technical sharing and communication. Mistakes and omissions are inevitable. Colleagues are welcome to put forward valuable opinions and questions so that we can make progress together. This article is original content, and any form of reprint must indicate the source and the original author.
Huawei HarmonyOS is an operating system independently developed by Huawei, aiming to build a full-scenario intelligent ecosystem. It supports various device forms, including mobile phones, tablets, wearable devices, automobiles, etc., and realizes a modular design through a microkernel architecture to ensure the security and reliability of the system.
The architecture of the HarmonyOS system adopts a microkernel design. The core functions run in the microkernel, while other functional modules run in lightweight daemon processes. This design ensures the security and reliability of the system and allows for independent upgrades of different modules.
The core concept of the HarmonyOS system is "Distributed OS". It supports seamless collaboration between various devices and can be adapted according to different device forms. In addition, the HarmonyOS system also adopts the concept of "Distributed Capabilities", distributing computing, storage, network and other capabilities to each device to realize a truly full-scenario intelligent ecosystem.
ArkTS is a declarative programming language developed by Huawei for the HarmonyOS system. It is built based on TypeScript and extends with features specific to the HarmonyOS platform. ArkTS provides concise syntax and rich functionality, enabling developers to develop HarmonyOS applications in a more efficient manner.

The Architecture and Core Concepts of HarmonyOS

The architecture of the HarmonyOS system adopts a microkernel design. The core functions run in the microkernel, while other functional modules run in lightweight daemon processes. This design ensures the security and reliability of the system and allows for independent upgrades of different modules.
The core concept of the HarmonyOS system is "Distributed OS". It supports seamless collaboration between various devices and can be adapted according to different device forms. In addition, the HarmonyOS system also adopts the concept of "Distributed Capabilities", distributing computing, storage, network and other capabilities to each device to realize a truly full-scenario intelligent ecosystem.

The Basic Syntax and Type System of ArkTS

ArkTS is an extended version of TypeScript. It inherits the syntax and type system of TypeScript and adds some specific syntactic sugar and functionality.
Basic Syntax

  • ArkTS supports common programming language features, such as variable declaration, function definition, control flow statements, etc.
  • ArkTS supports modular development. You can use the import and export keywords to import and export modules.
  • ArkTS supports the definition of classes and interfaces. You can use the class and interface keywords to define classes and interfaces. Type System
  • ArkTS supports type annotations. You can use type annotations to specify the type of a variable.
  • ArkTS supports interfaces and type guards. You can use interfaces and type guards to ensure type safety.
  • ArkTS supports enumeration types and union types. You can use enumeration types and union types to define more complex types. ### Setting up the HarmonyOS Development Environment To start HarmonyOS development, you need to install the DevEco Studio development tool and the HarmonyOS SDK.
  • Download and Install DevEco Studio: You can download the DevEco Studio development tool from the Huawei official website.
  • Create a HarmonyOS Project: Create a new HarmonyOS project in DevEco Studio, and select the appropriate device type and platform version.
  • Write Code: Write the code of the HarmonyOS application using ArkTS, and use the debugging tools of DevEco Studio for debugging. ### A Simple "Hello World" Application The following is an example code of a simple "Hello World" application:
// Index.ets
import { Entry, Component } from '@ohos.arkui.arkui';
import { Text } from '@ohos.arkui.arkui';
@Entry
@Component
struct Index {
    @State message: string = 'Hello World';
    build() {
        Column() {
            Text(this.message)
               .fontSize(24)
               .margin(10)
               .width('100%')
               .height('100%');
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

This code defines a component named Index and displays a text message "Hello World" in the component. You can save this code to a file named Index.ets and run the application in DevEco Studio, and then you can see the "Hello World" text displayed on the screen.

Setting up the HarmonyOS Development Environment

To start HarmonyOS development, you need to install the DevEco Studio development tool and the HarmonyOS SDK.

  1. Download and Install DevEco Studio: You can download the DevEco Studio development tool from the华为官方网站.
  2. Create a HarmonyOS Project: Create a new HarmonyOS project in DevEco Studio, and select the appropriate device type and platform version.
  3. Write Code: Write the code of the HarmonyOS application using ArkTS, and use the debugging tools of DevEco Studio for debugging. ### In-depth Learning
  4. ArkTS Official Documentation: https://developer.huawei.com/consumer/cn/doc/development/arkts/arkts-index-V5
  5. HarmonyOS Development Documentation: https://developer.huawei.com/consumer/cn/doc/development/harmonyos-v5
  6. DevEco Studio Official Documentation: https://developer.huawei.com/consumer/cn/doc/development/devide/DevEco-Studio ### Summary Through the above introduction, you can understand the basic concepts and usage methods of the Huawei HarmonyOS system and the ArkTS programming language. The HarmonyOS system is a powerful operating system, and ArkTS is a feature-rich programming language that can help you easily develop HarmonyOS applications. Hope this article can help you get started with HarmonyOS development and embark on your journey of HarmonyOS application development.

Top comments (0)