
【JAVA_基础】
年轻正好
这个作者很懒,什么都没留下…
展开
-
[网络编程]——TCP_Socket通信_聊天室_客户端多线程.初步形成
/** * 创建服务器,加入多线程 * 写出数据:输出流 * 读取数据:输入流 * @author Administrator * *//** * 创建服务器 * 写出数据:输出流 * 读取数据:输入流 * @author Administrator *//数据的发送 线程public class send implements Runnable{ private Bu原创 2016-04-19 00:44:37 · 1237 阅读 · 0 评论 -
[网络编程]——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 · 1193 阅读 · 0 评论 -
[网络编程]——网络编程_TCP_Socket通信_聊天室.雏形
聊天室雏形:/** * 创建客户端:发送数据+接收数据 * 写出数据:输出流 * 读取数据:输入流 * 输入流和输出流在同一个线程楼内,应该彼此独立 * @author Administrator * */public class Client { public static void main(String[] args) throws UnknownHostExcept原创 2016-04-16 20:34:37 · 483 阅读 · 0 评论 -
[网络编程]——网络编程_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 · 444 阅读 · 0 评论 -
[网络编程]——UDP
/** * 客户端 * 1、创建客户端+端口 * 2、准备数据 * 3、数据打包(发送的地点及端口) * 4、发送 * 5、释放 * 非面向连接 服务器没有打开,发送数据 可能会造成数据丢失 * @author Administrator * */public class MyClient { public static void main(String[] args)原创 2016-04-14 00:40:36 · 372 阅读 · 0 评论 -
[网络编程]——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 · 584 阅读 · 0 评论 -
[网络编程]——InetAddress_InetSocketAddress
public class Inet01 { /** * 没有封装端口 * @author Administrator * */ /** * @param args * @throws UnknownHostException * @throws MalformedURLException */ public static void main(String[原创 2016-04-14 00:07:00 · 666 阅读 · 0 评论 -
[线程]——任务调度
/** * 了解 * 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 · 360 阅读 · 0 评论 -
[设计模式]——生产者消费者模式_信号灯法
/** * 一个场景,共同的资源 * 生产者消费者模式信号灯法 * wait()等待,释放锁 sleep 不释放锁 * notify()/notifyAll():唤醒 * 与synchronized一起使用 * @author Administrator * */public class product_customer { private String pic; //信号原创 2016-04-12 20:22:19 · 682 阅读 · 0 评论 -
[线程]——死锁
//过多的同步方法可能造成死锁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 · 430 阅读 · 0 评论 -
[线程]——线程同步与锁定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 · 341 阅读 · 0 评论 -
[设计模式]——单例模式_doubleChecking
/** * 单例创建的方式 * 1、懒汉式 * 1)构造器私有化 * 2)声明私有的静态属性 * 3)对外提供访问属性的静态方法,确保该对象存在 * * @author Administrator * */public class MyJvm2 { private static MyJvm2 instance; private MyJvm2(){ } publi原创 2016-04-11 23:29:31 · 484 阅读 · 0 评论 -
[线程]——线程同步与锁定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 · 344 阅读 · 0 评论 -
[线程]——线程基本信息.优先级
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 · 396 阅读 · 0 评论 -
[线程]——线程阻塞
/** * 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 · 416 阅读 · 0 评论 -
[线程]——停止线程
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 · 480 阅读 · 0 评论 -
[线程]——三种方式.创建线程
第一种:/** * 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 · 542 阅读 · 0 评论 -
[设计模式]——静态代理
/** * 静态代理 设计模式 * 1、真实角色 * 2、代理角色: 持有真实角色的引用 * 3、二者 实现相同的接口 * * @author Administrator * */public class StaticProxy { /** * @param args */ public static void main(String[] args) { //创原创 2016-04-10 09:50:50 · 410 阅读 · 0 评论 -
[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 · 434 阅读 · 0 评论 -
[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 · 453 阅读 · 0 评论 -
[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 · 397 阅读 · 0 评论 -
[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 · 349 阅读 · 0 评论 -
[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 · 341 阅读 · 0 评论 -
[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 · 1005 阅读 · 0 评论 -
[IO]——对象处理流.序列化
/** * 不是所有的对象都可以序列化 * 不是所有的属性都需要序列化 transient * @author Administrator * */public class ObjectDemo01 { public static void main(String[] args) throws IOException, ClassNotFoundException { ser原创 2016-04-09 12:25:59 · 480 阅读 · 0 评论 -
[IO]——处理流.字节数组
/** * 数据类型处理流(基本+string)处理流 * 1、输入流DataInputStream readerXxx * 2、输出流DataOutPutStream writeXxx * 新增方法不能使用多态 * java.io.EOFException:没有读取到相关的内容 * @author Administrator * */public class demo4原创 2016-04-09 01:33:53 · 424 阅读 · 0 评论 -
[IO]——处理流
/** * 数据类型处理流(基本+string)处理流 * 1、输入流DataInputStream readerXxx * 2、输出流DataOutPutStream writeXxx * 新增方法不能使用多态 * java.io.EOFException:没有读取到相关的内容 * @author Administrator * */public class demo3原创 2016-04-09 01:18:59 · 321 阅读 · 0 评论 -
[IO]——节点流.组合
/** * 1、文件--程序-》字节数组 * 1)文件输入流 * 字节数组输出流 * 2、字节数组--程序-》文件 * 1)字节数组输入流 * 文件输出流 * @author Administrator * */public class demo02 { public static void main(String[] args) throws IO原创 2016-04-09 00:43:37 · 386 阅读 · 0 评论 -
[IO]——节点流
/** * 字节数组,节点流 * 数组的长度有限,数据量不会很大 * 文件内容不用太大 * 1、文件内容--程序-》字节数组 * 2、字节数组-程序-》文件 * @author Administrator * */public class demo01 { public static void main(String[] args) throws IOException {原创 2016-04-08 20:26:14 · 434 阅读 · 0 评论 -
[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 · 408 阅读 · 0 评论 -
[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 · 347 阅读 · 0 评论 -
[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 · 358 阅读 · 0 评论 -
[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 · 321 阅读 · 0 评论 -
[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 · 354 阅读 · 0 评论 -
[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 · 300 阅读 · 0 评论 -
[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 · 336 阅读 · 0 评论 -
[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 · 738 阅读 · 0 评论 -
[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 · 305 阅读 · 0 评论 -
[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 · 334 阅读 · 0 评论 -
[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 · 287 阅读 · 0 评论