常用API-01-Math
![](https://img-blog.csdnimg.cn/cd92c52311fa499594471df93b44af6a.jpeg)
常用API-02-练习:两道数学算法题![](https://img-blog.csdnimg.cn/c7f03dadcd0c497bb5eead5c8e1f39c7.png)
常用API-03-System
![](https://img-blog.csdnimg.cn/87b8d2d99e2c493a86376b55f2e11847.png)
![](https://img-blog.csdnimg.cn/50b7a504690a4238be9961771f330384.png)
![](https://img-blog.csdnimg.cn/e51f790375ac45d7a0ef2c87f13c4b84.png)
![](https://img-blog.csdnimg.cn/61a5093e42c24a4b8c1cb8a22ffbc60b.png)
![](https://img-blog.csdnimg.cn/67be2266e1114a07a1b3633b936bec2e.png)
Student stu=(Student)arr2[i] 强制转换
常用API-04-Runtime (表示当前虚拟机的运行环境)![](https://img-blog.csdnimg.cn/6a67da76e7014274bf279fd9a0df93ad.png)
![](https://img-blog.csdnimg.cn/781cb2dfb92743d6bd2b2106fb048264.png)
![](https://img-blog.csdnimg.cn/2dd0e351131a452a8e2b68fd1ce01492.png)
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
public class MyJframe extends JFrame implements ActionListener {
JButton yesBut = new JButton("好看爆了");
JButton midBut = new JButton("一般般吧");
JButton noBut = new JButton("不好看,有点磕碜");
JButton dadBut = new JButton("爸爸╥﹏╥饶了我吧");
//决定了上方的按钮是否展示
boolean flag = false;
public MyJframe() {
initJFrame();
initView();
//显示
this.setVisible(true);
}
private void initView() {
this.getContentPane().removeAll();
if (flag) {
//展示按钮
dadBut.setBounds(50, 20, 300, 30);
dadBut.addActionListener(this);
this.getContentPane().add(dadBut);
}
JLabel text = new JLabel("你觉得自己好看吗?");
text.setFont(new Font("微软雅黑", 0, 33));
text.setBounds(120, 150, 300, 50);
yesBut.setBounds(200, 250, 100, 30);
midBut.setBounds(200, 325, 100, 30);
noBut.setBounds(160, 400, 180, 30);
yesBut.addActionListener(this);
midBut.addActionListener(this);
noBut.addActionListener(this);
this.getContentPane().add(text);
this.getContentPane().add(yesBut);
this.getContentPane().add(midBut);
this.getContentPane().add(noBut);
this.getContentPane().repaint();
}
private void initJFrame() {
//设置宽高
this.setSize(500, 600);
//设置标题
this.setTitle("颜值自测");
//设置关闭模式
this.setDefaultCloseOperation(3);
//置顶
this.setAlwaysOnTop(true);
//居中
this.setLocationRelativeTo(null);
//取消内部默认布局
this.setLayout(null);
}
@Override
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == yesBut) {
showJDialog("你的电脑被你好看爆了,将在一分钟后关机");
try {
Runtime.getRuntime().exec("shutdown -s -t 60");
} catch (IOException ioException) {
ioException.printStackTrace();
}
flag = true;
initView();
} else if (obj == midBut) {
System.out.println("测试者点击了一般般");
showJDialog("输入错误,已帮你点击'好看爆了'");
showJDialog("你的电脑被你好看爆了,将在一分钟后关机");
try {
Runtime.getRuntime().exec("shutdown -s -t 60");
} catch (IOException ioException) {
ioException.printStackTrace();
}
flag = true;
initView();
} else if (obj == noBut) {
System.out.println("测试者点击了不帅");
showJDialog("输入错误,已帮你点击'好看爆了'");
showJDialog("你的电脑被你好看爆了,将在一分钟后关机");
try {
Runtime.getRuntime().exec("shutdown -s -t 60");
} catch (IOException ioException) {
ioException.printStackTrace();
}
flag = true;
initView();
} else if (obj == dadBut) {
System.out.println("测试者点击了求饶");
showJDialog("叫爸爸");
try {
Runtime.getRuntime().exec("shutdown -a");
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
public void showJDialog(String content) {
//创建一个弹框对象
JDialog jDialog = new JDialog();
//给弹框设置大小
jDialog.setSize(300, 250);
//让弹框置顶
jDialog.setAlwaysOnTop(true);
//让弹框居中
jDialog.setLocationRelativeTo(null);
//弹框不关闭永远无法操作下面的界面
jDialog.setModal(true);
jDialog.setTitle("温馨提示");
//创建Jlabel对象管理文字并添加到弹框当中
JLabel warning = new JLabel(content);
warning.setFont(new Font("微软雅黑", 5, 12));
warning.setBounds(0, 0, 200, 150);
jDialog.getContentPane().add(warning);
//让弹框展示出来
jDialog.setVisible(true);
}
}
常用API-05-Object
任意类的构造方法 都有 隐藏的super(); 用于 默认访问父类无参构造
为什么默认访问父类无参构造 不访问有参构造 因为顶级父类中只有无参构造;重写如下:
@Override
public String toString() {
return name+", "+age;
}
equals方法
大厂面试题![](https://img-blog.csdnimg.cn/46541f7cb5c34b7f84d7d14b6564a6dc.png)
![](https://img-blog.csdnimg.cn/31c0c2e9172644a6bfbeadc97d5f9699.png)
常用API-06-浅克隆、深克隆和对象工具类Objects
![](https://img-blog.csdnimg.cn/c0ba327338ba4c23b41b13298efd837b.jpeg)
重写:![](https://img-blog.csdnimg.cn/000a46dc63c44e2da10a7758d2104695.jpeg)
![](https://img-blog.csdnimg.cn/dd846c51bb5d4bdd86b9ca3a3a90124b.jpeg)
![](https://img-blog.csdnimg.cn/8cf43f91752146d6b9bceded1f51ba3d.jpeg)
![](https://img-blog.csdnimg.cn/47dc9e7cae484f63881c8229e942db45.jpeg)
第三方:![](https://img-blog.csdnimg.cn/920a370ed782407f836ab29bb9afffcd.jpeg)
![](https://img-blog.csdnimg.cn/b75d0cc14bbf413487037d32723b25c4.jpeg)
![](https://img-blog.csdnimg.cn/69dc4bbad891462c8677a563273907e5.jpeg)
![](https://img-blog.csdnimg.cn/6db3f979674b4e1ca414344f689f3722.jpeg)
objects.equals( s1,s2 ); 细节:
1.方法的底层会判断s1是否为null,如果为null,直接返回false;
2.如果s1不为null,那么就利用s1再次调用equals方法;
3.此时 s1是Student类型,所以最终会调用Student中的equals方法.
如果没有重写,比较地址值 ;重写了,比较属性值.
常用API-07-BigInteger(大整数)基本使用和原理解析![](https://img-blog.csdnimg.cn/9c0080d077a94877972c057c6c05e0cf.png)
![](https://img-blog.csdnimg.cn/ab8f3720156c4b0685baddbd0c15bcac.png)
![](https://img-blog.csdnimg.cn/58bf8b964d98430abef8a80e4a8a9f3e.png)
最常用的构造方法:
long取值范围之内选用4.valueof();小范围细节优化,节约内存
不确定到底多少或非常大用2(String value);
bd9.add(bd10) -> ab9+ba10;BigInteger max/min(BigInteger val); 此函数不会 创建新对象 而是直接拿最值 给新的BigIntegar
BigInteger原理解析![](https://img-blog.csdnimg.cn/71c7c30016d64f48ba68711981f18be4.png)
十进制276... 转二进制 32位一组 再转二进制 再存储到数组中
常用API-08-BigDecima基本使用和原理解析![](https://img-blog.csdnimg.cn/2a364ea0edec42c58170eed9405329bb.png)
![](https://img-blog.csdnimg.cn/39e5e346896a4ee0b161b305d2574728.png)
![](https://img-blog.csdnimg.cn/a554db0d990e457295a9d092983227d6.png)
![](https://img-blog.csdnimg.cn/5335dbfecdf240799221e8de4187da87.png)
构造方法获取BigDecimal对象
public BigDecimal(double val); public BigDecimal(String val);
静态方法获取BigDecimal对象 (上面右边(3).)
public static BigDecimal valueOf (double val);
只要括号里面不是0~10的 整数 就new
![](https://img-blog.csdnimg.cn/ebe42b2e8c1c4bbfbe9e21029fe26117.png)
![](https://img-blog.csdnimg.cn/4d306b4627404b5c812925745f6ee1d0.png)
BigDecimal divide(val,精确几位,舍入模式); 底层存储方式:
![](https://img-blog.csdnimg.cn/a83b8d17bd0a4d53b379c2d57c3e25ef.png)
![](https://img-blog.csdnimg.cn/5a58368865144f9bb9bf2fae188118ee.png)
"xx.xx" 字符串拆解成字符(包括'.','-') 再转换成ascll码 存到数组中![](https://img-blog.csdnimg.cn/610fdc2925874010b07f4a07871a40d9.png)
常用API-09-正则表达式初体验和基本规则
作用:1.检验字符串是否满足规则 2.在一段文本中查找满足要求的内容
![](https://img-blog.csdnimg.cn/1afe282e1b5a4b44a0a5153bb5d99a8f.png)
![](https://img-blog.csdnimg.cn/c57edad529d74a668354700e12476541.png)
![](https://img-blog.csdnimg.cn/6741499313b8477899eb238ee2caf369.png)
![](https://img-blog.csdnimg.cn/664a2f24db5844d3835b808e2a1c30b1.png)
![](https://img-blog.csdnimg.cn/4c2a63836bf14f6e8845cf55eba8b241.png)
![](https://img-blog.csdnimg.cn/7966ef681463483da340a73b0495b52e.png)
![](https://img-blog.csdnimg.cn/74350b66db22454b8d3876a96d6c5aad.png)
![](https://img-blog.csdnimg.cn/60b7a9eb0d9c4cfaa7eb7c3dda07b57e.png)
转义字符: \ 改变后面那个字符原本的含义
![](https://img-blog.csdnimg.cn/b6d4628c021c494691c32f26d4198910.png)
![](https://img-blog.csdnimg.cn/95ef3925475a4288a837e96c11c528e4.png)
![](https://img-blog.csdnimg.cn/0b6043f8d84341229872bb2a863b955d.png)
常用API-10-正则表达式基本练习
快捷正则! ![](https://img-blog.csdnimg.cn/20079127421643989a7233bc9006b8c9.png)
常用API-11-正则表达式基本练习2
忽略abc大小写:(?i)abc; 忽略bc大小写:a(?i)bc; 忽略b大小写:a((?i)b)c;
常用API-12-爬虫
pattern:表示正则表达式
Matcher:文本匹配器 作用按照正则表达式 的规则去读取字符串,从头开始读取.
在大串中去找符合匹配规则的字串
正确方法 解析方法
matcher(str);find();group();
网络爬虫:
package a08regex;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class RegexDemo {
//爬取网络信息
public static void main(String[] args) throws IOException {
//创建一个URL对象
URL url = new URL("https://mp.csdn.net/mp_blog/creation/editor/125702270");
//连接上这个网址
//细节: 要保证网络畅通
URLConnection conn = url.openConnection();
//创建一个对象去读取网络中的数据
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
//regex是正则表达式 pattern:正则表达式的对象
//String regex="[1-9]\\d{17}";
//Pattern pattern=Pattern.compile(regex);
//读取的时候 每次读一整行line
while ((line = br.readLine()) != null) {
System.out.println(line);
//拿着文本匹配器的对象matcher按照pattern的规则去读取 当前的一行信息
//Matcher matcher=pattern.matcher(line);
//while(matcher.find()){
// System.out.println(matcher.group());
//}
}
br.close();
}
}