java调用webservice接口 几种方法

简介: webservice的 发布一般都是使用WSDL(web service descriptive language)文件的样式来发布的,在WSDL文件里面,包含这个webservice暴露在外面可供使用的接口。今天搜索到了非常好的 webservice provider列表

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文件,我自己是看不懂的,尤其我不是专门搞这行的,即使一段时间看懂,后来也就忘记了。直接调用模式如下:

[java] view plain copy

 

在CODE上查看代码片派生到我的代码片

  1. import java.util.Date;
  2. import java.text.DateFormat;
  3. import org.apache.axis.client.Call;
  4. import org.apache.axis.client.Service;
  5. import javax.xml.namespace.QName;
  6. import java.lang.Integer;
  7. import javax.xml.rpc.ParameterMode;
  8. public class caClient {
  9.     public static void main(String[] args) {
  10.         try {
  11.             String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";
  12.             // 直接引用远程的wsdl文件
  13.             // 以下都是套路
  14.             Service service = new Service();
  15.             Call call = (Call) service.createCall();
  16.             call.setTargetEndpointAddress(endpoint);
  17.             call.setOperationName("addUser");// WSDL里面描述的接口名称
  18.             call.addParameter("userName",
  19.                     org.apache.axis.encoding.XMLType.XSD_DATE,
  20.                     javax.xml.rpc.ParameterMode.IN);// 接口的参数
  21.             call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
  22.             String temp = "测试人员";
  23.             String result = (String) call.invoke(new Object[] { temp });
  24.             // 给方法传递参数,并且调用方法
  25.             System.out.println("result is " + result);
  26.         } catch (Exception e) {
  27.             System.err.println(e.toString());
  28.         }
  29.     }
  30. }

 

2,直接SOAP调用远程的webservice

这种模式我从来没有见过,也没有试过,但是网络上有人贴出来,我也转过来

[java] view plain copy

 

在CODE上查看代码片派生到我的代码片

  1. import org.apache.soap.util.xml.*;
  2. import org.apache.soap.*;
  3. import org.apache.soap.rpc.*;
  4. import java.io.*;
  5. import java.net.*;
  6. import java.util.Vector;
  7. public class caService {
  8.     public static String getService(String user) {
  9.         URL url = null;
  10.         try {
  11.             url = new URL(
  12.                     "http://192.168.0.100:8080/ca3/services/caSynrochnized");
  13.         } catch (MalformedURLException mue) {
  14.             return mue.getMessage();
  15.         }
  16.         // This is the main SOAP object
  17.         Call soapCall = new Call();
  18.         // Use SOAP encoding
  19.         soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
  20.         // This is the remote object we're asking for the price
  21.         soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");
  22.         // This is the name of the method on the above object
  23.         soapCall.setMethodName("getUser");
  24.         // We need to send the ISBN number as an input parameter to the method
  25.         Vector soapParams = new Vector();
  26.         // name, type, value, encoding style
  27.         Parameter isbnParam = new Parameter("userName", String.class, user,
  28.                 null);
  29.         soapParams.addElement(isbnParam);
  30.         soapCall.setParams(soapParams);
  31.         try {
  32.             // Invoke the remote method on the object
  33.             Response soapResponse = soapCall.invoke(url, "");
  34.             // Check to see if there is an error, return "N/A"
  35.             if (soapResponse.generatedFault()) {
  36.                 Fault fault = soapResponse.getFault();
  37.                 String f = fault.getFaultString();
  38.                 return f;
  39.             } else {
  40.                 // read result
  41.                 Parameter soapResult = soapResponse.getReturnValue();
  42.                 // get a string from the result
  43.                 return soapResult.getValue().toString();
  44.             }
  45.         } catch (SOAPException se) {
  46.             return se.getMessage();
  47.         }
  48.     }
  49. }

 

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实现的具体细节不感兴趣,那么你只需要看接口文件即可,

在使用的时候,引入这个接口即可,就好像使用本地类一样。

一:webService介绍

1.什么是webService

webService是一种使用http传输SOAP协议数据的远程调用技术

2.webService三要素

SOAP:规范XML标签

WSDL:服务端的使用说明书

UDDI:目录

二:webService入门小程序

1.服务端

(1)、开发步骤
A、创建接口

[java] view plain copy

 
  1. package com.webservice.jaxws;
  2. public interface WeatherService {
  3.     //查询天气的方法
  4.     public String queryWeather(String cityName);
  5. }

 

B、创建实现类,在实现类上加入@WebService注解,该注解的作用是标识该实现类是webservice的服务类,发布该实现类中的public方法

[java] view plain copy

 
  1. package com.webservice.jaxws;
  2. import javax.jws.WebService;
  3. /**
  4.  * 天气查询的实现类
  5.  * @author Administrator
  6.  *
  7.  */
  8. @WebService
  9. public class WeatherServiceImpl implements WeatherService {
  10.     //查询天气
  11.     public String queryWeather(String cityName) {
  12.         System.out.println(cityName + "天气是:晴天");
  13.         return "晴";
  14.     }
  15. }

 

C、发布服务,使用EndPoint类中的publish()方法发布,参数分别为服务访问的地址和服务的实现类

[java] view plain copy

 
  1. package com.webservice.jaxws;
  2. import javax.xml.ws.Endpoint;
  3. public class ServerPoint {
  4.     public static void main(String[] args) {
  5.         //参数1:服务地址,weather为服务的名称
  6.         //参数2:服务实现类
  7.         Endpoint.publish("http://127.0.0.1:12345/weather", new WeatherServiceImpl());
  8.     }
  9. }
D、测试服务是否发布成功,阅读使用说明书,确认要调用的类、方法、参数等

● WSDL访问地址:

http://localhost:12345/weather?wsdl

● WSDL说明书阅读方式:从下往上阅读

E、如何发布SOAP1.2版本的服务端

●   引入第三方jar包

●   在服务实现类上加入注解 @BindingType(SOAPBinding.SOAP12HTTP_BINDING)

[java] view plain copy

 
  1. package com.webservice.jaxws;
  2. import javax.jws.WebService;
  3. import javax.xml.ws.BindingType;
  4. import javax.xml.ws.soap.SOAPBinding;
  5. /**
  6.  * 天气查询的实现类
  7.  * @author Administrator
  8.  *
  9.  */
  10. @WebService
  11. @BindingType(SOAPBinding.SOAP12HTTP_BINDING)
  12. public class WeatherServiceImpl implements WeatherService {
  13.     //查询天气
  14.     public String queryWeather(String cityName) {
  15.         System.out.println(cityName + "天气是:晴天");
  16.         return "晴";
  17.     }
  18. }

2.客户端

 
(1)、开发步骤
A、在工作空间创建用于存放使用wsimport命令生成的客户端代码的java工程

B、使用jdk提供的wsimport命令生成客户端代码

●  wsimport命令是jdk提供的,作用是根据使用说明书生成客户端代码,wsimport只支持SOAP1.1客户端的生成
●  wsimport常用参数

-d:默认参数,用于生成.class文件
-s:生成.java文件
-p:指定生成java文件的包名,不指定则为WSDL说明书中namespace值得倒写

C、在doc窗口进入java工程项目的src目录,执行wsimport命令

D、在Eclipse中刷新java项目,将生成的客户端代码copy到客户端工程中

E、创建服务视图,类名从<service>标签的name属性获取

F、获取服务实现类,视图实例调用getProt()方法,实现类的类名从portType的name属性获取

G、调用查询方法,方法名从portType下的operation标签的name属性获取

[java] view plain copy

 
  1. package com.webservice.client;
  2. import com.webservice.jaxws.WeatherServiceImpl;
  3. import com.webservice.jaxws.WeatherServiceImplService;
  4. public class Client {
  5.     public static void main(String[] args) {
  6.         //创建视图
  7.         WeatherServiceImplService wsis = new WeatherServiceImplService();
  8.         //获取服务实现类
  9.         WeatherServiceImpl wsi = wsis.getPort(WeatherServiceImpl.class);
  10.         //调用查询方法
  11.         String weather = wsi.queryWeather("北京");
  12.         System.out.println(weather);
  13.     }
  14. }

三:webService三要素详解

1.WSDL

(1)、定义

WSDL即web服务描述语言,它是服务端的使用说明书,是XML格式的文档,说明服务地址、服务类、方法、参数和返回值,是伴随服务发布成功,自动生成的

(2)、文档结构

●   <service>    服务视图,webservice的服务结点,它包括了服务端点

●   <binding>     为每个服务端点定义消息格式和协议细节

●   <portType>   服务端点,描述 web service可被执行的操作方法,以及相关的消息,通过binding指向portType

●   <message>   定义一个操作(方法)的数据参数(可有多个参数)

●   <types>        定义 web service 使用的全部数据类型

2.SOAP

(1)、定义

SOAP即简单对象访问协议(Simple Object Access Protocol),使用http发送XML格式的数据,他不是webservice的专有协议

 

(2)、结构 SOAP = HTTP + XML

(3)、协议的格式

Envelope:必须有,此元素将整个 XML 文档标识为一条SOAP消息

Header:可选元素,包含头部信息

Body:必须有,包含所有调用和响应信息

Fault:可选元素,提供有关在处理此消息时所发生的错误信息

(4)、版本
A、SOAP1.1

●   请求

[html] view plain copy

 
  1. POST /weather HTTP/1.1
  2. Accept: text/xml, multipart/related
  3. Content-Type: text/xml; charset=utf-8
  4. SOAPAction: "http://jaxws.ws.itcast.cn/WeatherInterfaceImpl/queryWeatherRequest"
  5. User-Agent: JAX-WS RI 2.2.4-b01
  6. Host: 127.0.0.1:54321
  7. Connection: keep-alive
  8. Content-Length: 211
  9. <?xml version="1.0" ?>
  10. <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  11. <S:Body><ns2:queryWeather xmlns:ns2="http://jaxws.ws.itcast.cn/"><arg0>北京</arg0></ns2:queryWeather>
  12. </S:Body>
  13. </S:Envelope>

 

●   响应

[html] view plain copy

 
  1. HTTP/1.1 200 OK
  2. Transfer-encoding: chunked
  3. Content-type: text/xml; charset=utf-8
  4. Date: Fri, 04 Dec 2015 03:45:56 GMT
  5. <?xml version="1.0" ?>
  6. <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  7. <S:Body>
  8. <ns2:queryWeatherResponse xmlns:ns2="http://jaxws.ws.itcast.cn/"><return>晴</return></ns2:queryWeatherResponse>
  9. </S:Body>
  10. </S:Envelope>

 

B、SOAP1.2

●   请求

[html] view plain copy

 
  1. POST /weather HTTP/1.1
  2. Accept: application/soap+xml, multipart/related
  3. Content-Type: application/soap+xml; charset=utf-8;
  4. action="http://jaxws.ws.itcast.cn/WeatherInterfaceImpl/queryWeatherRequest"
  5. User-Agent: JAX-WS RI 2.2.4-b01
  6. Host: 127.0.0.1:54321
  7. Connection: keep-alive
  8. Content-Length: 209
  9. <?xml version="1.0" ?>
  10. <S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
  11. <S:Body><ns2:queryWeather xmlns:ns2="http://jaxws.ws.itcast.cn/"><arg0>北京</arg0></ns2:queryWeather>
  12. </S:Body>
  13. </S:Envelope>

 

●   响应

[html] view plain copy

 
  1. HTTP/1.1 200 OK
  2. Transfer-encoding: chunked
  3. Content-type: application/soap+xml; charset=utf-8
  4. Date: Fri, 04 Dec 2015 03:55:49 GMT
  5. <?xml version='1.0' encoding='UTF-8'?>
  6. <S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
  7. <S:Body>
  8. <ns2:queryWeatherResponse xmlns:ns2="http://jaxws.ws.itcast.cn/"><return>晴</return></ns2:queryWeatherResponse>
  9. </S:Body>
  10. </S:Envelope>

 

C、SOAP1.1 和 SOAP1.2的区别

●   相同点

请求方式都是POST

协议格式都一样,都有envelope和body

●   不同点

①、数据格式不同

SOAP1.1:text/xml;charset=utf-8
SOAP1.2:application/soap+xml;charset=utf-8
②、命名空间不同

四:webservice客户端的四种调用方式

1.生成客户端调用方式

(1)、开发步骤

A、wisimport生成客户端代码

B、创建服务视图

C、获取实现类

D、调用查询方法

2.service编程实现调用

(1)、开发步骤
A、wisimport生成客户端代码
B、使用serivce类创建服务视图
C、获取服务实现类
D、调用查询方法

[java] view plain copy

 
  1. import java.io.IOException;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import javax.xml.namespace.QName;
  5. import javax.xml.ws.Service;
  6. import cn.itcast.mobile.MobileCodeWSSoap;
  7. /**
  8.  * 
  9.  * <p>Title: ServiceClient.java</p>
  10.  * <p>Description:Service编程实现客户端</p>
  11.  */
  12. public class ServiceClient {
  13.     public static void main(String[] args) throws IOException {
  14.         //创建WSDL地址,不是服务地址
  15.         URL url = new URL("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl");
  16.         //创建服务名称
  17.         //1.namespaceURI - 命名空间地址
  18.         //2.localPart - 服务名称
  19.         QName qname = new QName("http://WebXml.com.cn/", "MobileCodeWS");
  20.         //Service创建视图
  21.         //参数:
  22.         //1.wsdlDocumentLocation - 使用说明书地址
  23.         //2.serviceName - 服务名称
  24.         Service service = Service.create(url, qname);
  25.         //获取实现类
  26.         MobileCodeWSSoap mobileCodeWSSoap = service.getPort(MobileCodeWSSoap.class);
  27.         //调用查询方法
  28.         String result = mobileCodeWSSoap.getMobileCodeInfo("188888888", "");
  29.         System.out.println(result);
  30.     }
  31. }

特点:方便管理,是一个标准的开发方式

3.HttpURLConnection调用方式

(1)、开发步骤
A、创建服务地址
B、打开服务地址的一个连接
C、设置连接参数
●   注意
a、POST必须大写,如果小写会出如下异常:
b、如果不设置输入输出,会报如下异常:
D、组织SOAP协议数据,发送给服务器
E、接收服务端的响应

[java] view plain copy

 
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStream;
  6. import java.net.HttpURLConnection;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9. /**
  10.  * 
  11.  * <p>Title: HttpClient.java</p>
  12.  * <p>Description:HttpURLConnection调用方式</p>
  13.  */
  14. public class HttpClient {
  15.     public static void main(String[] args) throws IOException {
  16.         //1:创建服务地址
  17.         URL url = new URL("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx");
  18.         //2:打开到服务地址的一个连接
  19.         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  20.         //3:设置连接参数
  21.         //3.1设置发送方式:POST必须大写
  22.         connection.setRequestMethod("POST");
  23.         //3.2设置数据格式:Content-type
  24.         connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
  25.         //3.3设置输入输出,新创建的connection默认是没有读写权限的,
  26.         connection.setDoInput(true);
  27.         connection.setDoOutput(true);
  28.         //4:组织SOAP协议数据,发送给服务端
  29.         String soapXML = getXML("1866666666");
  30.         OutputStream os = connection.getOutputStream();
  31.         os.write(soapXML.getBytes());
  32.         //5:接收服务端的响应
  33.         int responseCode = connection.getResponseCode();
  34.         if(200 == responseCode){//表示服务端响应成功
  35.             InputStream is = connection.getInputStream();
  36.             InputStreamReader isr = new InputStreamReader(is);
  37.             BufferedReader br = new BufferedReader(isr);
  38.             StringBuilder sb = new StringBuilder();
  39.             String temp = null;
  40.             while(null != (temp = br.readLine())){
  41.                 sb.append(temp);
  42.             }
  43.             System.out.println(sb.toString());
  44.             is.close();
  45.             isr.close();
  46.             br.close();
  47.         }
  48.         os.close();
  49.     }
  50.     /**
  51.      * <?xml version="1.0" encoding="utf-8"?>
  52.         <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  53.             <soap:Body>
  54.                 <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
  55.                     <mobileCode>string</mobileCode>
  56.                     <userID>string</userID>
  57.                 </getMobileCodeInfo>
  58.             </soap:Body>
  59.         </soap:Envelope>
  60.      * @param phoneNum
  61.      * @return
  62.      */
  63.     public static String getXML(String phoneNum){
  64.         String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  65.         +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  66.             +"<soap:Body>"
  67.             +"<getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\">"
  68.                 +"<mobileCode>"+phoneNum+"</mobileCode>"
  69.               +"<userID></userID>"
  70.             +"</getMobileCodeInfo>"
  71.          +" </soap:Body>"
  72.         +"</soap:Envelope>";
  73.         return soapXML;
  74.     }
  75. }

4.Ajax调用方式

[html] view plain copy

 
  1. <!doctype html>
  2. <html lang="en">
  3.  <head>
  4.   <title>Ajax调用方式</title>
  5.   <script type="text/javascript">
  6.     function queryMobile(){
  7.         //创建XMLHttpRequest对象
  8.         var xhr = new XMLHttpRequest();
  9.         //打开链接
  10.         xhr.open("post","http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx",true);
  11.         //设置content-type
  12.         xhr.setRequestHeader("content-type","text/xml;charset=utf-8");
  13.         //设置回调函数
  14.         xhr.onreadystatechange=function(){
  15.             //判断客户端发送成功&&服务端响应成功
  16.             if(4 == xhr.readyState && 200 == xhr.status){
  17.                 alert(xhr.responseText);
  18.             }
  19.         }
  20.         //组织SOAP协议数据
  21.         var soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  22.         +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  23.             +"<soap:Body>"
  24.             +"<getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\">"
  25.                 +"<mobileCode>"+document.getElementById("phoneNum").value+"</mobileCode>"
  26.               +"<userID></userID>"
  27.             +"</getMobileCodeInfo>"
  28.          +" </soap:Body>"
  29.         +"</soap:Envelope>";
  30.         alert(soapXML);
  31.         //发送请求
  32.         xhr.send(soapXML);
  33.     }
  34.   </script>
  35.  </head>
  36.  <body>
  37.     手机号归属地查询:<input type="text" id="phoneNum" /><input type="button" value="查询" onclick="javascript:queryMobile();"/>
  38.  </body>
  39. </html>

五、深入开发:用注解修改WSDL内容

1.WebService的注解都位于javax.jws包下:

@WebService-定义服务,在public class上边

targetNamespace:指定命名空间

name:portType的名称
portName:port的名称
serviceName:服务名称
endpointInterface:SEI接口地址,如果一个服务类实现了多个接口,只需要发布一个接口的方法,可通过此注解指定要发布服务的接口。
@WebMethod-定义方法,在公开方法上边
operationName:方法名
exclude:设置为true表示此方法不是webservice方法,反之则表示webservice方法
 
@WebResult-定义返回值,在方法返回值前边
name:返回结果值的名称
 
@WebParam-定义参数,在方法参数前边
name:指定参数的名称
作用:

通过注解,可以更加形像的描述Web服务。对自动生成的wsdl文档进行修改,为使用者提供一个更加清晰的wsdl文档。
当修改了WebService注解之后,会影响客户端生成的代码。调用的方法名和参数名也发生了变化,必须重新生成客户端代码

 
示例:

[java] view plain copy

 
  1. import javax.jws.WebMethod;
  2. import javax.jws.WebParam;
  3. import javax.jws.WebResult;
  4. import javax.jws.WebService;
  5. import javax.xml.ws.BindingType;
  6. import javax.xml.ws.soap.SOAPBinding;
  7. /**
  8.  * 
  9.  * <p>Title: WeatherInterfaceImpl.java</p>
  10.  * <p>Description:SEI实现类</p>
  11.  */
  12. @WebService(
  13.         targetNamespace="http://service.itcast.cn",
  14.         name="WeatherWSSoap",
  15.         portName="WeatherWSSoapPort",
  16.         serviceName="WeatherWS"
  17.         )
  18. @BindingType(SOAPBinding.SOAP12HTTP_BINDING)
  19. public class WeatherInterfaceImpl implements WeatherInterface {
  20.     @WebMethod(
  21.             operationName="getWeather",
  22.             exclude=false
  23.             )
  24.     @Override
  25.     public @WebResult(name="result")String queryWeather(@WebParam(name="cityName")String cityName) {
  26.         System.out.println("from client..."+cityName);
  27.         String weather = "晴";
  28.         return weather;
  29.     }
  30. }

原文地址http://www.bieryun.com/617.html

相关文章
|
13天前
|
Java
Java中ReentrantLock中tryLock()方法加锁分析
Java中ReentrantLock中tryLock()方法加锁分析
12 0
|
3天前
|
Java 关系型数据库 MySQL
Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
【4月更文挑战第12天】Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
27 3
|
4天前
|
存储 Java
Java动态转发代理IP的实现方法
Java动态转发代理IP的实现方法
21 11
|
5天前
|
Java 开发者
探索 Java 的函数式接口和 Lambda 表达式
【4月更文挑战第19天】Java 中的函数式接口和 Lambda 表达式提供了简洁、灵活的编程方式。函数式接口有且仅有一个抽象方法,用于与 Lambda(一种匿名函数语法)配合,简化代码并增强可读性。Lambda 表达式的优点在于其简洁性和灵活性,常用于事件处理、过滤和排序等场景。使用时注意兼容性和变量作用域,它们能提高代码效率和可维护性。
|
6天前
|
Java
Java接口中可以定义哪些方法?
【4月更文挑战第13天】
7 0
Java接口中可以定义哪些方法?
|
7天前
|
设计模式 Java
Java接口与抽象类
Java接口与抽象类
17 0
|
12天前
|
Java Shell
Java 21颠覆传统:未命名类与实例Main方法的编码变革
Java 21颠覆传统:未命名类与实例Main方法的编码变革
13 0
|
12天前
|
安全 Java 编译器
接口之美,内部之妙:深入解析Java的接口与内部类
接口之美,内部之妙:深入解析Java的接口与内部类
34 0
接口之美,内部之妙:深入解析Java的接口与内部类
|
13天前
|
Java
Java中关于ConditionObject的signal()方法的分析
Java中关于ConditionObject的signal()方法的分析
21 4
|
13天前
|
安全 Java
append在Java中是哪个类下的方法
append在Java中是哪个类下的方法
22 9