av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

php&java(二)

瀏覽:2日期:2024-02-27 09:10:32
例子1:創(chuàng)建和使用你自己的JAVA類 創(chuàng)建你自己的JAVA類非常容易。新建一個(gè)phptest.java文件,將它放置在你的java.class.path目錄下,文件內(nèi)容如下: public class phptest{ /** * A sample of a class that can work with PHP * NB: The whole class must be public to work,;;* and of course the methods you wish to call * directly. * * Also note that from PHP the main method * will not be called;;;*/ public String foo; /** * Takes a string and returns the result * or a msg saying your string was empty */ public String test(String str) {;;;;if(str.equals("")) { ;;;;;;str = "Your string was empty. ";;;;;};;;;return str;;;;} /** * whatisfoo() simply returns the value of the variable foo. */;;;public String whatisfoo() {;;;;return "foo is " + foo;;;;} /** * This is called if phptest is run from the command line with * something like *;;java phptest * or *;;java phptest hello there */ public static void main(String args[]) { phptest p = new phptest(); ;;;;;if(args.length == 0) { String arg = ""System.out.println(p.test(arg)); }else{ for (int i=0; i < args.length; i++) { String arg = args[i]; System.out.println(p.test(arg));;;;} } } } 創(chuàng)建這個(gè)文件后,我們要編譯好這個(gè)文件,在DOS命令行使用javac phptest.java這個(gè)命令。 為了使用PHP測(cè)試這個(gè)JAVA類,我們創(chuàng)建一個(gè)phptest.php文件,內(nèi)容如下: <?php $myj = new Java("phptest"); echo "Test Results are <b>" . $myj->test("Hello World") . "</b>"; $myj->foo = "A String Value" echo "You have set foo to <b>";;;. $myj->foo . "</b><br>n" echo "My java method reports: <b>" . $myj->whatisfoo() . "</b><br>n";?> 如果你得到這樣的警告信息:java.lang.ClassNotFoundException error ,這就意味著你的phptest.class文件不在你的java.class.path目錄下。 注意的是JAVA是一種強(qiáng)制類型語(yǔ)言,而PHP不是,這樣我們?cè)趯⑺鼈內(nèi)诤蠒r(shí),容易導(dǎo)致錯(cuò)誤,于是我們?cè)谙騄AVA傳遞變量時(shí),要正確指定好變量的類型。如:$myj->foo = (string) 12345678; or $myj->foo = "12345678"這只是一個(gè)很小的例子,你可以創(chuàng)建你自己的JAVA類,并使用PHP很好的調(diào)用它!
標(biāo)簽: Java
主站蜘蛛池模板: 久久精品免费 | 国产一区在线免费观看 | 色接久久 | 国产成人综合av | 国产98在线 | 免费, | 狠狠的操| 一级黄色片日本 | 成人激情视频在线观看 | 国产一区成人 | 久久精品视频在线播放 | 日日干夜夜干 | 国产真实精品久久二三区 | 天天av综合 | 久久www免费视频 | 久久久久九九九九 | 91精品久久 | 亚欧洲精品在线视频免费观看 | 91色网站 | 久久91精品久久久久久9鸭 | 国产农村妇女精品一区 | 欧美激情综合五月色丁香小说 | 欧美亚洲国产精品 | 99久久99| 国产精久久久久久久妇剪断 | 久久久99国产精品免费 | 欧日韩在线 | 日本久草 | 97精品国产一区二区三区 | 成人精品视频在线观看 | 中文字幕视频在线 | 一区二区三区高清 | 精产国产伦理一二三区 | 毛片区 | 中文字幕日韩欧美一区二区三区 | 伊人久久精品一区二区三区 | 天堂三级| 午夜寂寞影院在线观看 | 91久久| 日韩www| 欧美区在线观看 | 色在线免费视频 |