- 博客(67)
- 资源 (2)
- 问答 (1)
- 收藏
- 关注
原创 [网络编程]——TCP_Socket通信_聊天室_客户端多线程.初步形成
/** * 创建服务器,加入多线程 * 写出数据:输出流 * 读取数据:输入流 * @author Administrator * *//** * 创建服务器 * 写出数据:输出流 * 读取数据:输入流 * @author Administrator *//数据的发送 线程public class send implements Runnable{ private Bu
2016-04-19 00:44:37 1181
原创 [网络编程]——TCP_Socket通信_聊天室_客户端多线程
工具类:public class CloseUtil { public static void closeAll(Closeable...io){ for(Closeable temp:io){ if (temp!=null) { try { temp.close(); } catch (IOException e) { // TODO Auto-g
2016-04-17 00:04:50 1119
原创 [网络编程]——网络编程_TCP_Socket通信_聊天室.雏形
聊天室雏形:/** * 创建客户端:发送数据+接收数据 * 写出数据:输出流 * 读取数据:输入流 * 输入流和输出流在同一个线程楼内,应该彼此独立 * @author Administrator * */public class Client { public static void main(String[] args) throws UnknownHostExcept
2016-04-16 20:34:37 431
原创 [网络编程]——网络编程_TCP_Socket通信
建立服务器与客户端的连接/** * 创建服务器 * @author Administrator * */public class server { public static void main(String[] args) throws IOException { ServerSocket sever=new ServerSocket(7897); Socket socket
2016-04-16 20:19:19 335
原创 [网络编程]——UDP
/** * 客户端 * 1、创建客户端+端口 * 2、准备数据 * 3、数据打包(发送的地点及端口) * 4、发送 * 5、释放 * 非面向连接 服务器没有打开,发送数据 可能会造成数据丢失 * @author Administrator * */public class MyClient { public static void main(String[] args)
2016-04-14 00:40:36 330
原创 [网络编程]——URL
public class URL01 { /** * @param args * @throws MalformedURLException */ public static void main(String[] args) throws MalformedURLException { //绝对路径构建 URL url = new URL("http://www.baid
2016-04-14 00:18:11 500
原创 [网络编程]——InetAddress_InetSocketAddress
public class Inet01 { /** * 没有封装端口 * @author Administrator * */ /** * @param args * @throws UnknownHostException * @throws MalformedURLException */ public static void main(String[
2016-04-14 00:07:00 592
原创 [线程]——任务调度
/** * 了解 * Timer() * schedule(TimerTask task, Date time) schedule(TimerTask task, Date firstTime, long period) 自学quartz * @author Administrator * */public class Timer01 { public static
2016-04-12 22:36:26 313
原创 [设计模式]——生产者消费者模式_信号灯法
/** * 一个场景,共同的资源 * 生产者消费者模式信号灯法 * wait()等待,释放锁 sleep 不释放锁 * notify()/notifyAll():唤醒 * 与synchronized一起使用 * @author Administrator * */public class product_customer { private String pic; //信号
2016-04-12 20:22:19 612
原创 [线程]——死锁
//过多的同步方法可能造成死锁public class SynDemo03 { public static void main(String[] args) { Object g=new Object(); Object m=new Object(); Test t1=new Test(g, m); Test2 t2=new Test2(g, m); Thread prox
2016-04-11 23:57:07 342
原创 [线程]——线程同步与锁定2_synchronized
/** * 单例设计模式:确保一个类只有一个对象 * @author Administrator * */public class SynDemo02 { public static void main(String[] args) { JvmThread thread1=new JvmThread(200); JvmThread thread2=new JvmThread(6
2016-04-11 23:32:56 300
原创 [设计模式]——单例模式_doubleChecking
/** * 单例创建的方式 * 1、懒汉式 * 1)构造器私有化 * 2)声明私有的静态属性 * 3)对外提供访问属性的静态方法,确保该对象存在 * * @author Administrator * */public class MyJvm2 { private static MyJvm2 instance; private MyJvm2(){ } publi
2016-04-11 23:29:31 432
原创 [线程]——线程同步与锁定1_synchronized
public class SynDemo01 { public static void main(String[] args) { //真实角色 WebTicket web=new WebTicket(); //代理 Thread Tom=new Thread(web, "张三"); Thread Jess=new Thread(web, "李四"); Thread Ch
2016-04-11 19:35:21 296
原创 [线程]——线程基本信息.优先级
public class MyThread implements Runnable{ private boolean flag=true; private int num=0; @Override public void run() { while(flag){ System.out.println(Thread.currentThread().getName()+"-->"+n
2016-04-10 20:55:31 353
原创 [线程]——线程阻塞
/** * join:合并线程 * @author Administrator * */public class Joining extends Thread{ public static void main(String[] args) throws InterruptedException { Joining demo=new Joining(); Thread t=new
2016-04-10 18:23:27 346
原创 [线程]——停止线程
public class demo01 { public static void main(String[] args) { Study s=new Study(); new Thread(s).start(); //外部干涉 for (int i = 0; i < 1000; i++) { if (i==50) {//外部干涉 s.stop(); }
2016-04-10 16:46:46 370
原创 [线程]——三种方式.创建线程
第一种:/** * 1\模拟龟兔赛跑 继承Thread+重写RUN(线程体) * 2\使用线程:创建子类对象+对象.strat() 线程启动 * @author Administrator * */public class Rabbits extends Thread{ @Override public void run() { //线程体 for(int i=0;i<2
2016-04-10 16:02:08 495
原创 [设计模式]——静态代理
/** * 静态代理 设计模式 * 1、真实角色 * 2、代理角色: 持有真实角色的引用 * 3、二者 实现相同的接口 * * @author Administrator * */public class StaticProxy { /** * @param args */ public static void main(String[] args) { //创
2016-04-10 09:50:50 365
原创 [IO]——文件的分割与合并
public class SplitFile { //文件的路径 private String filePath; //文件名 private String fileName; //文件大小 private long length; //块数 private int size; //每块的大小 private long blockSize; //分割后的存放目录 priva
2016-04-09 22:46:24 363
原创 [IO]——装饰设计模式
public class Voice { private int voice=10; public Voice() { // TODO Auto-generated constructor stub } public Voice(int voice) { super(); this.voice = voice; } public int getVoice() { ret
2016-04-09 18:16:44 407
原创 [IO]——封装输入
/** * 封装输入 * @author Administrator * */public class BufferedIn { public static void main(String[] args) throws IOException { InputStream is=System.in; BufferedReader br=new BufferedReader(
2016-04-09 14:47:43 351
原创 [IO]——重定向
/** * 三个常量 * system.in 输入流 键盘输入 * system.out输出流 控制台输出 * system.err * ---》重定向 * setin(),setout(),seterr() * filedescriptor.in filedescriptor.out * @author Administrator * */public class sy
2016-04-09 14:44:53 286
原创 [IO]——打印流
/** * PrintStream打印流-->处理流 * @author Administrator * */public class PrintStreamDemo01 { public static void main(String[] args) throws FileNotFoundException { PrintStream ps=System.out; ps.pr
2016-04-09 13:56:09 266
原创 [IO]——关闭流方法
public class FileUtil { /** * 工具类关闭流 * 可变参数:...只能形参最后一个位置 处理方式与数组一致 */ public static void close(Closeable ... io){ for(Closeable temp:io){ try { if (null!=temp) { temp.close();
2016-04-09 13:31:37 915
原创 [IO]——对象处理流.序列化
/** * 不是所有的对象都可以序列化 * 不是所有的属性都需要序列化 transient * @author Administrator * */public class ObjectDemo01 { public static void main(String[] args) throws IOException, ClassNotFoundException { ser
2016-04-09 12:25:59 408
原创 [IO]——处理流.字节数组
/** * 数据类型处理流(基本+string)处理流 * 1、输入流DataInputStream readerXxx * 2、输出流DataOutPutStream writeXxx * 新增方法不能使用多态 * java.io.EOFException:没有读取到相关的内容 * @author Administrator * */public class demo4
2016-04-09 01:33:53 356
原创 [IO]——处理流
/** * 数据类型处理流(基本+string)处理流 * 1、输入流DataInputStream readerXxx * 2、输出流DataOutPutStream writeXxx * 新增方法不能使用多态 * java.io.EOFException:没有读取到相关的内容 * @author Administrator * */public class demo3
2016-04-09 01:18:59 274
原创 [IO]——节点流.组合
/** * 1、文件--程序-》字节数组 * 1)文件输入流 * 字节数组输出流 * 2、字节数组--程序-》文件 * 1)字节数组输入流 * 文件输出流 * @author Administrator * */public class demo02 { public static void main(String[] args) throws IO
2016-04-09 00:43:37 330
原创 [IO]——节点流
/** * 字节数组,节点流 * 数组的长度有限,数据量不会很大 * 文件内容不用太大 * 1、文件内容--程序-》字节数组 * 2、字节数组-程序-》文件 * @author Administrator * */public class demo01 { public static void main(String[] args) throws IOException {
2016-04-08 20:26:14 359
原创 [IO]——指定字符集
public class Conver { public static void main(String[] args) { String str="中国"; byte[] date=str.getBytes(); //字节数不完整 System.out.println(new String(date,0,3)); } /** * 编码和解码字符集必须相同,否则乱码
2016-04-07 23:39:17 366
原创 [IO]——编码和解码
public class Conver { public static void main(String[] args) { String str="中国"; byte[] date=str.getBytes(); //字节数不完整 System.out.println(new String(date,0,3)); } /** * 编码和解码字符集必须相同,否则乱码
2016-04-07 23:38:16 300
原创 [IO]——缓冲流
/** * 字符缓冲流+新增方法(不发生多态) * @author Administrator * */public class buffered { public static void main(String[] args) { //创建源仅限于字符的纯文本 File src=new File("E:/others/goodOrBad11.txt"); File des
2016-04-07 20:24:55 290
原创 [IO]——纯文本复制
public class demo03 { public static void main(String[] args) { //创建源仅限于字符的纯文本 File src=new File("E:/others/goodOrBad11.txt"); File dest=new File("E:/others/goodOrBad22.txt"); //选择流 Reader r
2016-04-07 19:49:31 258
原创 [IO]——纯文本写出
/** * 写出文件 * @author Administrator * */public class demo2 { public static void main(String[] args) { //创建源 File dest=new File("E:/others/goodOrBad11.txt"); Writer wr=null; try { wr=ne
2016-04-07 19:48:48 280
原创 [IO]——纯文本读取
/** * 纯文本读取 * @author Administrator * */public class demo01 { public static void main(String[] args) { //创建源 File src=new File("E:/others/good.txt"); //选择流 Reader reader=null; try {
2016-04-07 19:47:37 261
原创 [IO]——文件夹的拷贝
/** * 文件夹的拷贝 * 1、文件 复制 copyFile() * 2、文件夹 创建 mkdirs() * 3、递归查找子孙级 * @author Administrator * */public class CopyDir { public static void main(String[] args) { //原目录 String srcPath="E:/othe
2016-04-06 23:48:04 285
原创 [IO]——FileUtil
public class FileUtil {//文件的拷贝 public static void copyFile(String srcPath,String destPath) throws IOException ,FileNotFoundException{ //1、建立联系 源 File src=new File(srcPath);//确保源存在,且为文件 File des
2016-04-06 23:39:08 620
原创 [IO]——文件复制
/** * * 1、建立联系,File对象,源头,目的地 * 2、选择流,文件输入流,InputStream FileInputStream * 文件输出流,OutputStream FileOutputStream * 3、操作,拷贝 * byte[] flush=new byte[1024] * int len=0; * while(-1!=(le
2016-04-06 23:24:31 232
原创 [IO]——文件写入
/** * 1、建立联系,File对象,目的地 * 2、选择流,文件输出流,OutputStream FileOutputStream * 3、操作,write()+flush * 4、释放资源:关闭 * @author Administrator * */public class Demo02 { public static void main(String[] args) {
2016-04-06 22:37:18 274
原创 [IO]——文件的读取
//文件的读取/** * 1、建立联系,File对象 * 2、选择流,文件输入流,InputStream FileInputStream * 3、操作,byte[]car=new byte[1024]+read+读取大小 * 4、释放资源:关闭 * @author Administrator * */public class Demo01 { public static voi
2016-04-06 22:26:53 253
HashSet疑问,请前辈们指教
2016-03-24
TA创建的收藏夹 TA关注的收藏夹
TA关注的人