The question and Answer page of the Java Special Commando Book

Source: Internet
Author: User
Tags keep alive

Hello everyone, the Java Commando has been officially released in early September. This book may be a lot of people will have different feelings, most of them are expected.


However, if you have any questions, you can get back to me in the blog and I will respond to them in the text.


Here are some questions that some of my classmates have asked me recently:

"There is a problem with code compilation on the disc, how do I use it?" 】:

Explanation: The code for this book is mostly based on JDK 1.6, and a small portion will depend on JDK 1.7. However, the dependency between the code is not strong, so when switching the JDK version, the corresponding class comments should be OK. There are some dependent packages in the Lib directory, and if you have one, you don't need those packages.


"Effective in Java and the JVM specification see overrides equals always rewrite hashcode, but Fat Brother's book says they don't have a big relationship":

Explain:

1, to pay attention to a little, what is a specification, is a predetermined, for example, when you provide an API for others, a parameter passed, another parameter must be passed, this is a specification. This book emphasizes personal skills, understand what is inside the end, in essence, they do not have strong dependencies, otherwise, Java only need to design a grammar, and do not need 2, or only rewrite one of them when the direct compilation does not pass, because there is no need to superfluous, hehe!


2, therefore, Fat brother in the book has such a paragraph: " This is like: Does the sword need a scabbard? Baby, do you need a treasure chest? Does the male have to need a female? Does the Earth need a moon? and not: Does the tree need soil? Does life need food? Does the fish have to need water? Does the world need sunshine? "What does that mean?" Is that they are naturally paired, but are not forced to rely on, not the tree must depend on the sudden, life needs the relationship of food, because their purpose is different.


3, in the text mentioned that their match point is in the hash class algorithm, such as HashMap, HashSet, Courrenthashmap, etc., this is a common convention, just to facilitate Java to write the basic components of these hash algorithms, Of course, if you write an algorithm yourself, you can also use hashcode to implement it in a similar way.


4, if you think that day Hashcode this name is not good to listen to, equals the name is not pleasant, or these two methods can not meet the needs of the abnormal, you may define a set of interfaces, define a set of specifications, let others to rewrite, Haha, a little high feeling!


5, finally summed up a sentence, many things do not evaluate right and wrong, we in with things in their own understanding to become more and more clear, to form their own deep understanding, this is the book hope you can understand. At the same time rewriting is a habit, but not as a truth, otherwise many students do not know why the need to rewrite, this book really want you to understand the principle based on the understanding of why you need to do so.


"Join is not good, will poll death, but Fat Brother's book has such code, not good":

1, fat brother does not deny that join at some point is really bad, but we have to understand, join still exist without being annotated: @Deprecated, the official does not say that it is not a recommended method, it has its own purpose.


2, in the book join is to wait for the end of multiple threads to do other things, in the later article there are more ways to accomplish similar functions, and better than the join, but also can do a lot of join do not do things. So join is a guide first, not a fat guy, at least when you're writing a test program, it's handy to join.


3, will poll death, this statement has 2 points, respectively, is polling, Death , in fact, for the join basically is not set up, first of all, although tracking source you can see such a piece of code:

while (IsAlive ()) {
Wait (0);
}

The execution factor of this code is that the join () method does not pass any parameters, it will come here (ask my classmates think this is the JVM bottom C code, in fact, it is the Java part of the code, in the source package can be directly seen). Although it is a while loop, but this while loop is just to keep alive, the actual runtime is not polling, because the wait (0) method, the value passed in is 0, it will wait until there is interrupt or notify occurs, based on the thread itself to do wait (0) The probability of this notify is very low (unless it is deliberately simulated), generally to the end of the thread loop will only go in once, even a few times, is not what polling.


About blocking, ask my classmates think that blocking is the bottom of the continuous doing while loop if (xx) {break} action, this understanding is problematic, blocking in a sense you can think that the thread is not working, but in the OS register the activation of the event, the thread will not get the CPU scheduling, When the corresponding event matures, it will continue to run. In turn, if the underlying block is doing while (true) {if (xx) {break;}} Then a blocked thread is enough to get a CPU full, and this can be done on several threads in parallel on the operating system (assuming, of course, that each thread is constantly looping). Therefore blocking and internal polling are not the same thing.


Death, the purpose of join is to wait for the thread to end, the thread does not end, then wait is inevitable, with other framework if the business requirements must wait for all tasks to complete, as long as the task has not run out, it will inevitably be death, this is no doubt. Just the death of the join is an uncontrolled wait, and if it waits, it needs to be interrupted externally, perhaps other frameworks have a better way.


In addition, join is based on thread end running, and in many cases we want threads to be reused, such as a thread-pool-based task, as long as some related tasks end, the task can do the next thing, without requiring the thread to exit. These are presented in the fifth chapter of this book.


Finally, the other disadvantage of the join waiting for the thread to end is the order in which the join waits for the thread to end, not the actual order in which the thread ends, and when you expect to get the order of the end of a batch of tasks, you can't do it through a simple join, unless you add an end time to your thread and then sort it out. Wouldn't that be quite a hassle?


"The text of the 1th chapter of the book, the 22nd page has a sentence wrong"

Error statement:

For example: The value returned by integer.valueof ("10", 16) is the value returned by16,integer.valueof ("Ten"), which is 2, so that the conversion between arbitrary conversions can be achieved.

Correct statement:

For example: The value returned by integer.valueof ("10", 16) is 16,integer.valueof ("Ten",2) The returned value is 2, so that the conversion between any binary can be achieved.


"The text of the 2nd chapter of this book, the full text 48th page has a sentence to write wrong"

Error statement:

What is the relationship between this conclusion and Cacheline? Because the Java array is allocated in memory first (or Java does not really have a two-dimensional array), and then allocates multiple second subspace arrays, that is, a[0][x] and a[0][x] are located on two different arrays, space will not be together naturally

Correct statement:

What is the relationship between this conclusion and Cacheline? Because the Java array is allocated in memory first (or Java does not really have a two-dimensional array), and then allocates multiple second subspace arrays, that is, a[0][x] and a[1][x] are located on two different arrays, space will not be together naturally .


"There is no knowledge of data structures or container classes"

1, in fact, the data structure is in the lines of the book, I believe if you do not have the basis of data structure, read this book a little confused. This book does not specifically to explain the data structure, but in Java through space, algorithm ideas and so naturally brought out, to know that the data structure is ultimately to serve our program, to help us better understand the program, and Java data structure is a concrete implementation of space, it will have some small changes, But never had to leave the subject.

2, the container, this concept is more rampant, many places everywhere quoted this noun, Web container, Java Collection class is also called container, some middleware and platform is also called container. If the Web container, in the Book of the 4th chapter will be a part of the source of the explanation, the next book will introduce some pits. The collection class has some small interesting introduction, of course, the introduction is not much, we learn more from the principle of its space, time, lock, concurrency, but I would like you to understand the underlying object's memory structure and then understand the collection class, because the basic object understanding, the memory structure of the collection class is the combination of data structure, Ease.


"Want to mention optimization":

Optimization of the topic is relatively large, in fact, small fat write this book, one of the purposes is to hope that you understand the problem fundamentally, when you learn to understand the problem fundamentally, in fact, optimization is no longer a big problem, the only problem is that you need to think boldly and practice with a variety of experiments. Through the theory deduction practice, the practice confirms the theory, the theory further directs the direction. To continue to do optimization, your understanding of the optimization itself is not only a blind test of the conclusion, but there are clear objectives of the test conclusion, you can analyze the specific scenarios and guidance optimization program, even if the debug parameters test, but also with purpose, or even if the performance up, we do not know exactly how many pits to change a scene. Of course, the pit is inevitable, we can anticipate in advance let us do a bit more professional.


"Does the book have some introduction to popular technology":

This may not be found in this book too much, popular technology even in the next book will only mention some ideas and methods, fat elder brother think the popular technology too much, can not finish, speak out of the outdated, but they are through these basic theory combination, and some more is bold innovation and break the idea of self. We learn the technology, more hope to understand some of the essence, let oneself to the industry's technology has the confidence, the science related technology is quick, and not only learn to use, but learn better than others, can solve the problem more than others, than I can foresee there may be risk, there may be pits, So we can solve the problem from the relative long-term and global angle, and solve the problem fundamentally.


Even if some of the pits we encounter are "flawed" (it does exist, because Java relies on too many three-party packages, the three-way package itself has a mishap or your architecture itself has a mishap), this mishap is caused by some perverted operation, if we know the nature of some technology, as we know about the details of the business, There can also be many ideas to reduce the probability of the occurrence of the mishap to a very low level, even if the occurrence can also occur in this low probability, because we can predict, so can be handled by some special code means.


In addition, thank you for the support of this book, the current shipping situation than I think of the good.



"Java Commando book" Quiz Feedback page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.