07 2020 档案
摘要:范围 Private Protected Public Default 本类 是 是 是 是 本包的类 否 是 是 是 子类 否 是 是 否 非子类的外包类 否 否 是 否
阅读全文
摘要:使用throws声明的方法表示此方法不处理异常,而是交给方法的调用处进行处理; public class Math { public int div(int i,int j)throws Exception{ System.out.println("********计算开始********"); i
阅读全文
摘要:public class Demo07 { public static void main(String[] args) { final Printer p = new Printer(); new Thread() { public void run() { while (true) { p.pr
阅读全文
摘要:public class Demo06 { public static void main(String[] args) { Thread t1 = new Thread() { public void run() { for (int i = 0; i < 10; i++) { System.ou
阅读全文
摘要:join(); 当前线程暂停,等待指定的线程执行结束后,当前线程在继续。 join(int); 可以等待指定的毫秒之后继续。 public class Demo05 { public static void main(String[] args) { Thread t1 = new Thread()
阅读全文
摘要:public static void main(String[] args) { Thread t1 = new Thread() { public void run() { for (int i = 0; i < 2; i++) { System.out.println(getName() + "
阅读全文
摘要:public class Demo03 { public static void main(String[] args) throws InterruptedException { Test01(); new Thread(){ public void run(){ for(int i = 0;i<
阅读全文
摘要:public class Demo02 { public static void main(String[] args) { Test01(); new Thread(){ public void run(){ System.out.println(getName()+".......ccccccc
阅读全文
摘要:public class Demo02 { public static void main(String[] args) {第一种方法: new Thread("构造方法设置线程名字"){ public void run(){ System.out.println(this.getName()+".
阅读全文
摘要:public class Demo01 { public static void main(String[] args) {//方法一: new Thread() { //1.继承Thread类 public void run() { //2.重写run方法 for (int i = 0; i <
阅读全文
摘要:多态性在面向对象中是一个最重要的概念,在java中面向对象主要有一下两种主要体现: 1.方法的重载和重写。 2.对象的多态性。 对象的多态性主要分为以下两种类型。 1.向上转型:子类对象 > 父类对象 2.向下转型 父类对象 >子类对象 对于向上转型,程序会自动完成,而对于向下转型时,必须要明确的指
阅读全文
摘要:使用final声明的类不能有子类,使用final声明的方法不能被子类重写,使用final声明的变量即为常量,常量不可以修改;final修饰的引用数据地址值不可以改变,属性可以改变。 final变量的命名规则:在使用final声明变量时要求全部的字母大写。
阅读全文
摘要:方法一:直接继承Thread类 class Mythread extends Thread { // 1.继承Threadpublic void run() {// 2.重写run方法for (int i = 0; i < 1000; i++) { // 3.将要执行的代码写在run方法中Syste
阅读全文
摘要:package demo; import java.util.ArrayList; public class Demo3 { public static void main(String[] args) { System.out.println(getLucklyNum(8)); } public
阅读全文
摘要:package demo; import java.math.BigInteger; /* * 求出1000阶乘所有零和尾部零的个数 */public class Demo2 { public static void main(String[] args) { test(); test2(); }
阅读全文
摘要:普通代码块:直接在方法或者语句中定义的代码块。 构造快:构造代码块是直接写在类中的代码块,构造快优先于构造放法执行,每次实例化对象都会执行构造块中的代码。 静态代码块:使用static关键字声明的代码块,优先于主方法执行,而在类中定义的静态代码块会优先于构造块执行,而且不管实例化多少个对象,静态代码
阅读全文
摘要:静态变量和静态方法 static关键字最基本的用法是: 1、被static修饰的变量属于类变量,可以通过类名.变量名直接引用,而不需要new出一个对象来 2、被static修饰的方法属于类方法,可以通过类名.方法名直接引用,而不需要new出一个对象来 被static修饰的变量、被static修饰的方
阅读全文
摘要:1.this 可以强调本类中的方法。 2.表示类中的属性(this.name = name)、调用本类的构造方法this(),调用时只能放在构造方法的首行,this调用构造方法时一定要留一个构造方法作为出口,即程序中至少存在一个构造方法不使用this调用其他的构造方法,一般留无参构造作为出口。 3.
阅读全文
摘要:public class digui { /* * * 需求4:从键盘接收一个文件夹路径,把文件夹中的所有文件以及文件夹的名字按层级打印,例如: 把文件夹中的所有文件以及文件夹的名字按层级打印 * */ public static void main(String[] args) throws Ex
阅读全文
摘要:public class digui { /* * * * 需求3:从键盘接收两个文件夹路径,把其中一个文件夹中(包含内容)拷贝到另一个文件夹中 * */ public static void main(String[] args) throws Exception { File src = get
阅读全文
摘要:String str6 = "hello"; String str7 = "HELLO"; System.out.println(str6.equalsIgnoreCase(str7)); System.out.println(str6.replaceAll("l", "8")); //将所有的L替
阅读全文
摘要:String str6 = "hello"; String str7 = "HELLO"; System.out.println(str6.equalsIgnoreCase(str7)); //不区分大小写比较字符串的内容
阅读全文
摘要:String str5 = "293陕西力拓888"; System.out.println(str5.startsWith("293")); System.out.println(str5.endsWith("888")); if(str5.startsWith("293")) { System.
阅读全文
摘要:String str3 = "helloworld"; System.out.println(str3.substring(3)); System.out.println(str3.substring(2, 8)); String[] arr = str3.split("ow"); for (Str
阅读全文
摘要:String str3 = "helloworld"; System.out.println(str3.substring(3)); System.out.println(str3.substring(2, 8)); String[] arr = str3.split("ow"); for (Str
阅读全文
摘要:String str = " 好好学习,天天向上 "; System.out.println(str.charAt(5)); // 取出指定位置的字符 System.out.println("str的长度为:" + str.length()); // 取得一个字符串的长度 System.out.pr
阅读全文
摘要:public class StringAPIDemo1 { public static void main(String[] args) { String str = "HELLO"; char c[] = str.toCharArray(); // 将字符串变为字符数组 for (int i =
阅读全文
摘要:匿名对象就是没有明确的给出名字的对象,一般匿名对象只是用一次,而且匿名对象只在堆内存中开辟空间,而不存在栈内存的引用。 匿名对象的作用:基本上作为其他类实例化对象的参数或返回值传递。 语法格式:new 对象名(参数列表); 1.作为参数 class Test {public static void
阅读全文
摘要:构造方法的概述和作用:A、给对象的数据(属性)进行初始化。B、构造方法的格式和特点:方法名和类名相同、没有返回值类型,连void都没有、没有具体的返回值return。 构造方法的重载:方法名相同,参数列表不同。 构造方法的定义格式: class 类名称{ 访问权限 类名称(类型1,参数1,类型2,参
阅读全文
摘要:public class digui { /* * 需求1:从键盘接收一个文件夹路径,统计该文件夹大小 * 需求2:从键盘接收一个文件夹路径,删除该文件夹和文件夹下所有的文件 * */ public static void main(String[] args) { File dir = getDi
阅读全文
摘要:public class Properties { public static void main(String[] args) throws FileNotFoundException, IOException { test1(); test2(); java.util.Properties pr
阅读全文
摘要:public class Properties { public static void main(String[] args) { test1(); java.util.Properties prop = new java.util.Properties(); prop.setProperty("
阅读全文
摘要:Properties类表示了一个持久的属性值。 Properties可以保存在流中或从流中加载。 属性列表中每个键及对应值都是一个字符串。 public class Properties { public static void main(String[] args) { java.util.Pro
阅读全文
摘要:for(数据类型 变量名称:数组名称){ syso(变量名称); } public static void main(String[] args){ fun(1); //不传递参数 fun(2,5); //传递两个参数 fun(7,6,5,6,8); //传递五个参数 } public static
阅读全文
摘要:public static void main(Strign [] args){ int [] arr = {3,6,9}; //使用静态初始化定义数组 fun(arr); //传递数组引用 for(int i = 0; i < arr.length; i++){ //循环输出 syso(arr[i
阅读全文
摘要:public static void main(String[] args) { System.out.println("计算结果为:" + sum(100)); } public static int sum(int num) { if (num == 1) { return 1; } else
阅读全文
摘要:方法的重载就是方法名相同,但参数类型和参数的个数不同。 方法的重载,既可以发生在普通方法上,也可以发生在构造方法上。方法的重载,既可以发生在同类中,也可以发生在父子类中。 Java方法的重载:返回类型、修饰符可以相同,也可不同。要求同名的方法必须有不同的参数表,仅有返回类型不同是不足以区分两个重载的
阅读全文
摘要:public staitic 返回值类型 方法名称(类型 参数1,类型 参数2,...){ 程序语句; [return 表达式]; }; 在定义类时,全部单词的首字母必须大写,那么在定义方法时也有命名规范要求,即第一个单词的首字母小写,之后每个单词的首字母大写。
阅读全文
摘要:二维数组的声明格式:与一维数组不同的是二维数组在分配内存的时候必须告诉编译器二维数组行与列的个数。 int [][] arr = new int [行的个数][列的个数]; public static void main(String[] args){ int [][] arr = new int[
阅读全文
摘要:什么是标准输入输出流? System.in 是InputStream, 标准输入流,默认可以从键盘输入读取字符数据。 System.out是printStream,标准输出流,默认可以向Console中输出字符和字节数据。 修改标准输入输出流 修改输入流:System.setIn(InputStre
阅读全文
摘要:import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.ArrayL
阅读全文
摘要:该流可以将一个对象写出,或者读取一个对象到程序中,也就是执行了序列化和反序列化的操作。 1.创建一个PERSON对象实现Serializable接口。 public class Person implements Serializable { private String name; private
阅读全文
摘要:RandomAccessFile类不属于流,是Object类的子类,但它融合了InputStream和OutputStream的功能,支持对随机访问文件的读取和写入。 public static void main(String[] args) throws IOException{ RandomA
阅读全文
摘要:public static void main(String[] args) throws IOException{ 1.read(byte[] b)是字节输入流的方法,创建FileInputStream,关联a.txt FileInputStream fis = new FileInputStre
阅读全文
摘要:Public static void main(string[] args){ FileInputStream fis = new FileInputStream("e.txt"); ByteArrayOutputStream baos = new ByteArrayOutputStream();
阅读全文
摘要:public static void main(string[] args){ FileInputStream fis1 = new FileInputStream (a.txt); FileInputStream fis1 = new FileInputStream (b.txt); FileIn
阅读全文
摘要:public static void main(string[] args){ FileInputStream fisl = new FileInputStream ("a.txt"); //创建字节输入流关联a.txt文件 FileInputStream fis2 = new FileInputS
阅读全文

浙公网安备 33010602011771号