??xml version="1.0" encoding="utf-8" standalone="yes"?>天天av综合,97se亚洲,国产精品伦理久久久久久http://blogjava.net/stevenjohn/category/51240.html那些青春的岁?/description>zh-cnThu, 21 May 2015 19:00:30 GMTThu, 21 May 2015 19:00:30 GMT60Java for foreachhttp://www.aygfsteel.com/stevenjohn/archive/2015/05/21/425223.htmlabinabinThu, 21 May 2015 15:59:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2015/05/21/425223.htmlhttp://www.aygfsteel.com/stevenjohn/comments/425223.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2015/05/21/425223.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/425223.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/425223.htmljava 有for(;;)?for(Object obj : List/Array)

最明显的一个:前者是有范_后者是全部?br />

q码来说各有好处:for更灵z,foreach更简?br />

for和foreach都是java中重要的集合遍历Ҏ 
for循环?你可以选择从前往后遍历,也可以从后往前遍历,也可以不遍历默写?
但是foreach只能从前往后遍历,而且每一个都会遍历一ơ,他们之间的选择得看你项目程序中的需求而定
JVM在解释执行行Q都会将for与foreach解释成iterator?/pre>

ȝ如下Q?/p>

1.如果只是遍历集合或者数l,用foreach好些Q快些?/p>

2.如果寚w合中的D行修改,p用for循环了?br />其实foreach的内部原理其实也是Iterator,但它不能像Iterator一样可以h为的控制Q而且也不能调用iterator.remove()Q?br />更不能用下标来讉K每个元素Q所以不能用于增加,删除{复杂的操作?/p>





abin 2015-05-21 23:59 发表评论
]]>
JDK动态代理和CGLib动态代?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2015/04/22/424585.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Tue, 21 Apr 2015 16:22:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2015/04/22/424585.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/424585.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2015/04/22/424585.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/424585.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/424585.html</trackback:ping><description><![CDATA[<div>静态代?/div><div>静态代理相Ҏ说比较简单,无非是聚合+多态:</div><div></div><div>参考:设计模式W记 – Proxy 代理模式 (Design Pattern)</div><div></div><div>动态代?/div><div>我们知道Q通过使用代理Q可以在被代理的cȝҎ的前后添加一些处理方法,q样pCcMAOP的效果。而JDK中提供的动态代理,是实现AOP的绝好底层技术?/div><div></div><div>JDK动态代?/div><div>JDK动态代理主要涉及到java.lang.reflect包中的两个类QProxy和InvocationHandler。InvocationHandler是一个接口,通过实现该接口定义横切逻辑Qƈ通过反射机制调用目标cȝ代码Q动态将横切逻辑和业务逻辑~制在一赗?/div><div></div><div>Proxy利用InvocationHandler动态创Z个符合某一接口的实例,生成目标cȝ代理对象?/div><div></div><div>例子QJavaW记 – 反射 动态代?/div><div></div><div>CGLib动态代?/div><div>q有一个叫CGLib的动态代理,CGLib全称为Code Generation LibraryQ是一个强大的高性能Q高质量的代码生成类库,可以在运行期扩展JavacM实现Java接口QCGLib装了asmQ可以再q行期动态生成新的class。和JDK动态代理相比较QJDK创徏代理有一个限Ӟ是只能为接口创Z理实例,而对于没有通过接口定义业务Ҏ的类Q则可以通过CGLib创徏动态代理?/div><div><br /><p>CGLib采用非常底层的字节码技术,可以Z个类创徏子类Qƈ在子cM采用Ҏ拦截的技术拦截所有父cL法的调用Qƈ势l入横切逻辑?/p> <div class="wmqeeuq" id="JDK动态代理和CGLib的比?>JDK动态代理和CGLib的比?/div> <p>CGLib所创徏的动态代理对象的性能比JDK所创徏的代理对象性能高不,大概10倍,但CGLib在创Z理对象时所p的时间却比JDK动态代理多大概8倍,所以对于singleton的代理对象或者具有实例池的代理,因ؓ无需频繁的创建新的实例,所以比较适合CGLib动态代理技术,反之则适用于JDK动态代理技术。另外,׃CGLib采用动态创建子cȝ方式生成代理对象Q所以不能对目标cM的finalQprivate{方法进行处理。所以,大家需要根据实际的情况选择使用什么样的代理了?/p> <p>同样的,Spring的AOP~程中相关的ProxyFactory代理工厂内部是使用JDK动态代理或CGLib动态代理的Q通过动态代理,增强(advice)应用到目标类中?/p><br /><div>JDK动态代理主要用到java.lang.reflect包中的两个类QProxy和InvocationHandler.</div> <div> </div> <div>InvocationHandler是一个接口,通过实现该接口定义横切逻辑Qƈ通过反射机制调用目标cȝ代码Q动态的横切逻辑和业务逻辑~织在一赗?/div> <div> </div> <div>Proxy利用InvocationHandler动态创Z个符合某一接口的实例,生成目标cȝ代理对象?/div><br /></div><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/424585.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2015-04-22 00:22 <a href="http://www.aygfsteel.com/stevenjohn/archive/2015/04/22/424585.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java 帔R?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2015/03/31/424000.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Tue, 31 Mar 2015 10:22:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2015/03/31/424000.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/424000.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2015/03/31/424000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/424000.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/424000.html</trackback:ping><description><![CDATA[<div> If you are not sure about the string pool usage, try -XX:+PrintStringTableStatistics JVM argument. It will print you the string pool usage when your program terminates.</div><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/424000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2015-03-31 18:22 <a href="http://www.aygfsteel.com/stevenjohn/archive/2015/03/31/424000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java中StaticҎ和StaticE序块的用法ȝhttp://www.aygfsteel.com/stevenjohn/archive/2015/03/25/423823.htmlabinabinWed, 25 Mar 2015 07:24:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2015/03/25/423823.htmlhttp://www.aygfsteel.com/stevenjohn/comments/423823.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2015/03/25/423823.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/423823.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/423823.htmlStatic 静态:q里主要记录的是静态程序块和静态方?/p>

如果有些代码必须在项目启动的时候就执行,需要用静态代码块,q种代码是主动执行的;需要在目启动的时候就初始化但是不执行,在不创徏对象的情况下,可以供其他程序调?而在调用的时候才执行Q这需要用静态方?q种代码是被动执行的. 静态方法在cd载的时?已l加?可以用类名直接调用?/p>

静态代码块和静态方法的区别是:

静态代码块是自动执行的;

静态方法是被调用的时候才执行?

静态方法:如果我们在程序编写的时候需要一个不实例化对象就可以调用的方法,我们可以用静态方法,具体实现是在Ҏ前面加上staticQ如下:

public static void method(){}

在用静态方法的时候需要注意一下几个方面:

在静态方法里只能直接调用同类中其他的静态成员(包括变量和方法)Q而不能直接访问类中的非静态成员。这是因为,对于非静态的Ҏ和变量,需要先创徏cȝ实例对象后才可用,而静态方法在使用前不用创ZQ何对象。(备注Q静态变量是属于整个cȝ变量而不是属于某个对象的Q?/p>

静态方法不能以M方式引用this和super关键字,因ؓ静态方法在使用前不用创ZQ何实例对象,当静态方法调用时Qthis所引用的对象根本没有生?/p>

静态程序块Q当一个类需要在被蝲入时执行一D늨序,q样可以使用静态程序块?/p>

public class DemoClass {

private DemoClass(){}

public static DemoClass _instance;

static{

if(null == _instance ){

_instance = new DemoClass();

}

}

public static DemoClass getInstance(){

return _instance;

}

}

q样的程序在c被加蝲的时候就执行了static中的代码?/p>

Ps:java中类的装载步骤:

在Java中,c装载器把一个类装入Java虚拟ZQ要l过三个步骤来完成:装蝲、链接和初始化,其中链接又可以分成校验、准备和解析三步Q除了解析外Q其它步骤是严格按照序完成的,各个步骤的主要工作如下:

所谓装载就是寻找一个类或是一个接口的二进制Ş式ƈ用该二进制Ş式来构造代表这个类或是q个接口的class对象的过E。其中类或接口的名称是给定了的?/p>

装蝲Q查扑֒导入cL接口的二q制数据Q?/p>

链接Q执行下面的校验、准备和解析步骤Q其中解析步骤是可以选择的;

校验Q检查导入类或接口的二进制数据的正确性;

准备Q给cȝ静态变量分配ƈ初始化存储空_

解析Q将W号引用转成直接引用Q?/p>

初始化:Ȁzȝ的静态变量的初始化Java代码和静态Java代码?/p>

abin 2015-03-25 15:24 发表评论
]]>
JAVA内存占用http://www.aygfsteel.com/stevenjohn/archive/2014/08/01/416458.htmlabinabinFri, 01 Aug 2014 08:54:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2014/08/01/416458.htmlhttp://www.aygfsteel.com/stevenjohn/comments/416458.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2014/08/01/416458.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/416458.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/416458.html阅读全文

abin 2014-08-01 16:54 发表评论
]]>
java位运?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405417.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Fri, 18 Oct 2013 14:43:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405417.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/405417.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405417.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/405417.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/405417.html</trackback:ping><description><![CDATA[<div><h1><a id="cb_post_title_url" style="margin: 0px; padding: 0px; color: #ff6600; text-decoration: initial;">java位运?br /><br /><div>http://www.cnblogs.com/highriver/archive/2011/08/15/2139600.html<br />单点dQ?br /><div>http://www.aygfsteel.com/rabbit/archive/2013/10/18/405392.html</div><br /></div></a></h1></div><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/405417.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2013-10-18 22:43 <a href="http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405417.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java 占用字节?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405416.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Fri, 18 Oct 2013 14:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405416.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/405416.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405416.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/405416.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/405416.html</trackback:ping><description><![CDATA[<span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #f1fedd; "><pre id="best-content-843701432" accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; "><span style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; font-size: 14px; line-height: 24px; background-color: #f1fedd; "></span></a><pre id="best-content-843701432" accuse="aContent" mb-10"="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; "></a><a decor-none"="" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; ">数据cd</a> 大小(二进制位? 范围 默认?<br /><br />byte(字节) 8 -128 - 127 0<br />shot(短整? 16 -32768 - 32768 0<br />int(整型) 32 -2147483648-2147483648 0<br />long(长整? 64 -9233372036854477808-9233372036854477808 0 <br />float(<a decor-none"="" target="_blank" rel="nofollow" data-word="1" style="color: #2d64b3; text-decoration: none; ">点?/a>) 32 -3.40292347E+38-3.40292347E+38 0.0f<br />double(双精? 64 -1.79769313486231570E+308-1.79769313486231570E+308 0.0d<br />char(字符? 16 ‘ \u0000 - u\ffff ’ ‘\u0000 ’<br /></pre></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 'courier new', courier, 宋体, monospace; line-height: 24px; white-space: pre-wrap; background-color: #f1fedd; "><a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; "><span style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; font-size: 14px; line-height: 24px; background-color: #f1fedd; "></span></a><pre id="best-content-843701432" accuse="aContent" mb-10"="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; display: inline !important; "><a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; ">boolean(</a><a decor-none"="" target="_blank" rel="nofollow" data-word="2" style="color: #2d64b3; text-decoration: none; ">布尔?/a>) 1 true/false false</pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #f1fedd; "><pre accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><br /><br /></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #ffffff; "><h1 class="mb-5" accuse="qTitle" style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 16px; font: normal normal bold 16px/26px 'Microsoft YaHei', SimHei, arial; word-break: break-all; "><span id="wmqeeuq" class="ask-title" style="display: inline-block; width: 595px; overflow-x: hidden; overflow-y: hidden; ">JAVA基本数据cd所占字节数是多?</span></h1></span><span id="wmqeeuq" class="Apple-style-span" style="color: #494949; font-family: simsun; background-color: #e2e2e2; "><div>byte  <wbr>  <wbr> 1字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>short  <wbr>  <wbr>2字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>int  <wbr>  <wbr>  <wbr>4字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>long  <wbr>  <wbr> 8字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>char  <wbr>  <wbr> 2字节QC语言中是1字节Q可以存储一个汉?/div><div>float  <wbr>  <wbr>4字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>double  <wbr> 8字节  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr>  <wbr> <wbr></div><div>boolean  <wbr>false/true(理论上占?bit,1/8字节Q实际处理按1byte处理)  <wbr>  <wbr>  <wbr> </div></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #f1fedd; "><pre accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><div><pre id="best-content-875525478" accuse="aContent" mb-10"="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; color: #333333; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f1fedd; ">JAVA是采用Unicode~码。每一个字节占8位。你电脑pȝ应该?32位系l,q样每个int是 4个字?br /></pre></div></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #ffffff; "><pre id="answer-content-252602844" accuse="aContent" class="answer-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; ">其中一个字节由8个二q制位组?br /><br /></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #ffffff; "><pre id="answer-content-487363632" accuse="aContent" class="answer-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; ">Java一共有8U基?a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; ">数据cd</a>Q原?a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; ">数据cd</a>Q: <br />cd 存储要求 范围Q包含) 默认?包装c?br />?int 4字节Q?2位) -231~ 231-1 0 Integer<br />?short 2字节Q?6位) -215~215-1 0 Short<br />c?long 8字节Q?4位) -263~263-1 0 Long<br />?byte 1字节Q?位) -27~27-1 0 Byte<br />点 float 4字节Q?2位) -3.4e+38 ~ 3.4e+38 0.0f Float<br />cd double 8字节Q?4位) -1.7e+308 ~ 1.7e+308 0 Double<br />字符 char 2字节Q?6位) u0000~uFFFFQ?#8216;’~‘Q?#8217;Q?‘0’ Character<br /> Q?~216-1Q?5535Q) <br />布尔 boolean 1/8字节Q?位) true, false FALSE Boolean</pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #ffffff; "><pre accuse="aContent" class="answer-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><br /><br /><br /></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff; "><span style="color: #333333; font-family: Arial; line-height: 26px; font-size: 18px; ">在移动开发中׃Ud讑֤内存的局限性,往往需要考虑使用的数据类型所占用的字节数。下面简单介l下Java中几U基本数据类型,以加p忆?br /><span style="color: #ff0000; ">在Java中一共有8U基本数据类型,其中?U整型,2UQ点类型,1U用于表CUnicode~码的字W单元的字符cd?U用于表C真值的booleancd。(一个字节等?个bitQ?/span><br /><br /><span style="color: #3333ff; ">1.整型</span><br />cd              存储需?    bit?   取D?nbsp;     备注<br />int                 4字节           4*8 <br />short             2字节           2*8    Q?2768?2767<br />long              8字节           8*8<br />byte              1字节           1*8     Q?28?27<br /><br /><span style="color: #3333ff; ">2.点?/span><br />cd              存储需?    bit?   取D?nbsp;     备注<br />float              4字节           4*8                  floatcd的数值有一个后~F(例如Q?.14F)<br />double          8字节           8*8                       没有后缀F的QҎ??.14)默认为doublecd<br /><br /><span style="color: #3333ff; ">3.charcd</span><br />cd              存储需?    bit?    取D?nbsp;     备注<br />char              2字节          2*8<br /><br /><span style="color: #3333ff; ">4.booleancd</span><br />cd              存储需?   bit?   取D?nbsp;     备注<br />boolean        1字节          1*8      false、true<br /></span><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "></span><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "><span style="font-size: 18px; "><br /></span></p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "><span style="font-size: 18px; "><span style="color: #ff0000; ">补充Q?/span>Java有一个能够表CZQ意精度的书包,通常UCؓ“大数?#8221;(big number)。虽然被UCؓ大数|但它q不是一UJavacdQ而是一个Java对象?/span></p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "><span style="font-size: 18px; ">如果基本的整数和点数精度不能够满需求,那么可以使用java.math包中的两个很有用的类Q?span style="color: #ff0000; ">BigIntegerBigDecimal(Android SDK中也包含了java.math包以及这两个c?</span>q两个类可以处理包含L长度数字序列的数倹{BigIntegercdCL_ֺ的整数运,BigDecimal实现了Q意精度的点数运。具体的用法可以参见Java API?/span></p><div><span style="font-size: 18px; "><div>http://blog.csdn.net/witsmakemen/article/details/8974200<br /></div></span></div></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #ffffff; "><pre accuse="aContent" class="answer-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><br /></pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #f1fedd; "><pre id="best-content-428742571" accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; ">int常见?个字节,跟操作系l有关系?br />turbo cQ以及Turbo c的一些衍生编译器Q他们用的一?a class="inner-link decor-none" target="_blank" rel="nofollow" data-word="0" style="color: #2d64b3; text-decoration: none; ">~译E序</a>Q是dos时代的编译器Q是上世U?0q代的物,严重q时Q属于老掉牙的产品Q他们编译出来的E序?6位操作系ldos下的E序Q所以长度ؓ16位,即两个字节。windowsZ兼容dosQ所以turbo c生成的文件也可以在windows中运行?br />其他一般就都是4个字节了?/pre></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5; ">操作pȝ16位的时候,int 2字节Q操作系l?2位的时候,int 4字节Q由?2位系l之前占LCQ实际现在就是64位系l,Z兼容性考虑Qint也是4字节?/span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: arial, 宋体, sans-serif, 'Microsoft YaHei', tahoma; line-height: 24px; background-color: #f1fedd; "><pre accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; "><div><pre accuse="aContent" mb-10"="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; color: #333333; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f1fedd; "><br /></pre></div><br /><br /></pre></span><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/405416.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2013-10-18 22:31 <a href="http://www.aygfsteel.com/stevenjohn/archive/2013/10/18/405416.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA~程中URL传值符L转换http://www.aygfsteel.com/stevenjohn/archive/2013/08/22/403200.htmlabinabinThu, 22 Aug 2013 12:23:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2013/08/22/403200.htmlhttp://www.aygfsteel.com/stevenjohn/comments/403200.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2013/08/22/403200.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/403200.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/403200.html有些W号在URL中是不能直接传递的Q如果要在URL中传递这些特D符P那么p使用他们的编码了。下表中列出了一些URLҎW号及编?/p>

十六q制?/p>

 

1 + URL ?可C空?/td> %2B
2 I格 URL中的I格可以?h者编?/td> %20
3 / 分隔目录和子目录 %2F
4 ? 分隔实际?URL 和参?/td> %3F
5 % 指定Ҏ字符 %25
6 # 表示书签 %23
7 & URL 中指定的参数间的分隔W?/td> %26
8 = URL 中指定参数的?/td> %3D

 
  解决的方法:

  replace() Ҏ如果直接用str.replace("-","!") 只会替换W一个匹配的字符.

  而str.replace(/\-/g,"!")则可以替换掉全部匚w的字W?g为全局标志)?/p>

  replace()

  js中替换字W变量如下:

  data2=data2.replace(/\%/g,"%25");

  data2=data2.replace(/\#/g,"%23");

  data2=data2.replace(/\&/g,"%26");



abin 2013-08-22 20:23 发表评论
]]>
java中的堆、栈、常量池http://www.aygfsteel.com/stevenjohn/archive/2013/05/23/399677.htmlabinabinThu, 23 May 2013 14:39:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2013/05/23/399677.htmlhttp://www.aygfsteel.com/stevenjohn/comments/399677.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2013/05/23/399677.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/399677.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/399677.htmlJava内存分配:

1. 寄存器:我们在程序中无法控制
2. 栈:存放基本cd的数据和对象的引用,但对象本w不存放在栈中,而是存放在堆?br />3. 堆:存放用new产生的数?br />4. 静态域Q存攑֜对象中用static定义的静态成?br />5. 帔R池:存放帔R
6. 非RAM(随机存取存储?/span>)存储Q硬盘等怹存储I间
----------------------------------------------------------------------------------------------------------------------

a.在函C定义的一些基本类型的变量数据和对象的引用变量都在函数的栈内存中分配?nbsp; 
当在一D代码块定义一个变量时QJava在栈中个变量分配内存空_当该变量退作用域后QJava会自动释放掉变量所分配的内存空_该内存空间可以立卌另作他用?nbsp; 
b.堆内存用来存攄new创徏的对象和数组?nbsp;在堆中分配的内存Q由Java虚拟机的自动垃圾回收器来理?nbsp; 
在堆中生了一个数l或对象后,q可以在栈中定义一个特D的变量Q让栈中q个变量的取值等于数l或对象在堆内存中的首地址Q栈中的q个变量成了数l或对象的引用变量?nbsp; 引用变量q当于是ؓ数组或对象v的一个名Uͼ以后可以在E序中用栈中的引用变量来访问堆中的数组或对象。引用变量就相当于是?数组或者对象v的一个名U。引用变量是普通的变量Q定义时在栈中分配,引用变量在程序运行到其作用域之外后被释放。而数l和对象本n在堆中分配,即ɽE序q行C?new 产生数组或者对象的语句所在的代码块之外,数组和对象本w占据的内存不会被释放,数组和对象在没有引用变量指向它的时候,才变为垃圾,不能在被使用Q但仍然占据内存I间不放Q在随后的一个不定的时间被垃圾回收器收赎ͼ释放掉)。这也是 Java 比较占内存的原因?nbsp;
实际上,栈中的变量指向堆内存中的变量Q这是 Java 中的指针Q?nbsp;
c.帔R?/span>(constant pool)指的是在~译期被定Qƈ被保存在已编译的.class文g中的一些数据。除了包含代码中所定义的各U基本类型(如int、long{等Q和对象型(如String及数l)的常量?final)q包含一些以文本形式出现的符号引用,比如Q?cd接口的全限定名; 字段的名U和描述W; Ҏ和名U和描述W?虚拟机必Mؓ每个被装载的cdl护一个常量池。常量池是该类型所用到帔R的一个有序集和,包括直接帔RQstring,integer和floating point帔RQ和对其他类型,字段和方法的W号引用。对于String帔RQ它的值是在常量池中的。而JVM中的帔R池在内存当中是以表的形式存在的,对于StringcdQ有一张固定长度的CONSTANT_String_info表用来存储文字字W串|注意Q该表只存储文字字符串|不存储符号引用。说到这里,对常量池中的字符串值的存储位置应该有一个比较明了的理解了?/p>

在程序执行的时?帔R?/span>会储存在Method Area,而不是堆?
d.Java的堆是一个运行时数据?cȝ(对象从中分配I间。这些对象通过new、newarray、anewarray和multianewarray{指令徏立,它们不需要程序代码来昑ּ的释放。堆是由垃圾回收来负责的Q堆的优势是可以动态地分配内存大小Q生存期也不必事先告诉编译器Q因为它是在q行时动态分配内存的QJava的垃圾收集器会自动收走这些不再用的数据。但~点是,׃要在q行时动态分配内存,存取速度较慢?nbsp;

栈的优势是,存取速度比堆要快Q仅ơ于寄存器,栈数据可以共享。但~点是,存在栈中的数据大与生存期必L定的,~Z灉|性。栈中主要存放一些基本类型的变量数据Qint, short, long, byte, float, double, boolean, charQ和对象句柄(引用)?nbsp;

栈有一个很重要的特D性,是存在栈中的数据可以共享。假设我们同时定义: 
int a = 3; 
int b = 3Q?nbsp;
~译器先处理int a = 3Q首先它会在栈中创徏一个变量ؓa的引用,然后查找栈中是否?q个|如果没找刎ͼ将3存放q来Q然后将a指向3。接着处理int b = 3Q在创徏完b的引用变量后Q因为在栈中已经?q个|便将b直接指向3。这P出Ca与b同时均指?的情c?nbsp;

q时Q如果再令a=4Q那么编译器会重新搜索栈中是否有4|如果没有Q则?存放q来Qƈ令a指向4Q如果已l有了,则直接将a指向q个地址。因此a值的改变不会影响到b的倹{?nbsp;

要注意这U数据的׃n与两个对象的引用同时指向一个对象的q种׃n是不同的Q因U情况a的修改ƈ不会影响到b, 它是q译器完成的,它有利于节省I间。而一个对象引用变量修改了q个对象的内部状态,会媄响到另一个对象引用变量?/p>

/*****************************************************************************/

 

String是一个特D的包装cL据。可以用Q?nbsp;
String str = new String("abc"); 
String str = "abc"; 
两种的Ş式来创徏Q第一U是用new()来新建对象的Q它会在存放于堆中。每调用一ơ就会创Z个新的对象?nbsp;
而第二种是先在栈中创Z个对Stringcȝ对象引用变量strQ然后通过W号引用?span style="color: #ff0000;">字符串常量池里找有没?abc",如果没有Q则?abc"存放q?span style="color: #ff0000;">字符串常量池Qƈ令str指向”abc”Q如果已l有”abc” 则直接ostr指向“abc”?nbsp;

比较c里面的数值是否相{时Q用equals()ҎQ当试两个包装cȝ引用是否指向同一个对象时Q用==Q下面用例子说明上面的理论?nbsp;
String str1 = "abc"; 
String str2 = "abc"; 
System.out.println(str1==str2); //true 
可以看出str1和str2是指向同一个对象的?nbsp;

String str1 =new String ("abc"); 
String str2 =new String ("abc"); 
System.out.println(str1==str2); // false 
用new的方式是生成不同的对象。每一ơ生成一个?nbsp;

因此用第二种方式创徏多个”abc”字符?在内存中其实只存在一个对象而已. q种写法有利与节省内存空? 同时它可以在一定程度上提高E序的运行速度Q因为JVM会自动根据栈中数据的实际情况来决定是否有必要创徏新对象。而对于String str = new String("abc")Q的代码Q则一概在堆中创徏新对象,而不其字符串值是否相{,是否有必要创建新对象Q从而加重了E序的负担?nbsp;

另一斚w, 要注? 我们在用诸如String str = "abc"Q的格式定义cLQL惛_然地认ؓQ创ZStringcȝ对象str。担心陷阱!对象可能q没有被创徏Q而可能只是指向一个先前已l创建的对象。只有通过new()Ҏ才能保证每次都创Z个新的对象?nbsp;
׃Stringcȝimmutable性质Q当String变量需要经常变换其值时Q应该考虑使用StringBufferc,以提高程序效率?nbsp;
1. 首先String不属?U基本数据类型,String是一个对象?nbsp;
因ؓ对象的默认值是nullQ所以String的默认g是nullQ但它又是一U特D的对象Q有其它对象没有的一些特性?nbsp;

2. new String()和new String(”")都是x一个新的空字符Ԍ是空串不是nullQ?nbsp;

3. String str=”kvill”QString str=new String (”kvill”)的区?br />
看例1Q?nbsp;

String s0="kvill"; 
String s1="kvill"; 
String s2="kv" + "ill"; 
System.out.println( s0==s1 ); 
System.out.println( s0==s2 ); 
l果为: 
true 
true 

首先Q我们要知结果ؓ?span style="background-color: #ffff00;">Java会确保一个字W串帔R只有一个拷贝?nbsp;
因ؓ例子中的s0和s1中的”kvill”都是字符串常量,它们在编译期p定了,所以s0==s1为trueQ?#8221;kv”?#8221;ill”也都是字W串帔RQ当一个字W串由多个字W串帔Rq接而成Ӟ它自p定也是字W串帔RQ所以s2也同样在~译期就被解析ؓ一个字W串帔RQ所以s2也是帔R池中” kvill”的一个引用。所以我们得出s0==s1==s2Q用new String() 创徏的字W串不是帔RQ不能在~译期就定Q所以new String() 创徏的字W串不放入常量池中,它们有自q地址I间?nbsp;

看例2Q?nbsp;
String s0="kvill"; 
String s1=new String("kvill"); 
String s2="kv" + new String("ill"); 
System.out.println( s0==s1 ); 
System.out.println( s0==s2 ); 
System.out.println( s1==s2 ); 
l果为: 
false 
false 
false 

?中s0q是帔R池中"kvill”的应用,s1因ؓ无法在编译期定Q所以是q行时创建的新对?#8221;kvill”的引用,s2因ؓ有后半部?new String(”ill”)所以也无法在编译期定Q所以也是一个新创徏对象”kvill”的应?明白了这些也q道ؓ何得出此l果了?nbsp;

4. String.intern()Q?nbsp;
再补充介l一点:存在?class文g中的帔R池,在运行期被JVM装蝲Qƈ且可以扩充。String的intern()Ҏ是扩充帔R池的 一个方法;当一个String实例str调用intern()ҎӞJava查找帔R池中是否有相同Unicode的字W串帔RQ如果有Q则q回其的引用Q如果没有,则在帔R池中增加一个Unicode{于str的字W串q返回它的引用;看例3清楚了 

?Q?nbsp;
String s0= "kvill"; 
String s1=new String("kvill"); 
String s2=new String("kvill"); 
System.out.println( s0==s1 ); 
System.out.println( "**********" ); 
s1.intern(); 
s2=s2.intern(); //把常量池?kvill"的引用赋ls2 
System.out.println( s0==s1); 
System.out.println( s0==s1.intern() ); 
System.out.println( s0==s2 ); 
l果为: 
false 
********** 
false //虽然执行了s1.intern(),但它的返回值没有赋ls1 
true //说明s1.intern()q回的是帔R池中"kvill"的引?nbsp;
true 

最后我再破除一个错误的理解Q有Q?#8220;使用 String.intern() Ҏ则可以将一?String cȝ保存C个全局 String 表中 Q如果具有相同值的 Unicode 字符串已l在q个表中Q那么该Ҏq回表中已有字符串的地址Q如果在表中没有相同值的字符Ԍ则将自己的地址注册到表?#8221;如果我把他说的这个全局?String 表理解ؓ帔R池的话,他的最后一句话Q?#8221;如果在表中没有相同值的字符Ԍ则将自己的地址注册到表?#8221;是错的: 

看例4Q?nbsp;
String s1=new String("kvill"); 
String s2=s1.intern(); 
System.out.println( s1==s1.intern() ); 
System.out.println( s1+" "+s2 ); 
System.out.println( s2==s1.intern() ); 
l果Q?nbsp;
false 
kvill kvill 
true 

在这个类中我们没有声名一?#8221;kvill”帔RQ所以常量池中一开始是没有”kvill”的,当我们调用s1.intern()后就在常量池中新d了一?#8221;kvill”帔RQ原来的不在帔R池中?#8221;kvill”仍然存在Q也׃?#8220;自q地址注册到常量池?#8221;了?nbsp;
s1==s1.intern()为false说明原来?#8221;kvill”仍然存在Qs2现在为常量池?#8221;kvill”的地址Q所以有s2==s1.intern()为true?nbsp;

5. 关于equals()?=: 
q个对于String单来说就是比较两字符串的Unicode序列是否相当Q如果相{返回true;?=是比较两字符串的地址是否相同Q也是是否是同一个字W串的引用?nbsp;

6. 关于String是不可变?nbsp;
q一说又要说很多Q大家只要知道String的实例一旦生成就不会再改变了Q比如说QString str=”kv”+”ill”+” “+”ans”; 是?个字W串帔RQ首?#8221;kv”?#8221;ill”生成?#8221;kvill”存在内存中,然后”kvill”又和” ” 生成 “kvill “存在内存中,最后又和生成了”kvill ans”;q把q个字符串的地址赋给了str,是因ؓString?#8221;不可?#8221;产生了很多时变量,q也是Z么徏议用StringBuffer的原因了Q因为StringBuffer是可改变的?/p>

/*******************************************************************************/

下面是一些String相关的常见问题:

String中的final用法和理?br />final StringBuffer a = new StringBuffer("111");
final StringBuffer b = new StringBuffer("222");
a=b;//此句~译不通过

final StringBuffer a = new StringBuffer("111");
a.append("222");//~译通过

可见Qfinal只对引用??(卛_存地址)有效Q它q引用只能指向初始指向的那个对象,改变它的指向会导致编译期错误。至于它所指向的对象的变化Qfinal是不负责的?/p>

String 帔R池问题的几个例子

下面是几个常见例子的比较分析和理解:
[1]
String a = "a1"; 
String b = "a" + 1; 
System.out.println((a == b)); //result = true
String a = "atrue"; 
String b = "a" + "true"; 
System.out.println((a == b)); //result = true
String a = "a3.4"; 
String b = "a" + 3.4; 
System.out.println((a == b)); //result = true

分析QJVM对于字符串常量的"+"可接,程序编译期QJVM将帔R字符串的"+"q接优化接后的|?a" + 1来说Q经~译器优化后在class中就已经是a1。在~译期其字符串常量的值就定下来Q故上面E序最l的l果都ؓtrue?/p>

[2]
String a = "ab"; 
String bb = "b"; 
String b = "a" + bb; 
System.out.println((a == b)); //result = false

分析QJVM对于字符串引用,׃在字W串?+"q接中,有字W串引用存在Q而引用的值在E序~译期是无法定的,?a" + bb无法被编译器优化Q只有在E序q行期来动态分配ƈ连接后的新地址赋给b。所以上面程序的l果也就为false?/p>

[3]
String a = "ab"; 
final String bb = "b"; 
String b = "a" + bb; 
System.out.println((a == b)); //result = true

分析Q和[3]中唯一不同的是bb字符串加了final修饰Q对于final修饰的变量,它在~译时被解析为常量值的一个本地拷贝存储到自己的常量池中或嵌入到它的字节码中。所以此时的"a" + bb?a" + "b"效果是一L。故上面E序的结果ؓtrue?/p>

[4]
String a = "ab"; 
final String bb = getBB(); 
String b = "a" + bb; 
System.out.println((a == b)); //result = false 
private static String getBB() {
return "b"; 
}

分析QJVM对于字符串引用bbQ它的值在~译期无法确定,只有在程序运行期调用Ҏ后,方法的q回值和"a"来动态连接ƈ分配地址为bQ故上面E序的结果ؓfalse?/p>

通过上面4个例子可以得出得知:
String  s  =  "a" + "b" + "c";   
q价于String s = "abc";   

String  a  =  "a";   
String  b  =  "b";   
String  c  =  "c";   
String  s  =   a  +  b  +  c;  

q个׃一样了Q最l结果等于:   
StringBuffer temp = new StringBuffer();   
temp.append(a).append(b).append(c);   
String s = temp.toString();

׃面的分析l果Q可׃难推断出String 采用q接q算W(+Q效率低下原因分析,形如q样的代码:

public class Test {
public static void main(String args[]) {
String s = null;
for(int i = 0; i < 100; i++) {
s += "a";
}
}
}

每做一?+ ׃生个StringBuilder对象Q然后append后就扔掉。下ơ@环再到达旉C生个StringBuilder对象Q然?append 字符Ԍ如此循环直至l束?如果我们直接采用 StringBuilder 对象q行 append 的话Q我们可以节?N - 1 ơ创建和销毁对象的旉。所以对于在循环中要q行字符串连接的应用Q一般都是用StringBuffer或StringBulider对象来进行append操作?/p>

String对象的internҎ理解和分析:

public class Test4 {
private static String a = "ab"; 
public static void main(String[] args){
String s1 = "a";
String s2 = "b";
String s = s1 + s2;
System.out.println(s == a);//false
System.out.println(s.intern() == a);//true  
}
}

q里用到Java里面是一个常量池的问题。对于s1+s2操作Q其实是在堆里面重新创徏了一个新的对?s保存的是q个新对象在堆空间的的内容,所以s与a的值是不相{的。而当调用s.intern()ҎQ却可以q回s在常量池中的地址|因ؓa的值存储在帔R池中Q故s.intern和a的值相{?/p>

 

ȝ:

a.栈中用来存放一些原始数据类型的局部变量数据和对象的引?String,数组.对象{等)但不存放对象内容

b.堆中存放使用new关键字创建的对象.

c.字符串是一个特D包装类,其引用是存放在栈里的,而对象内容必L据创建方式不同定(帔R池和?.有的是编译期已l创建好Q存攑֜字符串常量池中,而有的是q行时才被创?使用new关键字,存放在堆中?/p>

 

本文转自Q?a style="color: #ff9900; text-decoration: initial;">http://zy19880423.javaeye.com/blog/434179



abin 2013-05-23 22:39 发表评论
]]>
jdk动态代理和java的多态有啥区别?http://www.aygfsteel.com/stevenjohn/archive/2012/12/11/392825.htmlabinabinTue, 11 Dec 2012 09:46:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/12/11/392825.htmlhttp://www.aygfsteel.com/stevenjohn/comments/392825.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/12/11/392825.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/392825.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/392825.html
动态代理,不是java语言Ҏ, 只是java提供动态方法拦截的一U方式(工具Q?br />有点cM hook
动态代理,只是动态的通过反射Q动态执行目标的相关操作Q?br />当然要想实现动态代理,必须该类有接?貌似cglib不需要的)
动态代理,是一U实现方?br />

多态,是oo语言的特?br />

多态表现在重蝲Q一个父cȝ变量可以引用子类的对?/p>


 



abin 2012-12-11 17:46 发表评论
]]>
Java 抽象cd接口适用场合http://www.aygfsteel.com/stevenjohn/archive/2012/11/22/391773.htmlabinabinThu, 22 Nov 2012 09:01:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/11/22/391773.htmlhttp://www.aygfsteel.com/stevenjohn/comments/391773.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/11/22/391773.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/391773.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/391773.html
对于抽象cd接口Q我个h觉得Q一般性的接口Q都可以用这两者,
1、接口,接口实现c,
2、普通类l承抽象c?br />
我想问下Q什么场合用接口好点Q什么场合用抽象cd?br />接口cM一个协议,一般只作定?br />面向对象的语意是完全不同?br />一U是实现Q一U是个别?br />看uml q道了
q个都用q,接口用的是最多的Q但是能不能l讲个语境,比如q里用抽象类比接口好点
目前Q有观点是Q用接?nbsp;解?br />不是q样圎ͼ模式里用的接口多Q但有些模式Q如模版Ҏ模式Q用到抽?br />看具体的使用
恩恩Q总觉得迷qLp的
之前我公总们写呼叫pȝ的时候,大量的用了抽象c?br />抽象cd以定义方法的内容Q具体实现留l子cd?br />抽象的目的是个别化,是各个子类都有自己的特?br />虽然都承父c,但有些方法需要重斎ͼ或新增,是实现了子cȝҎ?br />接口不一P接口只是单独?nbsp;realize


abin 2012-11-22 17:01 发表评论
]]>
Java ZIP文g压羃http://www.aygfsteel.com/stevenjohn/archive/2012/11/11/391170.htmlabinabinSun, 11 Nov 2012 15:32:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/11/11/391170.htmlhttp://www.aygfsteel.com/stevenjohn/comments/391170.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/11/11/391170.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/391170.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/391170.htmlpackage lc.abin.lee.basic.zip;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class CreateZip {
 public static String createZipFile(String filePath){
  String result="failure";
  try {
   FileOutputStream fileOut=new FileOutputStream("example.zip");
   CheckedOutputStream checkOut=new CheckedOutputStream(fileOut,new CRC32());
   ZipOutputStream zipOut=new ZipOutputStream(new BufferedOutputStream(checkOut));
   
   BufferedReader in=new BufferedReader(new FileReader(filePath));
   zipOut.putNextEntry(new ZipEntry(filePath));
   int line;
   while((line=in.read())!=-1){
    zipOut.write(line);
    zipOut.flush();
   }
   result="success";
   in.close();
   zipOut.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
  return result;
 }
 public static void main(String[] args) {
  String fileName="D:\\abin.txt";
  String result=createZipFile(fileName);
  System.out.println("result="+result);
 }
}



貌似q有炚w题,明天解决一?img src ="http://www.aygfsteel.com/stevenjohn/aggbug/391170.html" width = "1" height = "1" />

abin 2012-11-11 23:32 发表评论
]]>
Java Cloneablehttp://www.aygfsteel.com/stevenjohn/archive/2012/10/24/390150.htmlabinabinWed, 24 Oct 2012 05:27:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/10/24/390150.htmlhttp://www.aygfsteel.com/stevenjohn/comments/390150.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/10/24/390150.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/390150.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/390150.htmlpackage net.abin.lee.basic;

public class Can implements Cloneable{
 private int id;
 private String address;
 public Can() {
 }
 public Can(int id, String address) {
  super();
  this.id = id;
  this.address = address;
 }
 public Object clone()throws CloneNotSupportedException{
  return super.clone();
 }
 public int hashCode(){
  final int prime=31;
  int result=1;
  result=prime*result+id;
  result=prime*result+((address==null?0:address.hashCode()));
  return result;
 }
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
 
}










package net.abin.lee.basic;

import junit.framework.TestCase;

public class UserTest extends TestCase{
 public void test1() throws CloneNotSupportedException{
  User user1=new User("12","abin",3);
  User user2=user1;
  User user3=(User)user1.clone();
  System.out.println("user1=user2 :"+(user1==user2));
  System.out.println("user1equalsuser2 :"+(user1.equals(user2)));
  
  System.out.println("user1=user3 :"+(user1==user3));
  System.out.println("user1equalsuser3 :"+(user1.equals(user3)));
  
 }
 @Override
 protected void runTest() throws Throwable {
  System.out.println("55");
  super.runTest();
 }
}



abin 2012-10-24 13:27 发表评论
]]>
Java volatile的用?http://www.aygfsteel.com/stevenjohn/archive/2012/09/01/386728.htmlabinabinFri, 31 Aug 2012 16:27:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/09/01/386728.htmlhttp://www.aygfsteel.com/stevenjohn/comments/386728.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/09/01/386728.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/386728.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/386728.html/**
 * 双重查加?单例模式
 * @author abin
 * q个单例模式写法可以大大减少getInstance的时间消耗!
 */
public class SingletonOne {
  /** 
     * volatile关键词确保:当singleton变量被初始化成SingletonOne实例Ӟ多个U程正确地处理singleton变量 
     */ 
 private volatile static SingletonOne singleton=null;
 public SingletonOne(){}
 public static SingletonOne getInstance(){
  if(null==singleton){//查实例,如果不存在就q入同步区块
   synchronized (SingletonOne.class) {//注意Q只有第一ơ才d执行q里的代?
    if(null!=singleton){
     singleton=new SingletonOne();
    }
   }
  }
  return singleton;
 }
}





package com.abin.lee.collection.singleton;

public class SingletonTwo {
 /**
  * volatile关键词确保:当uniqueInstance变量被初始化成Singleton实例Ӟ
  * 多个U程正确地处理uniqueInstance变量
  */
 private volatile static SingletonTwo singleton = new SingletonTwo();

 private SingletonTwo() {
 }

 public static SingletonTwo getInstance() {
  return singleton;
 }
}



abin 2012-09-01 00:27 发表评论
]]>
l承中静态块、游d、构造器{的执行序 http://www.aygfsteel.com/stevenjohn/archive/2012/08/22/386034.htmlabinabinWed, 22 Aug 2012 07:07:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/22/386034.htmlhttp://www.aygfsteel.com/stevenjohn/comments/386034.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/22/386034.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/386034.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/386034.html  父类静态块
  子类静态块
  父类变量
  父类静态变?br />  父类游离?br />  父类构造器
  子类变量
  子类静态变?br />  子类游离?br />  子类的构造器

验证的代码:


package com.jlq.test;

public class Test1 {

private static String s1 = "父类静态变?;

private String s2 = "父类变量";

public Test1() {
System.out.println("父类构造器");
}
/**
* 静态代码块
*/

static {
System.out.println("父类静态块");

}
/**
* 游离?
*/
{
System.out.println(s2);
System.out.println(s1);
System.out.println("父类游离?);

}

public static void main(String[] args) {
new TestChild();
}

}

class TestChild extends Test1 {

private static String s1 = "子类静态变?;

private String s2 = "子类变量";
/**
* 静态代码块
*/

static {
System.out.println("子类静态块");

}
/**
* 游离?
*/
{
System.out.println(s2);
System.out.println(s1);
System.out.println("子类游离?);

}

public TestChild() {
System.out.println("子类的构造器");
}

}


abin 2012-08-22 15:07 发表评论
]]>
Java 重写equals和hashcodehttp://www.aygfsteel.com/stevenjohn/archive/2012/08/08/385078.htmlabinabinWed, 08 Aug 2012 08:30:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/08/385078.htmlhttp://www.aygfsteel.com/stevenjohn/comments/385078.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/08/385078.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/385078.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/385078.htmlpublic boolean equals(Object other) {
  if ((this == other))
   return true;
  if ((other == null))
   return false;
  if (!(other instanceof BtsfSysAlipayNotifyJournal))
   return false;
  BtsfSysAlipayNotifyJournal castOther = (BtsfSysAlipayNotifyJournal) other;

  return ((this.getId() == castOther.getId()) || (this.getId() != null
    && castOther.getId() != null && this.getId().equals(
    castOther.getId())))
    && ((this.getPartner() == castOther.getPartner()) || (this
      .getPartner() != null
      && castOther.getPartner() != null && this.getPartner()
      .equals(castOther.getPartner())))
    && ((this.getDiscount() == castOther.getDiscount()) || (this
      .getDiscount() != null
      && castOther.getDiscount() != null && this
      .getDiscount().equals(castOther.getDiscount())))
    && ((this.getPaymentType() == castOther.getPaymentType()) || (this
      .getPaymentType() != null
      && castOther.getPaymentType() != null && this
      .getPaymentType().equals(castOther.getPaymentType())))
    && ((this.getSubject() == castOther.getSubject()) || (this
      .getSubject() != null
      && castOther.getSubject() != null && this.getSubject()
      .equals(castOther.getSubject())))
    && ((this.getTradeNo() == castOther.getTradeNo()) || (this
      .getTradeNo() != null
      && castOther.getTradeNo() != null && this.getTradeNo()
      .equals(castOther.getTradeNo())))
    && ((this.getBuyerEmail() == castOther.getBuyerEmail()) || (this
      .getBuyerEmail() != null
      && castOther.getBuyerEmail() != null && this
      .getBuyerEmail().equals(castOther.getBuyerEmail())))
    && ((this.getGmtCreate() == castOther.getGmtCreate()) || (this
      .getGmtCreate() != null
      && castOther.getGmtCreate() != null && this
      .getGmtCreate().equals(castOther.getGmtCreate())))
    && ((this.getQuantity() == castOther.getQuantity()) || (this
      .getQuantity() != null
      && castOther.getQuantity() != null && this
      .getQuantity().equals(castOther.getQuantity())))
    && ((this.getOutTradeNo() == castOther.getOutTradeNo()) || (this
      .getOutTradeNo() != null
      && castOther.getOutTradeNo() != null && this
      .getOutTradeNo().equals(castOther.getOutTradeNo())))
    && ((this.getSellerId() == castOther.getSellerId()) || (this
      .getSellerId() != null
      && castOther.getSellerId() != null && this
      .getSellerId().equals(castOther.getSellerId())))
    && ((this.getTradeStatus() == castOther.getTradeStatus()) || (this
      .getTradeStatus() != null
      && castOther.getTradeStatus() != null && this
      .getTradeStatus().equals(castOther.getTradeStatus())))
    && ((this.getIsTotalFeeAdjust() == castOther
      .getIsTotalFeeAdjust()) || (this.getIsTotalFeeAdjust() != null
      && castOther.getIsTotalFeeAdjust() != null && this
      .getIsTotalFeeAdjust().equals(
        castOther.getIsTotalFeeAdjust())))
    && ((this.getTotalFee() == castOther.getTotalFee()) || (this
      .getTotalFee() != null
      && castOther.getTotalFee() != null && this
      .getTotalFee().equals(castOther.getTotalFee())))
    && ((this.getGmtPayment() == castOther.getGmtPayment()) || (this
      .getGmtPayment() != null
      && castOther.getGmtPayment() != null && this
      .getGmtPayment().equals(castOther.getGmtPayment())))
    && ((this.getSellerEmail() == castOther.getSellerEmail()) || (this
      .getSellerEmail() != null
      && castOther.getSellerEmail() != null && this
      .getSellerEmail().equals(castOther.getSellerEmail())))
    && ((this.getGmtClose() == castOther.getGmtClose()) || (this
      .getGmtClose() != null
      && castOther.getGmtClose() != null && this
      .getGmtClose().equals(castOther.getGmtClose())))
    && ((this.getPrice() == castOther.getPrice()) || (this
      .getPrice() != null
      && castOther.getPrice() != null && this.getPrice()
      .equals(castOther.getPrice())))
    && ((this.getBuyerId() == castOther.getBuyerId()) || (this
      .getBuyerId() != null
      && castOther.getBuyerId() != null && this.getBuyerId()
      .equals(castOther.getBuyerId())))
    && ((this.getUseCoupon() == castOther.getUseCoupon()) || (this
      .getUseCoupon() != null
      && castOther.getUseCoupon() != null && this
      .getUseCoupon().equals(castOther.getUseCoupon())))
    && ((this.getCreateTime() == castOther.getCreateTime()) || (this
      .getCreateTime() != null
      && castOther.getCreateTime() != null && this
      .getCreateTime().equals(castOther.getCreateTime())))
    && ((this.getLastUpdateTime() == castOther.getLastUpdateTime()) || (this
      .getLastUpdateTime() != null
      && castOther.getLastUpdateTime() != null && this
      .getLastUpdateTime().equals(
        castOther.getLastUpdateTime())))
    && ((this.getPaymentMethod() == castOther.getPaymentMethod()) || (this
      .getPaymentMethod() != null
      && castOther.getPaymentMethod() != null && this
      .getPaymentMethod()
      .equals(castOther.getPaymentMethod())));
 }

 public int hashCode() {
  int result = 17;

  result = 37 * result + (getId() == null ? 0 : this.getId().hashCode());
  result = 37 * result
    + (getPartner() == null ? 0 : this.getPartner().hashCode());
  result = 37 * result
    + (getDiscount() == null ? 0 : this.getDiscount().hashCode());
  result = 37
    * result
    + (getPaymentType() == null ? 0 : this.getPaymentType()
      .hashCode());
  result = 37 * result
    + (getSubject() == null ? 0 : this.getSubject().hashCode());
  result = 37 * result
    + (getTradeNo() == null ? 0 : this.getTradeNo().hashCode());
  result = 37
    * result
    + (getBuyerEmail() == null ? 0 : this.getBuyerEmail()
      .hashCode());
  result = 37 * result
    + (getGmtCreate() == null ? 0 : this.getGmtCreate().hashCode());
  result = 37 * result
    + (getQuantity() == null ? 0 : this.getQuantity().hashCode());
  result = 37
    * result
    + (getOutTradeNo() == null ? 0 : this.getOutTradeNo()
      .hashCode());
  result = 37 * result
    + (getSellerId() == null ? 0 : this.getSellerId().hashCode());
  result = 37
    * result
    + (getTradeStatus() == null ? 0 : this.getTradeStatus()
      .hashCode());
  result = 37
    * result
    + (getIsTotalFeeAdjust() == null ? 0 : this
      .getIsTotalFeeAdjust().hashCode());
  result = 37 * result
    + (getTotalFee() == null ? 0 : this.getTotalFee().hashCode());
  result = 37
    * result
    + (getGmtPayment() == null ? 0 : this.getGmtPayment()
      .hashCode());
  result = 37
    * result
    + (getSellerEmail() == null ? 0 : this.getSellerEmail()
      .hashCode());
  result = 37 * result
    + (getGmtClose() == null ? 0 : this.getGmtClose().hashCode());
  result = 37 * result
    + (getPrice() == null ? 0 : this.getPrice().hashCode());
  result = 37 * result
    + (getBuyerId() == null ? 0 : this.getBuyerId().hashCode());
  result = 37 * result
    + (getUseCoupon() == null ? 0 : this.getUseCoupon().hashCode());
  result = 37
    * result
    + (getCreateTime() == null ? 0 : this.getCreateTime()
      .hashCode());
  result = 37
    * result
    + (getLastUpdateTime() == null ? 0 : this.getLastUpdateTime()
      .hashCode());
  result = 37
    * result
    + (getPaymentMethod() == null ? 0 : this.getPaymentMethod()
      .hashCode());
  return result;
 }



abin 2012-08-08 16:30 发表评论
]]>
Java 拆分字符?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2012/03/27/372845.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Tue, 27 Mar 2012 12:04:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2012/03/27/372845.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/372845.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2012/03/27/372845.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/372845.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/372845.html</trackback:ping><description><![CDATA[<p>package com.abin.inter.test;</p> <p>public class SplitString1 {<br /> public static void main(String[] args) {<br />  StringBuffer stb = new StringBuffer();<br />  String unitId1 = "aaaaa";<br />  String callerNumber1 = "bbbbb";<br />  String calleeNumber1 = "ccccc";<br />  stb.append(unitId1).append("|").append(callerNumber1).append("|")<br />    .append(calleeNumber1);<br />  System.out.println("stb=" + stb.toString());<br />  String unitId = stb.toString()<br />    .substring(0, stb.toString().indexOf("|"));<br />  System.out.println("unitId=" + unitId);<br />  String temp1 = stb.toString().substring(unitId.length() + 1,<br />    stb.toString().length() - unitId.length());<br />  System.out.println("temp1=" + temp1);<br />  String callerNumber = temp1.substring(0, temp1.indexOf("|"));<br />  System.out.println("callerNumber=" + callerNumber);<br />  System.out.println("unitId.length()=" + unitId.length());<br />  System.out.println("callerNumber.length()=" + callerNumber.length());<br />  System.out.println("stb=" + stb.toString().length());<br />  String temp2 = stb.toString().substring(<br />    unitId.length() + callerNumber.length() + 2,<br />    stb.toString().length());<br />  System.out.println("temp2=" + temp2);<br />  String calleeNumber = temp2.substring(0, temp2.length());<br />  System.out.println("calleeNumber=" + calleeNumber);<br /> }<br />}<br /></p> <img src ="http://www.aygfsteel.com/stevenjohn/aggbug/372845.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2012-03-27 20:04 <a href="http://www.aygfsteel.com/stevenjohn/archive/2012/03/27/372845.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">ư</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">֦</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˷</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ӧ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ű</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̫</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƾ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͬ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ԫ</a>| <a href="http://" target="_blank">¹</a>| <a href="http://" target="_blank">˹</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ij</a>| <a href="http://" target="_blank">С</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>