Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中的生命周期方法_Java - Fatal编程技术网

java中的生命周期方法

java中的生命周期方法,java,Java,当一个类继承这个类并重写这些生命周期方法时,如何创建一个包含一些按某种顺序执行的方法的类(即类的生命周期方法) 例如: This is the method which is called by the browser only one time after loading the applet. In this method we write some block of statements which will perform one time operations, such as, ob

当一个类继承这个类并重写这些生命周期方法时,如何创建一个包含一些按某种顺序执行的方法的类(即类的生命周期方法)

例如:

This is the method which is called by the browser only one time after loading the applet.
In this method we write some block of statements which will perform one time operations, such as, obtaining the resources like opening the files, obtaining the database connection, initializing the parameters, etc.
  After calling the init method, the next method which is from second request to sub-sequent requests the start method only will be called i.e., short method will be called each and every time.
In this method we write the block of statement which provides business logic.
  This id the method which is called by the browser when we minimize the window. 
In this method we write the block of statements which will temporarily releases the resources which are obtained in init method.
This is the method which will be called by the browser when we close the window button or when we terminate the applet application.
In this method we write same block of statements which will releases the resources permanently which are obtained in init method.
  • 在Servlet中,首先调用init(),然后调用service(),最后在创建Servlet对象时自动调用destroy()

  • android中的活动具有生命周期方法onCreate()、onStart()、onResume()等,当活动的对象存在时会自动调用这些方法


  • 这些方法的顺序是由引用类的框架/容器强制执行的。我通常认为您的框架将要求客户端实现特定的接口(包含
    start()
    stop()
    等),框架本身将确定状态机和后续行为。

    JAVA的生命周期方法

    由于小程序在浏览器中运行,因此类小程序包含生命周期方法。 生命周期方法也称为回环方法

    在java.applet.applet中,我们有四种生命周期方法。他们是

    public void init (),
    public void start (),
    public void stop () 
    public void destroy ().
    
    1。Public void init():

    This is the method which is called by the browser only one time after loading the applet.
    In this method we write some block of statements which will perform one time operations, such as, obtaining the resources like opening the files, obtaining the database connection, initializing the parameters, etc.
    
      After calling the init method, the next method which is from second request to sub-sequent requests the start method only will be called i.e., short method will be called each and every time.
    In this method we write the block of statement which provides business logic.
    
      This id the method which is called by the browser when we minimize the window. 
    In this method we write the block of statements which will temporarily releases the resources which are obtained in init method.
    
    This is the method which will be called by the browser when we close the window button or when we terminate the applet application.
    In this method we write same block of statements which will releases the resources permanently which are obtained in init method.
    
    2。Public void start():

    This is the method which is called by the browser only one time after loading the applet.
    In this method we write some block of statements which will perform one time operations, such as, obtaining the resources like opening the files, obtaining the database connection, initializing the parameters, etc.
    
      After calling the init method, the next method which is from second request to sub-sequent requests the start method only will be called i.e., short method will be called each and every time.
    In this method we write the block of statement which provides business logic.
    
      This id the method which is called by the browser when we minimize the window. 
    In this method we write the block of statements which will temporarily releases the resources which are obtained in init method.
    
    This is the method which will be called by the browser when we close the window button or when we terminate the applet application.
    In this method we write same block of statements which will releases the resources permanently which are obtained in init method.
    
    3。公共作废停止():

    This is the method which is called by the browser only one time after loading the applet.
    In this method we write some block of statements which will perform one time operations, such as, obtaining the resources like opening the files, obtaining the database connection, initializing the parameters, etc.
    
      After calling the init method, the next method which is from second request to sub-sequent requests the start method only will be called i.e., short method will be called each and every time.
    In this method we write the block of statement which provides business logic.
    
      This id the method which is called by the browser when we minimize the window. 
    In this method we write the block of statements which will temporarily releases the resources which are obtained in init method.
    
    This is the method which will be called by the browser when we close the window button or when we terminate the applet application.
    In this method we write same block of statements which will releases the resources permanently which are obtained in init method.
    
    4。公共作废销毁():

    This is the method which is called by the browser only one time after loading the applet.
    In this method we write some block of statements which will perform one time operations, such as, obtaining the resources like opening the files, obtaining the database connection, initializing the parameters, etc.
    
      After calling the init method, the next method which is from second request to sub-sequent requests the start method only will be called i.e., short method will be called each and every time.
    In this method we write the block of statement which provides business logic.
    
      This id the method which is called by the browser when we minimize the window. 
    In this method we write the block of statements which will temporarily releases the resources which are obtained in init method.
    
    This is the method which will be called by the browser when we close the window button or when we terminate the applet application.
    In this method we write same block of statements which will releases the resources permanently which are obtained in init method.
    
    另一种不是生命周期方法的方法是public void paint()。这就是 将在start方法完成后由浏览器调用。此方法用于显示 数据将显示在浏览器上。Paint方法在内部调用名为drawString的方法,该方法的 原型如下所示。 java.awt.Graphics (Graphics=>public void抽绳(字符串、整数行位置、整数列位置)) 将小程序加载到图形类后,将自动创建图形类的对象
    浏览器。

    您需要应用程序容器(最简单的解释是它是某个类,它将按指定顺序执行类的指定方法)。但您需要更深入地理解应用程序容器的概念。我建议您阅读有关

    的最简单的内容,您的需求可以通过使用模板方法得到满足:

    public class Template {
      public void templateMethod() {
        detail1();
        detail2();
      }
      protected void detail1() {}
      protected void detail2() {}
    
    }


    然后,您可以对模板类进行子类化。

    创建类并定义方法。问题出在哪里?当一个类继承了我的类(它有生命周期方法)时,那么被一个新类覆盖的方法就会以某种顺序执行。请看一下模板方法模式。它允许人们在不改变算法结构的情况下重新定义算法的某些步骤。这是一个投票不足的问题。它需要对框架和应用程序容器有更深的理解。当你进入语言编译器时,事情会变得复杂。这对于应用程序来说是非常具体的。这是一个投票不足的问题。它需要对框架和应用程序容器有更深的理解。当你进入语言编译器时,事情变得复杂起来。