Here are some of the more advanced questions. The interview is usually very rarely asked. Because they may be able to keep the interviewer out. It's just that you can find yourself a time to practice.
System.exit (0) skips the run of the Finally block
System.setsecuritymanager (NewSecurityManager () {@Override Public voidCheckexit (intStatus) {Throw NewThreaddeath (); } });Try{System.exit (0); }finally{System. out. println ("in the Finally block"); }
System. Setsecuritymanager (New SecurityManager () { @ Override public void checkexit (int status) { throw new Threaddeath (); } } ) ; try { System. Exit (0); } finally { System. Out. println ("in the Finally Block"); } |
Why does this code output in the finally block? Why isn't the stack trace information printed? 2. String str = "Hello", in which STR is a string object unlike C + +, the variables in Java are either the underlying type or the reference. A variable cannot be an object. This means that expressions like this:
"Hello"; "Bye"; //Comparison of two references. Instead of the content//assigning the text reference to STR
string str = " Hello " ; string text = "Bye"  ; str == text ; //two references, not content str = text ; //Assigning a reference to the text to str |
In most cases there is no big difference, just writing easy causes confusion.
Final New Stringbuidler (); Sb.append ("Hello"//This reference is the final type, not the instance.) This instance can be changed by means of a method. It's just that this variable can't be changed.
final stringbuilder sb = new stringbuidler ( ) ; sb . append ( "Hello" ) ; //This reference is of the final type. Rather than this instance. method ( sb ) ; //is able to change this instance through a method, except that the variable is not modified |
- multithreaded programming is very difficult to assume you have no experience. Multithreaded programming is really hard. Let's say you just throw a bunch of code into a bunch of threads and run it, so the problem doesn't work out, it just can be a mess. But suppose you can do the thread on demand. Controls the interaction between threads. With a simple pattern that can be clearly defined by members of some teams, the problem becomes much simpler. Another challenge, of course, is that you have to let all the people in your team follow your rule:-)
- Don't worry about the different performance between different operations recently heard there's a problem , it involves the addition of integers, memory interview. and output to the console.
Although in these operations, each is slower than the previous one order of magnitude, but this buddy is to optimize the fastest operation here, addition, but also with some more expensive operation to replace it. Assuming you really want to optimize performance, you'd better use a cheap operation to replace those expensive operations, assuming that your bottleneck is in the hardware, for example, to read a large number of files from the hard disk. The code to change the software is useless, because the problem is not here at all.
- Random numbers are random
A specific set of random numbers is like a number in a pattern. I have already mentioned this question in this article.
Very many people do not believe that the numbers generated by the random number generator are in fact not random.
- Floating-point numbers should be avoided as much as possible, as they generate random errors
For the same operation. Floating-point numbers produce the same error every time. Errors are predictable and therefore controllable. Let's say you know what you're going to do, and stick with simple rules, like rounding the results, for example. Then the floating point will not be more wrong than BigDecimal. In addition, it is more readable, and more efficient than a hundredfold (the same time the garbage objects are also less).
- The time zone is immutable.
The reason for this misunderstanding is that, over time, the time zone is changing. This means that Europe/London in the new era is 1970/1/1 01:00 instead of 00:00, why? As London used daylight saving time for the two years from 1968 to 1971.
In the past few years, there have been many time zones have also changed. Moscow used to be the East Third District (GMT+3), now the Eastern District (Gmt+4) (from March 27, 2011).
If you look at the next 2010 years, you will find that it is the east and the east, not the eastern quarter.
There are some things you might be surprised to hear:
- When you read a non-volatile variable in the thread, you can finally read the value it updated.
A few days ago this problem appeared on the StackOverflow two back. In general, the JIT compiler optimizes code to inline non-volatile types of fields that the thread does not change.
Once this code is compiled (as you can see through-xx:+printcompilation), you'll probably never see a change to this field in one of the other threads.
The addition of random synchronization blocks or print statements can delay the operation of this optimization, or disrupt the JIT compiler. Let it not run this optimization.
- The Java interview question is all right.
There are a lot of Java-side questions that are either outdated (not updated for more than 10 years, and today's Java version numbers are out of sync), either misleading or possibly wrong. Unfortunately, none of these answers has been checked and sent everywhere.
I will take the stackoverflow above answer, as the answers here are better than the peer review. In general, such sites like Rose India are not on. The poor quality of the answers above is outrageous. If you like root planing, you can see how many spelling mistakes (class names and professional terms) or wrong words are in the above article. One reason for these problems is that there is no effective feedback mechanism to correct these errors.
Article from: http://it.deepinmind.com/java/2014/05/10/common-java-myths.html
10 Lies about Java