• java 基础复习


    第一天:

    1. JRE、JDK是什么?
    2. Jre是java虚拟机+核心类库
    3. JDK是jre+java工具开发包。

           2. 配置path的作用。

          在任何文件下都可以运行java虚拟机的指令

          

    第二天:

    1. 关键字、标识符 、注释的类型。
    2. 关键字:系统定义好了的,可以直接拿来用,我们不可以修改。
    3. 标识符:关键字和保留字。
    4. 自定义标识符:我们可以修改的自己定义
    5. 注释:单行注释//  多行注释/**/ 文档注释/**文档注释*/

           2. 变量的基本数据类型有那些?数据类型转换?

           整型,浮点型,布尔型,字符型。

             自动转换和强制转换

    第三天:

    1. if 判断语句
    2. if( 条件){
    3.     条件成功运行
    4. }

           2. while循环语句

    while (条件) {

           条件成功运行

          

    }

    1. switch语句
    2. switch (传入的变量) {
    3.         case value:判断
    4.               
    5.                break;
    6.  
    7.         default:
    8.                break;
    9.         }
    1. for循环语句。
    2. for (int i = 0; i <100; i++) {
    3.               
    4.         }
    5. }
    1. continue、break关键字。
    2. continue跳出本次循环执行下一次循环
    3. break终止整个循环

          

    第四天:

          

    1. 数组、 直接排序、冒泡排序、折半查找法、
    2. public class work1 {
    3.  
    4. /**
    5.  * @param args
    6.  */
    7. public static void main(String[] args) {
    8.         // TODO Auto-generated method stub
    9.   int[] a ={65,23,68,45,2,1};
    10.   //冒泡排序;
    11.   /*for (int i = 0; i < a.length; i++) {
    12.             for (int j = 0; j < a.length-1-i; j++) {
    13.                       if (a[j]>a[j+1]) {
    14.                              int temp =a[j];
    15.                              a[j]=a[j+1];
    16.                              a[j+1]=temp;
    17.                       }
    18.                }
    19.            
    20. }*/
    21.   //选择排序
    22.   /*int k;
    23.   for (int i = 0; i < a.length; i++) {
    24.         k=i;
    25.         for (int j = i+1; j < a.length; j++) {
    26.                if (a[k]<a[j]) {
    27.                       k=j;
    28.                }
    29.               
    30.                if (k==j) {
    31.                       int temp =a[i];
    32.                       a[i]=a[k];
    33.                       a[k]=temp;
    34.                }
    35.         }
    36. }*/
    37. //折半查找法
    38.   int temp=68;
    39.   int lest=0;
    40.   int ringt=a.length-1;
    41.   int mid=0 ;
    42.  
    43.   int flag=0;
    44.   while (flag==0 && lest<=ringt) {
    45.         mid = (lest+ringt)/2;
    46.         if (temp==a[mid]) {
    47.                flag=1;
    48.         }else if (temp<a[mid]) {
    49.                ringt=mid-1;
    50.         }else {
    51.                lest=mid+1;
    52.         }
    53. }
    54.   for (int i = 0; i < a.length; i++) {
    55.             System.out.println(a[i]);
    56. }
    57.   System.out.println("在数组中下表是"+mid);
    58. }
    59.  
    60. }

    练习题目:

          

    1. 目前有数组” int[] arr =  {11,2, 4, 2, 10, 11},定义一个函数清除该数组的重复元素,返回一个不能浪费长度的数组.
    2. public class Work2 {
    3.  
    4. public static void main(String[] args) {
    5.        
    6.         
    7.         int[] arr={11,2,0,2,10,11,11,2,6};
    8.         int[] arr1=zz(arr);
    9.           for (int i = 0; i < arr1.length; i++) {
    10.                    System.out.println(arr1[i]);
    11.                        }
    12.           System.out.println("arr.length="+arr.length+" arr1.length="+arr1.length);
    13. }
    14. public static int[] zz(int[] arr){
    15.         int a=0;
    16.         int b=0;
    17.         int c=961745;
    18.         for (int i = 0; i < arr.length; i++) {
    19.                  for (int j = i+1; j < arr.length; j++) {
    20.                       if (arr[i]==arr[j]&&arr[i]!=961745) {
    21.                              a++;
    22.                              arr[j]=c;
    23.                              continue;
    24.                       }
    25.                }
    26.         }
    27.         int[] arr1=new int[arr.length-a];
    28.  
    29.         for (int i = 0; i < arr.length; i++) {
    30.                  if (arr[i]!=c) {
    31.                       arr1[b]=arr[i];
    32.                       b++;
    33.                }
    34.                             
    35.         }
    36.        
    37.         return arr1;
    38. }
    39.  
    40. }

    第五天:

    1. 对象与类的概念。
    2. 类就对同一类事物的抽象描述
    3. 对象就是该类具体描述真实存在。

           2. 构造方法的基本概念、构造代码块的。构造函数与构造代码块的区别。

          构造方法;是系统自己调用的,只会初始化一次,我们可以自己写构造方法,java虚拟机就不创建无参的构造方法出来,我们可以初始化属性

    构造代码块;是运行在构造方法里面,可以初始化一些统一的成员,优先构造函数里面代码的执行。

      构造

    1. this关键字、this关键字 的作用?

    指调用者本身,如果跟局部变量跟成员变量重名可以使用this区分.

    练习题目:

    1. 使用java类描述一个学生类,学生具备id、name、age三个属性、还有行走的方法。要求一旦创建学生对象,学生对象就具备了属性值。  (考点:构造函数)

    class Student{

         int id;

         String name;

         int age;

         public Student(int id,String name,int age){

         

          this.id=id;

          this.name=name;

          this.age=age;

         

         }

        

         public void paly(){

          System.out.println("走路");

         }

    }

    public class Work {

     

         public static void main(String[] args) {

          // TODO Auto-generated method stub

          Student s = new Student(10086, "张政", 20);

          System.out.println(s.id+s.name+s.age);

     

         }

     

    }

    1. 使用java类描述一个学生类,学生具备id、name、age三个属性、还有行走的方法,走的方法中也有一个局部变量name,怎样才可以指定访问到成员变量的name呢?学生还具备一个比较年龄的方法。 (this关键字)
    2. class Student{
    3.       int id;
    4.       String name;
    5.       int age=20;
    6.       public Student(int id,String name,int age){
    7.              if (age>this.age) {
    8.                     this.age=age;
    9.              }else {
    10.                     age=this.age;
    11.              }
    12.              this.id=id;
    13.              this.name=name;
    14.             
    15.             
    16.       }
    17.      
    18.       public void paly(){
    19.             
    20.              System.out.println("走路");
    21.             
    22.       }
    23.             
    24. }
    25. public class Work {
    26.  
    27.       public static void main(String[] args) {
    28.              Student s = new Student(10086, "张政", 18);
    29.              System.out.println(s.id+s.name+s.age);
    30.  
    31.       }
    32.  
    33. }

            3. 模拟用户登陆注册,查看用户、退出系统。效果以下图。

        

                 

    import java.util.*;

    class ZuCe{

           static String[] name=new String[50];

           static int[] n=new int[50];

          

           public static void paly(){

                 

                  System.out.println("请选择功能: 注册(A)查看用户(B)退出系统(q)");

                  Scanner sca = new Scanner(System.in);

                  String str = sca.next();

                  if (str.equalsIgnoreCase("a")) {

                         yi();

                  }else if (str.equalsIgnoreCase("b")) {

                         er();

                  }else if (str.equalsIgnoreCase("c")) {

                         System.out.println("谢谢你的使用");

             }else {

                         System.out.println("输入错误请重启");

                  }

                 

           }

           public static void yi(){

                  System.out.println("请输入用户名:");

                  Scanner sca = new Scanner(System.in);

                  String str = sca.next();

                  System.out.println("请输入密码:");

                  Scanner sca1 = new Scanner(System.in);

                  int sum = sca1.nextInt();

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

                         if (name[i]==null) {

                                name[i]=str;

                                n[i]=sum;

                                break;

                         }

                  }

                  paly();

                 

           }

           public static void er(){

                  System.out.println("当前用户为:");

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

                         if (name[i]==null) {

                                break;

                         }

                        

                         System.out.println("用户名:"+name[i]+":"+n[i]);

                        

                  }

                  paly();

           }

          

    }

    public class Work4 {

           public static void main(String[] args) {

                 

                  System.out.println("欢迎你来到0217java基础班");

                  ZuCe.paly();

           }

    }

    第五天:

    1. static关键字的作用、单例设计模式。
    2. static 静态修饰符比对象早存在,与类一起存在,用static修饰了之后可以不用创建对象就可以调用
    3. class DanLie
    4. {
    5.      String name;
    6.       private static DanLie d = new DanLie();
    7.   private DanLie(){
    8.   
    9.   
    10.   }
    11.  
    12.   public static DanLie paly(){
    13.   
    14.       return d;
    15.   
    16.   }
    17.  
    18. }
    19.  
    20.  
    21. class  Work5
    22. {
    23. public static void main(String[] args)
    24. {
    25.  
    26.            DanLie d = DanLie.paly();
    27.            d.name="方可获得";
    28.            
    29.            DanLie d1 = DanLie.paly();
    30.        
    31.            
    32.            DanLie d2 = DanLie.paly();
    33.           
    34.         System.out.println(d.name);
    35.         System.out.println(d1.name);
    36.         System.out.println(d2.name);
    37.  
    38. }
    39. }

           2. 继承、继承要注意的细节。

         类名 extends 类名

    继承 : 可以优化代码,继承要满足is a 条件可以继承父类的属性和方法

    不能继承父类的私有变量和构造方法,运行子类的构造方法时会默认调用父类的无参构造。

          

          

    第六天:

    1. 抽象类
    2. abstract class 类名
    3. 抽象法现在抽象类里面的
    4. 具有相同的行为但是表现的不一样 我就需要一个抽象法来在父类定义这个行为
    5. 继承抽象类的子类必须实现抽象方法

           2. 接口

    Interface 接口名

          接口是一个特殊的类

          里面的方法都是抽象方法 实现接口的类必须实现里面的方法

            类名 implements 接口名

          接口里面可以定义属性 默认是用final修饰的、必须初始化实现接口的类可以这个属性.

           3. 多态  

      一个对象的多种表现形态(父类的)

    第七天:

    1. 内部类。
    2. 内部类。:定义在类中的类,称为内部类,
    3. 分为局部内部类和成员内部类;
    4. 成员内部类有两种访问方式:一个在外部类中定义方法创建内部类对象,在通过对象访问,另一个就是在其他类直接创建内部类对象。
    5. 局部内部类:是定义在方法中的类,只能有一种访问方式,方法创建内部类对象
    6. 注意点:如果局部内部类访问了方法中的局部变量,该变量要用final修饰

           2.自定义异常。

    自定义异常:由于java拥有的异常没那么多,有时候需要自定义异常,这个定义的异常要继承自Exception。

    异常体系:Throwable所有异常和错误的父类(error 和 exception)

    Exception:包括运行时异常和编译时异常。

    运行时异常:抛出运行时异常时,可以不用在方法上声明,调用者也可以不处理

    编译时异常:抛出编译时异常时,方法上必须声明,调用者也必须处理

  • 相关阅读:
    2016-09-13面试记录
    javascript中的深度拷贝的实现过程及深拷贝的几种方法。
    javascript中的for in循环
    常见的兼容问题及其解决方法。
    一次清空所有数据方法
    数组排序
    css对齐 挖坑~
    css reset样式重置
    CSS 表单
    CSS 表格
  • 原文地址:https://www.cnblogs.com/zzzhangzheng/p/6099318.html
Copyright © 2020-2023  润新知