上一页 1 2 3 4 5 6 ··· 11 下一页
摘要: 抽象出产品public abstract class AbstractProduct { private String motor; private int wheels; private Color color; public String getMotor() { return motor; } public void setMotor(String motor) { this.motor = motor; } public int getWheels() { return wheels; } public void setWheels(int wheels) { this.whe... 阅读全文
posted @ 2012-01-05 21:39 胖鹅 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 对工厂的抽象public interface Builder { void buildMotor(); void buildWheels(); void paintColor(); AbstractProduct getProduct();}bus工厂public class BusBuilder implements Builder { private String motor; private int wheels; private Color color; @Override public void buildMotor() { // TODO Auto-generated metho. 阅读全文
posted @ 2012-01-05 21:38 胖鹅 阅读(215) 评论(0) 推荐(1) 编辑
摘要: 定义一个接口public interface Filter { public String doFilter(String smg);}继承接口的处理方法public class CrudFilter implements Filter { String message; @Override public String doFilter(String smg) { // TODO Auto-generated method stub this.message = smg.replace("脏话", "*"); return message; }}publ 阅读全文
posted @ 2012-01-05 21:37 胖鹅 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 服务器端public class UDPServer { public static void main(String[]args) throws Exception{ byte[] buf = new byte[100]; DatagramPacket datagramPacket = new DatagramPacket(buf, buf.length); DatagramSocket datagramSocket = new DatagramSocket(9995); while(true){ datagramSocket.receive(datagramPa... 阅读全文
posted @ 2012-01-05 21:35 胖鹅 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 测试匹配整个字符串,然后找出符合字符串当中匹配子正则表达式的子字符串例如:匹配只有3到5个数字,只有两个public class Fenzu { public static void main(String[] args) { Pattern p = Pattern.compile("(\\d{3,5})([a-z]{2})"); String s = "123aa-3434bb-234ccc-00"; Matcher m = p.matcher(s); //分组查找是找出满足全部正则表达式的条件中之后再进行“局部”筛选 while(m.find()){ 阅读全文
posted @ 2012-01-05 21:34 胖鹅 阅读(431) 评论(0) 推荐(0) 编辑
摘要: User Location能做什么?1、获取用户的位置2、追踪用户的移动GPS定位比较准确,但是很费电GPS定位:使用GPS卫星定位,需要在AndroidManifest.xml中声明权限:NETWORK定位:使用信号接收塔和WIFI介入点进行定位,需要在AndroidManifest.xml文件中声明权限:1、Location Manager:用户管理android用户定位的服务2、Location Providers:提供了多种定位方式供开发者选择Criteria可以设置一系列的查询条件,可以根据指定的Criteria条件来过滤获得LocationProvider不同的LocationPr 阅读全文
posted @ 2012-01-05 21:32 胖鹅 阅读(289) 评论(0) 推荐(0) 编辑
摘要: public class MyRunner3 extends Thread { @Override public void run() { for(int i = 0; i < 5; i++){ System.out.println("i am " + getName()); try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }}public class TestThread3 {... 阅读全文
posted @ 2012-01-05 21:31 胖鹅 阅读(315) 评论(0) 推荐(0) 编辑
摘要: JDK1.5泛型在定义集合的时候同时定义集合中对象的类型增强程序的可读性和稳定性能把问题提前暴露在编译之前,让编译器发现,这样可以降低程序出错率//interface Map定义了存储key -- value 映射对,使用put方法添加数据//JDK1.5之后支持自动打包和解包public class HashMapDemo { public static void main(String[] args) { HashMap hashMap = new HashMap(); //自动将基础类型转换为对象,1实际上传递的还是Object hashMap.put("obj1", 阅读全文
posted @ 2012-01-05 21:30 胖鹅 阅读(150) 评论(0) 推荐(0) 编辑
摘要: synchronized只是保证在同一个时刻,其他线程不能访问锁定的资源,但是其他方法或者是变量不能锁定控制的解决死锁办法之一:1、将锁的粒度放粗一点(一口气锁住所有资源)//模拟“锁住”重要资源不能在一段时间类被多个线程使用public class TestThread implements Runnable{ TestSync testSync = new TestSync(); public static void main(String[] args) { TestThread thread = new TestThread(); Thread t1 = new Thread(th.. 阅读全文
posted @ 2012-01-05 21:28 胖鹅 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 元旦放假三天,天气很冷没有打算出去玩,就在家里琢磨着弄一下扒网站新闻,主要是同寝室的一个同事在弄,所以想学点东西,自己也动手写了一个,思路很简单,下面就描述一下是怎么实现的吧!首先进入主页网站中,然后选择自己想“扒”的信息模块,例如是新闻、经济、娱乐等等或者其他什么的,这样就能找到自己需要信息,然后把这个模块的url链接地址给读取出来,然后遍历读取到的URL地址,读取信息的内容。现在的网站一般都是动态生成的,也就是说新闻信息页面有自己的模板,那么所有的信息肯定是在某个DIV或者是容器中,只要找到这个控件的ID就能够得到里面的数据,然后把里面的数据找出来。下面的代码是我测试了某网站的信息,已经读 阅读全文
posted @ 2012-01-02 18:12 胖鹅 阅读(265) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 11 下一页