+ All Categories
Home > Documents > Plataforma Java 2 - Micro Edition (J2ME)

Plataforma Java 2 - Micro Edition (J2ME)

Date post: 18-Jan-2016
Category:
Upload: helia
View: 35 times
Download: 2 times
Share this document with a friend
Description:
Plataforma Java 2 - Micro Edition (J2ME). Prof. Afonso Ferreira Miguel, MSc. O que é Java. Simple Object oriented Architecture Neutral and Portable Distributed High performance Interpreted Multithreaded Robust Dynamic Secure. Java - Estrutura Geral. Ciclo de desenvolvimento:. - PowerPoint PPT Presentation
26
Plataforma Java 2 - Micro Edition (J2ME) Prof. Afonso Ferreira Miguel, MSc
Transcript
Page 1: Plataforma Java 2 - Micro Edition (J2ME)

Plataforma Java 2 - Micro Edition

(J2ME)

Prof. Afonso Ferreira Miguel, MSc

Page 2: Plataforma Java 2 - Micro Edition (J2ME)

O que é Java

•Simple

•Object oriented

•Architecture Neutral and Portable

•Distributed

•High performance

•Interpreted

•Multithreaded

•Robust

•Dynamic

•Secure

Page 3: Plataforma Java 2 - Micro Edition (J2ME)

Java - Estrutura Geral

Ciclo de desenvolvimento:

Plataforma:•The Java Virtual Machine (Java VM) •The Java Application Programming Interface (Java API)

Page 4: Plataforma Java 2 - Micro Edition (J2ME)

O que é J2ME

"a highly optimized Java run-time environment targeting a wide range of consumer products, including pagers, cellular phones, screen-phones, digital set-top boxes and car navigation systems."

Sun Microsystems

Announced in June 1999 at the JavaOne Developer Conference, J2ME brings the cross-platform functionality of the Java language to smaller devices, allowing mobile wireless devices to share applications. With J2ME, Sun has adapted the Java platform for consumer products that incorporate or are based on small computing devices.

Page 5: Plataforma Java 2 - Micro Edition (J2ME)

J2ME - Estrutura Geral

• Configuration basic run-time environment (core classes and a specific JVM);• Profile Application (domain-specific classes ).

Configuration

Profile

Virtual Machines

J2ME

Page 6: Plataforma Java 2 - Micro Edition (J2ME)

J2ME - Configuration

Configuration

Connected Limited Device Configuration (CLDC)• Utiliza KVM para dispositivos de 16 ou 32-bit com espaço de memória limitado (<500k);• Utilizada para pequenas aplicações J2ME;• Exemplo de wireless device : Palm Hand-held.

Connected Device Configuration (CDC)• Utiliza C virtual machine (CVM) para dispositivos de 32-bits• Aquitturas com mais de 2MB• Exemplo - Net TV box.

Page 7: Plataforma Java 2 - Micro Edition (J2ME)

Device x CLDC

• 160 to 512 kilobytes of total memory available for the Java platform;• Limited power, often battery powered;• Network connectivity, often with a wireless, inconsistent connection and with limited bandwidth;• User interfaces with varying degrees of sophistication; sometimes with no interface at all.

Exemplos:• wireless phones;• pagers;• mainstream personal digital assistants (PDAs);•small retail payment terminals.

Page 8: Plataforma Java 2 - Micro Edition (J2ME)

Device x CDC• Powered by a 32-bit processor;• Two megabytes or more of total memory available for the Java platform;•Network connectivity, often with a wireless, inconsistent connection and with limited bandwidth;• User interfaces with varying degrees of sophistication; sometimes with no interface.

• residential gateways;• PDAs;• Organizers;

• home appliances;• point-of-sale terminals;• car navigation systems.

Exemplos:

Page 9: Plataforma Java 2 - Micro Edition (J2ME)

CDC x CLDC

Conclusão: progs J2SE e J2ME na maioria das vezes não são compatíveis (interface)

"Write Once, Run Anywhere.“ ????

Page 10: Plataforma Java 2 - Micro Edition (J2ME)

J2ME - Profile

Profile

• Define o tipo de device suportado pela aplicação;• Construído sobre Configuration (CDC/CLDC);• Sobre CLDC, disponível em dois modelos:

• KJava;•MIDP - Mobile Information Device Profile (classes para telefones celulares e PDAs).

• Sobre CDC, disponível o Foundation Profile que permite criar profiles personalisados;

Page 11: Plataforma Java 2 - Micro Edition (J2ME)

Profile 1: KJava

Profile

• KJava é propriedade da Sun;• Roda sobre uma JVM (Java Virtual Machine) chamada KVM (KJava Virtual Machine);• Versões preliminares para telefones celulares e PDAs;• Construído sobre CLDC.

Page 12: Plataforma Java 2 - Micro Edition (J2ME)

Profile 2: MIDPMobile Information Device Profile

Profile

• MIDP é um padrão aberto (não proprietário);• Roda também sobre a JVM (Java Virtual Machine) chamada KVM;• Versões finais disponíveis para telefones celulares e PDAs;• Construído sobre CLDC.

Page 13: Plataforma Java 2 - Micro Edition (J2ME)

Kava x MIDP

Profile

• KJava foi o primeiro profile da Sun;• Foi adotado como padrão por vários desenvolvedores;• MIDP foi aprovado por um Java Community Process, garantindo a independência de fabricante;• Novos produtos geralmente são desenvolvidos para MIDP, brevemente desaparecendo o KJava;• 2001 Sun anuncia o lançamento do MIDP para PALM.

Page 14: Plataforma Java 2 - Micro Edition (J2ME)

J2ME x J2SE x J2EE

Page 15: Plataforma Java 2 - Micro Edition (J2ME)

Considerações para projeto em pequenos dispositivos

Keep it simple:• Remove unnecessary features;

Smaller is better:• Smaller applications use less memory and require shorter installation times;

Minimize run-time memory use:• Use scalar types in place of object types;• Do not depend on the garbage collector;• Use lazy instantiation, only allocating objects on an as-needed basis;• Release resources quickly, reuse objects, and avoid exceptions.

Page 16: Plataforma Java 2 - Micro Edition (J2ME)

Considerações para projeto em dispositivos móveis

Let the server do most of the work: move the computationally intensive tasks to the server, and let the server run them for you. Let the mobile device handle the interface and minimal amounts of computations, and let the server do the intensive work.

Choose the language carefully: J2ME still is in its infancy and may not be the best option. Other object-oriented languages, like C++, could be a better choice, depending on your needs.

Page 17: Plataforma Java 2 - Micro Edition (J2ME)

Considerações sobre desempenho

Use local variables: it is quicker to access local variables than to access class members.

Avoid string concatenation: string concatenation decreases performance and can increase the application's peak memory usage.

Use threads and avoid synchronization: any operation that takes more than 1/10 of a second to run requires a separate thread. Avoiding synchronization can increase performance as well.

Separate the model using the model-view-controller (MVC): MVC separates the logic from the code that controls the presentation.

Page 18: Plataforma Java 2 - Micro Edition (J2ME)

Configurando o sistema...Recursos necessários:

1. Java 2 SDK (j2sdk-1_4_0_01-windows-i586.exe);2. Java 2 ME – Wireless Toolkit (j2me_wireless_toolkit-

1_0_4_01-bin-win.exe);3. JCreator (jcrea250.zip);4. Palm-OS Emulator (emulator-win.zip);5. PALM-ROM Mirror (Palm Afonso.rom)

Page 19: Plataforma Java 2 - Micro Edition (J2ME)

Configurando o sistema...Procedimentos:

1. Instalar Java 2 SDK, Java 2 ME – Wireless Toolkit e Jcreator (nesta ordem) utilizando as definições padrão;

2. Instalar Palm-OS Emulator descompactando para um diretório padrão (PALM-EMUL);

3. Copiar Palm Afonso.rom para o mesmo diretório do item 2.

Page 20: Plataforma Java 2 - Micro Edition (J2ME)

Desenvolvendo aplicativos ...Considerações iniciais sobre inteface gráfica em MIDP:

MIDP possui tanto métodos de baixo-nível como de alto-nível.Métodos de baixo-nível permitem acessar a inteface do dispositivo

tratando pixel a pixel.Métodos de alto-nível, inserem controles próprios da API

aparecendo conforme a implementação MIDP para o dispositivo.

Page 21: Plataforma Java 2 - Micro Edition (J2ME)

Desenvolvendo aplicativos ...MIDLET

Page 22: Plataforma Java 2 - Micro Edition (J2ME)

J2ME Wireless Toolkit

Page 23: Plataforma Java 2 - Micro Edition (J2ME)

1ª aplicação... ... Hello World

•Criar projeto com botão New Project...

•Pressionar OK

Passo 1: Criando projeto no J2ME Wireless Toolkit

Page 24: Plataforma Java 2 - Micro Edition (J2ME)

1ª aplicação... ... Hello World

•Criar um Empty Project no diretório c:\Wtk104\apps\ com o mesmo nome do projeto criado no J2ME Wireless Toolkit (MeuTeste);•Criar um Java File chamado HelloWorld.java no diretório c:\Wtk104\apps\MeuTeste\src\

Passo 2: Criando projeto no JCreator

Page 25: Plataforma Java 2 - Micro Edition (J2ME)

1ª aplicação... ... Hello World

•Entrar com o código a seguir:•Salvar

Passo 3: código Java

import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet implements CommandListener{ private Form form;

public HelloWorld() { form = new Form("Isto é um teste"); form.append("Olá Mundo!"); form.addCommand( new Command( "Sair", Command.EXIT, 1 ) ); form.setCommandListener( this ); }

public void startApp() { Display display = Display.getDisplay(this); display.setCurrent( form ); }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { form = null; }

public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); }}

Page 26: Plataforma Java 2 - Micro Edition (J2ME)

1ª aplicação... ... Hello World

Passo 4: compilando e testando...

•Voltar ao J2ME Wireless Toolkit compilar o projeto com o botão Build;•Selecionar o device a ser emulado (Motorola_i85s);•Executar através do botão Run;•Selecionar a aplicação e executá-la através do botão Launch.


Recommended