马凯军201771010116《面向对象与程序设计java》第九周学习总结(代码片段)

zero-- zero--     2023-01-12     177

关键词:

一.理论知识部分

 异常、日志、断言和调试

1.异常:在程序的执行过程中所发生的异常事件,它中断指令的正常执行。

2.Java的异常处理机制可以控制程序从错误产生的位置转移到能够进行错误处理的位置。

3.程序中出现的常见的错误和问题有:用户输入错误、设备错误、物理限制、代码错误。

4.Java把程序运行时可能遇到的错误分为两类:

(1)非致命异常:通过某种修正后程序还能继续执行。这类错误叫作异常。如:文件不存在、无效的数组下标、空引用、网络断开、打印机脱机、磁盘满等。 Java中提供了一种独特的处理异常的机制,通过异常来处理程序设计中出现的错误。

(2)致命异常:程序遇到了非常严重的不正常状态,不能简单恢复执行,是致命性错误。如:内存耗尽、系统内部错误等。这种错误程序本身无法解决。

5.Java中所有的异常类都直接或间接地继承于Throwable类。除内置异常类外程序员可自定义异常类。

6.Java中的异常类可分为两大类:

(1)Error Error类层次结构描述了Java 运行时系统的内部错误和资源耗尽错误。应用程序不应该捕获这类异常,也不会抛出这种异常。

(2)Exception Exception类:重点掌握的异常类。Exception层次结构又分解为两个分支:一个分支派生于RuntimeException;另一个分支包含其他异常。RuntimeException为运行时异常类,一般是程序错误产生。

7.派生于RuntimeException的异常包含下面几种情况:错误的类型转换、数组访问越界、访问空指针等等。

8.Java将派生于Error类或RuntimeException类的所有异常称为未检查异常,编译器允许不对它们做出异常处理。

9.非运行时异常,程序本身没有问题,但由于某种情况的变化,程序不能正常运行,导致异常出现。

10.除了运行时异常之外的其它继承自Exception类的异常类包括: 试图在文件尾部后面读取数据、试图打开一个错误格式的URL等等。

11.编译器要求程序必须对这类异常进行处理(checked),称为已检查异常。

12.Exception的其它子类:EmptyStackException、NoSuchFieldException、NoSuchMethodException、ClassNotFoundException、CloneNotSupportedException、IllegalAccessException、InstantiationException、InterruptedException。

13.声明抛出异常:如果一个方法可能会生成一些异常,但是该方法并不确切知道如何对这些异常事件进行处理,此时,这个方法就需声明抛出这些异常。

“一个方法不仅需要告诉编译器将要返回什么值,还要告诉编译器可能发生什么异常”。

14.声明抛出异常在方法声明中用throws子句中来指明。 15.throws子句可以同时指明多个异常,说明该方法将不对这些异常进行处理,而是声明抛出它们。

16.以下4种情况需要方法用throws子句声明抛出异常:

方法调用了一个抛出已检查异常的方法。 程序运行过程中可能会发生错误,并且利用throw语句抛出一个已检查异常对象。 程序出现错误。例如,a[-1] = 0;Java虚拟机和运行时库出现的内部异常。

17.一个方法必须声明该方法所有可能抛出的已检查异常,而未检查异常要么不可控制(Error),要么应该避免发生(RuntimeException)。如果方法没有声明所有可能发生的已检查异常,编译器会给出一个错误消息。

18.当Java应用程序出现错误时,会根据错误类型产生一个异常对象,这个对象包含了异常的类型和错误出现时程序所处的状态信息。把异常对象递交给Java编译器的过程称为出。

19.抛出异常要生成异常对象,异常对象可由某些类的实例生成,也可以由JVM生成。抛出异常对象通过throw语句来实现。

 20.对于已存在的异常类,抛出该类的异常对象非常容易,步骤是:找到一个合适的异常类;创建这个类的一个对象;将该对象抛出。自定义异常类:定义一个派生于Exception的直接或间接子类。如一个派生于IOException的类。 23.自定义的异常类应该包括两个构造器:默认构造器;带有详细描述信息的构造器(超类Throwable的toString方法会打印出这些详细信息,有利于代码调试 程序运行期间,异常发生时,Java运行系统从异常生成的代码块开始,寻找相应的异常处理代码,并将异常交给该方法处理,这一过程叫作捕获。 某个异常发生时,若程序没有在任何地方进行该异常的捕获,则程序就会终止执行,并在控制台上输出异常信息。异常的代码范围,由try所限定的代码块中的语句在执行过程中可能会自动生成异常对象并抛出。

 

二.实验部分

 

1、实验目的与要求

 

(1) 掌握java异常处理技术;

 

(2) 了解断言的用法;

 

(3) 了解日志的用途;

 

(4) 掌握程序基础调试技巧;

 

2、实验内容和步骤

 

实验1:用命令行与IDE两种环境下编辑调试运行源程序ExceptionDemo1、ExceptionDemo2,结合程序运行结果理解程序,掌握未检查异常和已检查异常的区别。

 

//异常示例1

public class ExceptionDemo1

public static void main(String args[])

int a = 0;

System.out.println(5 / a);

//异常示例2

import java.io.*;

 

public class ExceptionDemo2

public static void main(String args[])

     

          FileInputStream fis=new FileInputStream("text.txt");//JVM自动生成异常对象

          int b;

          while((b=fis.read())!=-1)

          

              System.out.print(b);

          

          fis.close();

      

 

异常的解决:

 

技术分享图片
public class ExceptionDemo1 

    public static void main(String[] args) 
        int a = 0;
        if(a==0) 
            System.out.println("除数为零");
        
        else
        
            System.out.println(5 / a);
        
        
    

技术分享图片

 

技术分享图片

 

技术分享图片

 

技术分享图片
import java.io.*;

public class ExceptionDemo2 
    public static void main(String args[])  
     
          FileInputStream fis;
        try 
          fis = new FileInputStream("text.txt"); 
          int b;
          while((b=fis.read())!=-1)
          
              System.out.print(b);
          
          fis.close();
        catch (Exception e) 
              // TODO Auto-generated catch block
              e.printStackTrace();//打印堆栈信息
//            System.out.println("Hello.");
        //JVM自动生成异常对象
     
技术分享图片

 

技术分享图片

 

技术分享图片

 

技术分享图片
import java.io.*;

public class ExceptionDemo2 
    public static void main(String args[]) throws IOException 
     
          FileInputStream fis=new FileInputStream("text.txt");//JVM自动生成异常对象
          int b;
          while((b=fis.read())!=-1)
          
              System.out.print(b);
          
          fis.close();
      
技术分享图片

 

技术分享图片

 

未检查异常:编译器允许不对其做出异常处理。已检查异常:编译器要求程序必须对这类异常进行处理。

 

实验2 导入以下示例程序,测试程序并进行代码注释。

 

测试程序1:

 

l 在elipse IDE中编辑、编译、调试运行教材281页7-1,结合程序运行结果理解程序;

 

l 在程序中相关代码处添加新知识的注释;

 

l 掌握Throwable类的堆栈跟踪方法;

 

技术分享图片
package stackTrace;

import java.util.*;

/**
 * A program that displays a trace feature of a recursive method call.
 * @version 1.01 2004-05-10
 * @author Cay Horstmann
 */
public class StackTraceTest

   /**
    * Computes the factorial of a number
    * @param n a non-negative integer
    * @return n! = 1 * 2 * . . . * n
    */
   public static int factorial(int n)
   
      System.out.println("factorial(" + n + "):");
      Throwable t = new Throwable();//抛出异常
      StackTraceElement[] frames = t.getStackTrace();//获得构造这个对象时调用堆栈的跟踪
      for (StackTraceElement f : frames)
         System.out.println(f);
      int r;
      if (n <= 1) r = 1;
      else r = n * factorial(n - 1);
      System.out.println("return " + r);
      return r;
   

   public static void main(String[] args)
   
      Scanner in = new Scanner(System.in);
      System.out.print("Enter n: ");
      int n = in.nextInt();
      factorial(n);
   
技术分享图片

 

技术分享图片

 

堆栈跟踪是程序执行中一个方法调用过程的列表。它包含了程序执行过程中方法调用的特定位置。

 

测试程序2:

 

l Java语言的异常处理有积极处理方法和消极处理两种方式;

 

l 下列两个简答程序范例给出了两种异常处理的代码格式。在elipse IDE中编辑、调试运行源程序ExceptionalTest.java,将程序中的text文件更换为身份证号.txt,要求将文件内容读入内容,并在控制台显示;

 

l 掌握两种异常处理技术的特点。

 

//积极处理方式  

import java.io.*;

 

class ExceptionTest

public static void main (string args[])

   

       try

       FileInputStream fis=new FileInputStream("text.txt");

       

       catchFileNotFoundExcption e

       ……  

……

    

//消极处理方式

 

import java.io.*;

class ExceptionTest

public static void main (string args[]) throws  FileNotFoundExcption

     

      FileInputStream fis=new FileInputStream("text.txt");

     

 

 积极:

 

技术分享图片
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExceptionalTest 
    public static void main(String args[]) 
         try 
                FileInputStream fis = new FileInputStream("身份证号.txt");
                BufferedReader in = new BufferedReader(new InputStreamReader(fis));
                String a,b = new String();
                while ((a = in.readLine()) != null) 
                    b += a + "
 ";
                
                in.close();
                System.out.println(b);

             catch (FileNotFoundException e) 
                System.out.println("学生信息文件找不到");
                e.printStackTrace();
             catch (IOException e) 
                System.out.println("学生信息文件读取错误");
                e.printStackTrace();
            
        
        
技术分享图片

 

技术分享图片
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExceptionalTest 
    public static void main(String[] args) throws IOException 
        FileInputStream fis = new FileInputStream("身份证号.txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(fis));
        String a, b = new String();
        while ((a = in.readLine()) != null) 
            b += a+ "
 ";
        
        in.close();
        System.out.println(b);
    
技术分享图片

 

技术分享图片

 

实验3: 编程练习

 

练习1

 

编制一个程序,将身份证号.txt 中的信息读入到内存中;

 

l 按姓名字典序输出人员信息;

 

l 查询最大年龄的人员信息;

 

l 查询最小年龄人员信息;

 

输入你的年龄,查询身份证号.txt中年龄与你最近人的姓名、身份证号、年龄、性别和出生地;

 

l 查询人员中是否有你的同乡;

 

l 在以上程序适当位置加入异常捕获代码。

 

技术分享图片
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Collections;//对集合进行排序、查找、修改等;

public class Test 
    private static ArrayList<Citizen> citizenlist;

    public static void main(String[] args) 
        citizenlist = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        File file = new File("E:/java/身份证号.txt");
        //异常捕获
        try 
            FileInputStream fis = new FileInputStream(file);
            BufferedReader in = new BufferedReader(new InputStreamReader(fis));
            String temp = null;
            while ((temp = in.readLine()) != null) 

                Scanner linescanner = new Scanner(temp);

                linescanner.useDelimiter(" ");
                String name = linescanner.next();
                String id = linescanner.next();
                String sex = linescanner.next();
                String age = linescanner.next();
                String birthplace = linescanner.nextLine();
                Citizen citizen = new Citizen();
                citizen.setName(name);
                citizen.setId(id);
                citizen.setSex(sex);
                // 将字符串转换成10进制数
                int ag = Integer.parseInt(age);
                citizen.setage(ag);
                citizen.setBirthplace(birthplace);
                citizenlist.add(citizen);

            
         catch (FileNotFoundException e) 
            System.out.println("信息文件找不到");
            e.printStackTrace();
         catch (IOException e) 
            System.out.println("信息文件读取错误");
            e.printStackTrace();
        
        boolean isTrue = true;
        while (isTrue) 

            System.out.println("1.按姓名字典序输出人员信息");
            System.out.println("2.查询最大年龄的人员信息、查询最小年龄人员信息");
            System.out.println("3.查询人员中是否查询人员中是否有你的同乡");
            System.out.println("4.输入你的年龄,查询文件中年龄与你最近人的姓名、身份证号、年龄、性别和出生地");
            System.out.println("5.退出");
            int nextInt = scanner.nextInt();
            switch (nextInt) 
            case 1:
                Collections.sort(citizenlist);
                System.out.println(citizenlist.toString());
                break;
            case 2:
                int max = 0, min = 100;
                int m, k1 = 0, k2 = 0;
                for (int i = 1; i < citizenlist.size(); i++) 
                    m = citizenlist.get(i).getage();
                    if (m > max) 
                        max = m;
                        k1 = i;
                    
                    if (m < min) 
                        min = m;
                        k2 = i;
                    
                
                System.out.println("年龄最大:" + citizenlist.get(k1));
                System.out.println("年龄最小:" + citizenlist.get(k2));
                break;
            case 3:
                System.out.println("出生地:");
                String find = scanner.next();
                String place = find.substring(0, 3);
                for (int i = 0; i < citizenlist.size(); i++) 
                    if (citizenlist.get(i).getBirthplace().substring(1, 4).equals(place))
                        System.out.println("出生地" + citizenlist.get(i));
                
                break;
            case 4:
                System.out.println("年龄:");
                int yourage = scanner.nextInt();
                int near = peer(yourage);
                int j = yourage - citizenlist.get(near).getage();
                System.out.println("" + citizenlist.get(near));
                break;
            case 5:
                isTrue = false;
                System.out.println("程序已退出!");
                break;
            default:
                System.out.println("输入有误");
            
        
    

    public static int peer(int age) 
        int flag = 0;
        int min = 53, j = 0;
        for (int i = 0; i < citizenlist.size(); i++) 
            j = citizenlist.get(i).getage() - age;
            if (j < 0)
                j = -j;
            if (j < min) 
                min = j;
                flag = i;
            
        
        return flag;
    
技术分享图片

 

技术分享图片
public class Citizen implements Comparable<Citizen> 

    private String name;
    private String id;
    private String sex;
    private int age;
    private String birthplace;

    public String getName() 
        return name;
    

    public void setName(String name) 
        this.name = name;
    

    public String getId() 
        return id;
    

    public void setId(String id) 
        this.id = id;
    

    public String getSex() 
        return sex;
    

    public void setSex(String sex) 
        this.sex = sex;
    

    public int getage() 
        return age;
    

    public void setage(int age) 
        this.age = age;
    

    public String getBirthplace() 
        return birthplace;
    

    public void setBirthplace(String birthplace) 
        this.birthplace = birthplace;
    

    public int compareTo(Citizen other) 
        return this.name.compareTo(other.getName());
    

    public String toString() 
        return name + "	" + sex + "	" + age + "	" + id + "	" + birthplace + "
";
    
技术分享图片

结果:

 

技术分享图片

 

 

技术分享图片

 

技术分享图片

 

练习2

 

l 编写一个计算器类,可以完成加、减、乘、除的操作;

 

利用计算机类,设计一个小学生100以内数的四则运算练习程序,由计算机随机产生10道加减乘除练习题,学生输入答案,由程序检查答案是否正确,每道题正确计10分,错误不计分,10道题测试结束后给出测试总分;

 

将程序中测试练习题及学生答题结果输出到文件,文件名为test.txt

 

l 在以上程序适当位置加入异常捕获代码。

 

技术分享图片
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class calculator 

    public static void main(String[] args) 
        Scanner in = new Scanner(System.in);
        PrintWriter out = null;
        try 
            out = new PrintWriter("test.txt");
            int sum = 0;
            for (int i = 0; i < 10; i++) 
                int a = (int) Math.round(Math.random() * 10);
                int b = (int) Math.round(Math.random() * 10);
                int menu = (int) Math.round(Math.random() * 3);
                switch (menu) 
                case 1:
                    System.out.println(a + "+" + b + "=");
                    int c1 = in.nextInt();
                    if (c1 == (a + b)) 
                        sum += 10;
                        System.out.println("恭喜答案正确");
                     else 
                        System.out.println("抱歉,答案错误");
                    
                    break;
                case 2:
                    System.out.println(a + "-" + b + "=");
                    int c2 = in.nextInt();
                    if (c2 == (a - b)) 
                        sum += 10;
                        System.out.println("恭喜答案正确");
                     else 
                        System.out.println("抱歉,答案错误");
                    

                    break;
                case 3:
                    System.out.println(a + "*" + b + "=");
                    int c = in.nextInt();
                    if (c == a * b) 
                        sum += 10;
                        System.out.println("恭喜答案正确");
                     else 
                        System.out.println("抱歉,答案错误");
                    

                    break;
                case 4:
                    if (b == 0) 
                        System.out.println("除数为零");
                     else 
                        System.out.println(a + "/" + b + "=");
                    
                    int c4 = in.nextInt();
                    if (c4 == a / b) 
                        sum += 10;
                        System.out.println("恭喜答案正确");
                     else 
                        System.out.println("抱歉,答案错误");
                    

                    break;
                
            
            System.out.println("你的得分为" + sum);
            out.println("你的得分为" + sum);
            out.close();
         catch (FileNotFoundException e) 
            e.printStackTrace();
        
    

技术分享图片

 

技术分享图片

 

实验4:断言、日志、程序调试技巧验证实验。

 

实验程序1

 

 

 

//断言程序示例

public class AssertDemo

    public static void main(String[] args)        

        test1(-5);

        test2(-3);

    

    

    private static void test1(int a)

        assert a > 0;

        System.out.println(a);

    

    private static void test2(int a)

       assert a > 0 : "something goes wrong here, a cannot be less than 0";

        System.out.println(a);

    

 

 

 

l 在elipse下调试程序AssertDemo,结合程序运行结果理解程序;

 

l 注释语句test1(-5);后重新运行程序,结合程序运行结果理解程序;

 

l 掌握断言的使用特点及用法。

 

技术分享图片
public class AssertDemo 

    public static void main(String[] args) 
        test1(-5);
        test2(-3);
    

    private static void test1(int a) 
        assert a > 0;
        System.out.println(a);
    

    private static void test2(int a) 
        assert a > 0 : "something goes wrong here, a cannot be less than 0";
        System.out.println(a);
    
技术分享图片

 

技术分享图片

 

技术分享图片

 

实验程序2:

 

l 用JDK命令调试运行教材298页-300页程序7-2,结合程序运行结果理解程序;

 

l 并掌握Java日志系统的用途及用法。

 

技术分享图片
package logging;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.logging.*;
import javax.swing.*;

/**
 * A modification of the image viewer program that logs various events.
 * @version 1.03 2015-08-20
 * @author Cay Horstmann
 */
public class LoggingImageViewer

   public static void main(String[] args)
   
      if (System.getProperty("java.util.logging.config.class") == null
            && System.getProperty("java.util.logging.config.file") == null)
      
         try
         
            Logger.getLogger("com.horstmann.corejava").setLevel(Level.ALL);
            final int LOG_ROTATION_COUNT = 10;
            Handler handler = new FileHandler("%h/LoggingImageViewer.log", 0, LOG_ROTATION_COUNT);
            Logger.getLogger("com.horstmann.corejava").addHandler(handler);
         
         catch (IOException e)
         
            Logger.getLogger("com.horstmann.corejava").log(Level.SEVERE,
                  "Can‘t create log file handler", e);
         
      

      EventQueue.invokeLater(() ->
            
               Handler windowHandler = new WindowHandler();
               windowHandler.setLevel(Level.ALL);
               Logger.getLogger("com.horstmann.corejava").addHandler(windowHandler);

               JFrame frame = new ImageViewerFrame();
               frame.setTitle("LoggingImageViewer");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

               Logger.getLogger("com.horstmann.corejava").fine("Showing frame");
               frame.setVisible(true);
            );
   


/**
 * The frame that shows the image.
 */
class ImageViewerFrame extends JFrame

   private static final int DEFAULT_WIDTH = 300;
   private static final int DEFAULT_HEIGHT = 400;   

   private JLabel label;
   private static Logger logger = Logger.getLogger("com.horstmann.corejava");

   public ImageViewerFrame()
   
      logger.entering("ImageViewerFrame", "<init>");      
      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

      // set up menu bar
      JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);

      JMenu menu = new JMenu("File");
      menuBar.add(menu);

      JMenuItem openItem = new JMenuItem("Open");
      menu.add(openItem);
      openItem.addActionListener(new FileOpenListener());

      JMenuItem exitItem = new JMenuItem("Exit");
      menu.add(exitItem);
      exitItem.addActionListener(new ActionListener()
         
            public void actionPerformed(ActionEvent event)
            
               logger.fine("Exiting.");
               System.exit(0);
            
         );

      // use a label to display the images
      label = new JLabel();
      add(label);
      logger.exiting("ImageViewerFrame", "<init>");
   

   private class FileOpenListener implements ActionListener
   
      public void actionPerformed(ActionEvent event)
      
         logger.entering("ImageViewerFrame.FileOpenListener", "actionPerformed", event);

         // set up file chooser
         JFileChooser chooser = new JFileChooser();
         chooser.setCurrentDirectory(new File("."));

         // accept all files ending with .gif
         chooser.setFileFilter(new javax.swing.filechooser.FileFilter()
            
               public boolean accept(File f)
               
                  return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory();
               

               public String getDescription()
               
                  return "GIF Images";
               
            );

         // show file chooser dialog
         int r = chooser.showOpenDialog(ImageViewerFrame.this);

         // if image file accepted, set it as icon of the label
         if (r == JFileChooser.APPROVE_OPTION)
         
            String name = chooser.getSelectedFile().getPath();
            logger.log(Level.FINE, "Reading file 0", name);
            label.setIcon(new ImageIcon(name));
         
         else logger.fine("File open dialog canceled.");
         logger.exiting("ImageViewerFrame.FileOpenListener", "actionPerformed");
      
   


/**
 * A handler for displaying log records in a window.
 */
class WindowHandler extends StreamHandler

   private JFrame frame;

   public WindowHandler()
   
      frame = new JFrame();
      final JTextArea output = new JTextArea();
      output.setEditable(false);
      frame.setSize(200, 200);
      frame.add(new JScrollPane(output));
      frame.setFocusableWindowState(false);
      frame.setVisible(true);
      setOutputStream(new OutputStream()
         
            public void write(int b)
            
             // not called

            public void write(byte[] b, int off, int len)
            
               output.append(new String(b, off, len));
            
         );
   

   public void publish(LogRecord record)
   
      if (!frame.isVisible()) return;
      super.publish(record);
      flush();
   
技术分享图片

 

技术分享图片技术分享图片

 3.实验总结

       通过本次实验,我对编程中出现的一些基本错误有了了解,也学习到了他们的处理方法,对程序中出现的异常的种类以及出现错误时如何抛出错误,捕获错误也有了初步的掌握。并且了解到一些异常的专用词,也明白了什么是致命异常和非致命异常。通过编程实践,我也掌握了处理异常的方法,并且基本能够在程序中恰当的位置添加try、catch语句。

马凯军201771010116《面向对象程序设计(java)》第一周学习总结

马凯军201771010116《面向对象程序设计(java)》第一周学习总结第一部分:课程准备部分填写课程学习平台注册账号,平台名称注册账号博客园:www.cnblogs.com消遣流年。程序设计评测:https://pintia.cn/[email protected]代码托管平台... 查看详情

马凯军201771010116《面向对象与程序设计java》第十五周学习知识总结(代码片段)

                                 &n 查看详情

马凯军201771010116《面向对象与程序设计java》第十二周学习总结(代码片段)

一、理论与知识学习部分Java的抽象窗口工具箱(AbstractWindowToolkit,AWT)包含在java.awt包中,它提供了许多用来设计GUI的组件类和容器类。大部分AWT组件都有其Swing的等价组件,Swing组件的名字一般是在AWT组件名前面添加一个字母“J... 查看详情

马凯军201771010116《面向对象与程序设计java》第九周学习总结(代码片段)

一.理论知识部分 异常、日志、断言和调试1.异常:在程序的执行过程中所发生的异常事件,它中断指令的正常执行。2.Java的异常处理机制可以控制程序从错误产生的位置转移到能够进行错误处理的位置。3.程序中出现的常见的... 查看详情

马凯军201771010116《面向对象与程序设计java》第十一周学习总结(代码片段)

一.理论知识部分第九章 集合1.数据结构介绍:线性结构:线性表,栈,队列,串,数组,文件。非线性结构:树,图。散列表:又称为哈希表。散列表算法的基本思想是:以结点的关键字为自变量,通过一定的函数关系(散... 查看详情

马凯军201771010116《面向对象程序设计(java)》第七周学习总结(代码片段)

 理论与知识部分多态性:概念:指在程序中同一符号在不同的情况下具有不同的解释。超类中定义的域或方法,被子类继承之后,可以具有不同的数据类型或表现出不同的行为。这使得同一域或方法在超类及各个子类中具有... 查看详情

马凯军201771010116《面向对象程序设计(java)》第三周学习总结(代码片段)

 第一部分 理论知识学习与复习部分1、在第一章里主要对Java中常见的误解这部分进行了细读,也对Java的“白皮书”术语认真的看了一遍,对Java术语有了更深的理解。2、在第二章中对Java程序的编辑环境eclipse通过课本理... 查看详情

马凯军201771010116《面向对象程序设计(java)》第六周学习总结(代码片段)

第一部分:理论知识学习部分    枚举是一种特殊的数据类型,之所以特殊是因为它既是一种类(class)类型却又比类型多了些特殊的约束,但是这些约束的存在也造就了枚举类型的简洁,安全性以及便捷性。创建... 查看详情

马凯军201771010116《面向对象与程序设计java》第十七周学习总结(代码片段)

一.理论知识部分 Java的线程调度采用优先级策略:优先级高的先执行,优先级低的后执行;多线程系统会自动为每个线程分配一个优先级,缺省时,继承其父类的优先级;任务紧急的线程,其优先级较高;同优先级的线程按“... 查看详情

马凯军201771010116《面向对象与程序设计java》第十六周知识学习总结(代码片段)

一:理论知识部分1.线程的概念:程序是一段静态的代码,它是应用程序执行的蓝本。‐进程是程序的一次动态执行,它对应了从代码加载、执行至执行完毕的一个完整过程。多线程是进程执行过程中产生的多条执行线索。‐线... 查看详情

设计模式与面向对象

面向对象基础抽象封装继承多态组合良好的OO设计可复用可扩充可维护设计模式 查看详情

面向对象的程序设计

阅读目录一面向对象的程序设计的由来二什么是面向对象的程序设计及为什么要有它三类与对象四属性查找五绑定到对象的方法的特殊之处六对象之间的交互七练习八继承与派生九多态与多态性十封装十一绑定方法与非绑定方法... 查看详情

面向对象

一面向对象的程序设计的由来二什么是面向对象的程序设计及为什么要有它三类与对象四属性查找五绑定到对象的方法的特殊之处六对象之间的交互七练习八继承与派生九多态与多态性十封装十一绑定方法与非绑定方法十二小白... 查看详情

面向对象的编程思想和java中类的概念与设计

面向对象的编程思想学习,面向对象内容的三条主线;1.java类及类的对象2.面向对象的三大特征3.其他关键字学习内容:3.1面向对象与面向过程面向对象与面向过程在应用上的区别Java中类的概念与设计类与类之间的关系面向对象的... 查看详情

面向对象与面向过程区别

...步一步实现,使用时依次调用就可以了;区别:面向对象程序设计,往往是从问题的一部分着手,一点一点地构建出整个程序。面向对象设计以数据为中心,类作为表现数据的工具,成为划分程序的基本单位;面向对象是一个抽... 查看详情

面向对象(代码片段)

阅读目录一面向对象的程序设计的由来二什么是面向对象的程序设计及为什么要有它三类与对象四属性查找五绑定到对象的方法的特殊之处六对象之间的交互七练习八继承与派生九多态与多态性十封装十一绑定方法与非绑定方法... 查看详情

面向对象的程序设计

一面向对象的程序设计的由来二什么是面向对象的程序设计及为什么要有它三类和对象3.1类相关知识3.2对象相关知识3.3对象之间的交互3.4类名称空间与对象/实例名称空间3.5小结四继承与派生4.1什么是继承4.2继承与抽象(先抽象... 查看详情

java与面向对象设计

1面向对象与面向过程2.OO的特点 (1)封装性(2)继承性(3)多态性3.ClassandObject(1)defineaclass(2)gloablesandlocalvariables(3)constructor‘sdefinationandapplication(4)createanobjectdeclrationanobject allocatememory(5)us 查看详情