手记

第二十六节:复习Java语言基础-Java的

标题图

Java基础

什么是软件?.png

Java语言概述

Java语言概述.png

Java语言

语言描述
javaee企业版
javase标准版
javame小型版

JDK

JDK(Java开发工具包)

Java语言

语言Java语言
Java关键字
Java标识符
Java注释
Java常量
Java变量
Java运算符
Java语句
Java函数
Java数组
语言关键字
特点关键字中所有字母都为小写

关键字等.png

标识符

由26个英文字母大小写,0-9 ,_ $ 组成,不能以数字开头,不能使用关键字
Java中区分大小写

注释

注释.png

常量与变量

常量.png

数据类型

图片

运算符

算术运算符,赋值运算符,比较运算符,逻辑运算符,位运算符,三元运算符

位运算符

图片

流程控制

判断结构,选择结构,循环结构

if(条件表达式){
 执行语句;
}
if(条件表达式){
 执行语句;
}else{
 执行语句;
}
if(条件表达式){
 执行语句;
}else if (条件表达式){
 执行语句;
}else{
 执行语句;
}
switch(表达式){ case 值1:
  执行语句;  break; case 值2:
  执行语句;  break;
   ... default:
  执行语句;  break;
}
while(条件表达式){
 执行语句;
}
do {
 执行语句;
}while(条件表达式);
for(初始化表达式;条件表达式;操作表达式){
 执行语句;
}

break(跳出),  continue(继续)

函数

函数.png

// 返回两个整数的和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

内存结构

图片

常见问题

  1. 数组脚标越界异常

  2. 空指针异常


多线程

多线程.png

集合类

集合框架的构成及分类

图片

集合框架常用接口

Collection接口.png

IO流

IO流.png

字符流

创建文件步骤:

  1. FileWriter fw = new FileWriter(“Test.txt”);

  2. fw.write(“text”);

  3. fw.close();

读取文件步骤:

  1. FileReader fr = new FileReader(“Test.txt”);

  2. char[] ch = new char[1024];

  3. fr.read(ch);

缓冲区.png

字符流.png

字节流.png

匿名对象

什么是匿名对象,匿名对象是对象的简化形式,没有对象名,只能使用一次。

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();
 }
}

封装

封装为了提稿代码的复用性,隐藏了实现的细节,提供对外的访问。



作者:达叔小生
链接:https://www.jianshu.com/p/364c3b6319fb


1人推荐
随时随地看视频
慕课网APP