구분 | Java 5.0 | ActionScript 3.0 |
라이브러리 패키징 |
.jar | .swc |
상속 | class Employee extends Person{…} | class Employee extends Person{…} |
변수정의 및 초기화 |
String firstName=”John”; Date shipDate=new Date(); int i; int a, b=10; double salary; |
var firstName:String=”John”; var shipDate:Date=new Date(); var i:int; var a:int, b:int=10; var salary:Number; |
정의되지 않은 변수 | N/A | It’s an equivalent to the wild card type notation *. If you declare a variable but do not specify its type, the * type will apply. A default value: undefined var myVar:*; |
변수 scopes | block: declared within curly braces, local: declared within a method or a block member: declared on the class level no global variables |
No block scope: the minimal scope is a function local: declared within a function member: declared on the class level If a variable is declared outside of any function or class definition, it has global scope. |
문자열(String) | 2바이트 유니코드의 불변값 | 좌동 |
문장 종료 시 세미콜론(;) 사용 |
필수 | 라인별로 구분되면 생략가능 |
Strict equality operator | N/A | === for strict non-equality use !== |
상수 | final 키워드로 정의 final int STATE=”NY”; |
const 키워드로 정의 const STATE:int =”NY”; |
Type 체킹 | Static (checked at compile time) | Dynamic (checked at run-time) and static (it’s so called ‘strict mode’, which is default in Flex Builder) |
Type 체킹 연산자 |
instanceof | is (instanceof - 예전방식) |
as 연산자 | N/A | var orderId:String=”123”; var orderIdN:Number=orderId as Number; trace(orderIdN); // prints 123 |
기본형 | byte, int, long, float, double,short, boolean, char | 모든 기본형은 ActionScript 오브젝트임. Boolean, int, uint, Number, String 아래 문장은 같은 의미임. var age:int = 25; var age:int = new int(25); |
복잡한 유형 | N/A | Array, Date, Error, Function, RegExp, XML, 그리고 XMLList |
배열 및 초기화 | int quarterResults[]; quarterResults = new int[4]; int quarterResults[]={25,33,56,84}; |
var quarterResults:Array =new Array(); 또는 var quarterResults:Array=[]; var quarterResults:Array= [25, 33, 56, 84]; 특히, 인덱스 값 대신에 이름을 통해 요소에 접근가능함 (Hashtable 처럼) |
최상위 클래스 | Object | Object |
객체 캐스팅 (형변환) |
Person p=(Person) myObject; |
var p:Person= Person(myObject); |
UP 캐스팅 (다형성) |
class Xyz extends Abc{} Abc myObj = new Xyz(); |
class Xyz extends Abc{} var myObj:Abc=new Xyz(); |
가변유형 | N/A | var myObject:* var myObject: |
패키지 구문 |
package com.xyz; class myClass {…} |
package com.xyz{ class myClass{…} } |
접근 레벨 | public, private, protected, default | 좌동 |
Custom access levels: namespaces | N/A | Similar to XML namespaces. namespace abc; abc function myCalc(){} or abc::myCalc(){} use namespace abc ; |
콘솔출력 | System.out.println(); | trace(); |
임포트 구문 |
import com.abc.*; import com.abc.MyClass; |
좌동 |
Unordered key-value pairs | Hashtable, Map Hashtable friends = new Hashtable(); friends.put(”good”, “Mary”); friends.put(”best”, “Bill”); friends.put(”bad”, “Masha”); String bestFriend= friends.get(“best”); // bestFriend is Bill |
Associative Arrays Allows referencing its elements by names instead of indexes. var friends:Array=new Array(); friends[”best”]=”Bill”; friends[”bad”]=”Masha”; var bestFriend:String= friends[“best”] friends.best=”Alex”; var car:Object = {make:”Toyota”, model:”Camry”}; trace (car[”make”], car.model); // Output: Toyota Camry |
Hoisting | N/A | Compiler moves all variable declarations to the top of the function, so you can use a variable name even before it’s been explicitly declared in the code. |
클래스 인스턴스화 |
Customer cmr = new Customer(); Class cls = Class.forName(“Customer”); Object myObj= cls.newInstance(); |
var cmr:Customer = new Customer(); var cls:Class = flash.util.getClassByName(”Customer”); var myObj:Object = new cls(); |
Private 클래스 | private class myClass{…} | private 클래스는 없음 |
Private 생성자 | 지원 보통 싱글톤에서 사용함 |
미지원. Implementation of private constructors is postponed as they are not the part of the ECMAScript standard yet. To create a Singleton, use public static getInstance(), which sets a private flag instanceExists after the first instantiation. Check this flag in the public constructor, and if instanceExists==true, throw an error. |
클래스와 파일명 | A file can have multiple class declarations, but only one of them can be public, and the file must have the same name as this class. | A file can have multiple class declarations, but only one of them can be placed inside the package declaration, and the file must have the same name as this class. |
패키지 내에 정의할 수 있는 항목 |
Classes 와 interfaces | Classes, interfaces, variables, functions, namespaces, and executable statements. |
동적 클래스 (define an object that can be altered at runtime by adding or changing properties and methods). |
N/A | dynamic class Person { var name:String; } //Dynamically add a variable // and a function Person p= new Person(); p.name=”Joe”; p.age=25; p.printMe = function () { trace (p.name, p.age); } p.printMe(); // Joe 25 |
function closures | N/A. Closure is a proposed addition to Java 7. |
myButton.addEventListener(“click”, myMethod); A closure is an object that represents a snapshot of a function with its lexical context (variable’s values, objects in the scope). A function closure can be passed as an argument and executed without being a part of any object |
추상클래스 | 지원 | N/A |
함수 오버라이딩 | 지원 | 지원 override 명시해야 함 |
함수 오버로딩 | 지원 | 지원안함 |
인터페이스 | class A implements B{…} 메소드 골격과 final 변수를 정의함 |
class A implements B{…} 오직 펑션 구문만 정의 가능함 |
예외처리 | try, catch, throw, finally, throws 캐치하지 않은 예외는 호출자에게 전달됨 |
try, catch, throw, finally A method does not have to declare exceptions. Can throw not only Error objects, but also numbers: throw 25.3; Flash Player terminates the script in case of uncaught exception. |
정규식 | 지원 | 지원 |
'플렉스' 카테고리의 다른 글
Flex 에러 코드 사전 웹 어플리케이션 (0) | 2008.01.31 |
---|---|
crossdomain.xml 을 이용한 원격서버 모듈 로딩 (0) | 2008.01.31 |