随笔分类 - java
摘要:For an interface, the value of the super_class item must always be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info structure representing the classObject.=========================If an interface has no direct superinterfaces, then the i
阅读全文
摘要:1.线程调度计算机通常只有一个CPU,在任意时刻只能执行一条机器指令,每个线程只有获得CPU的使用权才能执行指令。线程调度是指按照特定机制为多个线程分配CPU的使用权.分类:分时调度模型和抢占式调度模型分时调度模型是指让所有的线程轮流获得cpu的使用权,并且平均分配每个线程占用的CPU的时间片这个也比较好理解。java虚拟机采用抢占式调度模型,是指优先让可运行池中优先级高的线程占用CPU,如果可运行池中的线程优先级相同,那么就随机选择一个线程,使其占用CPU。处于运行状态的线程会一直运行,直至它不得不放弃CPU。线程的调度不是跨平台的,它 不仅仅取决于java虚拟机,还依赖于操作系统。在某些操
阅读全文
摘要:/** * 将十进制形式的Unicode编码转换为字符,例如 36215->北 (起) * @param codePoints * @return */public static String fromCharCode(int... codePoints) { StringBuilder builder = new StringBuilder(codePoints.length); for (int codePoint : codePoints){ builder.append(Character.toChars(codePoint)); } return buil
阅读全文
摘要:http://www.cnblogs.com/jimmyqwy/archive/2010/07/10/1774934.html http://blog.csdn.net/wcydiyi/archive/2009/08/12/4432636.aspx
阅读全文
摘要://获取系统当前时间String time = null;DateFormat dateFormat = new SimpleDateFormat();time = dateFormat.format(Calendar.getInstance().getTime());System.out.println(time);SimpleDateFormat函数语法:常见标准的写法"yyyy-MM-dd HH:mm:ss",注意大小写,时间是24小时制,24小时制转换成12小时制只需将HH改成hh,不需要另外的函数。DateFormat format1 = new SimpleDa
阅读全文
摘要:转自:http://takkymj.javaeye.com/blog/734408 1、class搜索路径的重要性 理解class搜索路径对所有Java开发人员来说都很重要,但是,IDE的广泛使用掩盖了这项技术,使大家普遍对它缺乏了解,甚至包括好多老鸟。这个问题在开发用于发布的应用程序(原文为distributed applications,但好像译为“分布式应用”有点晦涩)时尤其严重,因为应用程序运行时的系统环境可能和开发时的大不相同。 本文详细描述了某些Java类被其他代码引用时,Java编译器和JVM如何使用类搜索路径(class search path )定位这些类。这儿用...
阅读全文
摘要:1.关于异常java.lang.Throwable是所有异常的父类,其直接子类分为Error, Exception 。Error用来表示编译时和系统错误Exception可以分为RuntimeException(unchecked Excetption)和非运行时异常。除了RuntimeException,其他的异常都是checked exception )前者不需要coder手动的捕获或者抛出。例如NullPointerExcepion,你不需要每次使用一个对象时都要判断他是否为null。如果RuntimeException没有被捕获,那么程序会在到达main()函数,在程序退出前,自动调用
阅读全文
摘要:1.jdk(java development kit)是开发工具包,相当于是一个编译器.里面包含了各种类库和工具(如javac.exe、jar.exe等)。 所用到的类库都放在了/lib/tools.jar中。如果先将tools.jar改名为tools1.jar,然后运行javac.exe,显示如下结果: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac /Main。javac.exe只是一个包装器(Wrapper),其实包含很多动作,而javac.exe就是用jav
阅读全文
摘要:if you use the {...} array form in anything but an initializer. WRONGprivate int[] foo() { int[] x = new Array[3]; x = {1,2,3}; return x; } RIGHTprivate int[] foo() { int[] x = {1,2,3}; return x; } ps:When using the initializers, an array must be declared, constructed and explicitly init...
阅读全文
摘要:http://deerchao.net/tutorials/regex/regex.htm
阅读全文
摘要:1.一个线程就是一个对象,需要继承Thread类或者extends Runnable接口。其中public class Thread extends Object implements Runnable (两者的关系)创建新执行线程有两种方法。一种方法是将类声明为 Thread 的子类。该子类应重写 Thread 类的 run 方法class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; } public void run() { // com
阅读全文
摘要:1、synchronized关键字的作用域有二种: 1)是某个对象实例内,synchronized aMethod(){}可以防止多个线程同时访问这个对象的synchronized方法(如果一个对象有多个synchronized方法,只要一个线程访问了其中的一个synchronized方法,其它线程不能同时访问这个对象中任何一个synchronized方法)。这时,不同的对象实例的synchronized方法是不相干扰的。也就是说,其它线程照样可以同时访问相同类的另一个对象实例中的synchronized方法; 2)是某个类的范围,synchronized static aStaticMeth
阅读全文
摘要:import java.io.File; public class FileTest{ public static void main(String[] args){ scan("c:/file/ss"); } public static void scan(String path){ if(path ==null) return ; File file = new File(path); //生成一个新的虚拟文件路径 file.mkdirs...
阅读全文
摘要:Class aClass = Class.forName(xxx.xx.xx);Object anInstance = aClass.newInstance();Class.forName("").newInstance()返回的是objectbut there is some limit for this method to create instancethat is your class constructor should no contain parameters, and you should cast the instance manually.Class D
阅读全文
摘要:1.java中的参数传递方式只有按值传递(都是创建一个参数的副本)。对象参数的传递也是按值传递,只不过传递的是对象的引用(A a = new A() ; 其中a即为类A的一个引用),引用存放的是对象的地址,所以在被调函数中改变对象中的属性,返回调用函数中,对象的属性也会被改变2.java程序运行时的内存分配有三种策略,分别是静态的,栈式的,和堆式的. 其中栈主要存放一些基本的数据类型(int, short, long, byte, float, double, boolean, char)和对象的句柄(即对象的引用) 而栈中主要存放对象本身和数组等内容,以及‘字符串常量池’(很小的一块内存),
阅读全文
摘要:1、序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来。虽然你可以用你自己的各种各样的方法来保存object states,但是Java给你提供一种应该比你自己好的保存对象状态的机制,那就是序列化。 2、什么情况下需要序列化 a)当你想把的内存中的对象状态保存到一个文件中或者数据库中时候; b)当你想用套接字在网络上传送对象的时候; c)当你想通过RMI传输对象的时候; 3、当对一个对象实现序列化时,究竟发生了什么? 在没有序列化前,每个保存在堆(Heap)中的对象都有相应的状态(state),即实例变量(in...
阅读全文
摘要:import java.net.URLDecoder;import java.net.URLEncoder;class Noname1{ public static void main(String[] args) throws java.io.UnsupportedEncodingException {String aa = "%D2%A6%D0%A2%BB%D4"; //姚孝辉URLDecoder url = new URLDecoder();String bb =new URLDecoder().decode(aa,"GB2312");String
阅读全文
摘要:import java.util.*;class A{public static void main(String args[]){String[] a = new String[10000];for(int i=0;i<10000;i++){a[i]=""+i;} a[0]="nimabi";a[9999]="nimabi";Set b = new HashSet();long t1 = System.currentTimeMillis(); for(int i=0;i<10000;i++){ if(!b.add(a[i
阅读全文
浙公网安备 33010602011771号