实例介绍
测试开发类教程,让你短时间内掌握测试开发相关工作!
个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson java代码规范 对于规范,每个公司不一样,对于我们测试人员而言,不需要讲究太多,列举一 下 ●包名全小写,全由字母组成,不要带有数字,下划线之类的 比如: com.demo. baixiaosheng ●类名首字母大写,驼峰式命名全由字母组成,不要带有数字,下划线之类的 比如: public class UserInfo ●常量要加上 final修饰符,常量及变量名最好要有意乂。非静态类常量与变量 名也是驼峰式命名,最好全由字母组成,不要带有数字,下划线之类 比如: public fina| String username ●静态常量与变量最好仝由大写字母组成,非驼峰式,中间用下载线隔廾 比如: public static fina| String USER NAME ●方法名最好全由字母组成,驼峰式命名,首字母小写,不要带有数字,下划 线之类的 比如: public void addUser() 方法命名要有一定的意义,比如增加用户,方法名为 add user() 代码要养在加注释的习惯 java的大小写是敏感的 这是一些常用的规范,其它的规范大家可以参考各自公司的要求。 著名的" Hello world!" package com. demo. baixiaosheng: public class HelloWorld I public String helloWorld i public string getHelloNorld()i return helloworldi 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson public void setHelloworld(String helloWorld) this. hellonorld helloworld public HelloWorld(string helloworld) i this. hellonorld= helloworld; public HelloWorld()( public void outputHelloworld([ System. out. println(helloWorld)i public static void main(string[] args)t String helloworld =Hello World!! Helloworld h -new Helloworld(; h. setHelloNorld(helloNorld) h. outputHelloWorld( HelloWorld w= new Helloworld(hellonorld) w.outrutHelloworld()i 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson Java第二天 for while if I的使用规则 1.for与 While都是循环,其语法规则分别为: for (initialization: Boolean expression; update) //Statements for(declaration expression) //Statements while (boolean expression) //statements 2.分别举例:如果有一个数组,我们分别的用这三种循环体来遍历 package com. demo. baixiaosheng: public class loopIest i private int[ testArray new int[12,4,3,5,1i public void testForLoop()( for (int i =0; 1< testArraylength; i++) System. out.println(testArray[i]) 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson public void testForloopEnhance()f for (int 1: testArray) t Systen. out ntIn(i) public void testWhileloop(( int index =0; while (index<testArray length)t System. out. println(testArray[index]) index++i public static void main(string[] args)t LoopTest t =new LoopTest()i t.test彐 troop(); t. testForloorEnhance()i testWhileloop() 3.既然提到∫循环,有两个关键字就不得不提∫: break continue ) break:退出当前循环体 2) continue:退岀当次循环并继续下一次循环,即当次循环伓中 continue语 句下面的代码不执行,并再继续下一次循环 4.f是表示判断的一个关键字。 第3第4综合举例: private int[] testArray new int[](2,4,3, 5, 1)i public void testForLoop() for (int i=0; i testArray length; i++ 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson if(testArray[i]==3)i continue; System.ot, println( testArray[i]);//最后输出结果为2451 public void testForLoopEnhance()t for (int i testArray) System,out. print1n(i);//最后输出结果为243 i王(1==3){ breaki 静态变量的使用 1.概念 静态变量,涉及到的关键字是 static,通俗点说我们可以理解为全局变量 任何对象都可以对其进行修改。但如果加了 final关键字,就表示是一个静态常 量,也就是全局常量,其它对象只能随意拿来用,但不能修改其值(前提是修饰 符是 public。代码如下: package com. demo. baixiaoshengi public class staticDemo i public static String USER NAmE ="haixiaosheng"; package com. demo. baixiaosheng: 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson public class staticDemoTest public static void main(string[] args)i System. out. printin (StaticDemo USER NAME StaticDemo. USER NAME =ceshibaixiaosheng"i System. out. println(StaticDemo. USER NAME)i static这个关键字,还可川于静态块 package com. demo. baixiaosheng: public class staticDemoTest s七a七ic System. out. println ("Hello world! )i public static void main(string[] args)( System. out. println(StaticDemo. USER NAME)i StaticDemo. USER NAME=ceshibaixiaosheng"i System. out. println(StaticDemo USER NAME) 2.说明 静态块可以被称为非静态类屮的构造器!即在用到该类时,会被第一时间执行到 且只执行一次,一般用丁配置文件的加载。大家可以去自行查询一下java的变量加载 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson String字符串的基本方法 1.字符串的常用AP有 package com. demo. baixiaosheng; public class stringDemo i private String demostring =ceshihaixiaosheng public void teststring ()( String dsg= demostring. concat(" very good!");//字符串相加, 也可用+来表示 System. out. println(dsg); //# Hceshibaixiaosheng very good int len= demostring.1 ength();//字符串的长度 System.ot. print1n(1en);//输出17 b。 olean eg=" baixiaosheng".eqa1s( demostring);//比较两个字 符串是否相等 System.out. print1n(eq);/输出fase String sub= demostring.3 astring(5,8);//取子字符串,从第5 个字符开始,到第8个字符,但不包含第8个字符 Systerr.out. print1n(sub);//输出bai String substring= demostring. substring(5);//取子字符串,从 第5个字符开始一直到字符串尾 Syster out println(subString);// Hbaixiaosheng b1 ean Sw- demostring. tartswith(" ceshi");//判断是否以某 个字符串开头 System.out. print1n(sw);//输出true boo1 ean ew- demostring. endswith(" baixiaosheng");//判断是 不以某个字符串结尾 System. out printin(ew);//输出true int subIndex= demo string. indexof("oai");//找出子字符串在字 符串中第一次出现的 index,如果找不到则返回-1 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 个人博客:htt://www.cnblogs.com/zhangfei/p/GITHUB:htt:/github.com/zhangfei19841004/zson System.out. print1n( subIndex);//输出5 int astindex= cemostring.1 astindexof("e");//找出子字符串 在字符串中最后一次出现的 index,如果找不到则返回-1 System.out. print1n(1 astIndex);//输出14 System, out. print1n( demostring. toUrpercase();//字符串中的 字母全变成大写, CESHIBAIXIAOSHENG System. out. print1n( demostring. tolower case());//字符串中的 字母全变成小写, ceshibaixiaosheng System.out. println(" baixiaosheng".txim();//将字符串首尾 的空格去掉, baixiaosheng String subReplace demoString replace("ceshi",");//447- 符串中的某段子字符串替换成新的子字符串 Syster out println(subReplace);//Hbaixiaosheng tring subReplacef demoString replaceFirst("e","")i// 将字符串屮的某段第一次出现的子字符串替换成新的子字符串,支持正则 System. out. println(subReplaceF);//Licshibaixiaosheng String subReplaccA -demoString replaceAll("e,"");//13.f 符串屮的所有出现的子字符串替换成新的子字符串,支持正则 System. out. println( subReplaceA);//aHcshibaixiaoshng public static void main(String[] args)( String Demo s= new String demo()i s. teststring()i 基本数据类型与复合数据类型的关系 ava有8大基本数据类型及其对应的复合数据类型为 本文档是由再见珥想(QQ408129370个人编写,未绎授权,严禁转载。 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论