美文网首页
最近学到的java常识

最近学到的java常识

作者: 吹洞箫饮酒杏花下 | 来源:发表于2017-09-12 14:11 被阅读0次

1.请求服务器的接口:其中涉及到http请求,url。

依赖org.apache.httpcomponents/httpclient/4.3.4

//1. 创建默认的httpClient实例.

CloseableHttpClient httpclient =null;

httpclient = HttpClients.createDefault();

//2. 创建httppost

HttpPost httpPost =newHttpPost(url1);

httpPost.addHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded");

// 3. 参数

String exp_id="0^0^0^0^0^0^0^0";

String utf16_gpoint="12950074.7,4836976.15";

List postBody =newArrayList();

postBody.add(newBasicNameValuePair("queryString",query));

postBody.add(newBasicNameValuePair("forceQuery","1"));

postBody.add(newBasicNameValuePair("exp_id","0^0^0^0^0^0^0^0"));

postBody.add(newBasicNameValuePair("gpoint","12950074.7,4836976.15"));

StringBuilder postData =newStringBuilder();

for(BasicNameValuePair namevalue : postBody) {

postData.append(namevalue.getName()).append("=")

.append(StringHelper.urlEncodeUtf16le(namevalue.getValue())).append("&");

}

postData.deleteCharAt(postData.length() -1);

StringEntity se =newStringEntity(postData.toString());

se.setContentEncoding("UTF-16LE");

se.setContentType("application/json");

httpPost.setEntity(se);

response = httpclient.execute(httpPost);

//解析返结果

HttpEntity entity = response.getEntity();

2. hadoop java map-reduce

依赖org.apache.hadoop  hadoop-core  0.20.2

程序输入处,int status = ToolRunner.run(new Main(),args);

构建Main类,extends Configured implements Tool 。在Main类中,重写run方法。在run方法中,定义Configuration conf = getConf(); 并进行配置。定义Jobjob =newJob(conf);可配置输入输出路径,配置mapreduce等各种。在Main类中实现public static class InputMapper extends Mapper,public static class OutputReducer extends Reducer

3. xml 处理

StringReader reader =newStringReader(resStr);

InputSource source =newInputSource(reader);

SAXReader sr =newSAXReader();

Document doc = sr.read(source);

Element root = doc.getRootElement();

//遍历根节点下的子节点(同样也可以遍历某个含子节点的子节点)

for(Object obj : root.elements()) {

Element ele = (Element) obj;

//获取子节点的属性

if(ele.getName() =="process_node"){

for(Object ob:ele.elements()){

4. json串生成

JSONObject jsonObject =newJSONObject();

jsonObject.put("weight",((Element) xx).attribute("weight").getValue());

String jsonStr == jsonObject.toString();

5. maven 打包的配置    

http://www.jianshu.com/p/7a0e20b30401  

https://maven.apache.org/plugins/maven-shade-plugin/

include/exclude 掉

<include>junit/framework/**</include>     <exclude>org/junit/experimental/**</exclude>

通过设置 MainClass 创建一个可执行 Jar 包

包括把依赖打一个jar包、依赖jar包的冲突解决  relocation 

6. 多线程

相关文章

  • 最近学到的java常识

    1.请求服务器的接口:其中涉及到http请求,url。 依赖org.apache.httpcomponents/h...

  • 最近学到的常识

    1. 数据导入es 副本数< 机器数 。 2. maven打包 resource插件 ,可以设置把data和代码打...

  • 最近学到的

    1.和饭店合作,重点不在于引流,而在于将自己得服务延伸到餐饮。 2.经营好茶叶店,短期在团队,长期在品牌。 3.做...

  • 我最近学到的

    命运赠与的每一件礼物,都早已在背面标好了价格。 我最近学到的,可以说影响了我的整个思维模式的一个东西是,就像上面那...

  • 最近学到的道理

    失业第36天学到的道理。 1,要生存,自律比自由重要。 当我们闲下来,会干什么?追电影追剧刷抖音。如果我们具有统筹...

  • 最近学到的道理

    1、不要去做太过冒险的事 2、不要投资自己根本不懂得 3、永远不要羡慕别人 首先自己是是一个比较保守的,所以至今还...

  • Java基础

    一、Java编程入门 Java常识 Java主设计者James Gosling 1995.5.23 Sun发布了J...

  • 来看看那些年你误解的常识

    我们在生活中会学到许多常识,有的是父辈口耳相传下来的,有的是从书里学到的,但这之中许多我们以为是真理的常识...

  • java常识

    1、求绝对值:Math.abs(data);

  • JAVA相关文章索引(2)

    1.JAVA基本常识 java 中的几种注释方式 菜鸟轻松搞定Java集合HashMap遍历编程 StringBu...

网友评论

      本文标题:最近学到的java常识

      本文链接:https://www.haomeiwen.com/subject/omhpdxtx.html