【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)

上传人:从****越 文档编号:126767467 上传时间:2020-03-27 格式:DOCX 页数:15 大小:769.24KB
返回 下载 相关 举报
【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)_第1页
第1页 / 共15页
【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)_第2页
第2页 / 共15页
【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)_第3页
第3页 / 共15页
【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)_第4页
第4页 / 共15页
【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)》由会员分享,可在线阅读,更多相关《【精品文档】506关于计算机专业有关的外文文献翻译成品:在脚本语言中使用Java(中英文双语对照)(15页珍藏版)》请在金锄头文库上搜索。

1、此文档是毕业设计外文翻译成品( 含英文原文+中文翻译),无需调整复杂的格式!下载之后直接可用,方便快捷!本文价格不贵,也就几十块钱!一辈子也就一次的事!外文标题:Using Java in Scripting Languages外文作者:Kishori Sharan文献出处: Scripting in Java Integrating with Groovy and JavaScript,2018 (如觉得年份太老,可改为近2年,毕竟很多毕业生都这样做)英文2244单词,12911字符(字符就是印刷符),中文3250汉字。(如果字数多了,可自行删减,大多数学校都是要求选取外文的一部分内容进行翻

2、译的。)Using Java in Scripting LanguagesIn this chapter, you will learn:1.How to import Java classes into scripts2.How to create Java objects and use them in scripts3.How to call overloaded methods of Java objects4.How to create Java arrays5.How to extend a Java class and implement Java interfaces in s

3、cripts6.How to invoke superclass methods of an object from scriptsScripting languages allow using Java class libraries in scripts. Each scripting language has its own syntax for using Java classes. It is not possible, and is outside the scope of this book, to discuss the syntax of all scripting lang

4、uages. In this chapter, I will discuss the syntax of using Java constructs in Nashorn.Importing JavaTypesThere are four ways to import Java types into Nashorn script:1.Using the Packages global object2.Using the type( ) method of the Java global object3.Using the import Package( ) and import Class(

5、) functions 4.Using a Java Importer in a with clauseOf the four types of importing Java types, the second type, using the type( ) method of the global Java object, is preferred. The following sections will describe the four ways of importing Java type in script in detail.Using the Packages Global Ob

6、jectNashorn defines all Java packages as properties of a global variable named Packages. For example, the java. lang and javax. swing packages may be referred to as Packages. java. lang and Packages. javax. swing, respectively. The following snippet of code uses the java. util . List and javax. swin

7、g. JFrame in Nashorn:Nashorn declares java, javax, org, com, edu, and net as global variables that are aliases for Packages. java, Packages. javax, Packages. or g, Packages. com, Packages. edu, and Packages. net , respectively. Class names in examples in this book start with the prefix com, for exam

8、ple, com. jdojo. script . Test . To use this class name inside the JavaScript code, you may use Packages. com. jdojo. script . Test or com. jdojo. script . Test . However, if a class name does not start with one of these predefined prefixes, you must use the Packages global variable to access it; fo

9、r example, if your class name is p1. Test , you need to access it using Packages. p1. Test inside JavaScript code. The following snippet of code uses the java and javax aliases for Packages. java and Packages. javax:Using the Java Global ObjectAccessing packages as the properties of the Packages obj

10、ect was also supported in Rhino JavaScript in Java 7. Using the Packages object is slower and error-prone. Nashorn defines a new global object called Java that contains many useful functions to work with Java packages and classes. If you are using Java 8 or later, you should prefer using the Java ob

11、ject. The type( ) function of the Java object imports a Java type into the script. You need to pass the fully qualified name of the Java type to import. In Nashorn, the following snippet of code imports the java. util . ArrayList class and creates its object:You can also combine the two statements i

12、nto one. Make sure to add the call to Java. type( ) method in a pair of parentheses; otherwise, the statement will generate an error thinking that Java.type is a constructor function and you are trying to create a Nashorn object using a constructor function:In the code, you call the imported type re

13、turned from the Java. type( ) function as ArrayList that is also the name of the class that is imported. You do it to make the next statement read as if it was written Java. Readers of the second statement will know that you are creating an object of the ArrayList class. However, you can give the im

14、ported type any name you want. The following snippet of code imports java. util . Array List and calls it MyList :Using the importPackage() and importClass() Functions Rhino JavaScript allowed using the simple names of the Java types in script. Rhino JavaScript had two built-in functions called impo

15、rt Package( ) and import Class( ) to import all classes from a package and a class from a package, respectively. For compatibility reasons, Nashorn keeps these functions. To use these functions in Nashorn, you need to load the compatibility module from mozill a_compat . js file using the load( ) fun

16、ction. The following snippet of code rewrites the above logic in the previous section these functions:JavaScript does not import all classes from the java. lang package automatically because JavaScript classes with the same names, for example, String, Object , Number, and so on, will conflict with class names in the java. lang package. To use a class from the java. lang package, you can import it or use the Pack

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 期刊/会议论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号