創(chuàng)建你自己的JAVA類非常容易。新建一個phptest.java文件,將它放置在你的java.class.path目錄下,文件內(nèi)容如下:

public class phptest{
/**
* A sample of a class that can work wit " /> 哪灬你的鸣巴好大,在线视频中文字幕,99久久免费热在线精品

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php&java(二)

例子1:創(chuàng)建和使用你自己的Java
創(chuàng)建你自己的Java類非常容易。新建一個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)建這個文件后,我們要編譯好這個文件,在DOS命令行使用Javac phptest.Java這個命令。

為了使用php測試這個Java類,我們創(chuàng)建一個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是一種強制類型語言,而php不是,這樣我們在將它們?nèi)诤蠒r,容易導(dǎo)致錯誤,于是我們在向Java傳遞變量時,要正確指定好變量的類型。如:$myj->foo = (string) 12345678; or $myj->foo = "12345678";

這只是一個很小的例子,你可以創(chuàng)建你自己的Java類,并使用php很好的調(diào)用它!

php技術(shù)php&amp;amp;java(二),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 翁公与小莹在客厅激情 | 亚洲乱码AV久久久久久久 | 丝袜美女被啪啪不带套漫画 | 99精品视频在线 | 教室眠催白丝美女校花 | 久久久青青 | 国产剧情在线精品视频不卡 | yw193.c国产在线观看 | 青苹果乐园在线观看电视剧 | 91欧美秘密入口 | 色姣姣狠狠撩综合网 | 色愁愁久久久 | 小学生偷拍妈妈视频遭性教育 | bl 纯肉 高Hbl被强文 | 精品人妻伦九区久久AAA片69 | 99国内偷揿国产精品人妻 | 麻豆国产99在线中文 | 麻豆精品一卡2卡三卡4卡免费观看 | 国模孕妇模特季玥之粉红 | 一二三四在线播放免费观看中文版视频 | 亚洲中文字幕在线精品 | 日韩精品久久日日躁夜夜躁影视 | 亚洲色视在线观看视频 | 伊人网中文字幕 | 人禽l交视频在线播放 视频 | 草柳最新地址 | 插我一区二区在线观看 | 久久视频在线视频 | 国产睡熟迷奷系列精品 | 免费的好黄的漫画 | www.久艹 | 做暖暖视频在线看片免费 | 午夜理论片日本中文在线 | 光溜溜的美女直播软件 | 日韩一区二区三区精品 | 久久亚洲精品中文字幕60分钟 | 亚洲视频中文字幕 | 全免费午夜一级毛片 | 日韩人妻无码专区一本二本 | 看看妇女的B免费看 | 嫩草视频在线观看免费 |