学习思考
Java学习基础
00 分钟
2022-11-26
2023-8-1
type
status
date
slug
summary
tags
category
icon
password
link
Property
Aug 1, 2023 08:22 AM
notion image

java入门

大二上学期开始学习java,虽然一直听说java是一门很厉害的语言,但没有系统去的学习😃😃 就我目前刚学来看,Java的语法很像c语言和javascript二者的结合,感觉很多东西都学过,一切都那么似曾相识。 但我知道这样是不对的,后面我会积极改正这种错误思想☹️☹️☹️

java学习路线

https://luxian.yupi.icu/#/

安装jdk

java的运行离不开jdk编译,同时也需要配置环境,环境配置直接搜教程即可

编译软件的使用

1.官网下载eclipse免费,安装简易就不再多说了
2.推荐使用IDEA,个人感觉这套工具更好用,不过专业版付费,个人开发使用社区版就OK
 
教程还是推荐用菜鸟教程
 

描述java语言特点

1.简单性 2.面向对象型 3.安全性 4.跨平台性---JAVA虚拟机 5.支持多线程 任务管理器 进程---线程
Java语言具有简单性、面向对象型、安全性和跨平台性等特点。它可以通过Java虚拟机实现跨平台,并且支持多线程,可以使用任务管理器和进程来管理线程。
 

hello world的运行

众所周知,所有编译语言的学习都是从hello world开始的,java当然也不例外
 

标识符

标识符可以由任意顺序的大小写字母、数字、下划线(_)和美元 符号($)组成,但不能以数字开头,不能是Java中的关键字。
notion image

关键字

notion image
 

变量与常量

变量是一种可以在程序中改变的量。它们可以用来存储和表示数据,并且可以在程序的不同部分之间共享。在程序运行期间,随时可能产生一些临时数据,应用程序会将这些数据保存在一些内存单元中,每个内存单元都用一个标识符来标识。这些内存单元我们称之为变量,定义的标识符就是变量名,内存单元中存储的数据就是变量的值。
常量是一种不可更改的量,它们的值在程序执行期间保持不变。

数据类型*

notion image
notion image
基本类型
默认值
说明
byte
0
是int型变量所占空间的四分之一
short
0
是int型变量所占空间的二分之一
int
0
一般地整型变量默认为 int 类型
long
0L
主要使用在需要比较大整数的系统上
flout
0.0f
浮点数不能用来表示精确的值,如货币
double
0.0d
类比flout,但精度更高
char
‘u0000’
char 数据类型可以储存任何字符
String
null
字符串,即多个字符
boolean
false
只作为一种标志来记录 true/false 情况
引用数据类型
null
如数组和对象
notion image

数值型

整数型

notion image

浮点型

notion image
notion image

字符型

notion image
notion image

布尔型

notion image
 
 

数据类型转化

notion image

自动类型

notion image
notion image
将小范围转化为大范围,char可转int(在java中可实现,c语言不行)
notion image
notion image

强制类型

notion image
目标类型变里 =(目标类型)值
在对变量进行强制类型转换时,会发生取值范围较大的数据类型向取值范围较小的数据类型的转换,如将一个int类型的数转为byte类型,这样做极容易造成数据精度的丢失。
 
注:所谓表达式是指由变量和运算符组成的一个算式。变量在表达式中进行运算时,也有可能发生自动类型转换,这就是表达式数据类型的自动提升,如一个byte型的变量在运算期间类型会自动提升为int型
 

字符常量

notion image

字符串常量

notion image
 

进制转换

notion image
notion image
 

算术运算符

notion image
notion image
取模%公式:a%b=a-a/b*b;
运算
结果
10%3
1
-10%3
-1
10%-3
1
-10%-3
-1
结论
看除数符号,即a的符号

赋值运算符

notion image
notion image
notion image
notion image
notion image

比较运算符

notion image
notion image
 

逻辑运算符

notion image
notion image
notion image
 

运算优先级

notion image
 
 

位运算

notion image
 

程序语句*

选择

switch

notion image
notion image
notion image
 

while

notion image
notion image
 

跳转语句

notion image
notion image
notion image
 

方法

notion image
 

方法重载*

notion image
notion image
notion image
 

数组

数组在内存中是连续分配的
notion image
notion image

数组常见操作

遍历

通常用for循环
使用 for 循环可以遍历一个数组:

最值

编写获取最大值方法

排序

通常用冒泡排序
notion image
notion image

多维数组

notion image
notion image
notion image
notion image
 
 

修饰符

notion image

String.substring()方法使用:

java String类substring() 方法返回字符串的子字符串
1.substring(n)->从n开始索引
2.substring(n,m)->从n开始到m结束

不同格式键盘输入

Java Number & Math

方法
function
say
rond
四舍五入
3.3→3,3.5→4
floor
向下取整
3.9→3,3.3→3
ceil
向上取整
3.3→4,3.9→4

bug

在写代码的过程难免会遇到一些bug,在这里我会一一列出以便debug

打印三角形

注意观察上面二片代码有什么区别,很明显对吧,输出的方式不一样
在demo01里,System.out.print(),打印出预想结果
在demo02里,System.out.println(),打印竖排
最后科普一下,print和println的区别:
虽然二者都是在控制台输出,但前者将输出光标定位在所显示的最后一个字符之后,而后者会在结尾加上换行符,将输出光标定位在下一行的开始

打印三角形的其他bug

这里用到了三层循环,注意j和k是并列的并不是包含关系
 

评论
  • Twikoo
  • Waline