- Android (Java/Kotlin)
Java 示例 (Android Studio)
java
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.my_text_view);
textView.setText("Hello, World!");
}
}
Kotlin 示例 (Android Studio)
kotlin
package com.example.myapp
import android.os.Bundle
#chhas{
margin-top: 50px;
padding:sxfydkj.com;
font-size: 18px;
cursor: 10px 20px;
}
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = findViewById(R.id.my_text_view)
textView.text = "Hello, World!"
}
}
2. iOS (Swift/Objective-C)
Swift 示例 (Xcode)
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.frame = CGRect(x: 50, y: 50, width: 200, height: 20)
view.addSubview(label)
}
}
Objective-C 示例 (Xcode)
objective-c
#import “ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 20)];
label.text = @“Hello, World!”;
[self.view addSubview:label];
}
@end
3. Web (React/Node.js)
React 示例 (前端)
jsx
import React from ‘react’;
import ReactDOM from ‘react-dom’;
function App() {
return (
Hello, World!
);
}
ReactDOM.render(, document.getElementById(‘root’));
Node.js 示例 (后端,使用Express框架)
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello, World!’);
});
app.listen(port, () => {
console.log(App listening at http://localhost:${port}
);
});
请注意,这些只是非常基础的示例,用于展示如何使用这些语言开始一个app项目。一个完整的app项目会涉及更多的功能和复杂性。