Download Chapter 1 Programming and Mobile Development Platform

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Java syntax wikipedia, lookup

Falcon (programming language) wikipedia, lookup

Scala (programming language) wikipedia, lookup

Library (computing) wikipedia, lookup

C++ wikipedia, lookup

Go (programming language) wikipedia, lookup

Pwn2Own wikipedia, lookup

Name mangling wikipedia, lookup

Class (computer programming) wikipedia, lookup

Object-oriented programming wikipedia, lookup

.NET Framework wikipedia, lookup

C Sharp syntax wikipedia, lookup

Java (programming language) wikipedia, lookup

Java performance wikipedia, lookup

C Sharp (programming language) wikipedia, lookup

Chapter 1 Programming
and Mobile Development
说 明:
1. 词汇后的[1][2][4][5]等为相应词语释义
2. 词汇后的[z1][z2][z3][z4]等为相应词汇背景知识注
3. 带下划线的句子后面的[i][ii][iii][iv]等为对句子的译
Chapter 1 Programming
and Mobile Development
Background Knowledge
本章讲述有关Microsoft Visual
Studio .NET、C#编程语言以及手机操作系
– 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: 1026.
• C#是一种安全的、稳定的、简单的、优雅的、由C和C++衍生出来的
• JAVA是一种面向对象的程序设计语言,具有高性能、可移植性、简
• 随着移动设备的普及,移动设备开发平台也日渐火热,目前常见的移
– Android系统是开源的,谷歌在推出Android的时候就将其定位于
– 国外很多移动巨头都开始进行Android的开发,国内厂商可以借鉴
• 学习本章时,注意体会C#、Java语言的不同;按照文中所述方法,
Chapter 1 Programming
and Mobile Development
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]开放手机联盟包括手机制造商、手机芯片厂
Chapter 1 Programming
and Mobile Development
Section1 C# and
the .NET Framework
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
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.
(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] unveiling: v. 揭开面纱, 显露
[2] announcement: n., 宣告
[i] .NET平台是为Windows操作系统的API和服务提供全新的API的新的开发框架,
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.
[1] DNA: 此处不是指脱氧核糖核酸, 这是Distributed N Architexture的缩写,
[z1]SOAP指简单对象访问协议Simple Object Access Protocol,是一种轻量
[z2]WSDL是Web Services Description Language的缩写,是用来描述Web
服务和说明如何与Web服务通信的XML语言,用于描述Web Service及其
函数、参数和返回值。一些开发工具既能根据Web Service生成WSDL文
档,又能导入WSDL文档,生成调用相应Web Service代码。
[z3]UDDI是Universal Description Discovery and Integration的缩写,意为统
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] impressive: adj. 印象深刻的
(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.
(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,
(4) New .NET-enabled non-PC devices, from cell
phones to game boxes.
(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] polymorphism: adj. 多态的
[2] specification: n. 规范, 说明书
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.
[1] conform: v. 遵守
[2] interoperate: v. 互操作
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) 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.
(3) A number of related class libraries, collectively known as the
Framework Class Library (FCL[z2] ).
[1] flavor: n. 特色
种中间语言,Common Intermediate Language, CIL),使得各种不同
Figure 1 breaks down the .NET Framework into
its system architectural components.
Figure1. NET Framework architecture
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] analogous: adj. 类似的, 相似的
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] encapsulates:v. 形成胶囊
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] rudimentary: adj. 根本的
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
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
[z1]即“Network Address Translation”,是一个IETF(Internet Engineering
Task Force, Internet工程任务组)的标准,允许一个整体机构以一个公用IP
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.
(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] disarmingly simple: 使人倍感轻松
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.
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 objectoriented programming. 、
[1] encapsulation, inheritance, and
polymorphism: 封装, 继承和多态
[2] pillars: n. 柱子, 支柱
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
[1] pertaining to: 与…有关
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] stipulate: v. 规定, 保证
[2] promise: v. 承诺
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.
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.
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.
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] assembly: n. 程序集
(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 welldesigned language. It is also currently the
language most often used in articles and tutorials
about .NET programming.
[1] premise: n. 前提
[2] paraphrase: n. 解释
[3] versatile: adj. 通用的
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, Cfamily 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] arguably: adv. 可论证地
[2] compensation: n. 补偿
[3] lucrative: adj. 有利的
(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] trepidation, glee, and resentment: trepidation, adj. 颤
抖的; glee, adj. 高兴的; resentment: adj. 怨恨的
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.
(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] frankly: adj. 坦白地讲
Chapter 1 Programming
and Mobile Development
Section2 Java Overview
(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
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: 智能消费电子设备
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. 普及, 流行
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: 商界
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].
(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).
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: 独立的软件供应商, 指专门提
5 NAI;6 BMC;7 BEA;8 Infor;9 Sybase;10 SAS
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. 共享软件
Many freeware and shareware products are
also open source. The source code for opensource 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].
Often, open-source products require that you
publish any enhancements you make so the opensource community can continue to evolve those
products. One example of a popular open-source
product is the Linux[z1] Operating System.
[z1] Linux是类Unix计算机操作系统,是自由软件和
种应用软件等。Ubuntu、Red Hat Linux、SuSE等
(3) Basics of a Typical Java
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).
Figure 2. Typical Java Environment
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
[1] extension: n.扩展名
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.
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, type “javac” at the
command window of your system (i.e., the MSDOS 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.
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.
An application is a program (such as a wordprocessor 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.
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.
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.
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.
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.
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.
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.
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.
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.
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
Chapter 1 Programming
and Mobile Development
Section 3. Android
(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
[z2] iPhone由苹果公司在2007年推出,它将创新的移动
(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. 专利税
(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. 释放
(3) Tons of built-in services out of the box: Locationbased services use GPS or cell tower
triangulation[1] to let you customize the user
experience depending on where you are. A fullpowered 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. 同步
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.
(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
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
(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两词的词头组成的
(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移动
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. 基础, 支柱
(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, TMobile, and NTT DoCoMo[z2] .
[z1] 它是Mozilla Labs发布的一款Firefox插件,能够帮
[z2] NTT DoCoMo公司是日本电报电话公司,是目前
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.
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.
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
Figure 3. JDK Version
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
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.
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):
1. Start Eclipse, and select Help  Software
2. Click the Available Software tab if it’s not already
3. Click the Add Site... button.
4. Enter the location of the Android update site: If you
have trouble with this address, try using http in the
location instead of https.
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
6. Once the install is done, restart Eclipse.
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.
Figure 4. SDK Location
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.
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.
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.
Figure 5. An application
Figure 6. Application with a typing box.
Chapter 1 Programming
and Mobile Development
Thinking and Exercising
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.
The End of Chapter 1
Any question?