??xml version="1.0" encoding="utf-8" standalone="yes"?>91视频一区二区,免费a在线观看,色999日韩自偷自拍美女http://www.aygfsteel.com/yuxh/wayzh-cnTue, 17 Jun 2025 00:04:38 GMTTue, 17 Jun 2025 00:04:38 GMT60Hive2.1源码分析(一Q启动脚?/title><link>http://www.aygfsteel.com/yuxh/archive/2017/03/29/432418.html</link><dc:creator>yuxh</dc:creator><author>yuxh</author><pubDate>Wed, 29 Mar 2017 08:01:00 GMT</pubDate><guid>http://www.aygfsteel.com/yuxh/archive/2017/03/29/432418.html</guid><wfw:comment>http://www.aygfsteel.com/yuxh/comments/432418.html</wfw:comment><comments>http://www.aygfsteel.com/yuxh/archive/2017/03/29/432418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yuxh/comments/commentRss/432418.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yuxh/services/trackbacks/432418.html</trackback:ping><description><![CDATA[最q在|上看到的相x料都比较陈旧Q也太简略,参看了一下其他h的内容,针对Hive2.1.1做点分nQ?br /><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">1Q下载apache-hive-2.1.1-bin.tar.gz</div><div style="margin: 0px; color: #000000; font-family: mononoki,Helvetica,"Hiragino Sans GB",微Y雅黑,"Microsoft YaHei UI",SimSun,SimHei,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><p style="margin: 0px;">2Q解压羃Q下面的命o(h)行如启动报错Q请自行查略Hive启动配置</p><div style="margin: 0px;">3Q启?span style="line-height: 1.5;">hiveserver2</span> <span style="line-height: 1.5;">Q非必须Q用jdbc讉K的时候才使用Q?br /><div>bin目录?/div></span></div><div style="margin: 0px;">hive --service hiveserver2 -p10001来启?span style="line-height: 1.5;">hiveserver2</span> <span style="line-height: 1.5;">服务(默认?0000端口)</span></div><div style="margin: 0px;">nohup hive --service hiverserver2 -p10001可以在后台跑</div><div style="margin: 0px;">4Q?span style="line-height: 1.5;">hive脚本q行程</span><div style="margin: 0px;">bin目录下,使用命o(h)Ҏ(gu)为:(x)</div><div style="margin: 0px;"><div>./hive <parameters> --service serviceName <service parameters></div></div><div style="margin: 0px;">举例Qhive --debug :</div><div style="margin: 0px;">   查看bin/hive文g</div><div style="margin: 0px;">程中会(x)判断$1=‘--debug’?DEBUG=‘--debug’</div><div style="margin: 0px;"> <div style="margin: 0px;">if [ "$DEBUG" ]; then</div><div style="margin: 0px;">  if [ "$HELP" ]; then //<span style="line-height: 1.5;">如还?-helpQ就?x)执行debug_helpҎ(gu)?/span></div></div></div><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;">    debug_help</div><div style="margin: 0px;">    exit 0</div><div style="margin: 0px;">  else</div><div style="margin: 0px;">    get_debug_params "$DEBUG"</div><div style="margin: 0px;">    export <span style="color: red;">HADOOP_CLIENT_OPTS</span>="$HADOOP_CLIENT_OPTS $HIVE_MAIN_CLIENT_DEBUG_OPTS"http://<span style="line-height: 1.5;">讄HIVE_MAIN_CLIENT_DEBUG_OPTS的参C加入debug相应参数</span></div><div style="margin: 0px;">  fi</div><div style="margin: 0px;">fi</div></div><div style="margin: 0px;"></div><div style="margin: 0px;"><div style="margin: 0px;">if [ "$SERVICE" = "" ] ; then</div><div style="margin: 0px;">  if [ "$HELP" = "_help" ] ; then</div><div style="margin: 0px;">    SERVICE="help"</div><div style="margin: 0px;">  else</div><div style="margin: 0px;">    SERVICE="cli"     //默认赋值cli</div><div style="margin: 0px;">  fi</div><div style="margin: 0px;">fi</div></div><div style="margin: 0px;">q个shell脚本很多变量应该是在其他sh文g中定义,其中$SERVICE_LIST是其他很多sh文g的最开始Ş成的Qexport SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} "</div><div style="margin: 0px;"></div><div style="margin: 0px;"><div style="margin: 0px;">hive脚本最后的<span data-wiz-span="data-wiz-span" style="color: #ff0000;">$TORUN "$@"</span> Q默认情况下TORUN其实是cli,x?ext/cli.sh脚本Q该脚本中主要是调用/ext/util/execHiveCmd.sh 来执行最后的CliDriver?/div><div style="margin: 0px;"> ?span style="line-height: 1.5;">shell脚本中的$*Q?@?#</span><div style="margin: 0px;">举例_(d)(x)</div><div style="margin: 0px;">脚本名称叫test.sh 入参三个: 1 2 3</div><div style="margin: 0px;">q行test.sh 1 2 3?/div><div style="margin: 0px;">$*?1 2 3"Q一赯引号包住Q?/div><div style="margin: 0px;">$@?1" "2" "3"Q分别被包住Q?/div><div style="margin: 0px;">$#?Q参数数量)</div><span data-wiz-span="data-wiz-span">?/span></div><div style="margin: 0px;">即exec $HADOOP jar ${HIVE_LIB}/$JAR<span data-wiz-span="data-wiz-span"> $CLASS $HIVE_OPTS "$@" //1<br /></span></div><div style="margin: 0px;">其中:</div><div style="margin: 0px;">$HADOOP=<span style="line-height: 1.5;">$HADOOP_HOME/bin/hadoop</span><span style="line-height: 1.5;"> 【hive脚本中定?/span><span style="line-height: 1.5;">HADOOP=$HADOOP_HOME/bin/hadoop?/span></div><div style="margin: 0px;">$CLASS=org.apache.hadoop.hive.cli.CliDriver【传入的W一个参敎ͼ在cli.sh中有定义?/div><div style="margin: 0px;"></div><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">hadoop脚本Q?.7.3ZQ中最l会(x)执行Q?/div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"># Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS</div><div style="margin: 0px;">    HADOOP_OPTS="$HADOOP_OPTS $<span data-wiz-span="data-wiz-span" style="color: #ff0000;">HADOOP_CLIENT_OPTS</span>"</div><div style="margin: 0px;">    #make sure security appender is turned off</div><div style="margin: 0px;">    HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"</div><div style="margin: 0px;"> </div><div style="margin: 0px;">    export CLASSPATH=$CLASSPATH</div><div style="margin: 0px;">    exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@" //2</div></div><div style="margin: 0px; color: #000000; font-family: mononoki,Helvetica,"Hiragino Sans GB",微Y雅黑,"Microsoft YaHei UI",SimSun,SimHei,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">hive的debug参数是在启动hive脚本时放到HADOOP_OPTS中的</div></div><div style="margin: 0px;"></div><div style="margin: 0px;"><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;">1?处结合可得到最l的q行命o(h)Q查看一下运行结果:(x)ps -ef|grep CliDriver</div></div></div></div></div></div></div></div></div></div><br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">  </span><span style="color: #000000; ">/</span><span style="color: #000000; ">usr</span><span style="color: #000000; ">/</span><span style="color: #000000; ">java</span><span style="color: #000000; ">/</span><span style="color: #000000; ">jdk1.</span><span style="color: #000000; ">8</span><span style="color: #000000; ">.0_101</span><span style="color: #000000; ">/</span><span style="color: #000000; ">bin</span><span style="color: #000000; ">/</span><span style="color: #000000; ">java </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Xmx256m </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.net.preferIPv4Stack</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; "> </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.log.dir</span><span style="color: #000000; ">=</span><span style="color: #000000; ">.. </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.log.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hadoop.log </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.home.dir</span><span style="color: #000000; ">=</span><span style="color: #000000; ">.. </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.id.str</span><span style="color: #000000; ">=</span><span style="color: #000000; ">root </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.root.logger</span><span style="color: #000000; ">=</span><span style="color: #000000; ">INFO,console </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.library.path</span><span style="color: #000000; ">=</span><span style="color: #000000; ">.. </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.policy.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hadoop</span><span style="color: #000000; ">-</span><span style="color: #000000; ">policy.xml </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.net.preferIPv4Stack</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; "> </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Xmx512m </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dproc_hivecli </span><span style="color: #000000; ">-</span><span style="color: #000000; ">XX:</span><span style="color: #000000; ">+</span><span style="color: #000000; ">UseParallelGC </span><span style="color: #000000; ">-</span><span style="color: #000000; ">agentlib:jdwp</span><span style="color: #000000; ">=</span><span style="color: #000000; ">transport</span><span style="color: #000000; ">=</span><span style="color: #000000; ">dt_socket,server</span><span style="color: #000000; ">=</span><span style="color: #000000; ">y,address</span><span style="color: #000000; ">=</span><span style="color: #000000; ">8000</span><span style="color: #000000; ">,suspend</span><span style="color: #000000; ">=</span><span style="color: #000000; ">y </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dlog4j.configurationFile</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">log4j2.properties </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.util.logging.config.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">..<br />  </span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.security.logger</span><span style="color: #000000; ">=</span><span style="color: #000000; ">INFO,NullAppender org.apache.hadoop.util.RunJar </span><span style="color: #000000; "></span><span style="color: #000000; ">/</span><span style="color: #000000; ">yuxh</span><span style="color: #000000; ">/</span><span style="color: #000000; ">app</span><span style="color: #000000; ">/</span><span style="color: #000000; ">apache</span><span style="color: #000000; ">-</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">2</span><span style="color: #000000; ">.</span><span style="color: #000000; ">*/</span><span style="color: #000000; ">lib</span><span style="color: #000000; ">/</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">cli</span><span style="color: #000000; ">-</span><span style="color: #000000; ">2</span><span style="color: #000000; ">.</span><span style="color: #000000; ">*</span><span style="color: #000000;">.jar org.apache.hadoop.hive.cli.CliDriver</span></div></div></div></div></div><img src ="http://www.aygfsteel.com/yuxh/aggbug/432418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yuxh/" target="_blank">yuxh</a> 2017-03-29 16:01 <a href="http://www.aygfsteel.com/yuxh/archive/2017/03/29/432418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JBoss Forge 2入门教程http://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.htmlyuxhyuxhWed, 23 Sep 2015 13:14:00 GMThttp://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.htmlhttp://www.aygfsteel.com/yuxh/comments/427327.htmlhttp://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/427327.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/427327.html阅读全文

yuxh 2015-09-23 21:14 发表评论
]]>
appfuse3.5打印Hibernate sql参数http://www.aygfsteel.com/yuxh/archive/2015/07/22/426376.htmlyuxhyuxhWed, 22 Jul 2015 06:11:00 GMThttp://www.aygfsteel.com/yuxh/archive/2015/07/22/426376.htmlhttp://www.aygfsteel.com/yuxh/comments/426376.htmlhttp://www.aygfsteel.com/yuxh/archive/2015/07/22/426376.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/426376.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/426376.htmlappfuse3.5使用Hibernate4.3.6, 而Hibernate日志框架使用了jboss-loggingQ想在后台打出sql的参C直无法生效?/div>
查配|文Ӟ框架里面的两个配|文Ӟsrc/test/resources/log4j2.xmlQ单元测试时配置Q,src/main/resources/log4j2.xmlQ运行时配置Q?/div>
搞清log4j2的配|后Q各U修改(主要?/div>
  <Logger name="org.hibernate.SQL" level="trace"/>
  <Logger name="org.hibernate.type" level="trace"/>)
用junit试ȝ无法打印出真实参数。根据这些实践,定log4j2是用无误生效的Q只是org.hibernateq部分的logger一直未h
参考国内外|站Q一直无人回{hibernate4的这个问题,有h指出q部分Hibernate官方文档只是提了一句,一直未更新相关内容。最后有人提到应该是 jboss-logging ?/span>LoggerProvidersq个cȝ问题Q看实现对log4j2已经做支持。最后发?nbsp;jboss-logging使用的是3.2.0.betaQ对比相关类的源代码Q更改ؓ(f)3.2.0.FinalQ生效!

P.S 把这个问题提交给Appfuse官网Qissue APF-1478Q作者标志ؓ(f)4.0版本修复?/span>


yuxh 2015-07-22 14:11 发表评论
]]>Andriod webview实现文g上传http://www.aygfsteel.com/yuxh/archive/2012/03/12/371715.htmlyuxhyuxhMon, 12 Mar 2012 04:54:00 GMThttp://www.aygfsteel.com/yuxh/archive/2012/03/12/371715.htmlhttp://www.aygfsteel.com/yuxh/comments/371715.htmlhttp://www.aygfsteel.com/yuxh/archive/2012/03/12/371715.html#Feedback1http://www.aygfsteel.com/yuxh/comments/commentRss/371715.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/371715.html
Andriod ?.2版本为止Qwebview方式下?lt;input type="file" />点击后都没有反应。实际上层是有隐含的接口没实现的,可以自己重写q个Ҏ(gu)来实现。以phonegapZQ?br />
public class App extends DroidGap {
    
private ValueCallback<Uri> mUploadMessage;
    
private final static int FILECHOOSER_RESULTCODE = 1;

    
/** Called when the activity is first created. */
    @Override
    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
super.init();
        
// WebView wv = new WebView(this);
        
// wv.setWebViewClient(new WebViewClient());
        this.appView.setWebChromeClient(new CordovaChromeClient(App.this) {
            
// For Android 3.0+
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                mUploadMessage 
= uploadMsg;
                Intent i 
= new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType(
"image/*");
                App.
this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
            }

            
// The undocumented magic method override
            
// Eclipse will swear at you if you try to put @Override here
            public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                mUploadMessage 
= uploadMsg;
                Intent i 
= new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType(
"image/*");
                App.
this.startActivityForResult(Intent.createChooser(i, "File Chooser"), App.FILECHOOSER_RESULTCODE);
            }
        });

        
// setContentView(wv);
        super.loadUrl("file:///android_asset/www/login.html");
    }

    @Override
    
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        
if (requestCode == FILECHOOSER_RESULTCODE) {
            
if (null == mUploadMessage)
                
return;
            Uri result 
= intent == null || resultCode != RESULT_OK ? null : intent.getData();
            mUploadMessage.onReceiveValue(result);
            mUploadMessage 
= null;
        }
    }
}
如果直接的webview方式Qextends WebChromeClient卛_? 参考:(x)http://stackoverflow.com/questions/5907369/file-upload-in-webview

yuxh 2012-03-12 12:54 发表评论
]]>RCP与Document风格http://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.htmlyuxhyuxhSat, 08 Oct 2011 13:47:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.htmlhttp://www.aygfsteel.com/yuxh/comments/360224.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/10/08/360224.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/360224.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/360224.html有两USOAP message风格Q?em>document ?em>RPCQ?/em>他们定义了SOAP message body的格式。用document风格Ӟ包括wrapped和unwrappedQ,在wsdl中有一个非I的types部分Q这个部分用XML Schema language定义了web service要用到的cd?em>wsgen工具从SIBQ有SEIp够了Q中生成与XSD对应的javacR用java代码生成WSDL文g的时候需要一些javac,wsgen工具可以生成q些Javac,生成的这些javac被UCؓ(f)wsgen artifactsQ底层的JWScd?x)用到这些类Q特别是JAX-Bpd的包Q会(x)用来转换(marshal)javacd?that is, Java in-memory objects)为XMLcd的XML实例Q满XML Schema document的XML文档实例Q,

The inverse operation is used to convert (unmarshal) an XML document instance to an in-memory
object, an object of a Java type or a comparable type in some other language。因?em>wsgen工具生成的artifactsQ支持了Java为基的web service的互操作性。JAX-Bcd提供了Java和XSDcd转换的底层支持?/p>

For the most part, the wsgen utility can be used without our bothering to inspect the artifacts that it produces. For the most part, JAX-B remains unseen infrastructure.

wsgen artifacts实际上是wsdl message的数据类型,他们和XML Schema typel定Q每个message的XML Schema types从这些javacd得来的。注Q在当前的jdk1.6.24中,已经融入wsgen自动生成的过E,不需手动调用?/p>

wsgen工具可用来生成wsdl文gQ如Q? wsgen -cp "." -wsdl ch01.ts.TimeServerImpl 。这为TimeServer服务生成了wsdl。用wsgen生成的wsdl和通过讉K发布的服务生成的wsdl 有个很大的区别:(x)wsgen生成的没有endpoint,因ؓ(f)q个URL是在发布服务的时候决定的。其他地方两个wsdl是相同的?/p>

wsimport(以前叫wsdl2java?java2wsdl更Ş?em>)工具可用WSDL生成用来帮助写客L(fng)的artifacts .

1 先契U再~码方式
一个例子:(x)得到一个tempConvert.wsdl文gQ用命?wsimport -keep -p ch02.tc tempConvert.wsdl Q命令根据wsdl的portType生成一个SEIc,把SEI的interface换ؓ(f)classQ再把方法改为实现就可变为SIB。把该SIB发布Q再使用命o(h)wsimport -keep -p clientTC http://localhost:5599/tc?wsdlQ来生成客户端辅助类
2 ~码优先
服务被发布之后,?x)自动生成WSDL供客L(fng)使用。然而,使用annotations可以控制WSDL或WSDL-generated artifacts的生成?/p>

yuxh 2011-10-08 21:47 发表评论
]]>
区分getPath(), getAbsolutePath(), getCanonicalPath()http://www.aygfsteel.com/yuxh/archive/2011/06/24/352951.htmlyuxhyuxhFri, 24 Jun 2011 05:42:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/06/24/352951.htmlhttp://www.aygfsteel.com/yuxh/comments/352951.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/06/24/352951.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/352951.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/352951.html

来自

http://stackoverflow.com/questions/1099300/whats-the-difference-between-getpath-getabsolutepath-and-getcanonicalpath

C:\temp\file.txt" - this is a path, an absolute path, a canonical path

.\file.txt This is a path, It's not an absolute path nor canonical path.

C:\temp\myapp\bin\..\\..\file.txt This is a path, and an absolute path, it's not a canonical path

Canonical path is always an absolute path.

Converting from a path to a canonical path makes it absolute (通常?x)处理改变当前目录,所以像. ./file.txt 变ؓ(f)c:/temp/file.txt). The canonical path of a file just "purifies" the path, 去除和解析类?#8220; ..\” and resolving symlinks(on unixes)

In short:

  • getPath() gets the path string that the File object was constructed with, and it may be relative current directory.
  • getAbsolutePath() gets the path string after resolving it against the current directory if it's relative, resulting in a fully qualified path.
  • getCanonicalPath() gets the path string after resolving any relative path against current directory, and removes any relative pathing (. and ..), and any file system links to return a path which the file system considers the canonical means to reference the file system object to which it points.

Also, each of this has a File equivalent which returns the corresponding File object.

The best way I have found to get a feel for things like this is to try them out:

import java.io.File;
public class PathTesting {
        public static void main(String [] args) {
                File f = new File("test/.././file.txt");
                System.out.println(f.getPath());
                System.out.println(f.getAbsolutePath());
                try {
                        System.out.println(f.getCanonicalPath());
                }
                catch(Exception e) {}
        }
}

Your output will be something like:

test\..\.\file.txt
C:\projects\sandbox\trunk\test\..\.\file.txt
C:\projects\sandbox\trunk\file.txt

So, getPath() gives you the path based on the File object, which may or may not be relative; getAbsolutePath() gives you an absolute path to the file; and getCanonicalPath() gives you the unique absolute path to the file. Notice that there are a huge number of absolute paths that point to the same file, but only one canonical path.

When to use each? Depends on what you're trying to accomplish, but if you were trying to see if two Files are pointing at the same file on disk, you could compare their canonical paths.


yuxh 2011-06-24 13:42 发表评论
]]>
XML介绍http://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.htmlyuxhyuxhThu, 24 Mar 2011 01:05:00 GMThttp://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.htmlhttp://www.aygfsteel.com/yuxh/comments/346908.htmlhttp://www.aygfsteel.com/yuxh/archive/2011/03/24/346908.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/346908.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/346908.htmlDTDs

Introduced as part of the XML 1.0 specification, DTDs are the oldest constraint model around in the XML world. They're simply to use, but this simplicity comes at a price: DTDs are inflexible, and offer you little for data type validation as well.

XML Schema (XSD)

XML Schema is the W3C's anointed successor to DTDs. XML Schemas are literally orders of magnitude more flexible than DTDs, and offer an almost dizzying array of support for various data types. However, just as DTDs were simple and limited, XML Schemas are flexible, complex, and (some would argue) bloated. It takes a lot of work to write a good schema, even for 50- or 100-line XML documents. For this reason, there's been a lot of dissatisfaction with XML Schema, even though they are widely being used.

[prefix]:[element name]
元素Q?br>root元素必须包含所有文档中的元素,只能有一个root元素。元素名只能以下划线或字母开_(d)不能有空|区分大小写。开元素必须有对应闭元素Q也有类似html的简写,?lt;img src="http://www.aygfsteel.com/images/xml.gif" />Q。文档由DTD或schema来限制它是否合格?/pre>
属性:(x)
什么时候用属性?基本原则Q多个值的数据用元素,单值的数据用元素。如果数据有很多值或者比较长Q数据最可能属于元素。他主要被当作文本,?lt;rss:author>Doug Hally</rss:author> <journal:author>Neil Gaiman</journal:author>易搜索,好用。比如一本书的章节描q。然而如果数据主要作为单值处理的话,最好作为属性。如果搞不清楚,可以安全的用元素?/pre>
命名I间NamespacesQ?br>xml的命名空间是一U用一个特定的URI来关联XML文档里的一个或多个元素的方法。意味着元素是由名字和命名空间一h识别的。许多复杂的XML文g里,同一个名字会(x)有多个用途。比如,一个RSS feed有一个作者,q个作者同时是每个日记的。虽然这些数据都用author元素来表C,但他们不应该被当作同一?em>cd的数据。命名空间很好的解决了这个问题,命名I间说明书要求一个前~和唯一的URI联合h区分不同命名I间里的元素。如http://www.neilgaiman.com/entries作ؓ(f)URIQ联合前~journal用来表示日志相关的元素?br><rdf:RDF xmlns:rss="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:journal="http://www.neilgaiman.com/entries">Q然后就可用了Q?br><rss:author>Doug Hally</rss:author> <journal:author>Neil Gaiman</journal:author>实际上在使用命名I间前缀的时候再定义也可以的Q?br><rss:author xmlns:rss="http://www.w3.org/1999/02/22-rdf-syntax-ns#">Doug Hally</rss:author>
如果名字没有命名I间Q不代表在默认命名空间中Q而是xml处理器以在Q何命名空间以外方式解释他。要声明默认命名I间的话׃用后面冒号部分,?lt;Insured xmlns="使用的一些术?/strong>:
  • The name of a namespace (such as http://www.ibm.com/software) is the namespace URI.

  • The element or attribute name can include a prefix and a colon (as in prod:Quantity). A name in that form is called a qualified name, or QName, and the identifier that follows the colon is called a local name. If a prefix is not in use, neither is the colon, and the QName and local name are identical.

  • An XML identifier (such as a local name) that has no colon is sometimes called an NCName. (The NC comes from the phrase no colon.)

Entity references:
用来处理转义字符Q语法是& [entity name] ;XML解析器碰到这Uentity referenceQ就?x)用对应的值替换掉他。如&lt;Q?lt;Q?&gt;(>),&amp;(&),&quot;("),&apos;(')。注意entity reference是用户可定义的。比如多处用到版权提C,自己定义后以后更改就方便了:(x)<ora:copyright>&OReillyCopyright;</ora:copyright>。除了用来表C数据中的复杂或Ҏ(gu)字符外,entity referenceq会(x)有更多用途?/p>

不解析的数据Q?br>当传输大量数据给应用且不用xml解析的时候,CDATA有用了。当大量的字W需要用entity reference转义的时候,或空格必M留的时候,使用CDATA?lt;![CDATA[?]]>



yuxh 2011-03-24 09:05 发表评论
]]>js分割csv文g http://www.aygfsteel.com/yuxh/archive/2010/12/03/339669.htmlyuxhyuxhFri, 03 Dec 2010 01:06:00 GMThttp://www.aygfsteel.com/yuxh/archive/2010/12/03/339669.htmlhttp://www.aygfsteel.com/yuxh/comments/339669.htmlhttp://www.aygfsteel.com/yuxh/archive/2010/12/03/339669.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/339669.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/339669.htmlhttp://www.bennadel.com/blog/1504-Ask-Ben-Parsing-CSV-Strings-With-Javascript-Exec-Regular-Expression-Command.htmQ把csv文g按分隔符切割后放在数l中?
// This will parse a delimited string into an array of arrays. 
   // The default delimiter is the comma, but this

// can be overriden in the second argument.
    CSVToArray:function(strData, strDelimiter){
 
        
// Check to see if the delimiter is defined. If not,
        // then default to comma.
        strDelimiter = (strDelimiter || ",");
        
// Create a regular expression to parse the CSV values.
        var objPattern = new RegExp(
            (
                
// Delimiters.
                "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
 
                
// Quoted fields.
                "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
 
                
// Standard fields.
                "([^\"\\" + strDelimiter + "\\r\\n]*))"
            ),
            
"gi"
            );
 
 
        // Create an array to hold our data. Give the array
        // a default empty first row.
        var arrData = [[]];
 
        // Create an array to hold our individual pattern
        // matching groups.
        var arrMatches = null;
 
 
        // Keep looping over the regular expression matches
        // until we can no longer find a match.
        while (arrMatches = objPattern.exec( strData )){
 
            // Get the delimiter that was found.
            var strMatchedDelimiter = arrMatches[ 1 ];
 
            // Check to see if the given delimiter has a length
            // (is not the start of string) and if it matches
            // field delimiter. If id does not, then we know
            // that this delimiter is a row delimiter.
            if (
                strMatchedDelimiter.length &&
                (strMatchedDelimiter != strDelimiter)
                ){
 
                // Since we have reached a new row of data,
                // add an empty row to our data array.
                arrData.push( [] );
            }
 
 
            // Now that we have our delimiter out of the way,
            // let's check to see which kind of value we
            // captured (quoted or unquoted).
            if (arrMatches[ 2 ]){
 
                // We found a quoted value. When we capture
                // this value, unescape any double quotes.
                var strMatchedValue = arrMatches[ 2 ].replace(
                    new RegExp( 
"\"\"""g" ),
                    
"\""
                    );
 
            }
 else {
 
                
// We found a non-quoted value.
                var strMatchedValue = arrMatches[ 3 ];
            }

 
 
            
// Now that we have our value string, let's add
            // it to the data array.
            arrData[ arrData.length - 1 ].push( strMatchedValue );
        }
 
        
// Return the parsed data.
        return( arrData );
    }


yuxh 2010-12-03 09:06 发表评论
]]>
Java PuzzlersQ三-?循环Q?/title><link>http://www.aygfsteel.com/yuxh/archive/2010/11/15/338121.html</link><dc:creator>yuxh</dc:creator><author>yuxh</author><pubDate>Mon, 15 Nov 2010 11:59:00 GMT</pubDate><guid>http://www.aygfsteel.com/yuxh/archive/2010/11/15/338121.html</guid><wfw:comment>http://www.aygfsteel.com/yuxh/comments/338121.html</wfw:comment><comments>http://www.aygfsteel.com/yuxh/archive/2010/11/15/338121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yuxh/comments/commentRss/338121.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yuxh/services/trackbacks/338121.html</trackback:ping><description><![CDATA[<p>31 <br>while (i != 0)<br>    i >>>= 1; //无符号右U,不管正负左边都是?<br>Z表达式合法,q里的i必须是整?<tt>byte</tt>, <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, or <tt>long</tt>)。谜题的关键在于<tt>>>>=</tt> 是一个复合赋值操作符Q不q的是复合赋值操作符?x)默默的?span class="docEmphasis">narrowing primitive conversionsQ即从一个数据类型{换ؓ(f)一个更的数据cd?span class="docEmphStrong">Narrowing primitive conversions can lose information about the magnitude or precision of numeric values</span>。ؓ(f)了问题更具体,假设q样定义Q?br>short i = -1; 因ؓ(f)初始值i (<tt>(short)0xffff</tt>) 非零Q@环执行。第一步位UM(x)把i提升为int?tt>short</tt>, <tt>byte</tt>, or <tt>char</tt>cd的操作数都会(x)做这L(fng)操作。这?span class="docEmphasis">widening</span> primitive conversionQ没有信息丢失。这U提升有W号扩展Q因此结果是int?tt>0xffffffff</tt>。无W号右移一位生int?tt>0x7fffffff</tt>。ؓ(f)了把int值存回short变量QJava执行了可怕的narrowing primitive conversion,即简单去掉高十六位。这样又变回?tt>(short)0xffff</tt>。如果定义类?tt>short</tt> or <tt>byte</tt>型的负数Q都?x)得到类似结果。你如果定义的是char话,则不?x)无限@环,因ؓ(f)char值非负,位移之前的宽扩展不会(x)做符h展?br><br>ȝQ?span style="color: red">不要?tt>short</tt>, <tt>byte</tt>, or <tt>char</tt>变量上用复合赋值操作符</span>。这U表辑ּq行混合cd计算Q非常容易؜淆。更p糕的是隐含的窄映射?x)丢掉信息?br><br>32 <br>while (i <= j && j <= i && i != j) {}<br><tt>i <= j</tt> and <tt>j <= i</tt>, surely <tt>i</tt> must equal <tt>j</tt>Q对于实数来说是q样的。他非常重要Q有个名Uͼ(x)The ?relation on the real numbers is said to be <span id="wmqeeuq" class="docEmphasis">antisymmetric。Java's <tt><=</tt> operator used to be antisymmetric before release 5.0, but no longer.Java 5之前数据比较W号(<tt><, <=</tt>, <tt>></tt>, and <tt>>=</tt>) 需要两边的操作数必Mؓ(f)基础cd(<tt>byte</tt>, <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, <tt>float</tt>, or <tt>double).在Java 5变ؓ(f)两边操作Cؓ(f)凡是可{变ؓ(f)基础cd的类型。java 5引入autoboxing and auto-unboxing 。The boxed numeric types are <tt>Byte</tt>, <tt>Character</tt>, <tt>Short</tt>, <tt>Integer</tt>, <tt>Long</tt>, <tt>Float</tt>, and <tt>Double。具体点Q让上面q入无限循环Q?br></tt></tt></span>Integer i = new Integer(0);<br>Integer j = new Integer(0);<br> (<tt>i <= j</tt> and <tt>j <= i</tt>) perform <span id="wmqeeuq" class="docEmphasis">unboxing conversions</span> on <tt>i</tt> and <tt>j</tt> and compare the resulting <tt>int</tt> values numerically。i和j表示0Q所以表辑ּ为true?tt>i != j</tt>比较的是对象引用Q也为true。很奇怪规范没有把{号改ؓ(f)比较倹{原因很单:(x)兼容性。当一U语aq泛应用的时候,不能破坏已存在的规范来改变程序的行ؓ(f)。System.out.println(new Integer(0) == new Integer(0));L输出falseQ所以必M留。当一个是boxed numeric cdQ另一个是基本cd的时候可以值比较。因为java 5之前q是非法的,具体点:(x)<br>System.out.println(new Integer(0) == 0); //之前的版本非法,Java 5输出True<br>ȝQ?span style="color: red">当两边的操作数是boxed numericcd的时候,数字比较W和{于W号是根本不同的Q数字比较符是值比较,{号比较的是对象引用</span>?br><br>33 <br>while (i != 0 && i == -i) {}<br>有负可Ci一定是数字QNaN不行Q因Z不等于Q何数。事实上Q没有实数可以出现这U情c(din)但Java的数字类型ƈ没有完美表达实数。QҎ(gu)׃个符号位Q一个有效数字(数Q,一个指数构成。QҎ(gu)只有0才会(x)和自q负数相等Q所以i肯定是整数。有W号整数用的是二q制补码计算Q取反加一。补码的一大优势是用一个唯一的数来表C?。然而有一个对应的~点Q本来可表达偶数个|现在用一个表达了0Q剩下奇C来表C正负数Q意味着正数和负数的数量不一栗比如int|他的<tt>Integer.MIN_VALUE</tt>Q?tt>-2</tt><sup>31</sup>Q。十六进制表?tt>0x8000000</tt>。通过补码计算可知他的负数仍然不变。对他取负数是溢Z的,不过Java在整数计中忽略了溢出?br>ȝQJava使用二进制补码,是不对称的。有W号整数(<tt>int</tt>, <tt>long</tt>, <tt>byte</tt>, and <tt>short</tt>) 负数值比整数值多一个?br><br>34<br>        final int START = 2000000000;<br>        int count = 0;<br>        for (float f = START; f < START + 50; f++)<br>            count++;<br>        System.out.println(count);<br>注意循环变量是float。回忆谜?8 Q明显f++没有M作用。f的初始化值接q?tt>Integer.MAX_VALUE</tt>Q因此需?1位来准确表达Q但是floatcd只提供了24位精度。增加这样大的一个floatg?x)改变倹{看h?x)死循环Q运行程序会(x)发现Q输?。@环中f?tt>(float)(START + 50)做比较。但int和float比较的时候,自动把int先提CZؓ(f)float。不q的是三个会(x)引v_ֺ丢失的宽基本cd转换的其中之一Q另外两个是long到floatQlong到doubleQ。f的初始值巨大,?0再{换ؓ(f)float和直接把f转换为float是一L(fng)效果Q即<tt>(float)2000000000 == 2000000050Q所?tt>f < START + 50</tt> p|。只要把float改ؓ(f)int卛_修正?br></tt></tt>     没有计算器,你怎么知道 2,000,000,050 和float表示2,000,000,000一P…?br>The moral of this puzzle is simple: <span style="color: red" class="docEmphStrong">Do not use floating-point loop indices</span>, because it can lead to unpredictable behavior. If you need a floating-point value in the body of a loop, take the <tt>int</tt> or <tt>long</tt> loop index and convert it to a <tt>float</tt> or <tt>double</tt>. <span id="wmqeeuq" class="docEmphStrong">You may lose precision when converting an <tt>int</tt> or <tt>long</tt> to a <tt>float</tt> or a <tt>long</tt> to a <tt>double</tt></span>, but at least it will not affect the loop itself. <span id="wmqeeuq" class="docEmphStrong">When you use floating-point, use <tt>double</tt> rather than <tt>float</tt></span> unless you are certain that <tt>float</tt> provides enough precision <span id="wmqeeuq" class="docEmphasis">and</span> you have a compelling performance need to use <tt>float</tt>. The times when it's appropriate to use <tt>float</tt> rather than <tt>double</tt> are few and far between?br></span></p> <p><span id="wmqeeuq" class="docEmphasis">35 <br></span><span id="wmqeeuq" class="docEmphasis">下面E序模拟一个简单的旉<br>int minutes = 0; <br>for (int ms = 0; ms < 60*60*1000; ms++) <br>  if (ms %  60*1000 == 0) <br>     minutes++; <br> </span><span id="wmqeeuq" class="docEmphasis">System.out.println(minutes); </span><span id="wmqeeuq" class="docEmphasis"><br>l果?tt>60000Q问题在于布?yu)(dng)表辑ּms % 60*1000 == 0Q最单的修改Ҏ(gu)是:(x)if (ms % (60 * 1000) == 0) <br>更好的方法是<font color="#ff0000">用合适命名的帔R代替力数字</font>Q?/tt></span></p> <p><span id="wmqeeuq" class="docEmphasis"><tt></tt></span>private static final int MS_PER_HOUR = 60 * 60 * 1000; <br>private static final int MS_PER_MINUTE = 60 * 1000; <br>public static void main(String[] args) {<br>   int minutes = 0; <br>   for (int ms = 0; ms < MS_PER_HOUR; ms++) <br>     if (ms % MS_PER_MINUTE == 0) <br>        minutes++;<br>    System.out.println(minutes); <br>} <span id="wmqeeuq" class="docEmphasis"><br><font color="#ff0000">l不要用I格来分l;使用括号来决定优先</font></p></span><img src ="http://www.aygfsteel.com/yuxh/aggbug/338121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yuxh/" target="_blank">yuxh</a> 2010-11-15 19:59 <a href="http://www.aygfsteel.com/yuxh/archive/2010/11/15/338121.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java PuzzlersQ三-一 循环Q?/title><link>http://www.aygfsteel.com/yuxh/archive/2010/11/15/336547.html</link><dc:creator>yuxh</dc:creator><author>yuxh</author><pubDate>Mon, 15 Nov 2010 08:39:00 GMT</pubDate><guid>http://www.aygfsteel.com/yuxh/archive/2010/11/15/336547.html</guid><wfw:comment>http://www.aygfsteel.com/yuxh/comments/336547.html</wfw:comment><comments>http://www.aygfsteel.com/yuxh/archive/2010/11/15/336547.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yuxh/comments/commentRss/336547.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yuxh/services/trackbacks/336547.html</trackback:ping><description><![CDATA[<span style="color: #000000">24      <br />   for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {<br />         if (b == 0x90)<br />             System.out.print("Joy!");<br />     }<br /> <tt>Ox90</tt> 过了byte的取D?font face="Courier New">-128?27。byte和int比较是一U؜合类型比较。考虑个表辑ּ<tt>((byte)0x90 == 0x90)得到的是false。byte和int做比较的时候,Java先对byteq行了widening primitive conversion 再比较两个int倹{因为byte是有W号cdQ{变做了符h展,把负的byteD{换ؓ(f)相应的int倹{这个例子中(byte)0x90被{变ؓ(f)-112Q当然不{于int?<tt>0x90</tt>或者说+144。؜合比较总让惑,因ؓ(f)LpȝL升一个操作数来和另一U类型匹配。有几种方式可避免؜合比较。可以把int映射为byteQ之后比较两个byte|(x) <br /> if (b == (byte)0x90)<br />     System.out.println("Joy!");<br /> 另外Q可用mask抑制W号扩展Q把byte转换为intQ之后比较两个int|(x)<br /> if ((b & 0xff) == 0x90)<br />     System.out.println("Joy!");<br /> 但最好的Ҏ(gu)是把帔R值移出@环放到常量声明中?br /> <span id="wmqeeuq" class="docEmphStrong">    private static final byte TARGET = 0x90; // Broken!</span><br />     public static void main(String[] args) {<br />         for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++)<br />             if (b == TARGET)<br />                 System.out.print("Joy!");<br />     }<br /> 不幸的是Q上面编译通不q:(x)<tt>0x90</tt>对于bytecd来说不是一个有效倹{这样修改即可:(x)<br /> private static final byte TARGET = <span id="wmqeeuq" class="docEmphStrong">(byte)</span>0x90;<br /> <p class="docText">To summarize: <span id="wmqeeuq" class="docEmphStrong">Avoid mixed-type comparisons, because they are inherently confusing</span> (<a class="docLink" href="ch02lev1sec5.html#ch02lev1sec5">Puzzle 5</a>). To help achieve this goal, <span id="wmqeeuq" class="docEmphStrong">use declared constants in place of "magic numbers." </span>You already knew that this was a good idea; it documents the meanings of constants, centralizes their definitions, and eliminates duplicate definitions.现在你知道他q可以强制你为每一个常量定义适用的类型,避免一U؜合类型比较的来源?/p> <p class="docText">25 <br /> </span<br /> <font color="#000000">int j = 0;<br /> for (int i = 0; i < 100; i++)<br />   j = j++;<br /> System.out.println(j); //</font><font color="#000000">打印出的?<span></p> </font></tt></font> <p>问题出在 j = j++; {同于下列操作:(x)</p> <p>int tmp = j; j = j + 1; j = tmp; <br /> q次的教训和N7一P(x)<font color="#ff0000">在一个表辑ּ中不要给同一个变量赋Dq一ơ?/font></p> <p><font color="#000000">26</font></p> <p><font color="#000000">public static final int END = Integer.MAX_VALUE;<br /> public static final int START = END - 100;<br /> public static void main(String[] args) {<br />     int count = 0;<br />     for (int i = START; i <= END; i++)<br />        count++;<br />      System.out.println(count);<br /> }<br /> 看v来像100Q再仔细看@环是于{于Q应该是101Q结果是E序没有输出M|陷入一个死循环。问题出?tt>Integer.MAX_VALUEQ当l箋增加的时候,他?zhn)?zhn)变?tt>Integer.MIN_VALUE。如果你需要@环intD界,最好用long变量做烦引:(x)<br /> for (long i = START; i <= END; i++)  //输出101<br /> <font color="#ff0000">教训是:(x)<tt>int</tt>s are not integers。无Z时用基本cdQ注意边界倹{上溢或下溢?x)出C么情况?一般来说最好用大一点的cdQ基本类型是<tt>byte</tt>, <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, and <tt>long</tt>Q?/font>也可以不用longQ?/tt></tt></font></p> <p><font color="#000000">int i = START; <br /> do { <br />   count++; <br /> } while (i++ != END); <br /> 考虑到清晰和单,L用long索引Q除了一U特D情况:(x)如果要遍历所有int|q样用int索引的话?x)快两倍?br /> 一个@环四十亿int|调用Ҏ(gu)的常规用法:(x)</font><font color="#ff0000"></p> <pre><font color="#000000">// Apply the function f to all four billion int values int i = Integer.MIN_VALUE; do { f(i); } while (i++ != Integer.MAX_VALUE); </font></pre> <p><span style="color: #000000">27  位移<br /> <font color="#ff0000"><span style="color: #000000"><font style="color: #000000" color="#ff0000">Cjava是用二q制补码计算Q在M有符号基本类型中(<tt>byte</tt>, <tt>short</tt>, <tt>int</tt>, or <tt>long</tt>)都是用所有位|?来表C?1?<br /> </font><font color="#ff0000"><span style="color: #000000"><font color="#ff0000">        <span style="color: #000000"><font style="color: #000000" color="#ff0000">int i = 0;<br />         while (-1 << i != 0)       //左位U?br />             i++;<br />         System.out.println(i);<br /> </font>int型的-1?tt>0xffffffff</tt> 表示。不断左U,双?补位。移?2ơ,变ؓ(f)?Q蟩出@环打?2Q实际上E序?x)死循环。问题出?1<<32不等?而是{于-1Q因Z<span style="color: #ff0000">Uȝ号只用右Ҏ(gu)作数的低五位作ؓ(f)Ud距离</span>Q如果左操作数是long的话用六位。三个位UL作符Q?lt;<,>>,>>>都是q样。移动距LL0?1Q左Ҏ(gu)作数是long的话0?3。位U距ȝ32取模Q左Ҏ(gu)long则用64取模。给intgU?2位或llonggU?4位只?x)返回本w。所以不可能用位Ud全移除一个数据。幸q的是,有一个简单的办法解决q个问题。保存上一ơ的位移l果Q每一ơP代多Ud一位?br />         int distance = 0;<br />         for (int val = -1; val != 0; val <<= 1)<br />             distance++;<br />         System.out.println(distance);<br /> 修改后的E序说明了一个原则:(x)<span style="color: #ff0000">位移距离如果可能的话Q用帔R</span>?br /> 另外一个问题,许多E序员认为右UM个负的移动距,和左移一P反之亦然。事实上不是q样Q左UL左移Q右Ud是右UR负数距d留下低五位(long留六位)Q其余的|?变Z正数距离。比如,左移一个int?1的距,实际上是左移31位?br /> <br /> 28 无穷的表C?br /> for (int i = start; i <= start + 1; i++) {<br /> }<br /> 看v来@环两ơ就?x)结束,如果q样定义呢:(x)<br /> int start = Integer.MAX_VALUE - 1;//d@?br /> while (i == i + 1) {<br /> }<br /> q个不可能死循环Q如果i是无I呢QJava采用IEEE 754点数算术,用double或float来表C无I所以可以用M点数计表辑ּ得出无穷来初始化i。比如:(x)double i = 1.0 / 0.0;<br /> 更好的是可以利用标准库提供的帔R:double i = Double.POSITIVE_INFINITY;<br /> 事实上,Ҏ(gu)用不着用无I初始化i来引h循环。只要够大的QҎ(gu)够了:(x)double i = 1.0e40;<br /> q是因ؓ(f)点数越大,他的值和下一个数的DMp大。distribution of floating-point values is a consequence of their representation with a fixed number of <u>significant</u> bits. l够大的QҎ(gu)加一不会(x)改变|因ؓ(f)他不能填充这个数和下一个数之间的距RQҎ(gu)操作q回最接近准确数学l果的Q点倹{一旦两个相LQ点g间的距离大于2Q加1׃?x)有效果。floatcd来说Q超q?<sup>25</sup>Q或33,554,432Q再?无效;对double来说过2<sup>54</sup>Q接q?.8 x 10<sup>16</sup>Q再?无效?br />      盔R点C间的距离UCؓ(f)ulpQunit in the last place的羃写)。在Java 5?<tt>Math.ulpҎ(gu)被引入来计算float或double值的ulp?/tt></span></font></span></font></span></font></span></p> <p><span style="color: #000000"><font color="#ff0000"><span style="color: #000000"><font color="#ff0000"><span style="color: #000000"><font color="#ff0000"><span style="color: #000000"><tt>ȝQ?font color="#ff0000">不可能用float或double来表C无I另外,在一个大的QҎ(gu)上加一个小的QҎ(gu)Qg?x)改变。有点不合常理,实数q不是这栗记住二q制点数计只是近g实数计算?/font></tt></span></font></span></font></span></font></span></p> <p></font><font color="#ff0000"><span style="color: #000000"><span style="color: #000000"><span style="color: #000000"><span style="color: #000000"><tt>29 NaN</tt></span></span></span></span></font></span></span></p> <p>while (i != i) { } <br /> IEEE 754 点数计保留了一个特D值来来表CZ是数字的数量。NaN是Q点计不能很好定义的敎ͼ比如<tt>0.0 / 0.0。规范定?font color="#ff0000">NaN不等于Q何数包括自己</font>。因此double i = 0.0 / 0.0; 可让开始的{式不成立。也有标准库定义的常量:(x)</tt>double i = Double.NaN; 如果一个或多个操作Cؓ(f)NaNQ那么QҎ(gu)计算׃(x){于NaN?/p> <p>ȝQfloat和doule存在Ҏ(gu)的值NaNQ小心处理?/p> <p>30<br /> while (i != i + 0) { } q一ơ不能用float或者double?br /> <tt>+操作W除了数字,只能处理String?操作W会(x)被重载:(x)对于StringcdQ他做的是连接操作。如果操作数有非StringcdQ会(x)先做转换变ؓ(f)String之后再做q接。i一般用作数字,要是对String型变量这么命名容易引赯解?/tt></p> <p><tt>ȝQ?font color="#ff0000">操作W重载非常容易误gh。好的变量名Q方法名Q类名和好的注释对于E序的可L一样重要?/font></tt></p> <img src ="http://www.aygfsteel.com/yuxh/aggbug/336547.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yuxh/" target="_blank">yuxh</a> 2010-11-15 16:39 <a href="http://www.aygfsteel.com/yuxh/archive/2010/11/15/336547.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">ˮ</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>