第二十六节:复习Java语言基础-Java的概述,匿名对象,封装,构造函数
![标题图](http://upload-images.jianshu.io/upload_images/11158618-c5e451bbe0c79f41.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Java基础
![什么是软件?.png](https://upload-images.jianshu.io/upload_images/11158618-f2a375ee976702d4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Java语言概述
![Java语言概述.png](https://upload-images.jianshu.io/upload_images/11158618-fe3fc099f55f5fb4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Java语言
语言 | 描述 |
---|---|
javaee | 企业版 |
javase | 标准版 |
javame | 小型版 |
JDK
JDK(Java开发工具包)
Java语言
语言 | Java语言 |
---|---|
Java | 关键字 |
Java | 标识符 |
Java | 注释 |
Java | 常量 |
Java | 变量 |
Java | 运算符 |
Java | 语句 |
Java | 函数 |
Java | 数组 |
语言 | 关键字 |
---|---|
特点 | 关键字中所有字母都为小写 |
![关键字等.png](https://upload-images.jianshu.io/upload_images/11158618-fc598c8e6d53658d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
标识符
由26个英文字母大小写,0-9 ,_ $ 组成,不能以数字开头,不能使用关键字
Java中区分大小写
注释
![注释.png](https://upload-images.jianshu.io/upload_images/11158618-fd48098f15541a5f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
常量与变量
![常量.png](https://upload-images.jianshu.io/upload_images/11158618-d9626ac10f43b917.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
数据类型
![图片](https://upload-images.jianshu.io/upload_images/11158618-c667040adae77071.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
运算符
算术运算符,赋值运算符,比较运算符,逻辑运算符,位运算符,三元运算符
位运算符
![图片](https://upload-images.jianshu.io/upload_images/11158618-b007d82be06769ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
流程控制
判断结构,选择结构,循环结构
if(条件表达式){
执行语句;
}
if(条件表达式){
执行语句;
}else{
执行语句;
}
if(条件表达式){
执行语句;
}else if (条件表达式){
执行语句;
}else{
执行语句;
}
switch(表达式){
case 值1:
执行语句;
break;
case 值2:
执行语句;
break;
...
default:
执行语句;
break;
}
while(条件表达式){
执行语句;
}
do {
执行语句;
}while(条件表达式);
for(初始化表达式;条件表达式;操作表达式){
执行语句;
}
break(跳出), continue(继续)
函数
![函数.png](https://upload-images.jianshu.io/upload_images/11158618-c5f0bef06c4987b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
// 返回两个整数的和
int add(int x,int y){
return x+y;
}
// 返回三个整数的和
int add(int x,int y,int z){
return x+y+z;
}
// 返回两个小数的和
double add(double x,double y){
return x+y;
}
数组
![数组.png](https://upload-images.jianshu.io/upload_images/11158618-04f2c464378ef67c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
内存结构
![图片](https://upload-images.jianshu.io/upload_images/11158618-a17ba8d9d48eccbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
常见问题
- 数组脚标越界异常
- 空指针异常
多线程
![多线程.png](https://upload-images.jianshu.io/upload_images/11158618-fcc0ff57b700f77b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
集合类
集合框架的构成及分类
![图片](https://upload-images.jianshu.io/upload_images/11158618-f9b358ecaf37b7a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
集合框架常用接口
![Collection接口.png](https://upload-images.jianshu.io/upload_images/11158618-babde904ee424e59.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
IO流
![IO流.png](https://upload-images.jianshu.io/upload_images/11158618-6eaf89d045ade0b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
字符流
创建文件步骤:
- FileWriter fw = new FileWriter(“Test.txt”);
- fw.write(“text”);
- fw.close();
读取文件步骤:
- FileReader fr = new FileReader(“Test.txt”);
- char[] ch = new char[1024];
- fr.read(ch);
![缓冲区.png](https://upload-images.jianshu.io/upload_images/11158618-9faf63db99511f4c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![字符流.png](https://upload-images.jianshu.io/upload_images/11158618-dc14ce042883c07a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![字节流.png](https://upload-images.jianshu.io/upload_images/11158618-c5eb14ffd60417c8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
匿名对象
什么是匿名对象,匿名对象是对象的简化形式,没有对象名,只能使用一次。
class Student
{
// 创建属性
Stinrg name;
int tall;
// 定义方法
void study()
{
System.out.println("好好学习"+name);
}
}
class Demo
{
// 定义主函数
public static void main(String[] args)
{
// 创建类的对象
// 类类型的变量一定指向对象
Student stu = new Student();
// 调用对象的成员
stu.name = "dashu";
// 调用对象的方法
stu.study();
}
}
匿名对象的调用
new Student().study();
匿名对象的出现就会在堆内存中,因为有new嘛,但是匿名对象一旦调用就成为垃圾。
代码的复用性
class Student(){
public static void mian(String[] args)
{
Student stu1 = new Student();
stu1.name = "dashucoding";
stu1.tall = 12;
stu1.study();
Student stu2 = new Student();
stu2.name = "dashucoding";
stu2.tall = 12;
stu2.study();
Student stu3 = new Student();
show(stu3);
// show(new Student());
}
// 定义功能,进行封装
public static void show(Student stu){
stu.name = "dashucoding";
stu.tall = 12;
stu.study();
}
}
封装
封装为了提稿代码的复用性,隐藏了实现的细节,提供对外的访问。
构造函数
在类中就有默认的空参数构造函数,只要定义了一个类,该类就有一个空参数的构造函数。
结语
- 本文主要讲解 复习Java语言基础-Java的概述,匿名对象,封装,构造函数
- 下面我将继续对
Java
、Android
中的其他知识 深入讲解 ,有兴趣可以继续关注 - 小礼物走一走 or 点赞
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步