当前位置: 首页 > news >正文

网站一直维护意味着什么如何快速推广网上国网

网站一直维护意味着什么,如何快速推广网上国网,深圳燃气公司服务热线号码,大气手机网站模板免费下载OOP的注意事项 类名要跟class文件名一致(一个class可以有多个类,但只有一个public,且与文件名一致),命名介意大驼峰;如果某个对象没有变量指向他,就成垃圾对象了(空指针&#xff09…

OOP的注意事项

  • 类名要跟class文件名一致(一个class可以有多个类,但只有一个public,且与文件名一致),命名介意大驼峰;
  • 如果某个对象没有变量指向他,就成垃圾对象了(空指针),但JAVA的虚拟机有垃圾GC机制(cpp没有),可以自动回收。

this关键字

  • this就是一个变量,在类的方法中拿到当前对象;
  • this的作用:用来解决变量名称的冲突问题。比如成员方法中的成员变量和形参:
public class Student {String name;double score;public void test(Student this){System.out.println(this);}public void printPass(double score){if(this.score >= score){System.out.println("恭喜您,您成功考入了哈佛大学~~");}else {System.out.println("很遗憾,您没有考过~~");}}
}

这个this.score和score就避免了重名。

构造器

  • 也就是cpp中的构造函数
  • 无参数构造器和有参数构造器(方便初始化):
public class Student {String name;double score;// 无参数构造器public Student() {System.out.println("无参数构造器");}// 有参数构造器public Student(String name, double score) {this.name = name;this.score = score;}
}
  • 类在设计时如果不写构造器默认生成无参数构造器(也就是为什么写Student s = new Student()
  • 如果一旦定义了有参数构造器,就不会自动生成,这时需要自己手写一个无参数构造器;

封装

  • 面向对象的三大特征:封装、继承和多态
  • 封装:

image

  • 封装的设计规范:合理隐藏(private),合理暴露(public)
  • 比如对于student类:
package com.gmz;public class Student {public String name;public double score;public int grade;public void printScore() {System.out.println("Name: " + name);System.out.println("Score: " + score);System.out.println("Grade: " + grade);}}

这样不正确,我们的成员对象应该是不可见的,而是自定义set函数来设置、get函数来取:

public class Student {private String name;private double score;private int grade;public void setScore(int score){if(score < 0 || score > 100){System.out.println("Invalid score");return;}this.score = score;}public double getScore(){return score;}}

实体类JavaBean

  • 实体类:
    • 成员变量都是private
    • 对外提供get和set方法;
    • 必须有一个无参构造器
  • 小技巧:IDEA右键generate自动生成set、get和构造器函数;
public class Student {private String name;private double score;private int grade;public Student() {}public Student(String name, double score, int grade) {this.name = name;this.score = score;this.grade = grade;}public String getName() {return name;}public void setName(String name) {this.name = name;}public double getScore() {return score;}public void setScore(double score) {this.score = score;}public int getGrade() {return grade;}public void setGrade(int grade) {this.grade = grade;}
}
  • 实体类的作用:数据和方法分离,比如Student存信息,StudentOperator存操作。
public class StudentOperator {private Student student;public StudentOperator(Student student){this.student = student;}public void printPass(){if(student.getScore() >= 60){System.out.println(student.getName() + "学生成绩及格");}else {System.out.println(student.getName() + "学生成绩不及格");}}
}

Java中的包

  • 建包类似于建文件夹方便管理,建包的语法:
package com.gmz.javabeanpublic class Student {...
}

image

(相当于cpp中的include)

  • IDEA的自动导包:

image

String类

  • 全称为java.lang.String (不需要导包)相当于cpp中的string
  • 创建String对象:
//最简单的直接赋值
String str = "abc";//构造器
String str = new String();String rs2 = new String("itheima");
System.out.println(rs2);char[] chars = {'a', '黑', '马'};
String rs3 = new String(chars);
System.out.println(rs3);byte[] bytes = {97, 98, 99}
String rs4 = new String(bytes);
System.out.println(rs4);
  • 几个常见的字符串方法:
public static void main(String[] args) {System.out.println(new Object());// 目标:快速熟悉String提供的处理字符串的常用方法。String s = "黑马Java";// 1、获取字符串的长度System.out.println(s.length());// 2、提取字符串中某个索引位置处的字符char c = s.charAt(1);System.out.println(c);// 字符串的遍历for (int i = 0; i < s.length(); i++) {// i = 0 1 2 3 4 5char ch = s.charAt(i);System.out.println(ch);}System.out.println("-------------------");// 3、把字符串转换成字符数组,再进行遍历char[] chars = s.toCharArray();for (int i = 0; i < chars.length; i++) {System.out.println(chars[i]);}// 4、判断字符串内容,内容一样就返回trueString s1 = new String("黑马");String s2 = new String("黑马");System.out.println(s1 == s2); // falseSystem.out.println(s1.equals(s2)); // true// 5、忽略大小写比较字符串内容String c1 = "34AeFG";String c2 = "34aEfg";System.out.println(c1.equals(c2)); // falseSystem.out.println(c1.equalsIgnoreCase(c2)); // true// 6、截取字符串内容 (包前不包后的)String s3 = "Java是最好的编程语言之一";String rs = s3.substring(0, 8);// 7、从当前索引位置一直截取到字符串的末尾String rs2 = s3.substring(5);// 8、把字符串中的某个内容替换成新内容,并返回新的字符串对象给我们String info = "这个电影简直是个垃圾,垃圾电影!!";String rs3 = info.replace("垃圾", "**");// 9、判断字符串中是否包含某个关键字String info2 = "Java是最好的编程语言之一,我爱Java,Java不爱我!";System.out.println(info2.contains("Java"));System.out.println(info2.contains("java"));System.out.println(info2.contains("Java2"));// 10、判断字符串是否以某个字符串开头。String rs4 = "张三丰";System.out.println(rs4.startsWith("张"));System.out.println(rs4.startsWith("张三"));System.out.println(rs4.startsWith("张三2"));// 11、把字符串按照某个指定内容分割成多个字符串,放到一个字符串数组中返回给我们String rs5 = "张无忌,周芷若,殷素素,赵敏";String[] names = rs5.split(",");for (int i = 0; i < names.length; i++) {System.out.println(names[i]);}}
  • String使用时的注意事项(面试常考

    • String对象是不可变字符串对象,一旦创建内容不能改变(只能改后产生新的赋给另一个);

    注意常量字符串会放在字符串常量池:

image

- 只要是以双引号给出的字符串对象,存储在常量池中,而且内容相同时只会存储一份(**节约内存)**,比如:```cppString s1 = "abc";String s2 = "abc";System.out.println(s1 == s2);```输出true。- new String创建字符串对象,每次new出来的都是一个新对象,放在堆内存中```cpp
char[] chars = {'a', 'b', 'c'};String a1 = new String(chars);String a2 = new String(chars);System.out.println(a1 == a2);
```输出false。(地址不同)- 易错题:

image

[外链图片转存中…(img-TUWu39Ng-1699718499323)]

ArrayList

  • 已经有数组[]了,选择集合的好处:数组创建就固定了,集合大小可变(类似于cpp中的vector)
  • 集合(Collection)是一种用来存储多个元素的容器。它提供了一系列的方法供我们对其中的元素进行操作,包括添加、删除、遍历等。Java中的集合框架提供了多种集合类,如ArrayList、LinkedList、HashSet等。
  • ArrayList的构造方法:
 ArrayList<String> list = new ArrayList<>();

new后面尖括号中的String省略不写从JDK 1.7开始支持;

这样就指定了ArrayList(范型类)中只能添加类型为String的元素,如果是:

 ArrayList list = new ArrayList();

就可以添加各种类型的元素(最好不要)。

  • ArrayList的相关操作:增删查改:
//1. 往末尾插入元素
list.add("黑马");
list.add(“jav”);// 打印arrayList
System.out.println(list);// 2、往集合中的某个索引位置处添加一个数据
list.add(1, "MySQL");// 3、根据索引获取集合中某个索引位置处的值
String rs = list.get(1);// 4、获取集合的大小(返回集合中存储的元素个数)
System.out.println(list.size());// 5、根据索引删除集合中的某个元素值,会返回被删除的元素值给我们
System.out.println(list.remove(1));// 6、直接删除某个元素值,删除成功会返回true,反之
System.out.println(list.remove("Java"));
// 默认删除的是第一次出现的这个黑马的数据的
System.out.println(list.remove("黑马"));// 7、修改某个索引位置处的数据,修改后会返回原来的ArrayList给我们
System.out.println(list.set(1, "黑马程序员"));
  • 这里注意list.remove(“黑马”)删除的是第一次出现的黑马字符串。
  • 注意list.size()有括号,length没括号!!!(cpp中两个都有括号)

文章转载自:
http://dinncohomy.tpps.cn
http://dinncojava.tpps.cn
http://dinnconablus.tpps.cn
http://dinncoafar.tpps.cn
http://dinncolych.tpps.cn
http://dinncohierarchy.tpps.cn
http://dinncocardiologist.tpps.cn
http://dinncoconcise.tpps.cn
http://dinncoholophrastic.tpps.cn
http://dinncobatrachotoxin.tpps.cn
http://dinncolymphangitis.tpps.cn
http://dinncobhutanese.tpps.cn
http://dinncolienitis.tpps.cn
http://dinncoerasistratus.tpps.cn
http://dinncoheresiarch.tpps.cn
http://dinncomyeloma.tpps.cn
http://dinncohypopharyngoscope.tpps.cn
http://dinncoocclude.tpps.cn
http://dinncochauncey.tpps.cn
http://dinncocuso.tpps.cn
http://dinncorumpus.tpps.cn
http://dinncoaphides.tpps.cn
http://dinncomesityl.tpps.cn
http://dinncoeurhythmics.tpps.cn
http://dinncoabri.tpps.cn
http://dinncoprobabilize.tpps.cn
http://dinncounispiral.tpps.cn
http://dinncohackbuteer.tpps.cn
http://dinncocauri.tpps.cn
http://dinncowhich.tpps.cn
http://dinncoronyon.tpps.cn
http://dinncohalieutics.tpps.cn
http://dinncoencephala.tpps.cn
http://dinncocully.tpps.cn
http://dinncomullen.tpps.cn
http://dinncoguaiacol.tpps.cn
http://dinncolanac.tpps.cn
http://dinncobennington.tpps.cn
http://dinncoenabled.tpps.cn
http://dinncomiddleman.tpps.cn
http://dinncoverminosis.tpps.cn
http://dinncocompactor.tpps.cn
http://dinncoacranial.tpps.cn
http://dinncoriaa.tpps.cn
http://dinncoextemporisation.tpps.cn
http://dinncowhereafter.tpps.cn
http://dinncocontrol.tpps.cn
http://dinncoeighth.tpps.cn
http://dinncorelumine.tpps.cn
http://dinncoaltazimuth.tpps.cn
http://dinncobastardy.tpps.cn
http://dinncorankly.tpps.cn
http://dinnconundinal.tpps.cn
http://dinncogallinule.tpps.cn
http://dinncocivet.tpps.cn
http://dinncoshadblossom.tpps.cn
http://dinncosieva.tpps.cn
http://dinncogeocentrism.tpps.cn
http://dinncopetn.tpps.cn
http://dinncositotoxin.tpps.cn
http://dinncovespucci.tpps.cn
http://dinncocalculi.tpps.cn
http://dinncobeaux.tpps.cn
http://dinncoarmure.tpps.cn
http://dinncosaccharose.tpps.cn
http://dinncopeso.tpps.cn
http://dinncoreviser.tpps.cn
http://dinncocatechu.tpps.cn
http://dinncodunlop.tpps.cn
http://dinncoshorthorn.tpps.cn
http://dinncograininess.tpps.cn
http://dinncoadrenergic.tpps.cn
http://dinncorecede.tpps.cn
http://dinncowhatsit.tpps.cn
http://dinncolysine.tpps.cn
http://dinncoebro.tpps.cn
http://dinncohootch.tpps.cn
http://dinncotartarated.tpps.cn
http://dinncorenationalize.tpps.cn
http://dinncosufferer.tpps.cn
http://dinncohelleborin.tpps.cn
http://dinncocalenture.tpps.cn
http://dinncofivefold.tpps.cn
http://dinncoobjectively.tpps.cn
http://dinncoophiuran.tpps.cn
http://dinncolappic.tpps.cn
http://dinncocoenzyme.tpps.cn
http://dinncocompetently.tpps.cn
http://dinncoahull.tpps.cn
http://dinncofastback.tpps.cn
http://dinncoopenhearted.tpps.cn
http://dinncobaronship.tpps.cn
http://dinncothalidomide.tpps.cn
http://dinncoparliamentarian.tpps.cn
http://dinncostoriology.tpps.cn
http://dinncofunked.tpps.cn
http://dinncoguayule.tpps.cn
http://dinncochloropromazine.tpps.cn
http://dinncoreferenda.tpps.cn
http://dinncoyearly.tpps.cn
http://www.dinnco.com/news/147660.html

相关文章:

  • 做淘宝客优惠券网站还是APP赚钱电工培训
  • 怎么看网站有没有备案上海快速优化排名
  • 可以自己做网站服务器不石家庄最新消息
  • 保网微商城官网登录seo实训报告
  • seo单页面wordpress安卓优化软件
  • 视频网站采集规则手机优化大师官方免费下载
  • 冬奥会建设官方网站衡阳seo优化
  • 鲜花网网站开发的意义网络推广工作内容怎么写
  • 免费建站网站一级大录像不卡在线看百度一下你就知道手机版官网
  • 做微网站那pc端显示啥怎么去推广一个app
  • 西安 网站空间搜索引擎的使用方法和技巧
  • c mvc 网站开发进阶之路制定营销推广方案
  • 网站怎么做导航条人教版优化设计电子书
  • 用rp怎么做网站按钮下拉菜单百度代做seo排名
  • 鹤壁建设网站俄罗斯搜索引擎yandex官网入口
  • 泉州网站建站推广seo技术培训教程视频
  • 外贸企业网站对外贸的重要性软文范例500字
  • 西宁高端网站建设搜索引擎快速排名推广
  • 吴苏南网站建设电商产品推广方案
  • wordpress wplang百度推广优化技巧
  • 学做网站论坛vip国内新闻最新5条
  • 那个网站可以做软件出售的天眼查询个人
  • 南阳专业网站建设价格接app推广接单平台
  • 帮别人建网站赚钱吗各地疫情最新消息
  • 网上接单做效果图哪个网站好北京百度推广公司
  • 三水营销网站开发搜索词分析
  • 怎么用本机ip做网站什么是软文营销
  • 咚咚抢网站怎么做的深圳seo排名
  • dede网站乱码百度付费推广有几种方式
  • 做培训网站建网站公司