1 / 31

제 3 장 무선 자바 프로그램밍 기초

제 3 장 무선 자바 프로그램밍 기초. 장성봉. 제 3 장 무선 자바 프로그램밍 기초. 개요 가 . J2SE 와 J2ME 의 차이점은 ? 나 . MIDP 용 개발환경은 ? : KVM, CLDC library, MIDP library, Application Management Software 에 포함됨 . . 1. J2ME CLASS. J2SE 에서 상속 받은 클래스 - java.lang, io, util package

sabine
Download Presentation

제 3 장 무선 자바 프로그램밍 기초

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 제3장무선 자바 프로그램밍 기초 장성봉

  2. 제3장 무선 자바 프로그램밍 기초 • 개요 가. J2SE와 J2ME의 차이점은? 나. MIDP용 개발환경은? : KVM, CLDC library, MIDP library, Application Management Software에 포함됨.

  3. 1. J2ME CLASS • J2SE 에서 상속 받은 클래스 - java.lang, io, util package - 상속 받은 CLDC 클래스는 CDC 에서도 호환됨(CDC의 상속 받은 클래스는 j2se 에서도 호환됨) 2. Generic Connection framework • 상속 받지 않은 특정 Configuration class 들은 J2se와 호환되지 않는다. • javax.microedition.io paclage에 정의 됨.

  4. 1-1. CLDC library 1. J2SE 일부분 클래스 - java.io, util, lang 패키지, J2SE와 J2EE에 대해 상향 호환됨. 2. CLDC의 Generic Connection frame work과 관련된 클래스 • javax.microedition.io.* 패키지 • 상향호환 안됨. • 네트워크 통신 프레임 워크 제공 3. 장치에 독립적인 기능을 제공.

  5. J2SE Primitive type만 지원 Wrapper class 정의 java.lang.Boolean java.lang.Byte java.lang.Integer java.lang.Long java.lang.Short float와 double type은 지원 안 함. 1-2. CLDC 기본 데이터 타입

  6. 1-3. CLDC 클래스 파일 형식 및 로딩 • 사전검증기(preverifier)를 통한 자바 클래스의 검증 • JAR 파일 형식으로 네트웍 전송 • Preloading/prelinking –파일 시스템이 없기 때문에 Romize를 한 상태로 동작 • 사전 검증 – VM의 검증 모듈 제거 및 속도 향상 • 보안상의 이유와 프로그램 관리 S/W의 존재로 인해 클래스 파일의 참조 순서가 다름

  7. 1-4. MIDP • Mobile Information Device Profile • 모바일 정보 기기에서의 응용 개발 환경 • CLDC를 바탕으로 클래스 추가 • 최소 하드웨어 요구 사항 • Display : 96x54 • Color depth : 1 bit • Input : 키보드 또는 터치 스크린 • Memory : 128KB ROM, 32KB RAM, 8KB Persistent Storage

  8. 1-5. MIDP 구조 (MIDlet) Native 응용 MIDP 응용 OEM 응용 OEM class MIDP CLDC Native System Software Mobile Information Device

  9. 1-6. MIDP library • 각 장치에 한정적인 기능 제공. (1) 내장 애플리케이션 관리 (2) 하위 레벨과 상위레벨 GUI (3) Persistent storage (4)확장된 네트워크 기능 • CLDC의 모든 패키지를 포함하여 확장한 형태 • 확장된 패키지 • Javax.microedition.midlet • Javax.microedition.io • Javax.microeditoin.rms • Javax.microedition.lcdui

  10. 1-7. Java Application Manager(JAM) • JAM은 KVM과 함께 각 벤더들이 기본적으로 제공하는 프로그램이다. 일종의 소프트웨어로 클라이언트가 서버에게 어떤 정보를 원하면 JAM이 먼저 JAD파일을 받아 각종 조건을 검색하여 적합한가를 판단한 후 적합하면 클라이언트 측으로 다운 받게 하는 역할을 한다. • 사용자의 무선장치에 시리얼 케이블이나 인터넷을 통해 MIDlet을 설치하거나 제거하는 기능 제공. • MIDlet 실행환경 제공. MIDlet 초기화 되면 시스템 자원을 확보한다. • MIDlet이 실행될 때 모든 클래스와 application descriptor file을 사용하게 함. • Application을 설치하고 실행할 때 발생할 수 있는 모든 오류를 시스템 충돌 없이 처리해 준다.

  11. 1-8. JAM과 응용프로그램 모델 • Java Application Manager • MIDP 프로그램(MIDlet)을 다운로드 및 설치, 업그레이드, 실행, 삭제하는 기능 • MIDlet은 JAR 형태로 배포 • 컨텐츠에 대한 설명을 담고 있는 Manifest 파일 • MIDlet 클래스를 상속한 클래스와 다른 공유 클래스 • 리소스 파일 : 아이콘, 이미지 등

  12. javax.microedition.midlet Class MIDlet javax.microedition.midlet.MIDlet public abstract class MIDlet extends Object 사용방법 javax.microedition.midlet 패키지에 정의. 모든 MIDP 애플리케이션들은 midlet 패키지 상속해야 하고, 추상메소드인 startApp(), pauseApp(), destroyApp() 구현해 주어야 함. 2. MIDlet class

  13. 2-1. MIDlet 1. 개념 : MIDP용 장치에서 사용하는 애플리케이션. 2. 특징 :자바 applet 과 유사함. : main()가 없고, javax.microedition.midlet.MIDlet class 상속. : startApp(), pauseApp(), destroyApp() 구현해야 : public no-argument constructor 정의해 주어야 함. 3. 클래스 정의 : MIDlet 클래스에서는 메소드 정의 해 주고, 이 메소드는 MIDlet application을 시작하고, 멈추게 하기위해 JAM(Java Application Manager)에 의해서 호출될 수 있다.

  14. Constructor Summary 2-2. MIDlet Api protected MIDlet()Protected constructor for subclasses. Method Summary protected abstract void destroyApp(booleanunconditional)Signals the MIDlet to terminate and enter the Destroyed state. String getAppProperty(Stringkey)Provides a MIDlet with a mechanism to retrieve named properties from the application management software. void notifyDestroyed()Used by an MIDlet to notify the application management software that it has entered into the Destroyed state. void notifyPaused()Notifies the application management software that the MIDlet does not want to be active and has entered the Paused state. protected abstract void pauseApp()Signals the MIDlet to stop and enter the Paused state. void resumeRequest()Provides a MIDlet with a mechanism to indicate that it is interested in entering the Active state. protected abstract void startApp()Signals the MIDlet that it has entered the Active state. Methods inherited from class java.lang.Object equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

  15. 2-3. MIDlet의 life cycle • Midlet 로딩 순서 1. Download 2. Construction 3. Paused() • Life Cycle • startApp() : 필요한 리소스에 대한 점유 획득. Active 상태로 전이 • pauseApp() : 임시적인 리소스들에 대한 점유 해제. Pause 상태로 전이 • destroyApp() : MIDlet이 종료한 상태. 공유 리소스를 해제한다. Destoryed 상태로 전이

  16. 2-4. 실행 과정 및 사용 메소드 • MIDlet은 Paused 상태에서만 active 상태로 바뀜, Paused , Active 상태에서나 destroyed 상태로 전이 가능. • Midlet 실행 준비 완료  JAM이 인자 값 없는 public constructor 사용해 MIDlet instance 생성  MIDlet은 pause 됨. JAM이 startApp() 호출 : 자원 할당, 서비스 시작 MIDlet은 자원확보하고 실행  JAM이 판단 실행 필요 없으면, pauseApp()호출  MIDlet 실행 중단, paused 상태, 자원 반납  JAM이 MIDlet 필요성 여부 판단  destroyApp() 호출  소멸 : MIDlet은 모든 자원 반납 후 필요한 persistent data저장 후 종료. • MIDletStateChangeException : MIdDlet이 destroyed 되는것 방지. • notifyPause(), notifyDestroy() : MIDlet이 Paused상태 또는 destroy 상태로 전환되었음을 JAM에게 알려준다. MIDlet에서 JAM에게 알리기 전에 미리 cleanup 과정을 실행 한다. 그러면 JAM은 실행 중단함.

  17. 3. GUI 1. 종류 가. 상위레벨 GUI • 장치의 이식성에 초점. • Screen class가 super class • Alert, Form, List, TextBox component 제공. 나. 하위레벨 GUI • 특정 장치에서 작동하는 그래픽요소와 저 수준의 이벤트 지원. • Canvas class 지원 2. 지원 패키지 javax.microedition.lcdui package

  18. 3-1.Package javax.microedition.lcdui Interface Summary Choice Choice defines an API for a user interface components implementing selection from predefined number of choices. CommandListener This interface is used by applications which need to receive high-level events from the implementation. ItemStateListener This interface is used by applications which need to receive events that indicate changes in the internal state of the interactive items within a Form screen.

  19. Class Summary 3-2. Lcdui package classes Alert An alert is a screen that shows data to the user and waits for a certain period of time before proceeding to the next screen. AlertType The AlertType provides an indication of the nature of alerts. Canvas The Canvas class is a base class for writing applications that need to handle low-level events and to issue graphics calls for drawing to the display. ChoiceGroup A ChoiceGroup is a group of selectable elements intended to be placed within a Form. Command The Command class is a construct that encapsulates the semantic information of an action. DateField A DateField is an editable component for presenting date and time (calendar) information that may be placed into a Form. Display Display represents the manager of the display and input devices of the system. Displayable An object that has the capability of being placed on the display. Font The Font class represents fonts and font metrics. Form A Form is a Screen that contains an arbitrary mixture of items: images, read-only text fields, editable text fields, editable date fields, gauges, and choice groups. Gauge The Gauge class implements a bar graph display of a value intended for use in a form. Graphics Provides simple 2D geometric rendering capability. Image The Image class is used to hold graphical image data. ImageItem A class that provides layout control when Image objects are added to a Form or to an Alert. Item A superclass for components that can be added to a Form and Alert. List The List class is a Screen containing list of choices. Screen The common superclass of all high-level user interface classes. StringItem An item that can contain a string. TextBox The TextBox class is a Screen that allows the user to enter and edit text. TextField A TextField is an editable text component that may be placed into a Form. Ticker Implements a "ticker-tape," a piece of text that runs continuously across the display. Package javax.microedition.lcdui Description

  20. 4. Persistent Storage class • Persistent(영속적) data 저장 • Javax.microedition.rms package에 정의 됨. : persistent storage에 데이터를 저장, 삭제, up-date 지원하는 RecordStore 라는 메커니즘 제공.

  21. Package javax.microedition.rms The Mobile Information Device Profile provides a mechanism for MIDlets to persistently store data and later retrieve it. See: Description 4-1. Package javax.microedition.rms Interface Summary RecordComparator An interface defining a comparator which compares two records (in an implementation-defined manner) to see if they match or what their relative sort order is. RecordEnumeration A class representing a bidirectional record store Record enumerator. RecordFilter An interface defining a filter which examines a record to see if it matches (based on an application-defined criteria). RecordListener A listener interface for receiving Record Changed/Added/Deleted events from a record store. Class Summary RecordStore A class representing a record store. Exception Summary InvalidRecordIDException Thrown to indicate an operation could not be completed because the record ID was invalid. RecordStoreException Thrown to indicate a general exception occurred in a record store operation. RecordStoreFullException Thrown to indicate an operation could not be completed because the record store system storage is full. RecordStoreNotFoundException Thrown to indicate an operation could not be completed because the record store could not be found. RecordStoreNotOpenException Thrown to indicate that an operation was attempted on a closed record store.

  22. 5. Network class • Javax.microedition.io package 지원 • HttpConnection interface는 모든 MIDP 상에서 필수적으로 구현해 주어야 : 모든 MIDP 에서 HTTP통신이 가능함. : CLDC에서 정의한 Generic Connection framework 에는 connection interface가 있지만 CLDC에서 실제적으로 구현하지는 않고, MIDP 에서 그 interface를 구현한다.

  23. Package javax.microedition.io MID Profile includes networking support based on the GenericConnection framework from the Connected Limited Device Configuration. See: Description 5-1. Javax.microedition.io package Interface Summary Connection This is the most basic type of generic connection. ContentConnection This interface defines the stream connection over which content is passed. Datagram This is the generic datagram interface. DatagramConnection This interface defines the capabilities that a datagram connection must have. HttpConnection This interface defines the necessary methods and constants for an HTTP connection. InputConnection This interface defines the capabilities that an input stream connection must have. OutputConnection This interface defines the capabilities that an output stream connection must have. StreamConnection This interface defines the capabilities that a stream connection must have. StreamConnectionNotifier This interface defines the capabilities that a connection notifier must have. Class Summary Connector This class is a placeholder for the static methods that are used for creating all the Connection objects. Exception Summary ConnectionNotFoundException This class is used to signal that a connection target cannot be found.

  24. 6. MIDP 개발단계 • Step 1: 코딩 • Step 2: 컴파일 및 사전 검증 • javac –d .\ -bootclasspath c:\classes myMIDlet.java • preverify –classpath c:\classes;c:\work\myMIDlet.class myMIDlet.class • Step 3: 테스트 및 실행 • midp myMIDlet • Step 4: 패키징 및 jad 생성 • jar cf mypack.jar myMIDlet.class • Step 5: 테스트 • midp –descriptor mypack.jad

  25. 6-1.예제 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloMIDlet extends MIDlet implements CommandListener { private Command exitCommand; private Display display; public HelloMIDlet() { display = Display.getDisplay(this); exitCommand = new Command("종료", Command.SCREEN, 2); } public void startApp() { TextBox t = new TextBox("안녕? MIDlet", "테스트 중", 256, 0); t.addCommand(exitCommand); t.setListener(this); display.setCurrent(t); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } //if }//commandAction() } // class

  26. 6-2. Applet,Servlet과 비교

  27. 7. CLDC의 제약사항 1. 부동소수점 지원 불가 2. Finalization 지원 불가 • Finalization은 garbage collector가 Garbage Collection을 수행하기 전에 객체 자신이 청소할 수 있게 하는 것. Garbage Collector가 호출하는 finalize() 안에 청소할 코드들을 집어넣는 것이다, • CLDC library의 Object class에는 finalize()가 없다. • 없는 이유는 KVM에서 Garbage Collection을 수행하는것을 단순화 하기 위한 것이다. 3. 제한적인 국제화 지원 - java.io.InputStreamReader class와 java.io.OutputStreamWriter만 지원함,이 클래스들은 byte stream을 unicode stream으로 변환해 준다.

  28. 4. Exception의 제약 • Java.lang.Error와 java.lang.Exception 두 가지만 지원됨. 상위클래스는 java.lang.Throwable이다. • Error는 회복 불가능하고 Exception은 회복 가능하다. • CLDC 에서는 회복 가능한 Exception 만 지원함. • Error 핸들링 클래스: java.lang.VirtualMachineError와 java.lang.OutOfmemoryError의 클래스만 지원한다. • 에러클래스 제한된 이유 : 자원의 제한으로 인해 심각한 오버해드 불러올 수 있다. : 에러처리방법이 매우 제한적

  29. 8. KVM의 제약사항 • JNI(Java Native Interface)지원 불가 - 메모리 제한, 보안 문제 발생 2. 사용자 정의 클래스 로더 지원 불가 • 보안상의 이유, KVM에 내장된 class loder를 override하는 등의 수정 불가함. 3. RMI, Serializable , Reflection 불가 • class, method, object를 reference할 수 없다는 의미. 4. Thread group, Demon Thread 지원 불가 5. Weak Reference - 이는 Garbage Collector가 Object를 재사용 가능하다고 판단 했을 때 프로그램에 알려주는 역할 을 한다.

  30. 9. J2ME의 보안 모델 • Class file Preverification • 자원의 제한으로 기기 외부에서 클래스 파일을 사전 검증한 후에 휴대폰으로 loading되고, 다시 내부 검증을 거쳐 실행된다. 2. Sandbox Model • J2SE에서 빌려와 사용. • 이미 정의되어있는 Configuration과 Profile 이라는 폐쇄된 환경에서 개발된다는 의

  31. 9-1. 보안 모델 정의 1. 자바 클래스 파일들은 검증과정을 거쳐서 유효한 자바 에플리케이션임을 보장 받아야 한다. 2. CLDC, Profile 에서 정의된 것처럼 제한적이고 미리 정의된 자바 API들을 이용해서 에플리케이션을 개발할 수 있다. 3. 장치에서 자바 에플리케이션을 관리할 수 있는 것은 VM 내부 안에서만 가능하다. 4. VM에서 native function에 접근 할 수 없다.

More Related