java 怎么通过接口java获取接口实现类实现类

java如何通过socket实现服务端与客户端交互 - 快乐每一天~~ - ITeye博客
博客分类:
刚刚开始学习如何通过socket去发送信息下边的案例也是书上的在这留下笔记
Socket API:java .net.Socket继承于java.lang.Object,有八个构造器,其方法并不多,下面介绍使用最频繁的三个方法,其它方法大家可以见JDK文档。
  Accept方法用于产生"阻塞",直到接受到一个连接,并且返回一个客户端的Socket实例。"阻塞"是一个术语,它使程序运行暂时"停留"在这个地方,直到一个会话产生,然后程序继续;通常"阻塞"是由循环产生的。
  getInputStream方法获得网络连接输入,同时返回一个InputStream对象实例。
getOutputStream方法连接的另一端将得到输入,同时返回一个OutputStream对象实例。注意:其中getInputStream和getOutputStream方法均可能会产生一个IOException,它必须被捕获,因为它们返回的流对象,通常都会被另一个流对象使用。
服务端类代码:
* &p&作者 Administrator&/p&
* &p&功能描述:&/p&
* &p&创建时间:-2上午11:06:05&/p&
package com.
import java.io.DataInputS
import java.io.IOE
import java.io.InputS
import java.io.OutputS
import java.io.PrintS
import java.net.InetA
import java.net.ServerS
import java.net.S
* &p&作者 Administrator&/p&
* &p&功能描述:&/p&
* &p&创建时间:-2上午11:06:05&/p&
* @author Administrator
public class ClientServer {
public static void main(String[] args) {
//服务器接口类
ServerSocket sst=
//套接口类
Socket sc=
InputStream is=
OutputStream os=
//dataInput为input的子类
DataInputStream in=
//printStream为output的子类
PrintStream ps=
//构造对象端口为8000
sst =new ServerSocket(8000);
//建立套接口
sc=sst.accept();
//获取套接口的输入流
is=sc.getInputStream();
//构造数据的输入流datainput对象in
in=new DataInputStream(is);
//获取套接口的输出流
os=sc.getOutputStream();
//构造数据的输出流PrintStream对象os
ps=new PrintStream(os);
//获取客户端的IP
InetAddress Ip=sc.getInetAddress();
System.out.println("连接地址ip:"+Ip);
port=sc.getPort();
System.out.println("客户端端口"+port);
ps.println("Welcome");
//在in上读取一行
String str=in.readLine();
while(!str.equals("quit")){
System.out.println("客户说:"+str);
str=in.readLine();
System.out.println("客户离开");
} catch (IOException e) {
e.printStackTrace();
is.close();
os.close();
sc.close();
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
客户端类:
* &p&作者 Administrator&/p&
* &p&功能描述:&/p&
* &p&创建时间:-2上午11:18:47&/p&
package com.
import java.io.DataInputS
import java.io.IOE
import java.io.InputS
import java.io.OutputS
import java.io.PrintS
import java.net.ServerS
import java.net.S
import java.net.UnknownHostE
* &p&作者 Administrator&/p&
* &p&功能描述:&/p&
* &p&创建时间:-2上午11:18:47&/p&
* @author Administrator
public class Client {
public static void main(String[] args) {
//套接口类
Socket sc=
InputStream is=
OutputStream os=
//dataInput为input的子类
DataInputStream in=
//printStream为output的子类
PrintStream ps=
String str=
//创建客户端接口
sc=new Socket("192.168.12.48",8000);
System.out.println("come to server..");
is=sc.getInputStream();
os=sc.getOutputStream();
in=new DataInputStream(is);
ps=new PrintStream(os);
str=in.readLine();
System.out.println("server 说"+str);
byte bt[]=new byte[20];
System.in.read(bt);
String msg=new String (bt,0);
msg=msg.trim();
while(!msg.equals("quit")){
ps.println(msg);
System.in.read(bt);
msg=new String(bt,0);
msg=msg.trim();
//传输信息到服务端
ps.println(msg);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
is.close();
os.close();
sc.close();
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
浏览 16166
浏览: 84206 次
来自: 北京
试试用pageoffice插件读取excel。
确实存在问题...
字符串拼接是丑陋的 你总结得不错 :)
不错,对我有用!java反射机制,通过类名获取对象,通过方法名和参数调
//得到类对象
Class c = Class.forName("完整类名");
Object yourObj = c.newInstance();
//得到方法
Method methlist[] = cls.getDeclaredMethods();
for (int i = 0; i < methlist. i++) {
Method m = methlist[i];
//获取到方法对象,假设方法的参数是一个int,method名为setAge
Method sAge = c.getMethod("setAge", new Class[] {int.class});
//获得参数Object
Object[] arguments = new Object[] { new Integer(37)};
//执行方法
sAge.invoke(yourObj , arguments);
} catch (Exception e) {
getDeclaredMethod*()获取的是类自身声明的所有方法,包含public、protected和private方法。
getMethod*()获取的是类的所有共有方法,这就包括自身的所有public方法,和从基类继承的、从接口实现的所有public方法。
package com.sf.import java.lang.reflect.Mpublic class RefTest {
public static void main(String args[]) throws Exception {
Class clazz = Class.forName("com.sf.test.Test");
Object object = clazz.newInstance();
Method refTest = clazz.getDeclaredMethod("refTest");
Method refTest1 = clazz.getDeclaredMethod("refTest1",String.class);
refTest1.invoke(object, "0021212");
refTest.invoke(object);
package com.sf.public class Test {
public Test(){
public void refTest() {
System.out.println("");
public void refTest1(String string) {
System.out.println(string);java调用webservice接口 几种方法
- 匣子疯子 - ITeye博客
webservice的 发布一般都是使用WSDL(web service descriptive language)文件的样式来发布的,在WSDL文件里面,包含这个webservice暴露在外面可供使用的接口。今天搜索到了非常好的 webservice provider列表
http://www.webservicex.net/WCF/default.aspx
这上面列出了70多个包括很多方面的free webservice provider,utilities-&global weather就可以获取全球的天气预报。
下面我们来看Java如何通过WSDL文件来调用这些web service:
注意,以下的代码并没有经过真正的测试,只是说明这些情况,不同版本的Axis相差很大,大家最好以apache网站上的例子为准,这里仅仅用于说明其基本用法。
1,直接AXIS调用远程的web service
我觉得这种方法比较适合那些高手,他们能直接看懂XML格式的WSDL文件,我自己是看不懂的,尤其我不是专门搞这行的,即使一段时间看懂,后来也就忘记了。直接调用模式如下:
import java.util.D
import java.text.DateF
import org.apache.axis.client.C
import org.apache.axis.client.S
import javax.xml.namespace.QN
import java.lang.I
import javax.xml.rpc.ParameterM
public class caClient {
public static void main(String[] args) {
String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";
//直接引用远程的wsdl文件
//以下都是套路 Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");//WSDL里面描述的接口名称
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
String temp = "测试人员";
String result = (String)call.invoke(new Object[]{temp});
//给方法传递参数,并且调用方法
System.out.println("result is "+result);
catch (Exception e) {
System.err.println(e.toString());
2,直接SOAP调用远程的webservice
这种模式我从来没有见过,也没有试过,但是网络上有人贴出来,我也转过来
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import java.io.*;
import java.net.*;
import java.util.V
public class caService{
public static String getService(String user) {
url=new URL("http://192.168.0.100:8080/ca3/services/caSynrochnized");
} catch (MalformedURLException mue) {
return mue.getMessage();
// This is the main SOAP object
Call soapCall = new Call();
// Use SOAP encoding
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// This is the remote object we're asking for the price
soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");
// This is the name of the method on the above object
soapCall.setMethodName("getUser");
// We need to send the ISBN number as an input parameter to the method
Vector soapParams = new Vector();
// name, type, value, encoding style
Parameter isbnParam = new Parameter("userName", String.class, user, null);
soapParams.addElement(isbnParam);
soapCall.setParams(soapParams);
// Invoke the remote method on the object
Response soapResponse = soapCall.invoke(url,"");
// Check to see if there is an error, return "N/A"
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String f = fault.getFaultString();
// read result
Parameter soapResult = soapResponse.getReturnValue ();
// get a string from the result
return soapResult.getValue().toString();
} catch (SOAPException se) {
return se.getMessage();
3,使用wsdl2java把WSDL文件转成本地类,然后像本地类一样使用,即可。
这是像我这种懒人最喜欢的方式,仍然以前面的global weather report为例。
首先 java org.apache.axis.wsdl.WSDL2Java http://www.webservicex.net/globalweather.asmx.WSDL
原本的网址是http://www.webservicex.net/globalweather.asmx?WSDL,中间个各问号,但是Linux下面它不能解析,所以去掉问号,改为点号。
那么就会出现4个文件:
GlobalWeather.java GlobalWeatherLocator.java GlobalWeatherSoap.java GlobalWeatherSoapStub.java其中GlobalWeatherSoap.java是我们最为关心的接口文件,如果你对RMI等SOAP实现的具体细节不感兴趣,那么你只需要看接口文件即可,在使用的时候,引入这个接口即可,就好像使用本地类一样。
浏览 57186
浏览: 336177 次
来自: 珠海
没看到word文件啊
如何在java Web项目中开发WebService接口,地址 ...
元素不对应啊
非常好,再次感谢MyEclipse 查找接口实现类的方法[转+总结] - 生活在爪洼岛上 - ITeye博客
博客分类:
很多时候我们在研究一些程序的源代码时会遇到许多接口的实现类,但是在Eclipse中上溯查找的时候只能最终查到这个接口,而不能反过来直接查找接口的实现类。通常的办法就是查阅Java Doc,或者在源代码中直接查看到底使用了哪个实现类。但是通过Implementors 这个Eclipse插件就可以解决上面的问题了。这是一个专门用于查找接口方法实现类的工具,非常的方便和实用。
安装有两种方式,一种是直接下载插件(implementors package)然后手动安装到eclipse中,另外一种就是在Eclipse中直接使用 Eclipse update site: 。只要是使用过Eclipse的人应该都会安装插件,具体的安装细节就不再啰嗦了。
需要说明的是必须下载一个适用于你所使用的Eclipse版本的插件,目前最新的版本对应如下:
Latest version for Eclipse 2.1.x or Eclipse 3.0.x: v0.0.14Latest version for Eclipse 3.1+: v0.0.16
2. 使用1) 查看实现接口方法的类:在接口中选中待实现的方法名称,然后右键选择 Open Implementation 即可打开实现该接口方法的类。如果有多个类则会跳出一个选择列表供选择;2) 查看实现类所实现的接口:在接口实现类中选择方法名称,然后右键选择 Open Interface 即可打开接口中的方法。
如果MyEclipse的版本比较高了,比如本人目前使用8.5,就可以直接通过MyEclipse自身提供的快捷键
Control + T
可以直接查看方法实现类中的代码
浏览 10906
浏览: 925985 次
来自: 北京
您好关于登录页面的验验证码这块怎么解决的?还有登录成功后,跳转 ...
不错,谢谢!
不知楼主是不还在想请叫一下我自己开的Tomcat下载一个文件C ...}

我要回帖

更多关于 java获取接口的实现类 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信