首页 文章 精选 留言 我的

精选列表

搜索[估值水平],共10000篇文章
优秀的个人博客,低调大师

null或空值的判断处理

1,错误用法一: if (name == "") { //do something }2,错误用法二: if (name.equals("")) { //do something }3,错误用法三: if (!name.equals("")) { //do something } 我们来解说一下: 上述错误用法1是初学者最容易犯,也最不容易被发现的错误,因为它们的语法本身没问题,Java编译器编译时不报错。但这种条件可能在运行时导致程序出现bug,永远也不会为true,也就是时说,if块里的语句永远也不会被执行。 上述用法二,用法三 的写法,是包括很多Java熟手也很容易犯的错误,为什么是错误的呢?也许你会感到纳闷。 对,它们的写法本身没错,但是,少了一个null判断的条件,试想,如果name=null的情况下,会发生什么后果呢?后果是,你的程序将抛出NullPointerException异常,系统将被挂起,不再提供正常服务。 当然,如果之前已经对name作了null判断的情况例外。 正确的写法应该先加上name != null的条件,如例: if (name != null && !name.equals("")) { //do something } 或者 if (!"".equals(name)) {//将""写在前头,这样,不管name是否为null,都不会出错。 //do something } 下面,我们举一个简单的例子: TestNullOrEmpty.java public classTestNullOrEmpty { public static voidmain(String[] args) { String value = null; testNullOrEmpty(value); value = ""; testNullOrEmpty(value); value = " "; testNullOrEmpty(value); value = " hello me!"; testNullOrEmpty(value); } static voidtestNullOrEmpty(String value) { if(value == null) { //正确的写法 System.out.println(" value is null."); } else if("".equals(value)) { //正确的写法 System.out.println(" value is blank but not null."); } else{ System.out.println(" value is /"" + value + " /""); } if(value == "") { //NG 错误的写法 //别用这种写法 } } } 编译执行: c:/>javac TestNullOrEmpty.java c:/>JavaTestNullOrEmpty value is null. value is blank but not null. value is " " value is "hello me!"

优秀的个人博客,低调大师

ant 读取环境变量的值

参考:http://taink.iteye.com/blog/599735 [java] view plain copy print ? <!--指定环境变量参数为:SystemVariable--> <propertyenvironment="SystemVariable"/> <!--将tomcat.home指向环境变量TOMCAT_HOME指向的路径--> <propertyname="tomcat.home"value="${SystemVariable.TOMCAT_HOME}"/> <targetname="display"> <echomessage="${tomcat.home}"/> <mkdirdir="${tomcat.home}/test"/> </target> 实例 [java] view plain copy print ? <propertyname="manager.url"value="http://localhost:8080/manager"/> <!--指定环境变量参数为:SystemVariable--> <propertyenvironment="SystemVariable"/> <!--将tomcat.home指向环境变量TOMCAT_HOME指向的路径--> <propertyname="java.home"value="${SystemVariable.JAVA_HOME}"/> <targetname="compile"> <echomessage="${java.home}"/> <javacsrcdir="${src}" <classpathid="classpath"> <filesetdir="${java.home}\lib"><!--读取环境变量中的JAVA_HOME设置ant--> <includename="**/*.jar"/> </fileset> <filesetdir="${lib}"> <includename="**/*.jar"/> </fileset> </classpath> </javac> </target> 本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2011/11/21/2296929.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android Activity之间的传值示例

版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/78260581 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="online.geekgalaxy.activityargsdelivery"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MyActivity" android:label="@string/title_activity_my_activity2" > </activity> </application> </manifest> MainActivity.java package online.geekgalaxy.activityargsdelivery; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; public class MainActivity extends AppCompatActivity { private Button btnregister; private EditText editname; private RadioGroup rad; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnregister = (Button)findViewById(R.id.btnregister); editname = (EditText)findViewById(R.id.editname); rad = (RadioGroup)findViewById(R.id.radioGroup); btnregister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name,sex = ""; Intent it = new Intent(MainActivity.this,MyActivity.class); name = editname.getText().toString(); //遍历RadioGroup找出被选中的单选按钮 for(int i = 0;i < rad.getChildCount();i++) { RadioButton rd = (RadioButton)rad.getChildAt(i); if(rd.isChecked()) { sex = rd.getText().toString(); break; } } //新建Bundle对象,并把数据写入 Bundle bd = new Bundle(); bd.putCharSequence("user",name); bd.putCharSequence("sex",sex); //将数据包Bundle绑定到Intent上 it.putExtras(bd); startActivity(it); //关闭第一个Activity finish(); } }); } } MyActivity.java package online.geekgalaxy.activityargsdelivery; /** * Created by jailman on 2017/10/17. */ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MyActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_2); TextView txtshow = (TextView) findViewById(R.id.txtshow); //获得Intent对象,并且用Bundle出去里面的数据 Intent it = getIntent(); Bundle bd = it.getExtras(); //按键值的方式取出Bundle中的数据 String name = bd.getCharSequence("user").toString(); String sex = bd.getCharSequence("sex").toString(); txtshow.setText("尊敬的"+ name + " " + sex + "士"+"恭喜你,注册成功~"); } } layout activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请输入注册信息:"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:"/> <EditText android:hint="请输入用户名" android:id="@+id/editname" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性 别:" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/btnman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:checked="true"/> <RadioButton android:id="@+id/btnwoman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"/> </RadioGroup> </LinearLayout> <Button android:id="@+id/btnregister" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册"/> </LinearLayout> activity_2.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="online.geekgalaxy.activityargsdelivery.MyActivity"> <TextView android:id="@+id/txtshow" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> values strings.xml <resources> <string name="app_name">ActivityArgsDelivery</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <string name="title_activity_my_activity2">MyActivity2</string> </resources> build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "online.geekgalaxy.activityargsdelivery" minSdkVersion 25 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' }

优秀的个人博客,低调大师

MapReduce 按照Value值进行排序输出

文件输入: A 1 B 5 C 4 E 1 D 3 W 9 P 7 Q 2 文件输出: W 9 P 7 B 5 C 4 D 3 Q 2 E 1 A 1 代码如下: package comparator; import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.IntWritable.Comparator; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class comparator{ /** * @param args * @throws IOException * @throws IllegalArgumentException * @throws InterruptedException * @throws ClassNotFoundException */ public static class myComparator extends Comparator { @SuppressWarnings("rawtypes") public int compare( WritableComparable a,WritableComparable b){ return -super.compare(a, b); } public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { return -super.compare(b1, s1, l1, b2, s2, l2); } } public static class Map extends Mapper<Object,Text,IntWritable,Text>{ public void map(Object key,Text value,Context context) throws NumberFormatException, IOException, InterruptedException{ String[] split = value.toString().split("\t"); context.write(new IntWritable(Integer.parseInt(split[1])),new Text(split[0]) ); } } public static class Reduce extends Reducer<IntWritable,Text,Text,IntWritable>{ public void reduce(IntWritable key,Iterable<Text>values,Context context) throws IOException, InterruptedException{ for (Text text : values) { context.write( text,key); } } } public static void main(String[] args) throws IllegalArgumentException, IOException, ClassNotFoundException, InterruptedException { // TODO Auto-generated method stub Job job = new Job(); job.setJarByClass(comparator.class); job.setNumReduceTasks(1); //设置reduce进程为1个,即output生成一个文件 job.setMapperClass(Map.class); job.setReducerClass(Reduce.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(Text.class); //为job的输出数据设置key类 job.setOutputValueClass(IntWritable.class); //为job的输出设置value类 job.setSortComparatorClass( myComparator.class); //自定义排序 FileInputFormat.addInputPath(job, new Path(args[0])); //设置输入文件的目录 FileOutputFormat.setOutputPath(job,new Path(args[1])); //设置输出文件的目录 System.exit(job.waitForCompletion(true)?0:1); //提交任务 } }

优秀的个人博客,低调大师

马斯克称愿意帮助苹果,用 Grok 提升 Siri 智能水平

近日,马斯克在社交平台 X 上表态,表示愿意用 xAI 的最新模型 Grok 4.1 来“修复”苹果的语音助手 Siri。 起因是一位网友吐槽 Siri 表现迟缓、响应平平,并建议苹果直接改用 Grok,马斯克则回应 “I’m down(我愿意)”。 目前苹果方面尚未做出任何公开回应,双方也没有披露是否存在合作讨论。 马斯克旗下 AI 公司 xAI 近日正式推出 Grok 4.1,称这是一款前沿模型,为对话智能、情感理解和现实世界的实用性树立了新标准。 据介绍,Grok4.1 在创造性、情感互动、协作能力上大幅提升,同时保留此前的 “敏锐智能与可靠性”。为了实现上述提升,xAI 在 Grok 4 的大规模强化学习基础上,进一步优化了 “风格、人格、帮助性、与对齐”(alignment)等方面。其中特别使用了新的方法:以 “先进的代理(agentic)推理模型” 为奖励模型,自主评估并大规模迭代响应。

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册