In memory of my java posture — turn

Original address: https://segmentfault.com/a/1190000007122432?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

Currently working on node JS, I forgot a lot about my java knowledge. Therefore, I sorted it out and lamented that the industrial language still has considerable advantages.

Stream exception annotation security class loading keyword initializing multithreaded thread pool memory model

Java exceptions (including exception and error) are divided into: verifiable exceptions (checked exceptions) except for runtimeException and its subclasses, other exception classes and their subclasses belong to checked exceptions. The characteristic of this exception is that the java compiler will check it, that is, when this kind of exception may occur in the program, either catch it with a try catch statement or throw it with a throw clause declaration, otherwise the compilation will not pass. Non checked exceptions Unchecked exceptions include runtime exceptions (runtimeException and its subclasses) and errors (errors). Runtime exceptions and non runtime exceptions: runtimeException, NullPointerException (null pointer exception), indexoutofboundsexception (subscript out of bounds exception), etc. these exceptions are not checked, and can be caught or not handled in the program. These exceptions are generally caused by program logic errors. The program should avoid such exceptions as much as possible from a logical point of view. The characteristic of runtime exception is that the java compiler will not check it, that is, when such an exception may occur in the program, it will be compiled even if it is not caught with the try catch statement or thrown with the throw clause declaration. Exceptions other than runtimeException are exceptions that must be handled from the perspective of program syntax. If they are not handled, the program cannot be compiled. For example, IOException, sqlexception, etc. and user-defined exception exceptions, exceptions are generally not checked by users. Return to directory

Java se5 has three built-in standard annotations: < span class = "hljs property" > @ deprecated. The compiler will issue a warning if the annotation is used as its element, because the annotation < span class = "hljs property" > @ deprecated is deprecated code and deprecated code.

Strictly follow the object-oriented specification. This encapsulates the data details and only provides the interface to the user. Increased data level security. Pointer free operation. The operations in Java, except the basic types, are all referenced operations. References cannot be increased or decreased and cannot be directly given a memory address, which increases the security of the memory level. Array boundary check. In this way, there will be no security vulnerabilities such as cache overflow in C / C + +. Cast type. Objects of different types cannot be converted, otherwise ClassCastException language support for thread safety will be thrown. Java supports threads from the language level. Thus, a lot of thread control and support are done from the syntax and language itself. garbage collection. Exception。 Return to directory

Bootstrap classloader starts the class loader, which is the top class loader in the Java class loading hierarchy. It is responsible for loading the core class libraries in the JDK, such as rt.jar and resources jar、charsets. Jar, etc. Extension classloader is the extension class loader, which is responsible for loading the extension class library of Java. Java is loaded by default_ All jars under home / JRE / lib / ext /. The app classloader system class loader is responsible for loading all jars and class files in the application classpath directory. Note: in addition to the three classloaders provided by Java by default, users can also define their own classloaders as needed, and these custom classloaders must inherit from Java Lang.classloader class, It also includes two other classloaders provided by Java (extension classloader and app classloader). Bootstrap classloader does not inherit from classloader because it is not an ordinary Java class. The bottom layer is written in C + + and has been embedded into the JVM kernel. After the JVM is started, bootstrap classloader is also started. After loading the core class library, it is responsible for constructing extension classloader and app classloader class loaders.

Strictfp (strict float point) the strictfp keyword can be applied to a class, interface, or method. When a method is declared with the strictfp keyword, all float and double expressions in the method strictly comply with the FP strict limit and comply with the IEEE-754 specification. When the strictfp keyword is used for a class or interface, all codes in the class, including initializers and codes in nested types, will be strictly evaluated. Strict constraint means that the result of all expressions must be the expected result of IEEE 754 algorithm for operands, expressed in single precision and double precision formats. If you want to make your floating-point operation more accurate and not because the results executed by different hardware platforms are inconsistent, you can use the keyword strictfp. Transiant variable modifier. If an instance variable is declared with transient, its value does not need to be maintained when the object is stored. Volatile is used as the instruction keyword to ensure that this instruction will not be omitted due to compiler optimization. Modify variables to ensure that variables are re read from memory every time. The final modifier basic data member (as const) modifies the reference of the class or object, and the final (cannot overwrite) modifier class or parameter of the modifier method returns the directory

There are three main ways to implement Java multithreading: inherit the thread class, implement the runnable interface, and use executorservice, callable and future to implement multithreading with returned results. The first two methods have no return value after thread execution, and the last one has a return value. Return to directory

Thread pool under concurrent: name function < / TR > < tr > < td > scheduledexecutorservice < / td > < td > can be similar to timer / TimerTask, Solve problems that require repeated task execution < / td > < / TR > < tr > < td > ThreadPoolExecutor < / td > < td > the default implementation of executorservice < / td > < / TR > < td > scheduledthreadpoolexecutor < / td > < td > inherits the scheduledexecutorservice interface implementation of ThreadPoolExecutor, The class implementation of periodic task scheduling < / td > < / TR > executors newsinglethreadexecutor creates a single threaded thread pool. This thread pool has only one thread working, which is equivalent to a single thread executing all tasks in series. If the only thread ends abnormally, a new thread will replace it. This thread pool ensures that all tasks are executed in the order they are submitted. Newfixedthreadpool creates a fixed size thread pool. Each time a task is submitted, a thread is created until the thread reaches the maximum size of the thread pool. Once the size of the thread pool reaches the maximum, it will remain unchanged. If a thread ends due to execution exception, the thread pool will supplement a new thread. Newcachedthreadpool creates a cacheable thread pool. If the size of the thread pool exceeds the threads required to process the task, Then some idle threads (not executing tasks for 60 seconds) will be recycled. When the number of tasks increases, this thread pool can intelligently add new threads to process tasks. This thread pool does not limit the size of the thread pool, which is completely dependent on the operating system (or JVM) the maximum thread size that can be created. Newscheduledthreadpool creates a thread pool with unlimited size. This thread pool supports the need to execute tasks regularly and periodically. Return to the directory

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>