A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

This week I learnt multi thread and its child class almost. Actually,not all knowledge is understood clearly after class. Here are some issues I found during class and figure out the way to solve my problems.
1.        The definition between the main() method and main thread. Both of them are the same things in Java. Once the main thread is dead in the memory, the main method is also pop from Stack. And other threads can be run normally.
2.        The definition is said that every child class is unable to throw exceptions if the father class doesn’t throw exception. We all know that any class’ father class or indirect father class is Object class. I read the Object class’ code and found out there is no exception throwing. This is extremely wired. At last, I figure out it was my confused on the definition. The correct definition is that: If method statement doesn’t throw exception in father class, the method statement must not throw exceptions in child classes. And these classes are only able to use “try…catch” to solve the exception.
3.        The non-main thread name is still displayed as default name in the main method when creating a new thread while changing the thread name in a Thread class. This is because creating a new object in main method, the name changed in the Thread class can not be invoked, actually. The expected name can be gained only when assigning a new name to the thread while starting a new thread in main method.
4.        Figure out the differences in 3 terms:
RuntimeException: The exception will be shown only when running the program.
Non-RuntimeException: The exception will be shown when typing the code in IDE.
Grammar error: any error when typing code, such as missing “;”.
At last, the most important thing I learnt is that how to read a program and figure out its result. There are two ways to get the result. One is able to get the result quickly but sometimes incorrect result can be gotten. Because it cannot fit the grammar in Java. The other one is best way that it can get the result with the correct Java grammar. First of all, divide the statement and assignment in Member variables, and then move the assignment and Constructor Code to the Constructor method and make sure put them under the super() method in turn. (Member variables and Constructor Code have the same prior during running the code in Java.) And then figure the result with the following rules:
(Warning message: Invoke child class’ method overridden when running father class method while invoking super() method in the Constructor method of the child class.)
(1)        Run father’s static code if have.
(2)        Run child’s static code if have.
(3)        Run the code from up to down in father class.
(4)        Run the code from up to down in child class.

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马