易截截图软件、单文件、免安装、纯绿色、仅160KB

获取普通Java对象大小

缓存对象需要知道对象占用空间的大小,可以事先设置好每种类型的大小,此方法对普通的对象起效,Jive论坛中的对象也是采用这种办法来获取对象的大小的(取自Jive).
public class CacheSizes {
/**
* Returns the size in bytes of a basic Object. This method should only
* be used for actual Object objects and not classes that extend Object.
*
* @return the size of an Object.
*/
public static int sizeOfObject() {
return 4;
}
/**
* Returns the size in bytes of a String.
*
* @param string the String to determine the size of.
* @return the size of a String.
*/
public static int sizeOfString(String string) {
if (string == null) {
return 0;
}
return 4 + string.length()*2;
}
/**
* Returns the size in bytes of a primitive int.
*
* @return the size of a primitive int.
*/
public static int sizeOfInt() {
return 4;
}
/**
* Returns the size in bytes of a primitive char.
*
* @return the size of a primitive char.
*/
public static int sizeOfChar() {
return 2;
}
/**
* Returns the size in bytes of a primitive boolean.
*
* @return the size of a primitive boolean.
*/
public static int sizeOfBoolean() {
return 1;
}
/**
* Returns the size in bytes of a primitive long.
*
* @return the size of a primitive long.
*/
public static int sizeOfLong() {
return 8;
}
/**
* Returns the size in bytes of a primitive double.
*
* @return the size of a primitive double.
*/
public static int sizeOfDouble() {
return 8;
}
/**
* Returns the size in bytes of a Date.
*
* @return the size of a Date.
*/
public static int sizeOfDate() {
return 12;
}
/**
* Returns the size in bytes of a Properties object


相关文档:

理解JAVA中的接口和抽象类

  抽象类往往用来表征我们在对问题领域进行分析、 设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的具体概念的抽象,我们不能把它们实例化(拿不出一个具体的东西)所以称之为抽象。比如:我们要描述“水果”,它就是一个抽象,它有质量、体积等一些共性(水果有质量),但又缺乏特性(苹果、 ......

Java XMLParser chunck 问题参考

Is there a Push-based/Non-blocking XML Parser for Java?
http://stackoverflow.com/questions/1023759/is-there-a-push-based-non-blocking-xml-parser-for-java
http://old.nabble.com/parsing-an-xml-document-chunk-by-chunk-td22945319.html
http://markmail.org/message/ogqqcj7dt3lwkbov ......

认识理解Java中native方法

Java不是完美的,Java的不足除了体现在运行速度上要比传统的C++慢许多之外,Java无法直接访问到操作系统底层(如系统硬件等),为此Java使用native方法来扩展Java程序的功能。
  可以将native方法比作Java程序同C程序的接口,其实现步骤:
  1、在Java中声明native()方法,然后编译;
  2、用javah产生一个.h ......

Java 正则表达式 对于 乘号"*" 的处理

 String fm = "46+5*(120-37)";
  String[] item = fm.split("[+-/*/()]");
  for(String it: item){
   System.out.print(it+"  ");
  }
正则表达式中 转义:  *  ==>   /* ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号