人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

php&java(二)

php&java(二)

更新時(shí)間:2022-07-24 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

例子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)制類型語言,而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)用它!

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 正安县| 玉环县| 米泉市| 太仆寺旗| 应用必备| 罗平县| 钟山县| 仁怀市| 东兰县| 通道| 竹山县| 吉安县| 阿拉善盟| 辉县市| 油尖旺区| 田林县| 夹江县| 莱阳市| 临颍县| 高清| 北辰区| 镇沅| 清原| 塘沽区| 凤庆县| 垫江县| 洪湖市| 新泰市| 利川市| 鄱阳县| 磐安县| 肇州县| 黄浦区| 茌平县| 广宗县| 鹿邑县| 句容市| 柞水县| 苍南县| 达日县| 比如县|