Basic knowledge

  • The access rights in java are public, protected, private, default, and default cannot modify variables. A class defined as abstract needs to be inherited by subclasses, but it cannot be inherited and overridden if it is modified as final.

  • A final object reference cannot point to a different object, but the data in the final object can change.
  • HashMap and Hashtable: HashMap is actually a "linked list hash" data structure, that is, a combination of data and linked list. The underlying structure of HashMap is an array, and each item in the array is a linked list. An instance of HashMap has two parameters that affect its performance "initial capacity" and "filling factor". HashMap is not thread safe, Hashtable is thread safe. The key-value in HashMap is stored in Entry. Hashtable keys and values ​​are not allowed to appear null. HashMap can store null keys and null values. There is only one such key, and there can be multiple values. When judging whether it contains a certain value, the containsKey() method should be used to judge. There are three main ways to resolve conflicts, addressing method, zipper method, and re-hash method. HashMap uses zipper method to resolve hash conflicts. HashMap and Hashtable their inheritance is different. The use of hash values ​​is different. Hashtable directly uses the object hashCode, while HashMap re-calculates the hash value. The initial array size of HashMap is 16, and the increase method is an index of 2. The initial array size of Hashtabel is 11, and the increase method is old*2+1. Inheritance is different. Hashtable inherits Directory, and HashMap inherits AbstractMap

  • Analysis from action class: Struts1 requires Action class to inherit an abstract base class. A common problem of Struts1 is to use abstract class programming instead of interface. The Struts2 Action class can implement an Action interface or other interfaces. Struts2 provides an ActionSupport base class to implement common interfaces. The Action interface is not necessary. Any POJO object with the execute logo can be used as the Action interface of Struts2. From Servlet Dependency Analysis: Sturts1 Action relies on Servlet API, because HttpServeltRequest and HttpServeltResponse are passed to the execute method when an Action is called. Struts2 Action does not depend on the container, allowing the Action to be tested independently from the container, and if needed, the Struts2 Action can access the initial request and response. Action thread pattern analysis: Struts1 Action is a singleton pattern and must be thread-safe, because only one instance of Action handles all requests. Struts2 Action objects generate an instance for each request, so there are no thread safety issues.

  • Ant and Maven are both java-based build tools. Ant features: there is no agreed directory structure, and it must be clear what ant does and when to do it, and then compile and package. There is no life cycle, and the goal and the task series it implements must be defined. , without integrated dependency management. Maven has a convention, knows where your code is, where to put it, and has a life cycle. For example, maven install can automatically perform compilation, testing, packaging, etc., with dependency management and warehouse management.

  • Constructors are a special kind of method: the method name of the constructor must be the same as the class name. Constructors have no return type and cannot be defined as void, and the method type is not declared before the method name. The main function of the constructor is to complete the initialization of the object, and it can pass the parameters when defining the object to the object domain. A class can define multiple constructors. If no constructor is defined when the class is defined, the compilation system will automatically insert a parameterless default constructor, which does not execute any code. Constructors can be overloaded for the number, order, and type of parameters.

  • Java class loader : Bootstrap class loader (bootstrap class loader) It is used to load the core library of java and is implemented with native code. The extension class loader (extensions class loader) is used to load the extension library of java. The system class loader (system class loader) loads java classes according to the class path of the java application. Tomcat creates a loader for each app, which stores the ClassLoader of the WebApp. When you need to load the classes under WebApp, take out the ClassLoader to use.

  • Diagram of exception inheritance

     

  • This is the Struts project with MVC pattern diagram

  • J2EE中常用的名词解释EJB容器,Enterprise java bean容器,他提供给运行在其中的组件EJB各个管理功能。JNDI(java naming&directory interface)java命名目录服务,提供一个目录系,让其他各地的应用程序在其上留下自己的索引,从而满足快速查找和定位分布式应用程序的功能。JMS(java message service)java消息服务,主要实现各个应用程序之间的通讯,包括点对点和广播。JTA(java transaction api)java事物服务,提供各种分布式事务服务,应用程序只需要用其提供的接口即可。JAF(java action framework)java安全认证服务,提供一些安全控制方面的框架,让开发者通过各种部署和自定义实现自己的个性安全控制策略。RMI/IIOP(remote method invocation/internet)主要用于通过远程调用服务。

  • 用new创建的对象存放在堆区。函数中的临时变量在栈区。java中的字符串在字符串常量区

  • 从地址栏显示来说:forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容在发给浏览器,浏览器根本不知道服务器发送的内容从什么地方来,所以他的地址还是原来的地址。rediredt是服务器根据逻辑发送一个状态码,告诉浏览器重新请求那个地址,所以地址栏显示的是新的URL。从数据共享来说:forward转发页面和转发到的页面可以共享request里面的数据,redirect不共享数据。从运用角度来说:forward一般用于用户登录的时候,根据角色转发到相应的模块,redirect一般用于用户注销登录时用户返回主页面和跳转到其他网站等。从效率上来说:forward高,redirect低。

  • 依赖注入和控制反转是对同一件事情的不同描述,从某个方面讲,就是他们描述的角度不同,依赖注入是从应用程序的角度描述,应用程序依赖容器创建并注入它所需要的外部资源;而控制反转是从容器的角度在描述,容器控制应用程序,由容器反向向应用程序注入应用程序所需要的外部资源。

  • 复制数组方法效率:System.arraycopy>clone>Arrays.copyOf>for循环
  • java中常见线程有四种方法:继承Thread;实现接口Runable;实现Callable接口通过FutureTask包装器来创建Thread线程;使用ExecutorService、Callable、Future来实现有返回值的线程;前两种是没有返回值的;后两种是带有返回值的;
    //这是实现Callable接口用FutureTask包装器来实现线程
    Callable<V> oneCallable = new SomeCallable<V>();   
    //由Callable<Integer>创建一个FutureTask<Integer>对象:   
    FutureTask<V> oneTask = new FutureTask<V>(oneCallable);   
    //注释:FutureTask<Integer>是一个包装器,它通过接受Callable<Integer>来创建,它同时实现了Future和Runnable接口。 
      //由FutureTask<Integer>创建一个Thread对象:   
    Thread oneThread = new Thread(oneTask);   
    oneThread.start();   
    //至此,一个线程就创建完成了。
    import java.util.concurrent.*;  
    import java.util.Date;  
    import java.util.List;  
    import java.util.ArrayList;  
      
    /** 
    * 有返回值的线程;使用ExecutorService、Callable、Future来实现多线程 
    */  
    @SuppressWarnings("unchecked")  
    public class Test {  
    public static void main(String[] args) throws ExecutionException,  
        InterruptedException {  
       System.out.println("----程序开始运行----");  
       Date date1 = new Date();  
      
       int taskSize = 5;  
       // 创建一个线程池  
       ExecutorService pool = Executors.newFixedThreadPool(taskSize);  
       // 创建多个有返回值的任务  
       List<Future> list = new ArrayList<Future>();  
       for (int i = 0; i < taskSize; i++) {  
        Callable c = new MyCallable(i + " ");  
        // 执行任务并获取Future对象  
        Future f = pool.submit(c);  
        // System.out.println(">>>" + f.get().toString());  
        list.add(f);  
       }  
       // 关闭线程池  
       pool.shutdown();  
      
       // 获取所有并发任务的运行结果  
       for (Future f : list) {  
        // 从Future对象上获取任务的返回值,并输出到控制台  
        System.out.println(">>>" + f.get().toString());  
       }  
      
       Date date2 = new Date();  
       System.out.println("----程序结束运行----,程序运行时间【"  
         + (date2.getTime() - date1.getTime()) + "毫秒】");  
    }  
    }  
      
    class MyCallable implements Callable<Object> {  
    private String taskNum;  
      
    MyCallable(String taskNum) {  
       this.taskNum = taskNum;  
    }  
      
    public Object call() throws Exception {  
       System.out.println(">>>" + taskNum + "任务启动");  
       Date dateTmp1 = new Date();  
       Thread.sleep(1000);  
       Date dateTmp2 = new Date();  
       long time = dateTmp2.getTime() - dateTmp1.getTime();  
       System.out.println(">>>" + taskNum + "任务终止");  
       return taskNum + "任务返回运行结果,当前任务时间【" + time + "毫秒】";  
    }  
    }
    

      

  • 集合关系图

     

  • JVM加载类的方式,我们称为“双亲委托模式”:如果一个类加载器收到了类加载的请求,它首先不会自己去尝试加载这个类,而是把这个请求委托给自己的父类加载器,每一层的类加载器都是如此,因此所有的类加载请求最终都应该传送到顶层Bootstrap ClassLoader中,只有当父加载类无法完成加载请求时,子加载类才会尝试自己加载。“双亲委托模式”的最重要的用途是为了解决类载入过程中的安全性问题

  • jvm中划分三个代:年轻代(Young Generation),年老代(Old Generation),持久代(Permanent Generation)。年轻代:所有新生成的对象首先都放到年轻代,年轻代的目标是尽快收集那些生命周期比较短的对象,年轻代一般分为三个区域,一个Eden区,两个Survivor区,大部分对象在Eden区生成,当Eden区满时,还存活的对象将被复制到两个中的一个Survivor区,当这个Survivor区满时,此区的存活对象将被复制到另一个Survivor区,当这个区也满了,那么将从第一个Survivor区复制过来的目前还存活的对象将被复制到“年老区(Tenured)”。老年代:在年轻代中经过N次垃圾回收仍然存活的对象,就会被放到年老代。持久代:用于存放静态文件,如java类,方法等。GC的两种类型:Scavenge GC:一般情况下,当新对象生成,并且在Eden申请空间失败时,就会触发Scavenge GC,对Eden区域进行GC,清除非存活对象,并且把存活的对象转移到Survive区,然后整理Survive两个区。这种方式的GC是对年轻代的Eden区进行,不会影响到年老代。Full GC:对整个堆进行整理,因为对整个堆进行整理所以比Scavenge GC要慢,因此应该尽可能减少Full GC的次数。可能造成Full GC的原因:年老代被写满;持久代被写满;System.gc()被显示调用;通过Minor GC后进入年老代的平均大小大于年老代的可用内存;由Eden区、From Space区向To Space区复制时,对象大小大于To Space可用内存,则把该对象转移到年老代,且年老代的可用内存小于该对象大小。GC算法:标记清除算法;复制算法;标记整理算法。Minor GC:从年轻代空间回收内存被称为Minor GC,当Eden区没有足够的空间时,会发起一次Minor GC,将Eden区中存活的对象转移到Survivor区。Major GC:是清除年老代区域,当升到年老代的对象大于年老代剩余空间时会发生Miajor GC,发生Major GC时用户线程会暂停,会降低系统性能和吞吐量。java中一般不手动触发GC,但可以用不同的引用类来辅助垃圾回收的工作(比如:弱引用或软引用)。引用类:强引用;虚引用;弱引用;软引用。
  • jvm内存划分:一共分为五个块,其中线程共享区域为:java堆,方法区;线程私有区域为:jvm栈,本地方法栈,程序计数器。其中java堆包含了jvm的三代划分。

  • 匿名内部类:注意如下几点:1.由于匿名内部类不能是抽象类,所以它必须实现它的抽象父类或者接口里面的所有抽象方法,使用匿名内部类时,必须是继承一个类或者实现一个接口。2.匿名内部类中不能有构造函数的。3.匿名内部类中不能存在任何的静态成员变量和静态方法。4.匿名内部类是局部内部类,所以局部内部类的所有限制同样对它也有效。当所在的方法的形参需要被内部类里面使用时,该形参必须是被final修饰。
  • 结构模型模式

  •  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325288515&siteId=291194637