计算机专业外文翻译think in java

计算机专业外文翻译think in java
计算机专业外文翻译think in java

来自:think in java (3)

外文原文

The busy Java developer's guide to Scala: Class action

It makes sense for Java? developers to use objects as a first point of reference for understanding Scala. In this second installment of The busy Java developer's guide to Scala series, Ted Neward follows a basic premise of language measurement: that the power of a language can be measured in direct relation to its ability to integrate new facilities -- in this case, support for complex numbers. Along the way you'll see some interesting tidbits related to class definitions and usage in Scala. In last month's article , you saw just a touch of Scala's syntax, the bare minimum necessary to run a Scala program and observe some of its simpler features. The Hello World and Timer examples from that article let you see Scala's Application class, its syntax for method definitions and anonymous functions, just a glimpse of an Array[], and a bit on type-inferencing. Scala has a great deal more to offer, so this article investigates the intricacies of Scala coding.

Scala's functional programming features are compelling, but they're not the only reason Java developers should be interested in the language. In fact, Scala blends functional concepts and object orientation. In order to let the Java-cum-Scala programmer feel more at home, it makes sense to look at Scala's object features and see how they map over to Java linguistically. Bear in mind that there isn't a direct mapping for some of these features, or in some cases, the "mapping" is more of an analog than a direct parallel. But where the distinction is important, I'll point it out.

Scala has class(es), too

Rather than embark on a lengthy and abstract discussion of the class features that Scala supports, let's look at a definition for a class that might be used to bring rational number support to the Scala platform (largely swiped from "Scala By Example" -- see Resources):

else gcd(y%x, x)

}

private val g = gcd(n,d)

val numer:Int = n/g

val denom:Int = d/g

def +(that:Rational) =

new Rational(numer*that.denom + that.numer*denom, denom * that.denom)

def -(that:Rational) =

new Rational(numer * that.denom - that.numer * denom, denom * that.denom)

def *(that:Rational) =

new Rational(numer * that.numer, denom * that.denom)

def /(that:Rational) =

new Rational(numer * that.denom, denom * that.numer)

override def toString() =

"Rational: [" + numer + " / " + denom + "]"

}

While the overall structure of Listing 1 is lexically similar to what you've seen in Java code over the last decade, some new elements clearly are at work here. Before picking this definition apart, take a look at the code to exercise the new Rational class:

What you see in Listing 2 isn't terribly exciting: I create a couple of rational numbers, create two more Rationals as the addition and subtraction of the first two, and echo everything to the console. (Note that Console.println() comes from the Scala core library, living in scala.*, and is implicitly imported into every Scala program, just as https://www.360docs.net/doc/7d14901351.html,ng is in Java programming.) How many ways shall I construct thee?

Now look again at the first line in the Rational class definition:

Although you might think you're looking at some kind of generics-like syntax in Listing 3, it's actually the default and preferred constructor for the Rational class: n and d are simply the parameters to that constructor.

Scala's preference for a single constructor makes a certain kind of sense -- most classes end up having a single constructor or a collection of constructors that all "chain" through a single constructor as a convenience. If you wanted to, you could define more constructors on a Rational like so:

Note that Scala's constructor chain does the usual Java-constructor-chaining thing by calling into the preferred constructor (the Int,Int version).

Details, (implementation) details...

When working with rational numbers, it helps to perform a bit of numerical legerdemain: namely that of finding a common denominator to make certain operations easier. If you want to add 1-over-2 (also known as "one-half") to 2-over-4 (also known as "two-fourths"), the Rational class should be smart enough to realize that 2-over-4 is the same as 1-over-2, and convert it accordingly before adding the two together.

This is the purpose of the nested private gcd() function and g value inside of the Rational class. When the constructor is invoked in Scala, the entire body of the class is evaluated, which means g will be initialized with the greatest common denominator of n and d, and then used in turn to set n and d appropriately.

Looking back at Listing 1, it's also fairly easy to see that I created an overridden toString method to return the values of Rational, which will be very useful when I start exercising it from the RunRational driver code.

Notice the syntax around toString, however: the override keyword in the front of the definition is required so that Scala can check to make sure that a corresponding definition exists in the base class. This can help prevent subtle bugs created by accidental keyboard slips. (It was this same motivation that led to the creation of the @Override annotation in Java 5.) Notice, as well, that the return type is not specified -- it's obvious from the definition of the method body -- and that the returned value isn't explicitly denoted using the return keyword, which Java would require. Instead, the last value in the function is considered the return value implicitly. (You can always use return keyword if you prefer Java syntax, however.)

Some core values

Next up are the definitions of numer and denom, respectively. The syntax involved, offhand, would lead the Java programmer to believe that numer and denom are public Int fields that are initialized to the value of n-over-g and d-over-g, respectively; but this assumption is incorrect. Formally, Scala calls numer and denom methods without parameters, which are used to create a quick-and-easy syntax for defining accessors. The Rational class still has three private fields, n, d, and g, but they are hidden from the world by default private access in the case of n and d, and by explicit private access in the case of g.

The Java programmer in you is probably asking at this point, "Where are the corresponding "setters" for n and d?" No such setters exist. Part of the power of Scala is that it encourages developers to create immutable objects by default. Granted, syntax is available to create methods for modifying the internals of Rational, but doing so would ruin the implicit

thread-safe nature of this class. As a result, at least for this example, I'm going to leave Rational as it is.

Naturally, that raises the question of how one manipulates a Rational. Like https://www.360docs.net/doc/7d14901351.html,ng.Strings, you can't take an existing Rational and modify its values, so the only alternative is to create new Rationals out of the values of an existing one, or create it from scratch. This brings into focus the next set of four methods: the curiously named +, -, *, and / methods.

And no, contrary to what it might look like, this isn't operator-overloading.

Operator, ring me a number

Remember that in Scala everything is an object. In the last article, you saw how that principle applies to the idea that functions themselves are objects, which allows Scala programmers to assign functions to variables, pass functions as object parameters, and so on. An equally important principle is that everything is a function; that is to say, in this particular case, there is no distinction between a function named add and a function named +. In Scala, all operators are functions on a class. They just happen to have, well, funky names.

In the Rational class, then, four operations have been defined for rational numbers. These are the canonical, mathematical operations add, subtract, multiply, and divide. Each of these is named by its mathematical symbol: +, -, *, and /.

Notice, however, that each of these operators works by constructing a new Rational object each time. Again, this is very similar to how https://www.360docs.net/doc/7d14901351.html,ng.String works, and it is the default implementation because it yields thread-safe code. (If no shared state -- and internal state of an object shared across threads is implicitly shared state -- is modified by a thread, then there is no concern over concurrent access to that state.)

What's new with you?

The everything is a function rule has two powerful effects:

The first, as you've already seen, is that functions can be manipulated and stored as objects themselves. This leads to powerful re-use scenarios like the one explored in the first article in this series.

The second effect is that there is no special distinction between the operators that the

Scala-language designers might think to provide and the operators that Scala programmers think should be provided. For example, let's assume for a moment that it makes sense to provide an "inversion" operator, which will flip the numerator and denominator and return a new Rational (so that Rational(2,5) will return Rational(5,2)). If you decide that the ~ symbol best represents this concept, then you can define a new method using that as a name, and it will behave just as any other operator would in Java code, as shown in Listing 5:

Defining this unary "operator" in Scala is slightly tricky, but it's purely a syntactic nit:

The tricky part is, of course, the fact that you have to prefix the ~ name with "unary_" to tell the Scala compiler that it is intended to be a unary operator; therefore, the syntax will be "flipped" from the traditional reference-then-method syntax common in most object languages.

Note that this combines with the "everything is an object" rule to create some powerful -- but easy-to-explain -- code opportunities:

Naturally, the Scala compiler "does the right thing" for the straight integer addition examples, but syntactically it's all the same. This means that you can develop types that are no different from the "built-in" types that come as part of the Scala language.

The Scala compiler will even try to infer some meaning out of the "operators" that have some predetermined meaning, such as the += operator. Note how the following code just does what it should, despite the fact that the Rational class doesn't have an explicit definition for +=:

When printed, r5 has the value [13 / 12], which is exactly what it should be.

Scala under the hood

Remember that Scala compiles to Java bytecode, meaning that it runs on the JVM. If you need proof, look no further than the fact that the compiler is producing .class files that begin with 0xCAFEBABE, just like javac does. Also note what happens if you fire up the Java bytecode disassembler that comes with the JDK (javap) and point it at the generated Rational

class, as shown in Listing 9:

Listing 9. Classes compiled from rational.scala

C:\Projects\scala-classes\code>javap -private -classpath classes Rational

Compiled from "rational.scala"

public class Rational extends https://www.360docs.net/doc/7d14901351.html,ng.Object implements scala.ScalaObject{ private int denom;

private int numer;

private int g;

public Rational(int, int);

public Rational unary_$tilde();

public https://www.360docs.net/doc/7d14901351.html,ng.String toString();

public Rational $div(Rational);

public Rational $times(Rational);

public Rational $minus(Rational);

public Rational $plus(Rational);

public int denom();

public int numer();

private int g();

private int gcd(int, int);

public Rational(int);

public int $tag();

}

C:\Projects\scala-classes\code>

The "operators" defined in the Scala class transmogrify into method calls in the best tradition of Java programming, though they do seem to be based on funny names. Two constructors are defined on the class: one taking an int and one taking a pair of ints. And, if you happen to be at all concerned that the use of the upper-case Int type is somehow a https://www.360docs.net/doc/7d14901351.html,ng.Integer in disguise, note that the Scala compiler is smart enough to transform them into regular Java primitive ints in the class definition.

Testing, testing, 1-2-3...

It is a well-known meme that good programmers write code, and great programmers write tests; thus far, I have been lax in exercising this rule for my Scala code, so let?s see what

happens when you put this Rational class inside of a traditional JUnit test suite, as shown in Listing 10:

Listing 10. RationalTest.java

import org.junit.*;

import static org.junit.Assert.*;

public class RationalTest

{

@Test public void test2ArgRationalConstructor()

{

Rational r = new Rational(2, 5);

assertTrue(r.numer() == 2);

assertTrue(r.denom() == 5);

}

@Test public void test1ArgRationalConstructor()

{

Rational r = new Rational(5);

assertTrue(r.numer() == 0);

assertTrue(r.denom() == 1);

// 1 because of gcd() invocation during construction;

// 0-over-5 is the same as 0-over-1

}

@Test public void testAddRationals()

{

Rational r1 = new Rational(2, 5);

Rational r2 = new Rational(1, 3);

Rational r3 = (Rational) reflectInvoke(r1, "$plus", r2); //r1.$plus(r2);

assertTrue(r3.numer() == 11);

assertTrue(r3.denom() == 15);

}

// ... some details omitted

}

Aside from confirming that the Rational class behaves, well, rationally, the above test suite also proves that it is possible to call Scala code from Java code (albeit with a little bit of an impedance mismatch when it comes to the operators). The cool thing about this, of course, is

that it lets you try out Scala slowly, by migrating Java classes over to Scala classes without ever having to change the tests that back them.

The only weirdness you might notice in the test code has to do with operator invocation, in this case, the + method on the Rational class. Looking back at the javap output, Scala has obviously translated the + function into the JVM method $plus, but the Java Language Specification does not allow the $ character in identifiers (which is why it's used in nested and anonymous nested class names).

In order to invoke those methods, you either have to write the tests in Groovy or JRuby (or some other language that doesn't pose a restriction on the $ character), or you can write a little bit of Reflection code to invoke it. I go with the latter approach, which isn't all that interesting from a Scala perspective, but the result is included in this article's code bundle, should you be curious. (SeeDownload.)

Note that workarounds like these are only necessary for function names that aren't also legitimate Java identifiers.

A "better" Java

Back when I was first learning C++, Bjarne Stroustrup suggested that one way to learn C++ was to see it as "a better C" (see Resources). In some ways, Java developers today might come to see Scala as a "better Java," because it provides a more terse and succinct way of writing traditional Java POJOs. Consider the traditional Person POJO shown in Listing 11: Listing 11. JavaPerson.java (original POJO)

public class JavaPerson

{

public JavaPerson(String firstName, String lastName, int age)

{

this.firstName = firstName;

https://www.360docs.net/doc/7d14901351.html,stName = lastName;

this.age = age;

}

public String getFirstName()

{

return this.firstName;

}

public void setFirstName(String value)

{

this.firstName = value;

}

public String getLastName()

{

return https://www.360docs.net/doc/7d14901351.html,stName;

}

public void setLastName(String value)

{

https://www.360docs.net/doc/7d14901351.html,stName = value;

}

public int getAge()

{

return this.age;

}

public void setAge(int value)

{

this.age = value;

}

public String toString()

{

return "[Person: firstName" + firstName + " lastName:" + lastName + " age:" + age + " ]";

}

private String firstName;

private String lastName;

private int age;

}

Now consider its equivalent written in Scala:

It isn't a complete drop-in replacement, given that the original Person had some mutable setters. But considering the original Person also had no synchronization code around those mutable setters, the Scala version is safer to use. Also, if the goal is to truly reduce the number of lines of code in Person, you could remove the getFoo property methods entirely because Scala will generate accessor methods around each of the constructor parameters -- firstName() returns a String, lastName() returns a String, and age() returns an int).

Even if the need for those mutable setter methods is undeniable, the Scala version is still simpler, as you can see in Listing 13:

As an aside, notice the introduction of the var keyword on the constructor parameters. Without going into too much detail, var tells the compiler that the value is mutable. As a result, Scala generates both accessor (String firstName(void)) and mutator (void firstName_$eq(String)) methods. It then becomes easy to create setFoo property mutator methods that use the generated mutator methods under the hood.

Conclusion

Scala is an attempt to incorporate functional concepts and terseness without losing the richness of the object paradigm. As you've perhaps begun to see in this series, Scala also corrects some of the egregious (in hindsight) syntactic problems found in the Java language. This second article in the Busy Java developer's guide to Scala series has focused on Scala's object facilities, which let you start using Scala without having to dive too deeply into the functional pool. Based on what you've learned so far, you can already start using Scala to reduce your programming workload. Among other things, you can use Scala to produce the very same POJOs needed for other programming environments, such as Spring or Hibernate. Hold on to your diving caps and scuba gear, however, because next month's article will mark the beginning of our descent into the deep end of the functional pool.

外文翻译

面向Java开发人员的Scala指南:类操作

Java? 开发人员可以将对象作为理解Scala的出发点。本文是面向Java开发人员的Scala指南系列的第二期,作者Ted Neward遵循对一种语言进行评价的基本前提:一种语言的威力可以直接通过它集成新功能的能力衡量,在本文中就是指对复数的支持。跟随本文,您将了解在Scala中与类的定义和使用有关的一些有趣特性。

在上一期文章中,您只是稍微了解了一些Scala 语法,这些是运行Scala 程序和了解其简单特性的最基本要求。通过上一篇文章中的Hello World 和Timer 示例程序,您了解了Scala的Application类、方法定义和匿名函数的语法,还稍微了解Array[] 和一些类型推断方面的知识。Scala 还提供了很多其他特性,本文将研究Scala 编程中的一些较复杂方面。

Scala的函数编程特性非常引人注目,但这并非Java开发人员应该对这门语言感兴趣的惟一原因。实际上,Scala 融合了函数概念和面向对象概念。为了让Java和Scala 程序员感到得心应手,可以了解一下Scala 的对象特性,看看它们是如何在语言方面与Java对应的。记住,其中的一些特性并不是直接对应,或者说,在某些情况下,“对应” 更像是一种类比,而不是直接的对应。不过,遇到重要区别时,我会指出来。

Scala和Java一样使用类

我们不对Scala支持的类特性作冗长而抽象的讨论,而是着眼于一个类的定义,这个类可用于为Scala平台引入对有理数的支持(主要借鉴自“Scala By Example”,参见参考资料):

清单1. rational.scala

从词汇上看,清单1的整体结构与Java代码类似,但是,这里显然还有一些新的元素。在详细讨论这个定义之前,先看一段使用这个新Rational 类的代码:

清单2. RunRational

class Rational(n:Int, d:Int)

{

// ... as before

}

object RunRational extends Application

{

val r1 = new Rational(1, 3)

val r2 = new Rational(2, 5)

val r3 = r1 - r2

val r4 = r1 + r2

Console.println("r1 = " + r1)

Console.println("r2 = " + r2)

Console.println("r3 = r1 - r2 = " + r3)

Console.println("r4 = r1 + r2 = " + r4)

}

清单2 中的内容平淡无奇:先创建两个有理数,然后再创建两个Rational,作为前面两个有理数的和与差,最后将这几个数回传到控制台上(注意,Console.println()来自Scala核心库,位于scala.* 中,它被隐式地导入每个Scala程序中,就像Java编程中的https://www.360docs.net/doc/7d14901351.html,ng一样)。

用多少种方法构造类?

现在,回顾一下Rational类定义中的第一行:

清单3.Scala的默认构造函数

您也许会认为清单3 中使用了某种类似于泛型的语法,这其实是Rational类的默认的、首选的构造函数:n和d是构造函数的参数。

Scala优先使用单个构造函数,这具有一定的意义——大多数类只有一个构造函数,或者通过一个构造函数将一组构造函数“链接”起来。如果需要,可以在一个Rational上定义更多的构造函数,例如:

清单4. 构造函数链

注意,Scala的构造函数链通过调用首选构造函数(Int,Int版本)实现Java构造函数链的功能。

实现细节

在处理有理数时,采取一点数值技巧将会有所帮助:也就是说,找到公分母,使某些操作变得更容易。如果要将1/2与2/4相加,那Rational类应该足够聪明,能够认识到2/4和1/2是相等的,并在将这两个数相加之前进行相应的转换。嵌套的私有gcd()函数和Rational 类中的g值可以实现这样的功能。在Scala中调用构造函数时,将对整个类进行计算,这意味着将g初始化为n和d的最大公分母,然后用它依次设置n和d。

回顾一下清单1就会发现,我创建了一个覆盖的toString方法来返回Rational的值,在RunRational驱动程序代码中使用toString时,这样做非常有用。

然而,请注意toString的语法:定义前面的override关键字是必需的,这样Scala

才能确认基类中存在相应的定义。这有助于预防因意外的输入错误导致难于觉察的bug (Java 5中创建@Override注释的动机也在于此)。还应注意,这里没有指定返回类型——从方法体的定义很容易看出——返回值没有用return关键字显式地标注,而在Java 中则必须这样做。相反,函数中的最后一个值将被隐式地当作返回值(但是,如果您更喜欢Java语法,也可以使用return关键字)。

一些重要值

接下来分别是numer和denom的定义。这里涉及的语法可能让Java程序员认为numer和denom是公共的Int字段,它们分别被初始化为n-over-g和d-over-g;但这种想法是不对的。

在形式上,Scala调用无参数的numer和denom方法,这种方法用于创建快捷的语法以定义accessor。Rational类仍然有3个私有字段:n、d和g,但是,其中的n和d

被默认定义为私有访问,而g则被显式地定义为私有访问,它们对于外部都是隐藏的。此时,Java 程序员可能会问:“n和d各自的…setter?在哪里?”Scala中不存在这样的setter。Scala的一个强大之处就在于,它鼓励开发人员以默认方式创建不可改变的对象。但是,也可使用语法创建修改Rational内部结构的方法,但是这样做会破坏该类固有的线程安全性。因此,至少对于这个例子而言,我将保持Rational不变。

当然还有一个问题,如何操纵Rational呢?与https://www.360docs.net/doc/7d14901351.html,ng.String一样,不能直接修改现有的Rational的值,所以惟一的办法是根据现有类的值创建一个新的Rational,或者从头创建。这涉及到4个名称比较古怪的方法:+、-、* 和/。

与其外表相反,这并非操作符重载。

操作符

记住,在Scala中一切都是对象。在上一篇文章中,您看到了函数本身也是对象这一原则的应用,这使Scala程序员可以将函数赋予变量,将函数作为对象参数传递等等。另一个同样重要的原则是,一切都是函数;也就是说,在此处,命名为add的函数与命名为+ 的函数没有区别。在Scala中,所有操作符都是类的函数。只不过它们的名称比较古怪罢了。

在Rational类中,为有理数定义了4种操作。它们是规范的数学操作:加、减、乘、除。每种操作以它的数学符号命名:+、-、* 和/。

但是请注意,这些操作符每次操作时都构造一个新的Rational对象。同样,这与https://www.360docs.net/doc/7d14901351.html,ng.String非常相似,这是默认的实现,因为这样可以产生线程安全的代码(如果线程没有修改共享状态——默认情况下,跨线程共享的对象的内部状态也属于共享状态——则不会影响对那个状态的并发访问)。

有什么变化?

一切都是函数,这一规则产生两个重要影响:

首先,您已经看到,函数可以作为对象进行操纵和存储。这使函数具有强大的可重用性,本系列第一篇文章对此作了探讨。

第二个影响是,Scala语言设计者提供的操作符与Scala程序员认为应该提供的操作符之间没有特别的差异。例如,假设提供一个“求倒数”操作符,这个操作符会将分子和分母调换,返回一个新的Rational(即对于Rational(2,5)将返回Rational(5,2))。如果您认为~符号最适合表示这个概念,那么可以使用此符号作为名称定义一个新方法,该方法将和Java代码中任何其他操作符一样,如清单5所示:

清单5. 求倒数

在Scala 中定义这种一元操作符”需要一点技巧,但这只是语法上的问题而已:

清单6. 如何求倒数

当然,需要注意的地方是,必须在名称~之前加上前缀“unary_”,告诉Scala编译器它属于一元操作符。因此,该语法将颠覆大多数对象语言中常见的传统reference-

then-method语法。

这条规则与“一切都是对象” 规则结合起来,可以实现功能强大(但很简单)的代码:

清单7. 求和

当然,对于简单的整数加法,Scala编译器也会“得到正确的结果”,它们在语法上是完全一样的。这意味着您可以开发与Scala语言“内置”的类型完全相同的类型。

Scala编译器甚至会尝试推断具有某种预定含义的“操作符”的其他含义,例如+= 操作符。注意,虽然Rational类并没有显式地定义+=,下面的代码仍然会正常运行:

清单8. Scala 推断

打印结果时,r5的值为[13 / 12],结果是正确的。

Scala 内幕

记住,Scala将被编译为Java字节码,这意味着它在JVM上运行。如果您需要证据,那么只需注意编译器生成以0xCAFEBABE开头的.class文件,就像javac一样。另外请注意,如果启动JDK自带的Java字节码反编译器(javap),并将它指向生成的Rational 类,将会出现什么情况,如清单9所示:

清单9. 从rational.scala 编译的类

C:\Projects\scala-classes\code>javap -private -classpath classes Rational

Compiled from "rational.scala"

public class Rational extends https://www.360docs.net/doc/7d14901351.html,ng.Object implements scala.ScalaObject{ private int denom;

private int numer;

private int g;

public Rational(int, int);

public Rational unary_$tilde();

public https://www.360docs.net/doc/7d14901351.html,ng.String toString();

public Rational $div(Rational);

public Rational $times(Rational);

public Rational $minus(Rational);

public Rational $plus(Rational);

public int denom();

public int numer();

private int g();

private int gcd(int, int);

public Rational(int);

public int $tag();

}

C:\Projects\scala-classes\code>

Scala类中定义的“操作符”被转换成传统Java编程中的方法调用,不过它们仍使用看上去有些古怪的名称。类中定义了两个构造函数:一个构造函数带有一个int参数,另一个带有两个int参数。您可能会注意到,大写的Int类型与https://www.360docs.net/doc/7d14901351.html,ng.Integer有点相似,Scala编译器非常聪明,会在类定义中将它们转换成常规的Java原语int。

测试Rational 类

一种著名的观点认为,优秀的程序员编写代码,伟大的程序员编写测试;到目前为止,我还没有对我的Scala代码严格地实践这一规则,那么现在看看将这个Rational类放入一个传统的JUnit测试套件中会怎样,如清单10所示:

清单10. RationalTest.java

@Test public void test2ArgRationalConstructor()

{

Rational r = new Rational(2, 5);

assertTrue(r.numer() == 2);

assertTrue(r.denom() == 5);

}

@Test public void test1ArgRationalConstructor()

{

Rational r = new Rational(5);

assertTrue(r.numer() == 0);

assertTrue(r.denom() == 1);

// 1 because of gcd() invocation during construction;

// 0-over-5 is the same as 0-over-1

}

@Test public void testAddRationals()

{

Rational r1 = new Rational(2, 5);

Rational r2 = new Rational(1, 3);

Rational r3 = (Rational) reflectInvoke(r1, "$plus", r2); //r1.$plus(r2);

assertTrue(r3.numer() == 11);

assertTrue(r3.denom() == 15);

}

// ... some details omitted

}

除了确认Rational类运行正常之外,上面的测试套件还证明可以从Java代码中调用Scala代码(尽管在操作符方面有点不匹配)。当然,令人高兴的是,您可以将Java类迁移至Scala类,同时不必更改支持这些类的测试,然后慢慢尝试Scala。

您惟一可能觉得古怪的地方是操作符调用,在本例中就是Rational类中的+ 方法。回顾一下javap的输出,Scala显然已经将+函数转换为JVM方法$plus,但是Java语言规范并不允许标识符中出现$字符(这正是它被用于嵌套和匿名嵌套类名称中的原因)。

为了调用那些方法,需要用Groovy或JRuby(或者其他对$字符没有限制的语言)编写测试,或者编写Reflection代码来调用它。我采用后一种方法,从Scala的角度看这不是那么有趣,但是如果您有兴趣的话,可以看看本文的代码中包含的结果(参见下载)。

注意,只有当函数名称不是合法的Java标识符时才需要用这类方法。

“更好的” Java

我学习C++的时候Bjarne Stroustrup建议,学习C++的一种方法是将它看作“更好的C语言”(参见参考资料)。在某些方面,如今的Java开发人员也可以将Scala看作是“更好的Java”,因为它提供了一种编写传统Java POJO的更简洁的方式。考虑清单11中显示的传统Person POJO:

清单11. JavaPerson.java(原始POJO)

public class JavaPerson

{

public JavaPerson(String firstName, String lastName, int age)

{

this.firstName = firstName;

https://www.360docs.net/doc/7d14901351.html,stName = lastName;

this.age = age;

}

public String getFirstName()

{

return this.firstName;

}

public void setFirstName(String value)

{

this.firstName = value;

}

public String getLastName()

{

return https://www.360docs.net/doc/7d14901351.html,stName;

}

public void setLastName(String value)

{

https://www.360docs.net/doc/7d14901351.html,stName = value;

}

public int getAge()

{

return this.age;

外文翻译java

外文资料译文及原文 Java Java I/O 系统 对编程语言的设计者来说,创建一套好的输入输出(I/O)系统,是一项难度极高的任务。 这一点可以从解决方案的数量之多上看出端倪。这个问题难就难在它要面对的可能性太多了。不仅是因为有那么多I/O的源和目地(文件,控制台,网络连接等等),而且还有很多方法(顺序的『sequential』,随机的『random-access』,缓存的『buffered』,二进制的『binary』,字符方式的『character』,行的『by lines』,字的『by words』,等等)。 Java类库的设计者们用"创建很多类"的办法来解决这个问题。坦率地说Java I/O系统的类实在是太多了,以至于初看起来会把人吓着(但是,具有讽刺意味的是,这种设计实际上是限制了类的爆炸性增长)。此外,Java在1.0版之后又对其I/O类库作了重大的修改,原先是面向byte的,现在又补充了面向Unicode字符的类库。为了提高性能,完善功能,JDK 1.4又加了一个nio(意思是"new I/O"。这个名字会用上很多年)。这么以来,如果你想对Java的I/O 类库有个全面了解,并且做到运用自如,你就得先学习大量的类。此外,了解 I/O类库的演化的历史也是相当重要的。可能你的第一反应是"别拿什么历史来烦我了,告诉我怎么用就可以了!"但问题是,如果你对这段历史一无所知,很快就会被一些有用或是没用的类给搞糊涂了。

本章会介绍Java标准类库中的各种I/O类,及其使用方法。 File 类 在介绍直接从流里读写数据的类之前,我们先介绍一下处理文件和目录的类。 File类有一个极具欺骗性的名字;或许你会认为这是一个关于文件的类,但它不是。你可以用它来表示某个文件的名字,也可以用它来表示目录里一组文件的名字。如果它表示的是一组文件,那么你还可以用list( )方法来进行查询,让它会返回String数组。由于元素数量是固定的,因此数组会比容器更好一些。如果你想要获取另一个目录的清单,再建一个File对象就是了。实际上,叫它"FilePath"可能会更好一些。下面我们举例说明怎样使用这个类及其相关的FilenameFilter接口。 目录列表器 假设你想看看这个目录。有两个办法。一是不带参数调用list( )。它返回的是File对象所含内容的完整清单。但是,如果你要的是一个"限制性列表(restricted list)"的话——比方说,你想看看所有扩展名为.java的文件——那么你就得使用"目录过滤器"了。这是一个专门负责挑选显示File对象的内容的类。 下面就是源代码。看看,用了java.utils.Arrays.sort( )和11章的AlphabeticComparator之后,我们没费吹灰之力就对结果作了排序(按字母顺序): //: c12:DirList.java // Displays directory listing using regular expressions. // {Args: "D.*\.java"} import java.io.*; import java.util.*; import java.util.regex.*; import com.bruceeckel.util.*; public class DirList { public static void main(String[] args) { File path = new File("."); String[] list; if(args.length == 0) list = path.list(); else list = path.list(new DirFilter(args[0])); Arrays.sort(list, new AlphabeticComparator());

计算机专业毕业设计说明书外文翻译(中英对照)

Talking about security loopholes Richard S. Kraus reference to the core network security business objective is to protect the sustainability of the system and data security, This two of the main threats come from the worm outbreaks, hacking attacks, denial of service attacks, Trojan horse. Worms, hacker attacks problems and loopholes closely linked to, if there is major security loopholes have emerged, the entire Internet will be faced with a major challenge. While traditional Trojan and little security loopholes, but recently many Trojan are clever use of the IE loophole let you browse the website at unknowingly were on the move. Security loopholes in the definition of a lot, I have here is a popular saying: can be used to stem the "thought" can not do, and are safety-related deficiencies. This shortcoming can be a matter of design, code realization of the problem. Different perspective of security loo phole s In the classification of a specific procedure is safe from the many loopholes in classification. 1. Classification from the user groups: ● Public loopholes in the software category. If the loopholes in Windows, IE loophole, and so on. ● specialized software loophole. If Oracle loopholes, Apach e,

计算机专业外文文献及翻译

微软Visual Studio 1微软Visual Studio Visual Studio 是微软公司推出的开发环境,Visual Studio可以用来创建Windows平台下的Windows应用程序和网络应用程序,也可以用来创建网络服务、智能设备应用程序和Office 插件。Visual Studio是一个来自微软的集成开发环境IDE,它可以用来开发由微软视窗,视窗手机,Windows CE、.NET框架、.NET精简框架和微软的Silverlight支持的控制台和图形用户界面的应用程序以及Windows窗体应用程序,网站,Web应用程序和网络服务中的本地代码连同托管代码。 Visual Studio包含一个由智能感知和代码重构支持的代码编辑器。集成的调试工作既作为一个源代码级调试器又可以作为一台机器级调试器。其他内置工具包括一个窗体设计的GUI应用程序,网页设计师,类设计师,数据库架构设计师。它有几乎各个层面的插件增强功能,包括增加对支持源代码控制系统(如Subversion和Visual SourceSafe)并添加新的工具集设计和可视化编辑器,如特定于域的语言或用于其他方面的软件开发生命周期的工具(例如Team Foundation Server的客户端:团队资源管理器)。 Visual Studio支持不同的编程语言的服务方式的语言,它允许代码编辑器和调试器(在不同程度上)支持几乎所有的编程语言,提供了一个语言特定服务的存在。内置的语言中包括C/C + +中(通过Visual C++),https://www.360docs.net/doc/7d14901351.html,(通过Visual https://www.360docs.net/doc/7d14901351.html,),C#中(通过Visual C#)和F#(作为Visual Studio 2010),为支持其他语言,如M,Python,和Ruby等,可通过安装单独的语言服务。它也支持的 XML/XSLT,HTML/XHTML ,JavaScript和CSS.为特定用户提供服务的Visual Studio也是存在的:微软Visual Basic,Visual J#、Visual C#和Visual C++。 微软提供了“直通车”的Visual Studio 2010组件的Visual Basic和Visual C#和Visual C + +,和Visual Web Developer版本,不需任何费用。Visual Studio 2010、2008年和2005专业版,以及Visual Studio 2005的特定语言版本(Visual Basic、C++、C#、J#),通过微软的下载DreamSpark计划,对学生免费。 2架构 Visual Studio不支持任何编程语言,解决方案或工具本质。相反,它允许插入各种功能。特定的功能是作为一个VS压缩包的代码。安装时,这个功能可以从服务器得到。IDE提供三项服务:SVsSolution,它提供了能够列举的项目和解决方案; SVsUIShell,它提供了窗口和用户界面功能(包括标签,工具栏和工具窗口)和SVsShell,它处理VS压缩包的注册。此外,IDE还可以负责协调和服务之间实现通信。所有的编辑器,设计器,项目类型和其他工具都是VS压缩包存在。Visual Studio 使用COM访问VSPackage。在Visual Studio SDK中还包括了管理软件包框架(MPF),这是一套管理的允许在写的CLI兼容的语言的任何围绕COM的接口。然而,MPF并不提供所有的Visual Studio COM 功能。

JAVA外文文献+翻译

Java and the Internet If Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in computer programming. The answer isn’t immediately obvious if you’re coming from a traditional programming perspective. Although Java is very useful for solving traditional stand-alone programming problems, it is also important because it will solve programming problems on the World Wide Web. 1.Client-side programming The Web’s in itial server-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interpret and display them. Basic HTML contains simple mechanisms for data gathering: text-entry boxes, check boxes, radio boxes, lists and drop-down lists, as well as a button that can only be programmed to reset the data on the form or “submit” the data on the form back to the server. This submission passes through the Common Gateway Interface (CGI) provided on all Web servers. The text within the submission tells CGI what to do with it. The most common action is to run a program located on the server in a directory that’s typically called “cgi-bin.” (If you watch the address window at the top of your browser when you push a button on a Web page, you can sometimes see “cgi-bin” within all the gobbledygook there.) These programs can be written in most languages. Perl is a common choice because it is designed for text manipulation and is interpreted, so it can be installed on any server regardless of processor or operating system. Many powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with it. However, Web sites built on CGI programs can rapidly become overly complicated to maintain, and there is also the problem of response time. The response of a CGI program depends on how much data must

计算机专业外文文献翻译6

外文文献翻译(译成中文2000字左右): As research laboratories become more automated,new problems are arising for laboratory managers.Rarely does a laboratory purchase all of its automation from a single equipment vendor. As a result,managers are forced to spend money training their users on numerous different software packages while purchasing support contracts for each. This suggests a problem of scalability. In the ideal world,managers could use the same software package to control systems of any size; from single instruments such as pipettors or readers to large robotic systems with up to hundreds of instruments. If such a software package existed, managers would only have to train users on one platform and would be able to source software support from a single vendor. If automation software is written to be scalable, it must also be flexible. Having a platform that can control systems of any size is far less valuable if the end user cannot control every device type they need to use. Similarly, if the software cannot connect to the customer’s Laboratory Information Management System (LIMS) database,it is of limited usefulness. The ideal automation software platform must therefore have an open architecture to provide such connectivity. Two strong reasons to automate a laboratory are increased throughput and improved robustness. It does not make sense to purchase high-speed automation if the controlling software does not maximize throughput of the system. The ideal automation software, therefore, would make use of redundant devices in the system to increase throughput. For example, let us assume that a plate-reading step is the slowest task in a given method. It would make that if the system operator connected another identical reader into the system, the controller software should be able to use both readers, cutting the total throughput time of the reading step in half. While resource pooling provides a clear throughput advantage, it can also be used to make the system more robust. For example, if one of the two readers were to experience some sort of error, the controlling software should be smart enough to route all samples to the working reader without taking the entire system offline. Now that one embodiment of an ideal automation control platform has been described let us see how the use of C++ helps achieving this ideal possible. DISCUSSION C++: An Object-Oriented Language Developed in 1983 by BjarneStroustrup of Bell Labs,C++ helped propel the concept of object-oriented programming into the mainstream.The term ‘‘object-oriented programming language’’ is a familiar phrase that has been in use for decades. But what does it mean? And why is it relevant for automation software? Essentially, a language that is object-oriented provides three important programming mechanisms:

无线局域网-计算机毕业论文外文翻译

毕业设计(论文)外文资料翻译 系:信息工程学院 专业:计算机科学与技术 姓名: 学号: 外文出处:Chris Haseman. Android-essential (用外文写) s[M].London:Spring--Verlag,2008 .8-13. 附件: 1.外文资料翻译译文;2.外文原文。 指导教师评语: 签名: 年月日注:请将该封面与附件装订成册。

附件1:外文资料翻译译文 无线局域网 一、为何使用无线局域网络 对于局域网络管理主要工作之一,对于铺设电缆或是检查电缆是否断线这种耗时的工作,很容易令人烦躁,也不容易在短时间内找出断线所在。再者,由于配合企业及应用环境不断的更新与发展,原有的企业网络必须配合重新布局,需要重新安装网络线路,虽然电缆本身并不贵,可是请技术人员来配线的成本很高,尤其是老旧的大楼,配线工程费用就更高了。因此,架设无线局域网络就成为最佳解决方案。 二、什么情形需要无线局域网络 无线局域网络绝不是用来替代有限局域网络,而是用来弥补有线局域网络之不足,以达到网络延伸之目的,下列情形可能须要无线局域网络。 ●无固定工作场所的使用者 ●有线局域网络架设受环境限制 ●作为有线局域网络的备用系统 三、无线局域网络存取技术 目前厂商在设计无线局域网络产品时,有相当多种存取设计方式,大致可分为三大类:窄频微波技术、展频(Spread Spectrum)技术、及红外线(Infrared)技术,每种技术皆有其优缺点、限制及比较,接下来是这些技术方法的详细探讨。 1.技术要求 由于无线局域网需要支持高速、突发的数据业务,在室内使用还需要解决多径衰落以及各子网间串扰等问题。具体来说,无线局域网必须实现以下技术要求: 1)可靠性:无线局域网的系统分组丢失率应该低于10-5,误码率应该低 于10-8。

JAVA外文文献翻译基于Java技术的Web应用设计模型的比较研究

中文翻译 基于Java技术的Web应用设计模型的比较研究 来源:School of Computer Science and Engineering University of New South Wales Sydney, NSW 2052, Australia 作者:Budi Kurniawan and Jingling Xue 摘要 Servlet技术是在建立可扩展性Web应用中被应用最广泛的技术。在运用JAVA技术开发Web应用中有四种模型,分别是:Model 1、Model 2、Struts和JavaServer Faces JSF。Model 1使用一连串的JSP页面,Model 2采用了模型,视图,控制器MVC模式。Struts是一个采用了Model 2设计模型的框架,JSF是一种支持ready-to-use组件来进行快速Web应用开发的新技术。Model 1对于中等和大型的应用来说很难维护,所以不推荐使用。本文通过利用Model 2、Struts和JSF这三种模型分别构建三个不同版本的在线商店应用程序来比较和评价这三种模型在应用程序开发和性能上的差异。 1.绪论 当今Web应用是一种展现动态内容的最普遍的方式。构建Web应用有许多种方法,其中最流行的是Servlet技术。这种技术的流行是因为它比CGI、PHP等其他技术更具优越性。然而Servlet对于开发来说还是麻烦的,因为它在传送HTML 标签时需要程序员将他们组合成为一个字符串对象,再将这个对象传给浏览器。同样的,对于输出的一个很小的改动也要求Servlet被重新编译。基于这个原因SUN 公司发明了JavaServer Pages JSP技术。JSP允许HTML标签和Java代码混合在

计算机专业外文翻译

专业外文翻译 题目JSP Technology Conspectus and Specialties 系(院)计算机系 专业计算机科学与技术 班级 学生姓名 学号 指导教师 职称讲师 二〇一三年五月十六日

JSP Technology Conspectus and Specialties The JSP (Java Server Pages) technology is used by the Sun micro-system issued by the company to develop dynamic Web application technology. With its easy, cross-platform, in many dynamic Web application programming languages, in a short span of a few years, has formed a complete set of standards, and widely used in electronic commerce, etc. In China, the JSP now also got more extensive attention; get a good development, more and more dynamic website to JSP technology. The related technologies of JSP are briefly introduced. The JSP a simple technology can quickly and with the method of generating Web pages. Use the JSP technology Web page can be easily display dynamic content. The JSP technology are designed to make the construction based on Web applications easier and efficient, and these applications and various Web server, application server, the browser and development tools work together. The JSP technology isn't the only dynamic web technology, also not the first one, in the JSP technology existed before the emergence of several excellent dynamic web technologies, such as CGI, ASP, etc. With the introduction of these technologies under dynamic web technology, the development and the JSP. Technical JSP the development background and development history In web brief history, from a world wide web that most of the network information static on stock transactions evolution to acquisition of an operation and infrastructure. In a variety of applications, may be used for based on Web client, look no restrictions. Based on the browser client applications than traditional based on client/server applications has several advantages. These benefits include almost no limit client access and extremely simplified application deployment and management (to update an application, management personnel only need to change the program on a server, not thousands of installation in client applications). So, the software industry is rapidly to build on the client browser multilayer application. The rapid growth of exquisite based Web application requirements development of

JAVA思想外文翻译毕业设计

文献来源:Bruce Eckel.Thinking in Java [J]. Pearson Higher Isia Education,2006-2-20. Java编程思想 (Java和因特网) 既然Java不过另一种类型的程序设计语言,大家可能会奇怪它为什么值得如此重视,为什么还有这么多的人认为它是计算机程序设计的一个里程碑呢?如果您来自一个传统的程序设计背景,那么答案在刚开始的时候并不是很明显。Java除了可解决传统的程序设计问题以外,还能解决World Wide Web(万维网) 上的编程问题。 1、客户端编程 Web最初采用的“服务器-浏览器”方案可提供交互式内容,但这种交互能力完全由服务器提供,为服务器和因特网带来了不小的负担。服务器一般为客户浏览器产生静态网页,由后者简单地解释并显示出来。基本HTML语言提供了简单的数据收集机制:文字输入框、复选框、单选钮、列表以及下拉列表等,另外还有一个按钮,只能由程序规定重新设置表单中的数据,以便回传给服务器。用户提交的信息通过所有Web服务器均能支持的“通用网关接口”(CGI)回传到服务器。包含在提交数据中的文字指示CGI该如何操作。最常见的行动是运行位于服务器的一个程序。那个程序一般保存在一个名为“cgi-bin”的目录中(按下Web页内的一个按钮时,请注意一下浏览器顶部的地址窗,经常都能发现“cgi-bin”的字样)。大多数语言都可用来编制这些程序,但其中最常见的是Perl。这是由于Perl是专为文字的处理及解释而设计的,所以能在任何服务器上安装和使用,无论采用的处理器或操作系统是什么。 2、脚本编制语言 插件造成了脚本编制语言的爆炸性增长。通过这种脚本语言,可将用于自己客户端程序的源码直接插入HTML页,而对那种语言进行解释的插件会在HTML 页显示的时候自动激活。脚本语言一般都倾向于尽量简化,易于理解。而且由于它们是从属于HTML页的一些简单正文,所以只需向服务器发出对那个页的一

计算机专业外文文献及翻译

计算机专业外文文献及翻译 微软Visual Studio 1微软Visual Studio 是微软公司推出的软软软境~可以用软建来平台下的 Visual Studio Visual StudioWindows 软用程序和软软用程序~也可以用软建软服软、智能软软软用程序和网来网 插件。WindowsOffice Visual 是一自微软的个来集成软软软境;,~可以用软软由它来微StudioIDEinteqrated development environment软软窗~软手机窗~、框架、精软架框和微软的支持的控制台和软Windows https://www.360docs.net/doc/7d14901351.html,Silverlight 形用软界面的软用程序以及窗体软用程序~站网~软用程序和软服软网中的本地代软软同托管WindowsWeb 代软。 包含一由个智能感知和代软重构支持的代软软软器。集成的软软工作作软一源代软软软既个Visual Studio 软器又可以作软一台机器软软软器。其他置工具包括一软软内个窗体的软用程序~软软软软~软软软软~网数据软架GUI 构软软软。有乎各软面的件增强功能~包括增加软支持它几个插源代软控制系软;如和SubversionVisual ,添加新的工具集软软和可软化软软器~如并特定于域的软言或用于其他方面的软件软软生命周期SourceSafe 的工具;例如的客软端,软软软源管理器,。Team Foundation Server

支持不同的软程软言的服软方式的软言~允软代软软软器和软软器;在不同程 度上,支持它Visual Studio 几乎所有的软程软言~提供了一软言特定服软的存在。置的软言中包括个内中;通软C/C + +Visual C+,;通软,~,中;通软,,和,;作软+,https://www.360docs.net/doc/7d14901351.html,Visual https://www.360docs.net/doc/7d14901351.html,CVisual CFVisual Studio ,~软支持其他软言~如和等~可通软安软的软言服软。软也支持装独它的2010M,Python,Ruby 和软特定用软提供服软的也是存在的,微 XML/XSLT,HTML/XHTML ,JavaScriptCSS.Visual Studio软~,、,和。Visual BasicVisual JVisual CVisual C++ 微软提供了“直通软”的软件的和,和~Visual Studio 2010Visual BasicVisual CVisual C + +和版本~不需任何软用。、年和软软版~以及Visual Web DeveloperVisual Studio 201020082005 的特定软言版本;、、,、,,~通软微软的下软Visual Studio 2005Visual BasicC++CJ 软~软生免软。划学DreamSpark 2架构 不支持任何软程软言~解方案或工具本软。相反~允软入各软功能。特定的功决它插Visual Studio 能是作软一个软软包的代软。安软~软功能可以服软器得到。装个从提供三软服软,~VSIDESVsSolution它决提供了能软列软的软目和解方案~提供了口和用软界面功能;包括软软~工具软和工它窗; SVsUIShell 具口,和窗~软理它软软包的注。此外~册软可以软软软软和服软之软软软通信。所有的软软器~SVsShellVSIDE

Java的面向对象编程外文资料翻译

毕业设计(论文)外文资料翻译 系:计算机系 专业:计算机科学与技术 姓名: 学号: 外文出处:Ghosh,D..Java Object-oriented (用外文写) programming[J]. IEEE Transactions on Software Engineering,2009, 13(3):42-45. 附件: 1.外文资料翻译译文;2.外文原文。

注:请将该封面与附件装订成册。

附件1:外文资料翻译译文 Java的面向对象编程 ——面向对象编程和它的关键技术—继承和多态性 软件的重用可以节省程序开发时间。它鼓励重复使用已经调试好的高质量的软件,从而减少系统运行后可能出现的问题。这些都是令人振奋的可能性。多态性允许我们用统一的风格编写程序,来处理多种已存在的类和特定的相关类。利用多态性我们可以方便地向系统中添加新的功能。继承和多态对于解决软件的复杂性是一种有效可行的技术。当创建一个新的类时,而不用完整的写出新的实例变量和实例方法,程序员会指定新的类继承已定义的超类的实例变量和实例方法。这个新的类被称为一个子类。每个子类本身将来亦可有新的子类,而其本身将成为父类。一个类的直接父类就是该类所直接继承的类(通过关键字extends继承)。一个间接超类是通过从两级或更多级以上的类继承而来的。例如,从类JApplet(包javax.swing 中)扩展来的类Applet(包java.applet)。一个类单一的从一个父类继承而来。 Java 不支持多重继承(而C++可以),但它支持接口的概念。接口可以使Java实现许多通过多重继承才能实现的优点而没有关联的问题。我们将在本章讨论的接口的详细内容。我们会给出创建和使用接口的一般规律和具体实例。一个子类通常添加自己的实例变量和自己的实例方法,因此子类通常比父类大。一个子类比它的父类更具体并且代表一组更小、更专业的对象。通过单一继承,子类在开始时拥有父类的所有特性。继承性真正的力量在于它可以在定义子类时增加或取代从超类中继承来的特征。每个子类对象也是该类的父类的对象。例如,每一个我们所定义的小程序被认为是类JApplet 的对象。此外,因为Japplet继承了Applet,每一个我们所定义的小程序同时也被认为是一个Applet 的对象。当开发applets时,这些信息是至关重要的,因为一个小程序容器只有当它是一个Applet才可以执行一个程序。虽然子类对象始终可以作为它的父类的一种来看待,父类对象却不被认为是其子类类型的对象。我们将利用这种“子类对象是父类对象”的关系来执行一些强大的操作。例如,绘图程序可以显示一系列图形,如果所有的图形类型都直接或间接地继

计算机专业的外文文献.pdf

A Rapid Tag Identification Method with Two Slots in RFID Systems Yong Hwan Kim, Sung Soo Kim, Kwang Seon Ahn Department of Computer Engineering, Kyungpook National University Daegu, Korea {hypnus, ninny, gsahn}@knu.ac.kr Abstract—RFID is core technology in the area of ubiquitous compu-ting. Identify the objects begin with the reader’s query to the tag at-tached to the subject. When multiple tags exist in the reader’s inter-rogation zone, these tags simultaneously respond to the reader’s query, resulting in collision. In RFID system, the reader needs the anti-collision algorithm which can quickly identify all the tags in the interrogation zone. This paper proposes tree based Rapid Tag Identi-fication Method with Two Slots(RTIMTS). The proposed algorithm rapidly identifies a tag with the information of Two Slots and MSB(Most Significant Bit). Two Slots resolve the tag collision by receiving the response from the tag to the Slot 0 and 1. The reader can identify two tags at once using MSB of information added to the tag ID. With RTIMTS algorithm, the total time of tag identification can be shortened by decreasing the number of query-responses from the reader. Keywords-RFID; Anti-collision; Two Slots; the number of query-responses. I.I NTRODUCTION RFID(Radio Frequency Identification) is a technology that deciphers or identifies the tag information through a reader (or interrogator) without contact. RFID have become very popular in many service industries, purchasing and distribution logis-tics, industry, manufacturing companies and material flow systems. Automatic Identification procedures exist to provide information about people, animals, goods and products in tran-sit[1][2]. The reader receives required information from the tags by sending and receiving wireless signals with the tag. Since the communication between the readers and the tags shares wire-less channels, there exist collisions. The collisions can be di-vided into the reader collision and the tag collision. The reader collision occurs when multiple readers send request signals to one tag, and the tag receives the wrong request signal due to signal interference between readers. The tag collision occurs when more than two tags simultaneously respond to one reader and the reader cannot identify any tags. This kind of collision makes the reader take long time to identify tags within the read-er’s identification range and impossible to identify even one tag[3][4][5] [6]. Therefore, the collision is a crucial problem that must be re-solved in RFID systems, so many studies to resolve this prob-lem have been carried out as well as are ongoing. This paper focuses on the tag collision problem which occurs in the case where one reader identifies multiple tags. Figure 1 provides schematizations of reader collision and tag collision. This paper proposes the Rapid Tag Identification Method with Two Slots (RTIMTS), for faster tag identification in mul-ti-tag environment where one reader identifies multiple tags. In the transfer paper[7], the proposed algorithm designs the method that it does without the value extracting procedure of even(or odd) parity bit of ID bit(T pb),the number of identified ‘1’s(T1n), the number of remaining ‘1’s(T rn), and the number of collided bit (T cb) with simple it can predict a tagID. Maximum 4 tag IDs can be identified on one round by using Two slots. a) The Reader collision b) The Tag collision Figure 1. The collision problem in RFID System II.T HE R ELATED WORKS A. Query Tree Query Tree(QT) algorithm is a binary tree based anti colli-sion algorithm and has an advantage in easily implementation due to its simple operating mode[8]. QT sets the reader’s query and tag’s response as one round, and identifies tags by iterating the round. In each round, the reader requests prefix to tag’s ID. And when ID matches the prefix, each tag transmits all IDs including prefixes to the reader. At this time, if more than one tag simultaneously responds, the reader cannot recognize tag’s ID, but can recognize that there are currently more than two tags having the prefix. Then the reader adds ‘0’ or ‘1’ to the current prefix and queries the longer prefix to the tags again. When only one tag responds to the reader, it identifies the tag. In other words, the reader adds the prefix by 1 bit until only one tag responds and iterates this process until identifying all the tags within the range. Figure 2 shows the operating process of QT algorithms[10]. Figure 2 shows the process that four tags respond according to the readers’ query. In round 1, 2, 3, and 7, the collision oc-curs because more than two tags respond, and in round 4, 5, 8, and 9, tag can be identified because only one tag responds. The digital coding method applied to QT cannot detect the collision bits. When a collision occurs, the reader adds ‘0’ or ‘1’ to the 2009 Eighth IEEE International Symposium on Network Computing and Applications 978-0-7695-3698-9/09 $25.00 ? 2009 IEEE DOI 10.1109/NCA.2009.21 292

相关文档
最新文档