日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jdk入门_JDK 9 REPL:入门

發(fā)布時(shí)間:2023/12/3 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jdk入门_JDK 9 REPL:入门 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

jdk入門

會(huì)議是聚會(huì)Java名人的好地方。 Devoxx France是與Java語言架構(gòu)師,前同事和老朋友Brian Goetz( @briangoetz )見面的一個(gè)機(jī)會(huì)。 我們談?wù)摿薐DK 9,而他全都熱衷于REPL。 他提到,盡管Java SE 9中有很多重要功能 ,例如模塊化和HTTP2客戶端 ,但該工具將是最常被談?wù)摰摹?該聲明之所以有意義,是因?yàn)樗鼘⒄嬲喕疛ava API的探索,原型開發(fā),會(huì)議中的演示以及類似任務(wù),并且更加簡單。 這個(gè)博客來自我們?cè)谀抢锏挠懻撘约八麑?duì)REPL的強(qiáng)烈投票!

Read-Evaluate-Print-Loop在Lisp,Python,Ruby,Groovy,Clojure和其他語言中已經(jīng)存在了一段時(shí)間。 Unix shell是一個(gè)REPL,可以讀取shell命令,評(píng)估它們,打印輸出并返回循環(huán)以執(zhí)行相同的操作。

您可以在JEP 222中的JDK 9中閱讀有關(guān)REPL的全部信息。 JEP的摘要是:

提供一個(gè)交互式工具,該工具可以評(píng)估Java編程語言的聲明,語句和表達(dá)式:即,提供Java編程語言的讀取-評(píng)估-打印循環(huán)(REPL)。 另外,提供在其上構(gòu)建工具的API,從而使外部工具能夠提供此功能。 杰普222

JEP還明確闡明了動(dòng)機(jī):

沒有Foo類{public static void main(String [] args){…}}的儀式,學(xué)習(xí)和探索就變得簡化了。 杰普222

JEP 222的目標(biāo)是將REPL與JDK 9一起提供,但openjdk.java.net/projects/jdk9并未將其列為“目標(biāo)”或“建議目標(biāo)”。 好像是一個(gè)文檔錯(cuò)誤:)

從JDK 9 build 61開始,REPL未集成,需要單獨(dú)構(gòu)建。 最終,在發(fā)布JDK 9之前的某個(gè)時(shí)間,此工具將集成到內(nèi)部版本中。

讓我們看看在OSX上運(yùn)行它需要什么。 該博客遵循Java 9 REPL –入門指南來構(gòu)建和運(yùn)行REPL。 此外,它還提供了命令的完整日志輸出,這可能對(duì)某些人有幫助。

讓我們開始吧!

安裝JDK 9

  • 在撰寫本文時(shí),下載最新的版本 61。
  • 將JAVA_HOME設(shè)置為: export JAVA_HOME=`/usr/libexec/java_home -v1.9`

    在OSX上設(shè)置JAVA_HOME的更多詳細(xì)信息在這里 。

  • 驗(yàn)證版本: ~> java -version java version "1.9.0-ea" Java(TM) SE Runtime Environment (build 1.9.0-ea-b61) Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b61, mixed mode)
  • 檢出并安裝jline2

    jline2是一個(gè)用于處理控制臺(tái)輸入的Java庫。 看看這個(gè):

    workspaces> git clone git://github.com/jline/jline2.git Cloning into 'jline2'... remote: Counting objects: 6419, done. remote: Total 6419 (delta 0), reused 0 (delta 0), pack-reused 6419 Receiving objects: 100% (6419/6419), 3.23 MiB | 80.00 KiB/s, done. Resolving deltas: 100% (2945/2945), done. Checking connectivity... done.

    然后構(gòu)建它:

    jline2> mvn install [INFO] Scanning for projects... Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/scm/maven-scm-provider-gitexe/1.8.1/maven-scm-provider-gitexe-1.8.1.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/scm/maven-scm-provider-gitexe/1.8.1/maven-scm-provider-gitexe-1.8.1.pom (3 KB at 0.3 KB/sec). . .[INFO] Installing /Users/arungupta/workspaces/jline2/target/jline-2.13-SNAPSHOT-sources.jar to /Users/arungupta/.m2/repository/jline/jline/2.13-SNAPSHOT/jline-2.13-SNAPSHOT-sources.jar [INFO] Installing /Users/arungupta/workspaces/jline2/target/jline-2.13-SNAPSHOT-tests.jar to /Users/arungupta/.m2/repository/jline/jline/2.13-SNAPSHOT/jline-2.13-SNAPSHOT-tests.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 09:52 min [INFO] Finished at: 2015-05-06T19:23:14-07:00 [INFO] Final Memory: 25M/146M [INFO] ------------------------------------------------------------------------

    克隆并構(gòu)建JDK 9 REPL

    該項(xiàng)目的OpenJDK代號(hào)為Kulla,意為“建設(shè)者之神”。 該工具的計(jì)劃名稱為jshell 。

  • 簽出工作區(qū): workspaces> hg clone http://hg.openjdk.java.net/kulla/dev kulla requesting all changes adding changesets adding manifests adding file changes added 1453 changesets with 2226 changes to 172 files updating to branch default 109 files updated, 0 files merged, 0 files removed, 0 files unresolved
  • 獲取來源: workspaces> cd kulla kulla> chmod +x ./get_source.sh kulla> ./get_source.sh # Repositories: corba jaxp jaxws langtools jdk hotspot nashorn corba: hg clone http://hg.openjdk.java.net/kulla/dev/corba corbajaxp: hg clone http://hg.openjdk.java.net/kulla/dev/jaxp jaxpcorba: requesting all changesjaxp: requesting all changescorba: adding changesetsjaxp: adding changesetscorba: adding manifestsjaxp: adding manifestscorba: adding file changesjaxp: adding file changescorba: added 669 changesets with 4913 changes to 2576 filescorba: updating to branch defaultcorba: 1184 files updated, 0 files merged, 0 files removed, 0 files unresolvedjaxws: hg clone http://hg.openjdk.java.net/kulla/dev/jaxws jaxwsjaxws: requesting all changesjaxws: adding changesetsjaxws: adding manifestsjaxws: adding file changesjaxp: added 728 changesets with 10192 changes to 7393 filesjaxp: updating to branch defaultjaxp: 3044 files updated, 0 files merged, 0 files removed, 0 files unresolvedlangtools: hg clone http://hg.openjdk.java.net/kulla/dev/langtools langtoolslangtools: requesting all changeslangtools: adding changesetslangtools: adding manifestsjaxws: added 589 changesets with 20521 changes to 10746 filesjaxws: updating to branch defaultjaxws: 3750 files updated, 0 files merged, 0 files removed, 0 files unresolvedjdk: hg clone http://hg.openjdk.java.net/kulla/dev/jdk jdklangtools: adding file changesjdk: requesting all changesjdk: adding changesetsjdk: adding manifestslangtools: added 3173 changesets with 28112 changes to 9103 fileslangtools: updating to branch defaultlangtools: 7100 files updated, 0 files merged, 0 files removed, 0 files unresolvedhotspot: hg clone http://hg.openjdk.java.net/kulla/dev/hotspot hotspothotspot: requesting all changeshotspot: adding changesetshotspot: adding manifestshotspot: adding file changeshotspot: added 8073 changesets with 45889 changes to 6290 fileshotspot: updating to branch defaulthotspot: 5030 files updated, 0 files merged, 0 files removed, 0 files unresolvednashorn: hg clone http://hg.openjdk.java.net/kulla/dev/nashorn nashornnashorn: requesting all changesnashorn: adding changesetsnashorn: adding manifestsjdk: adding file changesnashorn: adding file changesnashorn: added 1252 changesets with 11596 changes to 3595 filesnashorn: updating to branch defaultnashorn: 2867 files updated, 0 files merged, 0 files removed, 0 files unresolvedjdk: added 11805 changesets with 116593 changes to 42135 filesjdk: updating to branch defaultjdk: 23192 files updated, 0 files merged, 0 files removed, 0 files unresolved # Repositories: . corba jaxp jaxws langtools jdk hotspot nashorn .: cd . && hg pull -ucorba: cd corba && hg pull -ujaxp: cd jaxp && hg pull -ujaxws: cd jaxws && hg pull -ulangtools: cd langtools && hg pull -ujdk: cd jdk && hg pull -uhotspot: cd hotspot && hg pull -unashorn: cd nashorn && hg pull -ujaxws: pulling from http://hg.openjdk.java.net/kulla/dev/jaxwscorba: pulling from http://hg.openjdk.java.net/kulla/dev/corbalangtools: pulling from http://hg.openjdk.java.net/kulla/dev/langtoolshotspot: pulling from http://hg.openjdk.java.net/kulla/dev/hotspotjdk: pulling from http://hg.openjdk.java.net/kulla/dev/jdk.: pulling from http://hg.openjdk.java.net/kulla/devjaxp: pulling from http://hg.openjdk.java.net/kulla/dev/jaxpnashorn: pulling from http://hg.openjdk.java.net/kulla/dev/nashornnashorn: searching for changesnashorn: no changes foundjaxws: searching for changesjaxws: no changes foundjaxp: searching for changesjaxp: no changes foundcorba: searching for changescorba: no changes foundjdk: searching for changeshotspot: searching for changeshotspot: no changes foundjdk: no changes found.: searching for changes.: no changes foundlangtools: searching for changeslangtools: no changes found
  • 編輯langtools/repl/scripts/compile.sh腳本,如下所示: #!/bin/sh JLINE2LIB=/Users/arungupta/workspaces/jline2/target/jline-2.13-SNAPSHOT.jar mkdir -p build javac -Xlint:unchecked -Xdiags:verbose -cp ${JLINE2LIB} -d build ../src/jdk.jshell/share/classes/*/*/*.java ../src/jdk.jshell/share/classes/*/*/*/*/*.java ../src/jdk.jshell/share/classes/*/*/*/*/*/*.java

    注意,唯一的編輯是OSX的#!/bin/sh并將JLINE2LIB添加到先前編譯的jline2工作區(qū)的位置。 從引用JDK 9的JAVA_HOME中拾取javac 。

  • 通過從langtools/repl目錄調(diào)用腳本來編譯REPL工具: repl> chmod +x ./scripts/compile.sh repl> ./scripts/compile.sh
  • 運(yùn)行JDK 9 REPL

  • 編輯langtools/repl/scripts/run.sh腳本,如下所示: #!/bin/sh JLINE2LIB=/Users/arungupta/workspaces/jline2/target/jline-2.13-SNAPSHOT.jar java -ea -esa -cp build:${JLINE2LIB} jdk.internal.jshell.tool.JShellTool "$@"

    注意,對(duì)于OSX唯一的編輯是!/bin/sh并添加JLINE2LIB 。

  • 將REPL運(yùn)行為: repl> ./scripts/run.sh | Welcome to JShell -- Version 0.428 | Type /help for help
  • JDK 9 REPL Hello World

    與引入Java的彈跳球或跳舞Duke引入不同,我們只將常規(guī)的Hello World用于REPL

    將“ Hello World”運(yùn)行為:

    -> System.out.println("Hello World"); Hello World

    瞧!

    沒有public static void main ,沒有類的創(chuàng)建,沒有儀式,只是干凈而簡單的Java代碼。 輸入的文本稱為“代碼段”。

    可以使用/list all查看完整的Java代碼,如下所示:

    -> /list all1 : import java.util.*;2 : import java.io.*;3 : import java.math.*;4 : import java.net.*;5 : import java.util.concurrent.*;6 : import java.util.prefs.*;7 : import java.util.regex.*;8 : void printf(String format, Object... args) { System.out.printf(format, args); }9 : System.out.println("Hello World");

    該代碼段可以另存為文件:

    -> /save test

    請(qǐng)注意,這不是Java文件。 保存的代碼段正是輸入的內(nèi)容:

    repl> more test System.out.println("Hello World");

    該工具可以退出為:

    -> /exit | Goodbye

    或者您可以按Ctrl + C。

    完整的命令列表很容易看到:

    -> /help Type a Java language expression, statement, or declaration. Or type one of the following commands:/l or /list [all] -- list the source you have typed/seteditor <executable> -- set the external editor command to use /e or /edit <name or id> -- edit a source entry referenced by name or id /- or /drop <name or id> -- delete a source entry referenced by name or id /s or /save [all|history] <file> -- save the source you have typed /o or /open <file> -- open a file as source input /v or /vars -- list the declared variables and their values /m or /methods -- list the declared methods and their signatures /c or /classes -- list the declared classes /x or /exit -- exit the REPL /r or /reset -- reset everything in the REPL /f or /feedback <level> -- feedback information: off, concise, normal, verbose, default, or ? /p or /prompt -- toggle display of a prompt /cp or /classpath <path> -- add a path to the classpath /h or /history -- history of what you have typed/setstart <file> -- read file and set as the new start-up definitions/savestart <file> -- save the default start-up definitions to the file /? or /help -- this help messageSupported shortcuts include: <tab> -- show possible completions for the current text Shift-<tab> -- for current method or constructor invocation, show a synopsis of the method/constructor

    JDK 9 REPL后續(xù)步驟和反饋

    請(qǐng)遵循REPL教程以了解有關(guān)該工具功能的更多信息。 快速概述:

    • 接受Java語句,變量,方法和類的定義,導(dǎo)入和表達(dá)式
    • 設(shè)置和顯示信息的命令,例如/list顯示代碼片段列表, /vars顯示變量列表, /save保存代碼片段, /open讀回它們。
    • 片段的歷史記錄可用,片段可以按數(shù)字進(jìn)行編輯,等等

    這是一個(gè)有用的RFE:

    • 將代碼段導(dǎo)出為完整的Java類

    隨后的博客將展示如何將其用于Java EE應(yīng)用程序的播放。 您將如何使用REPL?

    在kulla-dev上討論項(xiàng)目/問題。

    請(qǐng)享用!

    翻譯自: https://www.javacodegeeks.com/2015/05/jdk-9-repl-getting-started.html

    jdk入門

    創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

    總結(jié)

    以上是生活随笔為你收集整理的jdk入门_JDK 9 REPL:入门的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。