美文网首页
我把Java基础编程及思维导图整理的超级详细,小白都能看懂

我把Java基础编程及思维导图整理的超级详细,小白都能看懂

作者: 可乐教编程 | 来源:发表于2020-10-08 21:35 被阅读0次

    Java基础编程及其思维导图

    目录:

    Java学习导图

    一、Java基本语法

    1.关键字与标识符 2.变量分类 3.运算符 4.流程控制

    二、数组

    1.数组概述 2.一维数组 3.二维数组 4.数组常见算法 5.Arrays工具类使用

    三、面向对象

    Java类及其类成员三大特性(封装、继承、多态)关键字

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    Java学习思维导图

    一、Java基本语法

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    Java基本语法

    1.关键字与标识符

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    关键字与标识符

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    2.变量分类

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    定义变量格式

    变量类型 变量名 = 变量值;

    变量类型 变量名;变量名 = 变量值;

    变量使用注意点

    ① 变量必须先声明,后使用

    ② 变量都定义在其作用域内。在作用域内,它是有效的。换句话说,出了作用域,就失效了

    ③ 同一个作用域内,不可以声明两个同名的变量

    基本数据变量运算规则

    自动类型转换:结论:当容量小的数据类型的变量与容量大的数据类型的变量做运算时,结果自动提升为容量大的数据类型。byte 、char 、short --> int --> long --> float --> double特别的:当byte、char、short三种类型的变量做运算时,结果为int型

    说明:此时的容量大小指的是,表示数的范围的大和小。比如:float容量要大于long的容量

    强制类型转换:

    1.需要使用强转符:()

    2.注意点:强制类型转换,可能导致精度损失。

    3.运算符

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    算术运算符: + - + - * / % (前)++ (后)++ (前)-- (后)-- +

    特别说明:

    1.(前)++ :先自增1,后运算

    (后)++ :先运算,后自增1

    2.(前)-- :先自减1,后运算

    (后)-- :先运算,后自减1

    3.连接符:+:只能使用在String与其他数据类型变量之间使用。

    复制运算符:= += -= *= /= %=

    特别说明:

    1.运算的结果不会改变变量本身的数据类型

    2.

    开发中,如果希望变量实现+1的操作,有几种方法?(前提:int num = 10;)

    //方式一:num = num + 1;

    //方式二:num += 1;

    //方式三:num++; (推荐)

    比较运算符:== != > < >= <= instanceof

    特别说明:

    1.比较运算符的结果是boolean类型

    2.> < >= <= :只能使用在数值类型的数据之间。

    3. == 和 !=: 不仅可以使用在数值类型数据之间,还可以使用在其他引用类型变量之间。

    逻辑运算符:& && | || ! ^

    特别说明的:

    1.逻辑运算符操作的都是boolean类型的变量。而且结果也是boolean类型

    2.区分& 与 &&

    相同点1:& 与 && 的运算结果相同

    相同点2:当符号左边是true时,二者都会执行符号右边的运算

    不同点:当符号左边是false时,&继续执行符号右边的运算。&&不再执行符号右边的运算。

    开发中,推荐使用&&

    3.区分:| 与 ||

    相同点1:| 与 || 的运算结果相同

    相同点2:当符号左边是false时,二者都会执行符号右边的运算

    不同点3:当符号左边是true时,|继续执行符号右边的运算,而||不再执行符号右边的运算

    开发中,推荐使用||

    位运算符:<< >> >>> & | ^ ~

    特别说明:

    位运算符操作的都是整型的数据

    <<:在一定范围内,每向左移1位,相当于 * 2

    >>: 在一定范围内,每向右移1位,相当于/2

    三元运算符:(条件表达式)? 表达式1 : 表达式2

    特别说明

    说明

    ① 条件表达式的结果为boolean类型

    ② 根据条件表达式真或假,决定执行表达式1,还是表达式2.

    如果表达式为true,则执行表达式1。

    如果表达式为false,则执行表达式2。

    ③ 表达式1 和表达式2要求是一致的。

    ④ 三元运算符可以嵌套使用

    凡是可以使用三元运算符的地方,都可以改写为if-else

    反之,不成立。

    如果程序既可以使用三元运算符,又可以使用if-else结构,那么优先选择三元运算符。原因:简洁、执行效率高。

    4.流程控制

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    分支结构:

    1.if-else条件判断结构

    结构一:

    if (条件表达式) {

    执行表达式

    }

    结构二:二选一

    if (条件表达式) {

    执行表达式1

    }else{

    执行表达式2

    }

    结构三:n选一

    if (条件表达式) {

    执行表达式1

    }else if (条件表达式) {

    执行表达式2

    }else if (条件表达式) {

    执行表达式3

    }

    else{

    执行表达式n

    }

    2.switch-case选择结构

    switch (表达式) {

    case 常量1:

    执行语句1;

    break;

    case 常量2:

    执行语句2;

    break;

    default:

    执行语句n;

    break;

    }

    循环结构:

    1.循环结构的四要素

    ① 初始化条件

    ② 循环条件 —>是boolean类型

    ③ 循环体

    ④ 迭代条件

    说明:通常情况下,循环结束都是因为②中循环条件返回false了。

    2.三种循环结构:

    2.1 for循环结构

    for(①;②;④){

    }

    执行过程:① - ② - ③ - ④ - ② - ③ - ④ - … - ②

    2.2 while循环结构

    while(②){

    ③;

    ④;

    }

    执行过程:① - ② - ③ - ④ - ② - ③ - ④ - … - ②

    说明:

    写while循环千万小心不要丢了迭代条件。一旦丢了,就可能导致死循环!

    for和while循环总结:

    开发中,基本上我们都会从for、while中进行选择,实现循环结构。for循环和while循环是可以相互转换的!

    区别:for循环和while循环的初始化条件部分的作用范围不同我们写程序,要避免出现死循环。

    2.3 do-while循环结构

    do{

    ③;

    ④;

    }while(②);

    执行过程:① - ③ - ④ - ② - ③ - ④ - … - ②

    说明:

    1.do-while循环至少会执行一次循环体!

    2.开发中,使用for和while更多一些。较少使用do-while

    二、数组

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    1.数组概述

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    1.数组理解:数组(Array),是多个相同类型数据一定顺序排列的集合,并使用一个名字命名,并通过编号的方式对这些数据进行统一管理。

    2.数组相关的概念:

    数组名

    元素

    角标、下标、索引

    数组的长度:元素的个数

    3.数组的特点:

    数组是序排列的

    数组属于引用数据类型的变量。数组的元素,既可以是基本数据类型,也可以是引用数据类型

    创建数组对象会在内存中开辟一整块连续的空间

    数组的长度一旦确定,就不能修改。

    4. 数组的分类:

    ① 二维数:一维数组、二维数组、。。。

    ② 照数组元素的类型:基本数据类型元素的数组、引用数据类型元素的数组

    2.一维数组

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    1.一维数组的声明与初始化

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] ids;<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span>声明<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">//<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1.1</span> 静态初始化:数组的初始化和数组元素的赋值操作同时进行<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">ids = new <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[]{<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1001</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1002</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1003</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1004</span>};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1.2</span>动态初始化:数组的初始化和数组元素的赋值操作分开进行<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">String[] names = new String[<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">5</span>];<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"> <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] arr4 = {<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">2</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">3</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">4</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">5</span>};<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span>类型推断<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1234567</span></code>

    错误的方式:

    // int[] arr1 = new int[];

    // int[5] arr2 = new int[5];

    // int[] arr3 = new int[3]{1,2,3};

    2.一维数组元素的引用:通过角标的方式调用。

    数组的角标(或索引从0开始的,到数组的长度-1结束)

    3.数组的属性:length

    System.out.println(names.length);//5

    System.out.println(ids.length);

    说明:

    数组一旦初始化,其长度就是确定的。arr.length

    数组长度一旦确定,就不可修改。

    4.一维数组的遍历

    for(int i = 0;i < names.length;i++){

    System.out.println(names[i]);

    }

    5.一维数组元素的默认初始化值

    > 数组元素是整型:0

    > 数组元素是浮点型:0.0

    > 数组元素是char型:0或’\u0000’,而非’0’

    > 数组元素是boolean型:false

    > 数组元素是引用数据类型:null

    3.二维数组

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    1.如何理解二维数组?

    数组属于引用数据类型

    数组的元素也可以是引用数据类型

    一个一维数组A的元素如果还是一个一维数组类型的,则,此数组A称为二维数组。

    2.二维数组的声明与初始化

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;">int[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>] arr = new int[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>]{1,2,3};//一维数组<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">//静态初始化int[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);"></span>] arr1 = new int[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);"></span>]{{1,2,3},{4,5},{6,7,8}};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">//动态初始化1String[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);"></span>] arr2 = new String[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">3</span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">2</span>];<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">//动态初始化2String[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);"></span>] arr3 = new String[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">3</span>][<span class="hljs-symbol" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);"></span>];<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">//也是正确的写法:int[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>] arr4[<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);"></span>] = new int[][]{{1,2,3},{4,5,9,10},{6,7,8}};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">int[] arr5[] = {{1,2,3},{4,5},{6,7,8}};//类型推断12345678910</code>

    错误的方式:

    // String[][] arr4 = new String[][4];

    // String[4][3] arr5 = new String[][];

    // int[][] arr6 = new int[4][3]{{1,2,3},{4,5},{6,7,8}};

    3.如何调用二维数组元素:

    System.out.println(arr1[0][1]);//2

    System.out.println(arr2[1][1]);//null

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;">arr3[<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>] = <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">new</span> String[<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">4</span>];<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">out</span>.println(arr3[<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>][<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">0</span>]);<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">out</span>.println(arr3[<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">0</span>]);<span class="hljs-comment" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 153);">//</span><br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-comment" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 153);">123</span></code>

    4.遍历二维数组元素

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">for</span>(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span> i = <span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">0</span>; i lt arr.length;i++)<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">for</span>(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span> j = <span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">0</span>;j lt arr[i].length;j++){<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">out</span>.print(arr[i][j] + <span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">" "</span>)<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">}<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1234</span></code>

    4.数组常见算法

    1.数组的创建与元素赋值

    杨辉三角(二维数组)、回形数(二维数组)、6个数,1-30之间随机生成且不重复。

    2.针对于数值型的数组:

    最大值、最小值、总和、平均数等

    3.数组的复制与复制

    int[] array1,array2;

    array1 = new int[]{1,2,3,4};

    3.1 赋值:

    array2 = array1;

    如何理解:将array1保存的数组的地址值赋给了array2,使得array1和array2共同指向堆空间中的同一个数组实体。

    3.2 复制:

    array2 = new int[array1.length];

    for(int i = 0;i < array2.length;i++){

    array2[i] = array1[i];

    }

    如何理解:我们通过new的方式,给array2在堆空间中新开辟了数组的空间。将array1数组中的元素值一个一个的赋值到array2数组中。

    5.Arrays工具类使用

    1.理解:

    ① 定义在java.util包下。

    ② Arrays:提供了很多操作数组的方法。

    2.使用:

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;">//<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>.boolean equals(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] a,<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] b):判断两个数组是否相等。<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] arr1 = new <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[]{<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">2</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">3</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">4</span>};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] arr2 = new <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[]{<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">3</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">2</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">4</span>};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">boolean isEquals = Arrays.equals(arr1, arr2);System.out.println(isEquals);<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">2</span>.String toString(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] a):输出数组信息。<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.out.println(Arrays.toString(arr1));<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">3</span>.void fill(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] a,<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span> val):将指定值填充到数组之中。<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">Arrays.fill(arr1,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">10</span>);<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.out.println(Arrays.toString(arr1));<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">4</span>.void <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">sort</span>(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] a):对数组进行排序。<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">Arrays.sort(arr2);System.out.println(Arrays.toString(arr2));<span class="hljs-regexp" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(217, 99, 34);">//</span><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">5</span>.int binarySearch(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] a,<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span> key)<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[] arr3 = new <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span>[]{-<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">98</span>,-<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">34</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">2</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">34</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">54</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">66</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">79</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">105</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">210</span>,<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">333</span>};<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">int</span> <span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">index</span> = Arrays.binarySearch(arr3, <span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">210</span>);<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">if</span>(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">index</span> gt= <span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">0</span>){<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.out.println(<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">index</span>);<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">}<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">else</span>{<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">System.out.println(<span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">"未找到"</span>);<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">}<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">123456789101112131415161718192021222324252627</span></code>

    三、面向对象

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    java类及其类成员

    1.类的设计中,两个重要结构之一:属性

    对比:属性 vs 局部变量

    1.相同点:

    1.1 定义变量的格式:数据类型 变量名 = 变量值

    1.2 先声明,后使用

    1.3 变量都其对应的作用域

    2.不同点:

    2.1 在类中声明的位置的不同

    属性:直接定义在类的一对{}内

    局部变量:声明在方法内、方法形参、代码块内、构造器形参、构造器内部的变量

    2.2 关于权限修饰符的不同

    属性:可以在声明属性时,指明其权限,使用权限修饰符。

    常用的权限修饰符:private、public、缺省、protected —>封装性

    目前,大家声明属性时,都使用缺性就可以了。

    局部变量:不可以使用权限修饰符。

    2.3 默认初始化值的情况:

    属性:类的属性,根据其类型,都默认初始化值。

    整型(byte、short、int、long:0)

    浮点型(float、double:0.0)

    字符型(char:0 (或’\u0000’))

    布尔型(boolean:false)

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;">引用数据类型(类、数组、接口:<span class="hljs-literal" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(138, 115, 4);">null</span>)<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">局部变量:没默认初始化值。意味着,我们在调用局部变量之前,一定要显式赋值。特别地:形参在调用时,我们赋值即可。<span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">12345</span></code>

    2.4 在内存中加载的位置:

    属性:加载到堆空间中 (非static)

    局部变量:加载到栈空间

    2.类的设计中,两个重要结构之二:方法

    方法:描述类应该具的功能。

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;"><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1</span><span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">.举例:</span><br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-string" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(0, 117, 59);">1</span></code>

    public void eat(){}

    public void sleep(int hour){}

    public String getName(){}

    public String getNation(String nation){}

    2. 方法的声明:权限修饰符 返回值类型 方法名(形参列表){

    方法体

    }

    3. 说明:

    3.1 关于权限修饰符:默认方法的权限修饰符先都使用public

    Java规定的4种权限修饰符:private、public、缺省、protected -->封装性再细说

    3.2 返回值类型: 返回值 vs 没返回值

    3.2.1 如果方法返回值,则必须在方法声明时,指定返回值的类型。同时,方法中,需要使用 return关键字来返回指类型的变量或常量:“return 数据”。如果方法没返回值,则方法声明时,使用void来表示。通常,没返回值的方法中,就不需要使用return.但是,如果使用的话,只能“return;”表示结束此方法的意思。

    构造器(或构造方法):

    构造器的作用:

    1.创建对象

    2.初始化对象的信息

    使用说明:

    1.如果没显式的定义类的构造器的话,则系统默认提供一个空参的构造器

    2.定义构造器的格式:权限修饰符 类名(形参列表){}

    3.一个类中定义的多个构造器,彼此构成重载

    4.一旦我们显式的定义了类的构造器之后,系统就不再提供默认的空参构造器

    5.一个类中,至少会有一个构造器。

    三大特性(封装、继承、多态)

    面向对象的特征一:封装与隐藏

    1.为什么要引入封装性?

    我们程序设计追求“高内聚,低耦合”。

    高内聚 :类的内部数据操作细节自己完成,不允许外部干涉;

    低耦合 :仅对外暴露少量的方法用于使用。

    隐藏对象内部的复杂性,只对外公开简单的接口。便于外界调用,从而提高系统的可扩展性、可维护性。通俗的说,把该隐藏的隐藏起来,该暴露的暴露出来。这就是封装性的设计思想。

    2.封装性思想具体的代码体现:

    体现一:将类的属性xxx私化(private),同时,提供公共的(public)方法来获取(getXxx)和设置(setXxx)此属性的值

    private double radius;

    public void setRadius(double radius){

    this.radius = radius;

    }

    public double getRadius(){

    return radius;

    }

    体现二:不对外暴露的私有的方法

    体现三:单例模式(将构造器私有化)

    体现四:如果不希望类在包外被调用,可以将类设置为缺省的。

    3.Java规定的四种权限修饰符

    我把Java基础编程及思维导图整理的超级详细,小白都能看懂

    3.1 权限从小到大顺序为:private < 缺省 < protected < public

    3.2 具体的修饰范围:

    3.3 权限修饰符可用来修饰的结构说明:

    4.种权限都可以用来修饰类的内部结构:属性、方法、构造器、内部类

    修饰类的话,只能使用:缺省、public

    面向对象特征二:继承性

    1.继承性的格式:

    class A extends B{}

    A:子类、派生类、subclass

    B:父类、超类、基类、superclass

    2.子类继承父类以后有哪些不同?

    2.1体现:一旦子类A继承父类B以后,子类A中就获取了父类B中声明的所有的属性和方法。

    特别的,父类中声明为private的属性或方法,子类继承父类以后,仍然认为获取了父类中私的结构。只因为封装性的影响,使得人类不能直接调用父类的结构而已。

    2.2 子类继承父类以后,还可以声明自己特有的属性或方法:实现功能的拓展。

    子类和父类的关系,不同于子集和集合的关系。

    extends:延展、扩展

    3.Java中继承性的说明

    3.1.一个类可以被多个子类继承。

    3.2.Java中类的单继承性:一个类只能有一个父类

    3.3.子父类是相对的概念。

    3.4.子类直接继承的父类,称为:直接父类。间接继承的父类称为:间接父类

    3.5.子类继承父类以后,就获取了直接父类以及所间接父类中声明的属性和方法

    面向对象的特性三:多态性

    1.多态性的理解:可以理解为一个事物的多种形态。

    2.何为多态性:

    对象的多态性:父类的引用指向子类的对象(或子类的对象赋给父类的引用)

    举例:

    Person p = new Man();

    Object obj = new Date();

    3.多态性的使用:虚拟方法调用

    有了对象的多态性以后,我们在编译期,只能调用父类中声明的方法,但在运行期,我们实际执行的是子类重写父类的方法。

    总结:编译,看左边;运行,看右边。

    4.多态性的使用前提:

    ① 类的继承关系 ② 方法的重写

    6.多态性使用的注意点:

    对象的多态性,只适用于方法,不适用于属性(编译和运行都看左边)

    关键字

    关键字:this

    1.可以调用的结构:属性、方法;构造器

    2.this调用属性、方法:

    this理解为:当前对象 或 当前正在创建的对象

    2.1 在类的方法中,我们可以使用"this.属性"或"this.方法"的方式,调用当前对象属性或方法。但是通常情况下,我们都择省略"this."。特殊情况下,如果方法的形参和类的属性同名时,我们必须显式的使用"this.变量"的方式,表明此变量是属性,而非形参。

    2.2 在类的构造器中,我们可以使用"this.属性"或"this.方法"的方式,调用当前正在创建的对象属性或方法。但是,通常情况下,我们都择省略"this."。特殊情况下,如果构造器的形参和类的属性同名时,我们必须显式的使用"this.变量"的方式,表明此变量是属性,而非形参。

    3.this调用构造器:

    ① 我们在类的构造器中,可以显式的使用"this(形参列表)"方式,调用本类中指定的其他构造器

    ② 构造器中不能通过"this(形参列表)“方式调用自己

    ③ 如果一个类中有n个构造器,则最多有 n - 1构造器中使用了"this(形参列表)”

    ④ 规定:"this(形参列表)“必须声明在当前构造器的首行

    ⑤ 构造器内部,最多只能声明一个"this(形参列表)”,用来调用其他的构造器

    关键字:abstract

    abstract: 抽象的

    1.可以用来修饰:类、方法

    2.具体的:

    abstract修饰类:抽象类

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;"> 此类不能实例化<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"> 抽象类中一定有构造器,便于子类实例化时调用(涉及:子类对象实例化的全过程) 开发中,都会提供抽象类的子类,让子类对象实例化,完成相关的操作 <span class="hljs-comment" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 153);">---gt抽象的使用前提:继承性</span><br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-comment" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 153);">123</span></code>

    abstract修饰方法:抽象方法

    <code style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 1em; margin: 0px; padding: 0px; border: 0px;">抽象方法只方法的声明,没方法体<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;">包含抽象方法的类,一定是一个抽象类。反之,抽象类中可以没有抽象方法的。 若子类重写了父类中的所的抽象方法后,此子类方可实例化 若子类没重写父类中的所的抽象方法,则此子类也是一个抽象类,需要使用<span class="hljs-keyword" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(17, 75, 166);">abstract</span>修饰<br style="-webkit-tap-highlight-color: transparent; box-sizing: border-box;"><span class="hljs-number" style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; color: rgb(168, 46, 46);">1234</span></code>

    3.注意点:

    1.abstract不能用来修饰:属性、构造器等结构

    2.abstract不能用来修饰私方法、静态方法、final的方法、final的类

    关注作者-私:" Java "

    免费领取一份(Java学习视频,技术文档,电子书籍,面试等资料...)

    还可免费学习Java基础到项目实战课程!

    相关文章

      网友评论

          本文标题:我把Java基础编程及思维导图整理的超级详细,小白都能看懂

          本文链接:https://www.haomeiwen.com/subject/gzzhpktx.html