Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Programming and Mobile Development Platform 说 明: 1. 词汇后的 [1][2][4][5] 等为相应词语释义 2. 词汇后的 [z1][z2][z3][z4] 等为相应词汇背景知识注 释 3. 带下划线的句子后面的 [i][ii][iii][iv]

Similar presentations


Presentation on theme: "Chapter 1 Programming and Mobile Development Platform 说 明: 1. 词汇后的 [1][2][4][5] 等为相应词语释义 2. 词汇后的 [z1][z2][z3][z4] 等为相应词汇背景知识注 释 3. 带下划线的句子后面的 [i][ii][iii][iv]"— Presentation transcript:

1 Chapter 1 Programming and Mobile Development Platform 说 明: 1. 词汇后的 [1][2][4][5] 等为相应词语释义 2. 词汇后的 [z1][z2][z3][z4] 等为相应词汇背景知识注 释 3. 带下划线的句子后面的 [i][ii][iii][iv] 等为对句子的译 文 ( 翻译 )

2 Chapter 1 Programming and Mobile Development Platform Background Knowledge

3 本章讲述有关 Microsoft Visual Studio.NET 、 C# 编程语言以及手机操作系 统 Android 的相关知识,节选自如下文献: –Jesse Liberty. Programming C#, O’Reilly Press, 2001:.17-20. –Deitel, JAVA How to Program, the fourth Edition, 2009: 12-19. –Ed Burnette. Hello Android—— Introducting Google’s Mobile Development Platform, 2nd Edition, The Pragmatic Bookshelf, Texas, 2009: 10- 26.

4 C# 是一种安全的、稳定的、简单的、优雅的、由 C 和 C++ 衍生出来的 面向对象的编程语言。它在继承 C 和 C++ 强大功能的同时去掉了一些 它们的复杂特性(例如没有宏和模版,不允许多重继承)。 C# 综合了 VB 简单的可视化操作和 C++ 的高运行效率,以其强大的操作能力、优 雅的语法风格、创新的语言特性和便捷的面向组件编程的支持成 为.NET 开发的首选语言。 JAVA 是一种面向对象的程序设计语言,具有高性能、可移植性、简 单、面向对象、解释性语言、结构中立、类装载、安全、多线性、分 布式、动态等特性。它的执行过程是首先将源代码编译成字节码文件, 然后在不同各种不同平台的虚拟机上执行字节码,从而实现 “ 一次编 译,到处执行 ” 的跨平台特性。 随着移动设备的普及,移动设备开发平台也日渐火热,目前常见的移 动开发平台有塞班、 iPhone 以及当下正在逐步兴起的 Android 。学习 和采用 Android 的理由主要有: –Android 系统是开源的,谷歌在推出 Android 的时候就将其定位于 开源技术,所以 Android 也继承了开源技术的基本特征,即免费、 安全、易于开发,并且系统应用的移植很容易实现。 – 国外很多移动巨头都开始进行 Android 的开发,国内厂商可以借鉴 其开发经验,更好地促进移动软件技术的开发与应用。 学习本章时,注意体会 C# 、 Java 语言的不同;按照文中所述方法, 在 Eclipse 上搭建起开发 Android 应用程序的平台。同时,注意长句的 翻译。

5 Chapter 1 Programming and Mobile Development Platform Text

6 In this chapter, we will present the coding knowledge and the popular mobile development platform. C# and the.NET framework will be present first, then the comparability among C# and Visual Basic.NET, Java, C++ will be proposed. Java overview, including its history, its class libraries, its typical environment, will be present then. Android is a new open source software toolkit for mobile phones that was created by Google and the Open Handset Alliance[z1]. In a few years, it’s expected to be found in millions of cell phones and other mobile devices, making Android a major platform for application developers.[z1] [z1] 开放手机联盟包括手机制造商、手机芯片厂 商和移动运营商等,是谷歌公司于 2007 年 11 月宣 布组建的一个全球性组织,它支持谷歌可能发布 的手机操作系统或应用软件,共同开发名为 Android 的开放源代码的移动系统。[z1]

7 Chapter 1 Programming and Mobile Development Platform Section1 C# and the.NET Framework

8 The goal of C# is to provide a simple, safe, modern, object-oriented, Internet-centric, highperformance language for.NET development. C# is a new language, but it draws on the lessons learned over the past three decades. In much the way that you can see in young children the features and personalities of their parents and grandparents, you can easily see in C# the influence of Java, C++, Visual Basic, and other languages.

9 The focus of this section is the C# language and its use as a tool for programming on the.NET platform. You learn C# specifically to create.NET applications. This section does not consider C# in a vacuum but places the language firmly in the context of Microsoft's.NET platform and in the development of desktop and Internet applications.

10 (1) Overview of.NET When Microsoft announced C# in July 2000, its unveiling[1] was part of a much larger event: the announcement[2] of the.NET platform. The.NET platform is, in essence, a new development framework that provides a fresh application programming interface (API) to the services and APIs of classic Windows operating systems, especially Windows 2000, while bringing together a number of disparate technologies that emerged from Microsoft during the late 1990s[i].[1][2][i] [1][1] unveiling: v. 揭开面纱, 显露 [2][2] announcement: n., 宣告 [i][i].NET 平台是为 Windows 操作系统的 API 和服务提供全新的 API 的新的开发框架, 特别是 Windows2000 。它同时还集中微软在 20 世纪 90 年代后期开发的各种独 立的技术之大成。这里的 disparate 意为全异的,不同的。

11 Among the latter are COM+ component services, the ASP web development framework, a commitment to XML and object-oriented design, support for new web services protocols such as SOAP[z1], WSDL[z2], and UDDI[z3], and a focus on the Internet, all integrated within the DNA[1] architecture.[z1][z2][z3][1] [1] DNA: 此处不是指脱氧核糖核酸, 这是 Distributed N Architexture 的缩写, 它是微软.Net 架构的前身 [z1][z1]SOAP 指简单对象访问协议 Simple Object Access Protocol ,是一种轻量 的、简单的、基于 XML 的协议,允许 Java 对象和 COM 对象在分布式、分 散的、基于 Web 的环境中彼此通话。更一般地, SOAP 允许任何类型的对 象(或代码)在任何平台上,以任何一种语言相互通信。 [z2][z2]WSDL 是 Web Services Description Language 的缩写,是用来描述 Web 服务和说明如何与 Web 服务通信的 XML 语言,用于描述 Web Service 及其 函数、参数和返回值。一些开发工具既能根据 Web Service 生成 WSDL 文 档,又能导入 WSDL 文档,生成调用相应 Web Service 代码。 [z3][z3]UDDI 是 Universal Description Discovery and Integration 的缩写,意为统 一描述、发现和集成的协议,它使得商业实体能够彼此发现,定义它们怎 样在 Internet 上互相作用并在一个全球的注册体系架构中共享信息。

12 Microsoft says it is devoting 80% of its research and development budget to.NET and its associated technologies. The results of this commitment to date are impressive[1]. For one thing, the scope of.NET is huge. The platform consists of four separate product groups:[1] [1] impressive: adj. 印象深刻的

13 (1) A set of languages, including C# and Visual Basic.NET; a set of development tools, includingVisual Studio.NET; a comprehensive class library for building web services and web and Windows applications; as well as the Common Language Runtime (CLR[z1] ) to execute objects built within this framework.[z1] [z1]CLR 位于操作系统顶层[z1]

14 (2) A set of.NET Enterprise Servers, formerly known as SQL Server 2000, Exchange 2000, BizTalk 2000, and so on, that provide specialized functionality for relational data storage, email, B2B commerce, etc. (3) An offering of commercial web services, recently announced as Project Hailstorm; for a fee, developers can use these services in building applications that require knowledge of user identity, etc. (4) New.NET-enabled non-PC devices, from cell phones to game boxes.

15 (2) The.NET Framework Microsoft.NET supports not only language independence, but also language integration. This means that you can inherit from classes, catch exceptions, and take advantage of polymorphism[1] across different languages. The.NET Framework makes this possible with a specification[2] called the Common Type System (CTS) that all.NET components must obey. For example, everything in.NET is an object of a specific class that derives from the root class called System.Object. The CTS supports the general concept of classes, interfaces, delegates (which support callbacks), reference types, and value types.[1][2] [1][1] polymorphism: adj. 多态的 [2][2] specification: n. 规范, 说明书

16 Additionally,.NET includes a Common Language Specification (CLS[z1] ), which provides a series of basic rules that are required for language integration. The CLS determines the minimum requirements for being a.NET language. Compilers that conform[1] to the CLS create objects that can interoperate[2] with one another. The entire Framework Class Library (FCL[z2] ) can be used by any language that conforms to the CLS.[z1][1][2][z2] [1][1] conform: v. 遵守 [2][2] interoperate: v. 互操作 [z1] [z1] 公共语言规范 CLS 和通用类型系统一起确保语言的互操作 性。 CLS 是一个最低标准集,所有面向.NET 的编译器都必 须支持它。 [z2] [z2] 框架类库 FCL 由很多相关互联的类库组成,支持 Windows 应用程序、 Web 服务和数据访问等开发。

17 The.NET Framework sits on top of the operating system, which can be any flavor[1] of Windows, and consists of a number of components. Currently, the.NET Framework consists of:[1] (1) Four official languages: C#, VB.NET, Managed C++, and JScript.NET. (2) The Common Language Runtime (CLR[z1] ), an object-oriented platform for Windows and web development that all these languages share.[z1] (3) A number of related class libraries, collectively known as the Framework Class Library (FCL[z2] ).[z2] [1][1] flavor: n. 特色 [z1][z1]CLR 是公共语言运行时,用于把.NET 的语言翻译为机器可以执行的语言, 负责资源管理(内存分配和垃圾收集),并保证应用和底层操作系统之间 必要的分离。 [z2][z2]FCL 是.NET 框架类库,不论在 C# , J# , VB.NET 或其他.NET 开发语言中 使用的.NET 提供的类都是 FCL 中的类,就是说,.NET 的开发其实是和语 言无关的。不同语言编写的程序由于使用同一类库(等于被翻译成了同一 种中间语言, Common Intermediate Language, CIL ),使得各种不同 语言写的程序集可以通用。

18 Figure 1 breaks down the.NET Framework into its system architectural components. Figure1. NET Framework architecture

19 The most important component of the.NET Framework is the CLR, which provides the environment in which programs are executed. The CLR includes a virtual machine, analogous[1] in many ways to the Java virtual machine. At a high level, the CLR activates objects, performs security checks on them, lays them out in memory, executes them, and garbage-collects them. (The Common Type System is also part of the CLR.)[1] [1] analogous: adj. 类似的, 相似的

20 In Figure 1, the layer on top of the CLR is a set of framework base classes, followed by an additional layer of data and XML classes, plus another layer of classes intended for Web Services, Web Forms, and Windows Forms. Collectively, these classes are known as the Framework Class Library (FCL), one of the largest class libraries in history and one that provides an object-oriented API to all the functionality that the.NET platform encapsulates[1]. With more than 5,000 classes, the FCL facilitates rapid development of desktop, client/server, and other web services and applications.[1] [1] encapsulates:v. 形成胶囊

21 The set of framework base classes, the lowest level of the FCL, is similar to the set of classes in Java. These classes support rudimentary[1] input and output, string manipulation, security management, network communication, thread management, text manipulation, reflection and collections functionality, etc.[1] [1] rudimentary: adj. 根本的

22 Above this level is a tier of classes that extend the base classes to support data management and XML manipulation. The data classes support persistent management of data that is maintained on databases. These classes include the Structured Query Language (SQL) classes to let you manipulate persistent data stores through a standard SQL interface. Additionally, a set of classes called ADO.NET allows you to manipulate persistent data. The.NET Framework also supports a number of classes to let you manipulate XML data and perform XML searching and translations.

23 Extending the framework base classes and the data and XML classes is a tier of classes geared toward building applications using three different technologies: Web Services, Web Forms, and Windows Forms. Web Services include a number of classes that support the development of lightweight distributed components, which will work even in the face of firewalls and NAT[z1] software. Because Web Services employ standard HTTP and SOAP as underlying communications protocols, these components support plug-and-play across cyberspace.[z1] [z1] [z1] 即 “Network Address Translation” ,是一个 IETF(Internet Engineering Task Force, Internet 工程任务组 ) 的标准,允许一个整体机构以一个公用 IP 地址出现在 Internet 上,一种把内部私有网络 IP 地址翻译成合法网络 IP 地址 的技术。即在局域网内部使用内部地址,而当内部节点要与外部网络进行 通讯时就在网关将内部地址替换成公用地址,从而在外部公网上正常使用。 NAT 可以使多台计算机共享 Internet 连接,这一功能很好地解决了公共 IP 地址紧缺的问题。

24 Web Forms and Windows Forms allow you to apply rapid application development techniques to building web and windows applications. It usually means simply dragging and dropping controls onto your form, double-clicking a control, and writing the code to respond to the associated event.

25 (3) C# Language The C# language is disarmingly simple[1], with only about 80 keywords and a dozen built-in datatypes, but C# is highly expressive when it comes to implementing modern programming concepts. C# includes all the support for structured, component-based, object-oriented programming that one expects of a modern language built on the shoulders of C++ and Java.[1] [1] disarmingly simple: 使人倍感轻松

26 The C# language was developed by a small team led by two distinguished Microsoft engineers, Anders Hejlsberg and Scott Wiltamuth. Hejlsberg is also known for creating Turbo Pascal, a popular language for PC programming, and for leading the team that designed Borland Delphi, one of the first successful integrated development environments for client/server programming.

27 At the heart of any object-oriented language is its support for defining and working with classes. Classes define new types, allowing you to extend the language to better model the problem you are trying to solve. C# contains keywords for declaring new classes and their methods and properties, and for implementing encapsulation, inheritance, and polymorphism[1], the three pillars[2] of object- oriented programming. 、[1][2] [1][1] encapsulation, inheritance, and polymorphism: 封装, 继承和多态 [2][2] pillars: n. 柱子, 支柱

28 In C# everything pertaining to[1] a class declaration is found in the declaration itself. C# class definitions do not require separate header files or Interface Definition Language (IDL) files. Moreover, C# supports a new XML style of inline documentation that greatly simplifies the creation of online and print reference documentation for an application.[1] [1] pertaining to: 与 … 有关

29 C# also supports interfaces, a means of making a contract with a class for services that the interface stipulates[1]. In C#, a class can inherit from only a single parent, but a class can implement multiple interfaces. When it implements an interface, a C# class in effect promises[2] to provide the functionality the interface specifies.[1][2] [1][1] stipulate: v. 规定, 保证 [2][2] promise: v. 承诺

30 C# also provides support for structs, a concept whose meaning has changed significantly from C++. In C#, a struct is a restricted, lightweight type that, when instantiated, makes fewer demands on the operating system and on memory than a conventional class does. A struct can't inherit from a class or be inherited from, but a struct can implement an interface.

31 C# provides component-oriented features, such as properties, events, and declarative constructs (called attributes). Component-oriented programming is supported by the CLR's support for storing metadata with the code for the class. The metadata describes the class, including its methods and properties, as well as its security needs and other attributes, such as whether it can be serialized; the code contains the logic necessary to carry out its functions.

32 A compiled class is thus a self-contained unit; therefore, a hosting environment that knows how to read a class' metadata and code needs no other information to make use of it. Using C# and the CLR, it is possible to add custom metadata to a class by creating custom attributes. Likewise, it is possible to read class metadata using CLR types that support reflection.

33 An assembly[1] is a collection of files that appear to the programmer to be a single dynamic link library (DLL) or executable (EXE). In.NET, an assembly is the basic unit of reuse, versioning, security, and deployment. The CLR provides a number of classes for manipulating assemblies.[1] [1] assembly: n. 程序集

34 (4) C# Versus Visual Basic.NET The premise[1] of the.NET Framework is that all languages are created equal. To paraphrase[2] George Orwell, however, some languages are more equal than others. C# is an excellent language for.NET development. You will find it is an extremely versatile[3], robust and well- designed language. It is also currently the language most often used in articles and tutorials about.NET programming.[1][2][3] [1][1] premise: n. 前提 [2][2] paraphrase: n. 解释 [3][3] versatile: adj. 通用的

35 It is likely that many VB programmers will choose to learn C#, rather than upgrading their skills to VB.NET. This would not be surprising because the transition from VB6 to VB.NET is, arguably[1], nearly as difficult as from VB6 to C# —— and, whether it's fair or not, historically, C- family programmers have had higher earning potential than VB programmers. As a practical matter, VB programmers have never gotten the respect or compensation[2] they deserve, and C# offers a wonderful chance to make a potentially lucrative[3] transition.[1][2][3] [1][1] arguably: adv. 可论证地 [2][2] compensation: n. 补偿 [3][3] lucrative: adj. 有利的

36 (5) C# Versus Java Java programmers may look at C# with a mixture of trepidation, glee, and resentment[1]. It has been suggested that C# is somehow a "rip-off" of Java. I won't comment on the religious war between Microsoft and the "anyone but Microsoft" crowd except to acknowledge that C# certainly learned a great deal from Java. But then Java learned a great deal from C++, which owed its syntax to C, which in turn was built on lessons learned in other languages. We all stand on the shoulders of giants.[1] [1] trepidation, glee, and resentment: trepidation, adj. 颤 抖的 ; glee, adj. 高兴的 ; resentment: adj. 怨恨的

37 C# offers an easy transition for Java programmers; the syntax is very similar and the semantics are familiar and comfortable. Java programmers will probably want to focus on the differences between Java and C# in order to use the C# language effectively.

38 (6) C# versus C++ While it is possible to program in.NET with C++, it isn't easy or natural. Frankly[1], having worked for ten years as a C++ programmer and written a dozen books on the subject, I'd rather have my teeth drilled than work with managed C++. Perhaps it is just that C# is so much friendlier. In any case, once I saw C# I never looked back.[1] [1] frankly: adj. 坦白地讲

39 Chapter 1 Programming and Mobile Development Platform Section2 Java Overview

40 (1) History of Java Perhaps the microprocessor revolution’s most important contribution to date is that it made possible the development of personal computers, which now number in the hundreds of millions worldwide[i]. Personal computers have had a profound impact on people and the way organizations conduct and manage their business. [i] 微处理器革命对当今世界最大的贡献可能就是它使个人 电脑的发展成为可能,世界上至今有成千上万台个人电 脑。

41 Many people believe that the next major area in which microprocessors will have a profound impact is in intelligent consumer-electronic devices[1]. Recognizing this, Sun Microsystems funded an internal corporate research project called Green in 1991. The project resulted in the development of a C and C ++ based language that its creator, James Gosling, called Oak after an oak tree outside his window at Sun. It was later discovered that there already was a computer language called Oak. When a group of Sun people visited a local coffee place, the name Java was suggested, and it stuck. [1]intelligent consumer-electronic devices: 智能消费电子设备

42 The Green project ran into some difficulties. The marketplace for intelligent consumer-electronic devices was not developing as quickly as Sun had anticipated. Worse yet, a major contract for which Sun competed was awarded[1] to another company. So the project was in danger of being canceled. By sheer good fortune[2], the World Wide Web exploded in popularity[3] in 1993, and Sun people saw the immediate potential of using Java to create Web pages with so-called dynamic content. This breathed new life into the project. [1]awarded: v. 授予, 判给 [2]sheer good fortune: 幸运的是 [3]popularity: n. 普及, 流行

43 Sun formally announced Java at a major conference in May 1995. Ordinarily, an event like this would not have generated much attention. However, Java generated immediate interest in the business community[1] because of the phenomenal interest in the World Wide Web. [1]business community: 商界

44 Java is now used to create Web pages with dynamic and interactive content, to develop large-scale enterprise applications, to enhance the functionality of World Wide Web servers (the computers that provide the content we see in our Web browsers), to provide applications for consumer devices (such as cell phones, pagers and personal digital assistants) and for many other purposes[i]. [i]JAVA 现在被用于创建动态的、交互内容的 web 页,开发大规模的 企业级应用,增强 WWW 服务器的功能(这是一种能提供浏览器 端内容的计算机),为消费设备提供应用(如手机、传呼机、个 人数字助理)和很多其他的目的。

45 (2) Java Class Libraries Java programs consist of pieces called classes. Classes consist of pieces called methods that perform tasks and return information when they complete their tasks. You can program each piece you may need to form a Java program. However, most Java programmers take advantage of rich collections of existing classes in Java class libraries. The class libraries are also known as the Java APIs (Application Programming Interfaces).

46 Thus, there are really two pieces to learning the Java world. The first is learning the Java language itself so that you can program your own classes; the second is learning how to use the classes in the extensive Java class libraries. Class libraries are provided primarily by compiler vendors, but many class libraries are supplied by independent software vendors[1] (ISV [z1]s). Also, many class libraries are available from the Internet and World Wide Web as freeware or shareware. [1]independent software vendors: 独立的软件供应商, 指专门提 供软件和相关服务的公司 [z1] 全球十大 ISV : 1.Microsoft ; 2.Oracle ; 3.SAP ; 4.Compuware ; 5 NAI ; 6 BMC ; 7 BEA ; 8 Infor ; 9 Sybase ; 10 SAS

47 You can download freeware products and use them for free —— subject to any restrictions specified by the copyright owner. You also can download shareware[1] products for free, so you can try the software. Shareware products often are free of charge for personal use. However, for shareware products that you use regularly or use for commercial purposes, you are expected to pay a fee designated by the copyright owner. [1] shareware: n. 共享软件

48 Many freeware and shareware products are also open source. The source code for open- source products is freely available on the Internet, which enables you to learn from the source code, validate that the code serves its stated purpose and even modify the code[i]. [i] 开源产品的源代码可以从 Internet 上免费得到,这些 开源产品能够帮你学习源代码,验证其开发目的设 置,修改其代码。

49 Often, open-source products require that you publish any enhancements you make so the open- source community can continue to evolve those products. One example of a popular open-source product is the Linux[z1] Operating System. [z1] Linux 是类 Unix 计算机操作系统,是自由软件和 开放源代码发展中最著名的例子。一个典型的 Linux 发行版包括: Linux 内核、一些 GNU 程序库和工具、 命令行 shell ,图形界面和相应的桌面环境,以及多 种应用软件等。 Ubuntu 、 Red Hat Linux 、 SuSE 等 都是基于 Linux 的操作系统。

50 (3) Basics of a Typical Java Environment Java systems generally consist of several parts: an environment, the language, the Java Applications Programming Interface (API) and various class libraries. The following discussion explains a typical Java program development environment, as shown in Fig. 2. Java programs normally go through five phases to be executed. These are: edit, compile, load, verify and execute. We discuss these concepts in the context of the Java 2 Software Development Kit (J2SDK).

51 Figure 2. Typical Java Environment

52 Phase 1 consists of editing a file. This is accomplished with an editor program (normally known as an editor). The programmer types a Java program, using the editor, and makes corrections, if necessary. When the programmer specifies that the file in the editor should be saved, the program is stored on a secondary storage device, such as a disk. Java program file names end with the.java extension[1]. [1] extension: n. 扩展名

53 Two editors widely used on UNIX/ Linux systems are vi and emacs[z1]. On Windows NT/2000 or later version, simple edit programs like the DOS Edit command and the Windows Notepad will suffice. Java integrated development environments (IDEs), such as Forte for Java Community Edition, NetBeans, Borland’s JBuilder, Symantec’s Visual Cafe and IBM’s VisualAge have built-in editors that are integrated into the programming environment. [z1] 一般来说, vi 能做的 emacs 都能做,而且 emacs 可以更方便地 扩展。一般来说,远程修改一个小文件、修改系统配置文件用 vi 比较方便。 Emacs 是一种强大的文本编辑器,在程序员和其他以 技术工作为主的计算机用户中广受欢迎 。

54 In Phase 2, the programmer gives the command javac to compile the program. The Java compiler translates the Java program into byte codes —— the language understood by the Java interpreter. To compile a program called welcome.java, type “javac welcome.java” at the command window of your system (i.e., the MS- DOS prompt in Windows, the Command Prompt in Windows NT/2000 or the shell prompt in UNIX/Linux). If the program compiles correctly, the compiler produces a file called welcome.class. This is the file containing the bytecodes that will be interpreted during the execution phase.

55 Phase 3 is called loading. The program must first be placed in memory before it can be executed. This is done by the class loader, which takes the.class file (or files) containing the bytecodes and transfers it to memory. The.class file can be loaded from a disk on your system or over a network (such as your local university or company network or even the Internet). There are two types of programs for which the class loader loads.class files——applications and applets.

56 An application is a program (such as a word- processor program, a spreadsheet program, a drawing program or an e-mail program) that normally is stored and executed from the user’s local computer. An applet[z1] is a small program that normally is stored on a remote computer that users connect to via a World Wide Web browser. [z1]Applet 是采用 Java 创建的基于 HTML 的小程序。浏 览器将其暂时下载到用户的硬盘上,并在 Web 页打 开时在本地运行。一般的 Applet 只能通过 appletviewer 或者浏览器来运行,一般的 Java 程序 通过继承 Applet 类也可以嵌入网页运行。

57 Applets are loaded from a remote computer into the browser, executed in the browser and discarded when execution completes. To execute an applet again, the user must point a browser at the appropriate location on the World Wide Web and reload the program into the browser.

58 Applications are loaded into memory and executed by using the Java interpreter via the command java. When executing a Java application called welcome, the command java welcome invokes the interpreter for the welcome application and causes the class loader to load information used in the welcome program. The class loader also executes when a World Wide Web browser such as Netscape Navigator or Microsoft Internet Explorer loads a Java applet.

59 Browsers are used to view documents on the World Wide Web called Hypertext Markup Language (HTML) documents. HTML describes the format of a document in a manner that is understood by the browser application. An HTML document may refer to a Java applet. When the browser sees an applet referenced in an HTML document, the browser launches the Java class loader to load the applet (normally from the location where the HTML document is stored). Each browser that supports Java has a built-in Java interpreter.

60 After the applet loads, the browser’s Java interpreter executes the applet. Applets can also execute from the command line, using the appletviewer command provided with the J2SDK— the set of tools including the compiler (javac), interpreter (java), appletviewer and other tools used by Java programmers. Like Netscape Navigator and Microsoft Internet Explorer, the appletviewer requires an HTML document to invoke an applet.

61 For example, if the welcome.html file refers to the welcome applet, the appletviewer command is used as follows: appletviewer welcome.html. This causes the class loader to load the information used in the welcome applet. The appletviewer is a minimal browser——it knows only how to interpret references to applets and ignores all other HTML in a document.

62 Before the Java interpreter built into a browser or the appletviewer executes the bytecodes in an applet, the bytecodes are verified by the bytecode verifier in Phase 4. This ensures that the bytecodes for classes that are loaded from the Internet are valid and that they do not violate Java’s security restrictions. Java enforces strong security, because Java programs arriving over the network should not be able to cause damage to your files and your system. Note that bytecode verification also occurs in applications that download classes from a network.

63 Finally, in Phase 5, the computer, under the control of its CPU, interprets the program one bytecode at a time, thus performing the actions specified by the program.

64 Programs might not work on the first try. Each of the preceding phases can fail because of various errors. For example, an executing program might attempt to divide by zero (an illegal operation in Java just as it is in arithmetic). This would cause the Java program to print an error message. The programmer would return to the edit phase, make the necessary corrections and proceed through the remaining phases again to determine that the corrections work properly.

65 Most programs in Java input or output data. When we say that a program prints a result, we normally mean that the program displays results on the computer screen. Data may be output to other devices, such as disks and hardcopy printers.

66 Chapter 1 Programming and Mobile Development Platform Section 3. Android Platform

67 (1) What makes Android Special? There are already many mobile platforms on the market today, including Symbian[z1], iPhone[z2], Windows Mobile, BlackBerry, Java Mobile Edition, Linux Mobile (LiMo), and more. Why do we need another mobile standard? Android is the first environment that combines the following: [z1] 塞班是由诺基亚、索尼爱立信、摩托罗拉、西门子等 几家大型移动通讯设备商共同出资组建的一个合资公司 ,专门研发手机操作系统的平台。 [z2] iPhone 由苹果公司在 2007 年推出,它将创新的移动 电话、可触摸宽屏 iPod 以及具有桌面级电子邮件、网页 浏览、搜索和地图功能的突破性因特网通信设备三种产 品完美地融为一体。

68 (1) A truly open, free development platform based on Linux and open source: Handset[1] makers like it because they can use and customize the platform without paying a royalty[2]. [1]handset: n. 手机 [2]royalty: n. 专利税

69 (2) A component-based architecture inspired by Internet mashups[z1] : Parts of one application can be used in another in ways not originally envisioned[1] by the developer. You can even replace built-in components with your own improved versions. This will unleash[2] a new round of creativity in the mobile space. [1]envision: v. 想象, 预想 [2]unleash: v. 释放 [z1]Mashup 是当今网络上新出现的一种网络现象,利 用它,即使是没有任何编程技能的普通网民也可以 自己编写程序。

70 (3) Tons of built-in services out of the box: Location- based services use GPS or cell tower triangulation[1] to let you customize the user experience depending on where you are. A full- powered SQL database lets you harness[2] the power of local storage for occasionally connected computing and synchronization[3]. [1]triangulation: n. 三角测量 [2]harness: v. 利用 [3]synchronization: n. 同步

71 Browser and map views can be embedded directly in your applications. All these built-in capabilities help raise the bar on functionality while lowering your development costs.

72 (4) Automatic management of the application life cycle: Programs are isolated from each other by multiple layers of security, which will provide a level of system stability[1] not seen before in smart phones[i]. [1] stability: n. 稳定性 [i] 通过多层的安全机制,程序间彼此是隔离的。这样 就可以提供一种系统级别的安全稳定性,而这在早 期的智能手机中是没有的。注: Smart phone 是一 种在手机内安装了相应开放式操作系统的手机,通 常使用的操作系统有 Symbian OS 、 Windows Mobile 、 Linux 和 Palm 等。

73 The end user will no longer have to worry about what applications are active or close some programs so that others can run. Android is optimized for low-power, low-memory devices in a fundamental way that no previous platform has attempted.

74 (5) High-quality graphics and sound: Smooth, antialiased[1] 2D vector graphics and animation inspired by Flash are melded[2] with 3D accelerated OpenGL graphics to enable new kinds of games and business applications. CODECs[z1] for the most common industrystandard audio and video formats are built right in, including H.264 (AVC), MP3, and AAC. [1]antialiased: v. 平滑图像中的锯齿 [2]meld: v. 混合 [z1] 由编码器 COder 和译码器 DECoder 两词的词头组成的 缩略语,指数字通信中具有编码、译码功能的器件,能 有效减少数字存储占用的空间,一般用在视频会议、流 媒体、视频应用等场合。

75 (6) Portability across a wide range of current and future hardware: All your programs are written in Java and executed by Android’s Dalvik[z1] virtual machine, so your code will be portable across ARM, x86, and other architectures. Support for a variety of input methods is included such as keyboard, touch, and trackball. User interfaces can be customized for any screen resolution and orientation. [z1] Dalvik 虚拟机是谷歌等厂商合作开发的 Android 移动 设备平台的核心组成部分之一。它的运行是基于寄存器 的 ( 普通的 Java 虚拟机是基于栈的 ) ,效率更高,可以支 持已转换为.dex 格式的 Java 应用程序的运行。

76 Android offers a fresh take on the way mobile applications interact with users, along with the technical underpinnings[1] to make it possible. [1] underpinning: n. 基础, 支柱

77 (2) Quick Start on Android Android combines the ubiquity[z1] of cell phones, the excitement of open source software, and the corporate backing of Google and other Open Handset Alliance members like Intel, TI, T- Mobile, and NTT DoCoMo[z2]. [z1] 它是 Mozilla Labs 发布的一款 Firefox 插件,能够帮 助用户将所能构想到互联网服务聚合至浏览器中并 应用于页面信息的切割。 [z2] NTT DoCoMo 公司是日本电报电话公司,是目前 世界上最大的移动通信公司之一,也是最早推出 3G 商用服务的运营商之一。

78 The result is a mobile platform you can’t afford not to learn. Luckily, getting started developing with Android is easy. You don’t even need access to an Android phone—just a computer where you can install the Android SDK and phone emulator.

79 1 Installing the Tools The Android software development kit (SDK) works on Windows, Linux, and Mac OS X. The applications you create, of course, can be deployed on any Android devices. Before you start coding, you need to install Java, an IDE, and the Android SDK.

80 1.1 Java 5.0+ First you need a copy of Java. All the Android development tools require it, and programs you write will be using the Java language. JDK 5 or 6 is required. It’s not enough to just have a runtime environment (JRE[z1]); you need the full development kit. To verify you have the right version, run this command from your shell window, see figure 3. [z1] JDK 和 JRE 是有区别的。 JRE 是 Java2 Runtime Environment ,即 Java 运行环境,如果只需要运行 Java 程序或 Applet ,下载并安装它即可。如果要自行开发 Java 软件,应下载 JDK ,在 JDK 中附带有 J2RE 。

81 Figure 3. JDK Version

82 1.2 Eclipse Next, you should install a Java development environment if you don’t have one already. I recommend Eclipse, because it’s free and because it’s used and supported by the Google developers who created Android. If you don’t want to use Eclipse, support for other IDEs such as NetBeans and JetBrains IDEA is available from their respective communities. The minimum version of Eclipse is 3.3.1, but you should always use whatever is the most up-to-date production version.

83 1.3 Android Next, download the latest Android SDK from Google. After downloading the package that’s right for you, unpack the.zip file to a convenient directory. By default, the SDK will be expanded into a subdirectory. No special install program is needed but I do recommend you add the SDK’s bin directory to your PATH.

84 1.4 Eclipse Plug-In To make development easier, Google has written a plug-in for Eclipse called the Android Development Toolkit (ADT). To install the plug-in, follow these steps (note these directions are for Eclipse 3.4—different versions may have slightly different menus and options):

85 1. Start Eclipse, and select Help  Software Updates.... 2. Click the Available Software tab if it’s not already selected. 3. Click the Add Site... button. 4. Enter the location of the Android update site: https://dl-ssl.google.com/android/eclipse/. If you have trouble with this address, try using http in the location instead of https.

86 5. The Android site should now appear in the Available Software view. Select the checkbox next to it, and then click Install.... If you get an error message, then you may not have the right version of Eclipse. I strongly recommend using either the prebuilt Eclipse IDE for Java or the Eclipse IDE for Java EE Development packages, version 3.4 or newer. 6. Once the install is done, restart Eclipse.

87 7. When Eclipse comes back up, you may see a few error messages because you need to tell it where the Android SDK is located. Select Window  Preferences  Android (Eclipse  Preferences on Mac OS X), and enter the SDK install directory, see figure 4. Click OK. Now that everything is installed, it’s time to write your first program.

88 Figure 4. SDK Location

89 2 Creating Your First Program ADT comes with a built-in example program, or template, that we’re going to use to create a simple “Hello, Android” program in just a few seconds. Select File  New  Project... to open the New Project dialog box. Then select Android   Android Project, and click Next. Enter the responding information on project name, build target, application name, pageage name and create activity. Then, click Finish. The Android plug-in will create the project and fill it in with some default files. Eclipse will build it and package it up so it will be ready to execute.

90 If you get an error about missing source folders, select Project  Clean to fix it. OK, that takes care of writing the program; now all that’s left is to try running it. First we’ll run it under the Android Emulator.

91 3 Running on the Emulator To run your Android program, go to the Package Explorer window, right-click the HelloAndroid project, and select Run As  Android Application. Its shell is shown in figure 5. In the example, as the application’s name is “HelloApplication”, so it should click the HelloApplication icon in figure 5. Of course, you can add some other functions in the application. Figure 6 shows the application with a typing box, see figure 6.

92 Figure 5. An application

93 Figure 6. Application with a typing box.

94 Chapter 1 Programming and Mobile Development Platform Thinking and Exercising

95 1. Please list some main difference between the C# and Java. 2. Please list some main difference between the C# and C++. 3. Please translate the following passages from English into Chinese: (1) Passage 1: The goal of C# is to provide a simple, safe, modern, object-oriented, Internet-centric, highperformance language for.NET development. C# is a new language, but it draws on the lessons learned over the past three decades. In much the way that you can see in young children the features and personalities of their parents and grandparents, you can easily see in C# the influence of Java, C++, Visual Basic, and other languages. (2) Passage 2: Extending the framework base classes and the data and XML classes is a tier of classes geared toward building applications using three different technologies: Web Services, Web Forms, and Windows Forms. Web Services include a number of classes that support the development of lightweight distributed components, which will work even in the face of firewalls and NAT software. Because Web Services employ standard HTTP and SOAP as underlying communications protocols, these components support plug-and-play across cyberspace.

96 The End of Chapter 1 Any question?


Download ppt "Chapter 1 Programming and Mobile Development Platform 说 明: 1. 词汇后的 [1][2][4][5] 等为相应词语释义 2. 词汇后的 [z1][z2][z3][z4] 等为相应词汇背景知识注 释 3. 带下划线的句子后面的 [i][ii][iii][iv]"

Similar presentations


Ads by Google