首页 文章 精选 留言 我的

精选列表

搜索[Java],共10000篇文章
优秀的个人博客,低调大师

Java 面向对象 之 接口 interface

http://www.verejava.com/?id=16992815279749 /** 知识点: 接口 interface (重点中的重点) 面向接口的编程 接口的定义: 接口就是一个约定 题目: 主席说要建立和谐社会,温家宝说要为人民服务 思路: 1. 抽象出类: 主席(ChairMan), 省长(Governer) 2. 找出关系: 各省省长传达并实现 主席讲话方针 */ /** 注意: 1. 声明一个接口关键字为 interface 2. 接口中不允许定义方法的实现,只能是声明, 跟抽象类有所不同, 抽象类是 允许定义具体方法的. 所以接口有的时候也称为特殊的抽象类 3. 接口中方法的声明可以省略关键字 abstract ,抽象类中的抽象方法不能省略 4. 接口中方法默认都是public 的 5. 接口中的属性都是静态常量 static final 关键字可以省略,接口中属性默认 是public 的并且可以省略public ,不允许有private,protected 关键字修饰 6. 实现接口的类用关键字 implements 7. 实现类中必须 实现接口中的所有声明方法, 跟抽象类一样 8. 不能实例化接口, 必须有其实现类间接实例化, 跟抽象类一样 9. 如果要实现多个接口用, 隔开, 并且实现类要实现所有接口的方法, 而 抽象类不能多继承 10. 接口可以继承多个接口, 抽象类不行(这个就是为什么流行用面向接口编程的原因) 11. 类可以同时继承一个类和实现多个接口 */ public class TestInterface { public static void main(String[] args) { //输出主席名称 System.out.println(ChairMan.name); //实例化接口 //ChairMan chair=new ChairMan(); System.out.println("开各省大会了..."); Governer g1 = new Governer("北京市市长"); g1.buildHarmonyCommunity("教育"); g1.serviceForPeople("慈善"); Governer g2 = new Governer("河北省省长"); g2.buildHarmonyCommunity("联谊晚会"); g2.serviceForPeople("尊老爱幼"); g2.service(); } } interface ChairMan { String name = "主席"; //声明要建立和谐社会 public void buildHarmonyCommunity(String method); } interface PrimeMinister { String name = "总理"; //声明为人民服务 public void serviceForPeople(String method); } interface Leader extends ChairMan, PrimeMinister { } class LeiFeng { public void service() { System.out.println("全心全意为人民服务"); } } class Governer extends LeiFeng implements Leader { private String name;//省长名 public Governer(String name) { this.name = name; } //实现主席建立和谐社会的方针 public void buildHarmonyCommunity(String method) { System.out.println(name + " 我们是通过 " + method + " 来实现和谐社会"); } //实现总理为人民服务的方针 public void serviceForPeople(String method) { System.out.println(name + " 我们是通过 " + method + " 来为人民服务的"); } public String getName() { return this.name; } } http://www.verejava.com/?id=16992815279749

优秀的个人博客,低调大师

正则表达式(java

语法 正则.png 正则.png 正则.png 典型例子 ^\d+$ //匹配非负整数(正整数 + 0) ^[0-9][1-9][0-9]$ //匹配正整数 ^((-\d+)|(0+))$ //匹配非正整数(负整数 + 0) ^-[0-9][1-9][0-9]$ //匹配负整数 ^-?\d+$ //匹配整数 ^\d+(.\d+)?$ //匹配非负浮点数(正浮点数 + 0) ^(([0-9]+.[0-9][1-9][0-9])|([0-9][1-9][0-9].[0-9]+)|([0-9][1-9][0-9]))$ //匹配正浮点数 ^((-\d+(.\d+)?)|(0+(.0+)?))$ //匹配非正浮点数(负浮点数 + 0) ^(-(([0-9]+.[0-9][1-9][0-9])|([0-9][1-9][0-9].[0-9]+)|([0-9][1-9][0-9])))$ //匹配负浮点数 ^(-?\d+)(.\d+)?$ //匹配浮点数 ^[A-Za-z]+$ //匹配由26个英文字母组成的字符串 ^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串 ^[a-z]+$ //匹配由26个英文字母的小写组成的字符串 ^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串 ^\w+$ //匹配由数字、26个英文字母或者下划线组成的字符串 ^[\w-]+(.[\w-]+)*@[\w-]+(.[\w-]+)+$ //匹配email地址 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 匹配双字节字符(包括汉字在内):[^\x00-\xff] 匹配空行的正则表达式:\n[\s| ]*\r 匹配HTML标记的正则表达式:/<(.)>.</\1>|<(.*) />/ 匹配首尾空格的正则表达式:(^\s)|(\s$) 正则表达式用例 1、^\S+[a-z A-Z]$ 不能为空 不能有空格 只能是英文字母 2、\S{6,} 不能为空 六位以上 3、^\d+$ 不能有空格 只能是数字 4、(.*)(.jpg|.bmp)$ 只能是jpg和bmp格式 5、^\d{4}-\d{1,2}-\d{1,2}$ 只能是2004-10-22格式 6、^0$ 至少选一项 7、^0{2,}$ 至少选两项 8、^[\s|\S]{20,}$ 不能为空 二十字以上 9、^+?a-z0-9*@([a-z0-9]+(.|-))+[a-z]{2,6}$邮件 10、\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)([,;]\s\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)) 输入多个地址用逗号或空格分隔邮件 11、^(([0-9]+))?[0-9]{7,8}$电话号码7位或8位或前面有区号例如(022)87341628 12、^[a-z A-Z 0-9 *]+@[a-z A-Z 0-9 *]+(.[a-z A-Z 0-9 *]+)+(,[a-z A-Z 0-9 *]+@[a-z A-Z 0-9 *]+(.[a-z A-Z 0-9 ]+)+)$ 只能是字母、数字、下划线;必须有@和.同时格式要规范 邮件 13 ^\w+@\w+(.\w+)+(,\w+@\w+(.\w+)+)*$上面表达式也可以写成这样子,更精练。 14 ^\w+((-\w+)|(.\w+))@\w+((.|-)\w+).\w+$ [/size]

优秀的个人博客,低调大师

Java 面向对象 之 对象数组

http://www.verejava.com/?id=16992784958543 /** 知识点: 对象数组 1. 对象数组的使用 2. 对象数组的foreach 增强for循环 3. 可变参数 题目:乘客一次只能带2个箱子免费上飞机 思路: 1. 抽象出类 乘客(Customer) , 箱子(Box) 2. 乘客和箱子的关系 1对2的关系 Box->Customer */ public class ObjectArray { public static void main(String[] args) { //实例化一个乘客 Customer c = new Customer("黎明"); //实例化两个箱子一个装衣服, 一个装书 Box clothBox = new Box("装衣服"); clothBox.setId(1); clothBox.setWeight(20); Box bookBox = new Box("装书"); bookBox.setId(2); bookBox.setWeight(30); //将箱子添加到乘客 c.addBox(clothBox); c.addBox(bookBox); //打印该乘客的信息 System.out.println("乘客姓名: " + c.getName()); System.out.println("箱子编号, 箱子重量, 箱子描述"); Box[] boxes = c.getBoxes(); for (Box box : boxes) { System.out.println(box.getId() + "," + box.getWeight() + "," + box.getDescription()); } //测试可变参数 Box[] boxes2 = { clothBox, bookBox }; c.setBoxes();//不传参数 c.setBoxes(clothBox);//传一个参数 c.setBoxes(boxes2);//传一个数组 boxes = c.getBoxes(); for (Box box : boxes) { System.out.println(box.getId() + "," + box.getWeight() + "," + box.getDescription()); } } } class Customer { private String name;//乘客名字 private Box[] boxes = new Box[2];//箱子属于乘客, 添加箱子引用 public Customer(String name) { this.name = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Box[] getBoxes() { return this.boxes; } //乘客携带添加的箱子 //返回值: 如果添加成功返回true 否则false public boolean addBox(Box box) { for (int i = 0; i < boxes.length; i++) { if (boxes[i] == null) { boxes[i] = box; return true; } } return false; } public void setBoxes(Box... boxes) { this.boxes = boxes; } } class Box { private float weight;//箱子的重量 private int id;//箱子的编号 private String description;//描述 public Box(String description) { this.description = description; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } public int getId() { return this.id; } public void setId(int id) { this.id = id; } public float getWeight() { return this.weight; } public void setWeight(float weight) { this.weight = weight; } } http://www.verejava.com/?id=16992784958543

优秀的个人博客,低调大师

Java 面向对象 之 代码块

http://www.verejava.com/?id=16992781354342 /** 知识点: 代码块 1. 普通代码块 2. 构造代码块 3. 静态代码块 */ public class CodeBlock { //写在构造方法里的叫 构造代码块 public CodeBlock() { System.out.println("CodeBlock 初始化"); } //写在 static 块里的叫 静态代码块 static { System.out.println("static 执行"); } public static void main(String[] args) { //写在方法里的叫 普通代码块 System.out.println("hello"); new CodeBlock(); } } /** 注意: 静态代码块是在程序编译期运行 所以静态代码块会在构造方法前调用 */ http://www.verejava.com/?id=16992781354342

优秀的个人博客,低调大师

Java 面向对象 之 引用传递

http://www.verejava.com/?id=16992763271038 /** 知识点内容: 引用传递 1. 方法参数引用传递 2. 对象与对象之间的引用传递 3. this指针 本对象引用传递 */ public class Refenrence { public static void main(String[] args) { //实例化 工具类 Utils Utils utils = new Utils(); //定义一个计数器个变量 int count = 1; System.out.println(count); utils.increment(count); System.out.println(count); //定义一个计数器数组变量 int[] counts = { 1 }; System.out.println(counts[0]); utils.increment(counts); System.out.println(counts[0]); //定义一个计数器类变量 Count value = new Count(); value.setValue(1); System.out.println(value.getValue()); utils.increment(value); System.out.println(value.getValue()); } } //建一个工具类 class Utils { public void increment(int count) { count++; } public void increment(int[] counts) { counts[0]++; } public void increment(Count count) { count.setValue(count.getValue() + 1); } } class Count { private int value; public int getValue() { return this.value; } public void setValue(int value) { this.value = value; } } http://www.verejava.com/?id=16992763271038

优秀的个人博客,低调大师

Java 面向对象 之 封装方法

http://www.verejava.com/?id=16992728331734 /** 测试类的封装特性 类的封装特性就是, 将类的属性私有化private 然后提供公有的方法去访问 */ public class Encapsulation { public static void main(String[] args) { //实例化Person 类 //1. 引用对象不能访问类的私有属性 //2. 如果要访问私有属性, 一般类中要另外提供访问私有属性的公有方法 Person p = new Person(); //p.name="李明"; //p.age=22; p.setName("李明"); p.setAge(22); p.say(); System.out.println(p); System.out.println(p.getName() + " " + p.getAge()); } } class Person { //实现类属性的封装 前面加 private 关键字 private String name; private int age; //定义访问私有属性的公有方法 //括号中 String name 是 方法setName 的传入参数 public void setName(String name) { //this 代表当前对象的引用, 哪个对象引用该类,就是指的哪个引用 System.out.println(this); this.name = name; } //String 是方法getName 的返回值的类型 输出返回值 public String getName() { return this.name; } public void setAge(int age) { this.age = age; } public int getAge() { return this.age; } public void say() { System.out.println("我的名字叫:" + name + ",今年 " + age + " 岁"); } } /* 回顾总结 1. 在类当中定义的变量叫成员变量, 属性就是成员变量, 可以在整个类当中访问 2. 在方法中定义的变量叫局部变量, 只能在定义的方法当中访问 注意: 当局部变量和成员变量同名的时候, 局部变量回覆盖掉成员变量,所以当两个变量同名时 要区分成员变量必须加上 this */ http://www.verejava.com/?id=16992728331734

优秀的个人博客,低调大师

Java----------LeetCode----------46. 全排列

说起回溯算法,渊源颇深,我上次做过一道,本应该这次能拿下但是,又没拿下,不过这次有点理解它的思想了, 每次的回溯就是一个二叉树,简单的说,就是你执行的操作需要回溯时它会返回调用它的方法哪里的状态,进行下一步的执行。 public List<List<Integer>> permute(int[] nums) { List<List<Integer>> temp = new ArrayList<>(20); zuhe(temp,0,nums); return temp; } private void zuhe(List<List<Integer>> temp, int n, int[] nums) { /* * 每次让其加一个就行了,就空了, * */ if (nums.length == n) { List<Integer> integers =new ArrayList<>(20); for (int r:nums){ integers.add(r); } temp.add(integers); } for (int i = n, length = nums.length; i <length ; i++) { change(nums,i,n); zuhe(temp,n+1,nums); change(nums,i,n); } } public void change(int[] nums, int i, int j) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } 这个需要多练,具体自己体会

优秀的个人博客,低调大师

Java 目录和文件的复制

1.复制一个目录及其子目录、文件到另外一个目录 //复制一个目录及其子目录、文件到另外一个目录 public void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { if (!dest.exists()) { dest.mkdir(); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); // 递归复制 copyFolder(srcFile, destFile); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } } private void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { if (!dest.exists()) { dest.mkdir(); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); // 递归复制 copyFolder(srcFile, destFile); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[ 1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }

资源下载

更多资源
Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册