J2ME(Java ME)曾是功能機時代行動應用主流平台,雖已被 Android/iOS 取代,其輕量級架構與 API 設計仍具教學與維舊系統參考價值。本文整理開發者必須掌握的七大技術領域,並補充廠商擴充 API 概況。
| # | 技術 | 核心 API | 典型應用場景 |
|---|---|---|---|
| 1 | 高階 UI | Form, TextBox, List, Alert, Command, ItemStateListener | 登入畫面、設定選單、彈出提示 |
| 2 | 低階 UI | Canvas, Graphics, keyPressed/Released/Repeated, pointerPressed | 遊戲主迴圈、自繪元件、觸控手勢 |
| 3 | 記錄存儲 (RMS) | RecordStore, RecordEnumeration, RecordListener | 高分紀錄、設定檔、離線資料快取 |
| 4 | 聲音處理 | MIDP 1.0:廠商擴充(Nokia Sound, Siemens Audio)MIDP 2.0: javax.microedition.media.Player, Manager | 按鍵音效、背景音樂、語音提示 |
| 5 | 網路程式 | HttpConnection (GCF), SocketConnection (少數支援) | HTTP GET/POST 呼叫 Web Service、簡易 Socket 通訊 |
| 6 | 多執行緒 | Thread, Runnable, synchronized, wait/notify | 網路請求非阻塞 UI、遊戲邏輯/渲染分離 |
| 7 | 簡訊程式 | 廠商專屬:Nokia com.nokia.mid.sms, Siemens com.siemens.mp.sms | 驗證碼發送、營銷推播、裝置遠端控制 |
開發時需引入對應廠商 SDK,並以「反射+介面隔離」方式撰寫跨平台相容程式碼。
| J2ME 概念 | Android 對應 | iOS 對應 |
|---|---|---|
| MIDlet 生命週期 | Activity/Service 生命週期 | AppDelegate/ViewController 生命週期 |
| Canvas 繪圖 | SurfaceView / Canvas + OpenGL ES | Metal / Core Graphics |
| RMS | SharedPreferences / Room / SQLite | UserDefaults / CoreData / SQLite |
| GCF HttpConnection | OkHttp / Retrofit / HttpClient | URLSession / Alamofire |
HttpConnection 工具類,便於未來替換為 OkHttp。Manager.createPlayer(),棄用廠商專屬 API。