Welcom to RO_wsy's blog

随笔分类 -  java基础

摘要:本文将告诉你学习Java需要达到的25个目标,希望能够对你的学习及找工作有所帮助。对比一下自己,你已经掌握了这25条中的多少条了呢? 1.你需要精通面向对象分析与设计(OOA/OOD)、设计模式(GOF,J2EEDP)以及综合模式。你应该了解UML,尤其是 class,object,interaction以及statediagrams。 2.你需要学习Java语言的基础知识以及它的核心类库 (collections,serialization,streams,networking,?multithreading,reflection,event,handling,NIO,localizatio 阅读全文
posted @ 2012-12-21 12:01 RO_wsy 阅读(190) 评论(0) 推荐(0)
摘要:本文权当参考,不喜勿踩Summary of regular-expression constructs ConstructMatchesCharactersxThe character x\\The backslash character\0nThe character with octal value 0n (0<=n<=7)\0nnThe character with octal value 0nn (0<=n<=7)\0mnnThe character with octal value 0mnn (0<=m<=3, 0<=n<=7)\xhh 阅读全文
posted @ 2012-12-21 09:38 RO_wsy 阅读(262) 评论(0) 推荐(0)
摘要:volatile,本意是不稳定的,易挥发的,也就是说,用它修饰的变量时可变的,那么这个关键字有什么用呢?在多线程环境下,线程可以将线程间共享的变量保存在本地内存(如寄存器)中,而不是从内存中读取,这就可能会引发不一致的问题,另一个进程可能在此线程运行期间改变了变量的值,而此线程并没有看到变化。而volatile修饰的成员变量在每次被线程访问时,都强迫从共享内存中重读该成员变量的值。而且,当成员变量发生变化时,强迫线程将变化值回写到共享内存。这样在任何时刻,两个不同的线程总是看到某个成员变量的同一个值。Java语言规范中指出:为了获得最佳速度,允许线程保存共享成员变量的私有拷贝,而且只当线程进入 阅读全文
posted @ 2012-11-30 23:15 RO_wsy 阅读(581) 评论(0) 推荐(0)
摘要:import java.sql.*;import javax.sql.*;public final class JdbcUtil { /** * @param args */ private static String url = "jdbc:mysql://localhost:3306/jdbc"; // jdbc:mysql:///jdbc 本地默认端口可以省略 private static String user = "root"; private static String password = "123456"; priva 阅读全文
posted @ 2012-11-24 10:37 RO_wsy 阅读(179) 评论(0) 推荐(0)
摘要:客户端代码如下:import java.net.*;import java.io.*;public class ObjectClient { public static void main(String[] args) { try { Socket s = new Socket("127.0.0.1", 8001); // 实际编程不要写死 InputStream is = s.getInputStream(); ObjectInputStream ois = new ObjectInputStream(is); Student stu = (Student)oi... 阅读全文
posted @ 2012-11-23 10:18 RO_wsy 阅读(241) 评论(0) 推荐(0)
摘要:tcp服务器代码如下:import java.net.*;public class ReserveServer { public static void main(String[] args) { // 用户可自行指定端口号 try { ServerSocket ss; if (args.length < 1) { ss = new ServerSocket(8888); } else { ss = new ServerSocket(Integer.parseInt(args[0])); } while (true) { Socket s =... 阅读全文
posted @ 2012-11-23 09:35 RO_wsy 阅读(341) 评论(0) 推荐(0)
摘要:发送者类如下:import java.net.*;public class UdpSender { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { DatagramSocket ds = new DatagramSocket(); String info = "hello snooker 中国"; ds.send(new DatagramPacket(info.getBytes(), info.getBytes(... 阅读全文
posted @ 2012-11-22 15:48 RO_wsy 阅读(197) 评论(0) 推荐(0)
摘要:import java.io.*;public class Serialization { public static void main(String [] args) { Student stu1 = new Student(1, "Ronnie", 37, "snooker"); Student stu2 = new Student(2, "John", 37, "snooker"); try { ObjectOutputStream os = new ObjectOutputStream(new FileO 阅读全文
posted @ 2012-11-21 21:47 RO_wsy 阅读(339) 评论(0) 推荐(0)
摘要:import java.io.*;public class DataStreamTest { public static void main(String [] args) { try { FileOutputStream fos = new FileOutputStream("count.txt"); BufferedOutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos); dos.writeUTF("ab中国" 阅读全文
posted @ 2012-11-21 21:26 RO_wsy 阅读(163) 评论(0) 推荐(0)
摘要:72、EJB的角色和三个对象 一个完整的基于EJB的分布式计算结构由六个角色组成,这六个角色可以由不同的开发商提供,每个角色所作的工作必须遵循Sun公司提供的EJB规范,以保证彼此之间的兼容性。这六个角色分别是EJB组件开发者(Enterprise Bean Provider) 、应用组合者(Application Assembler)、部署者(Deployer)、EJB 服务器提供者(EJB Server Provider)、EJB 容器提供者(EJB Container Provider)、系统管理员(System Administrator)三个对象是Remote(Local)接口、Ho 阅读全文
posted @ 2012-11-21 14:37 RO_wsy 阅读(213) 评论(0) 推荐(0)
摘要:ByteArrayInputStream和ByteArrayOutputStream,用于以IO流的方式来完成对字节数组内容的读写,来支持类似内存虚拟文件或者内存映射文件的功能实例:import java.io.*;public class ByteArrayStreamTest { public static void main(String [] args) { String str = "abcdef"; ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes()); ByteArrayOutpu 阅读全文
posted @ 2012-11-21 14:33 RO_wsy 阅读(296) 评论(0) 推荐(0)
摘要:PipedOutputStream和PipedInputStream用于在应用程序中创建管道通信实例:import java.io.*;public class PipedStreamTest { public static void main(String [] args) { Sender sender = new Sender(); Receiver receiver = new Receiver(); PipedOutputStream outStream = sender.getOutStream(); PipedInputStream inStream = receiv... 阅读全文
posted @ 2012-11-21 13:01 RO_wsy 阅读(339) 评论(0) 推荐(0)
摘要:Reader和Writer是所有字符流类的抽象基类,用于简化对字符串的输入输出编程,即用于读写文本数据实例:import java.io.*;public class FileReaderWriterTest { public static void main(String [] args) { try { FileWriter writer = new FileWriter("hello.txt"); writer.write("love_snooker"); writer.close(); FileReader reader = new FileRe 阅读全文
posted @ 2012-11-21 12:41 RO_wsy 阅读(582) 评论(0) 推荐(0)
摘要:I/O类包括节点流类和包装流类FileOutputStream和FileInputStream创建磁盘文件的输入输出流对象创建FileInputStream实例对象时,指定的文件应当是存在和可读的,创建FileOutputStream实例对象时,如果指定的文件已经存在,这个文件中的原来内容将被清除创建FileOutputStream实例对象时,可以指定还不存在的文件名,不能指定一个已被其他程序打开的文件实例:import java.io.*;public class FileStreamTest { public static void main(String [] args) { try . 阅读全文
posted @ 2012-11-21 12:28 RO_wsy 阅读(321) 评论(0) 推荐(0)
摘要:RandomAccessFile类 只能访问文件,不能操作其他io设备 支持随机访问 在读写等长记录文件有优势实例:import java.io.*;class Employee { private String name; private int age; public static final int LEN = 8; String getName() { return name; } int getAge() { return age; } Employee(String name, int age) { if (name.length() > LEN) { // 为了构造等... 阅读全文
posted @ 2012-11-20 21:50 RO_wsy 阅读(203) 评论(0) 推荐(0)