Here are some of the more advanced questions that are rarely asked in interviews because they may shut out the interviewer. But you can find yourself some time to practice.
1. System.exit (0) skips the execution of 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 not print out the stack trace information?
2. String str = "Hello"; where 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 an expression like this:
String str = "Hello";
String Text = "Bye";
str = = text; Compare two references instead of content
str = text;//Assign text references to Str
In most cases there is not much difference, but it is confusing to write.
Final StringBuilder sb = new Stringbuidler ();
Sb.append ("Hello"); This reference is the final type, not the instance.
method (SB);//You can modify this instance by methods, but this variable cannot be modified
3.Java memory leaks are the same as C + + programmers understand
Memory leaks are defined on Wikipedia as "in computer science, memory leaks can occur if programs do not properly manage memory allocations." In object-oriented programming, this is a memory leak if an object in memory cannot be accessed in the code. "But in Java, objects are always available, and objects that are not strongly referenced are purged." Memory leaks This term in Java means that there are objects that should not exist in memory, usually some resources that are no longer in use are still stored in the collection.
4. Multithreaded programming is difficult
If you have no experience, multithreaded programming is really difficult. If you just throw a bunch of code into a bunch of threads to execute, then the problem can't be solved, it can only be a mess. But if you can do it on demand, control the interaction between threads, and use simple patterns that some members of the team can understand, the problem becomes much simpler. And one of the challenges is that you have to let everyone in the team follow your rules.
5. Do not care about the difference between different operating performance
Recently I heard that there is a problem, it involves the addition of integers, memory access, modulo, and output to the console. Although each of these operations is a bit slower than the previous one, the Buddy wants to optimize the fastest operation in the area, add, and replace it with more expensive operations. If you really want to optimize performance, you'd better replace those expensive operations with a cheap operation, if your bottleneck is in the hardware, for example to read a lot of files from the hard drive, it's no use modifying the code, because the problem is not here.
6. Random numbers are random.
A specific set of random numbers is like a number in a pattern. I have already talked about this problem in this article. Many people do not believe that the number generated by the random number generator is actually not random.
7. You should avoid using floating-point numbers as much as possible, because they produce random errors
For the same operation, floating-point numbers produce the same error each time. Errors are predictable and therefore controllable. If you know what you're going to do, and insist on using some simple rules, such as rounding the results, the floating-point number will not be more wrong than the BigDecimal, in addition to its more readable, and more efficient more than a hundredfold (also produces less garbage objects).
8. 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? Because London used daylight saving time during the two years from 1968 to 1971.
In the past few years, there have been many time zones have also changed. Moscow was formerly the eastern Region (GMT+3) and is now the East Quad (GMT+4) (starting from March 27, 2011). If you look at it for 2010 years, you will find it is in the eastern three areas instead of the East Quad.
There are some things you may sound like a surprise:
Sweden in 1721 has 30 days in February.
The first day of 1751 in England was March 25, 11 days worse than France.
After the United States adopted the Gregorian calendar, it went back hundreds of years, so that the dates originally recorded could be expressed in two calendars (usually to provide two dates for more precise purposes). For example, George Washington's birthday changed from February 1731 11 to February 1732 22.
9. When you read a volatile variable in a thread, you can eventually read the value that it updated.
A few days ago this problem appeared on the StackOverflow two back. In general, the JIT compiler optimizes code to inline a field of a volatile type that is not modified by this thread. Once the code has been compiled (you can see it through-xx:+printcompilation), the changes you make to the field on another thread will probably never be seen. Adding a random sync block or print statement can delay the execution of this optimization, or disrupt the JIT compiler so that it does not perform this optimization.
10.Java interview questions are correct.
There are a lot of Java face questions that are either outdated (not updated for more than 10 years, disconnected from the current Java version), misleading, and possibly even wrong. Unfortunately, none of these answers had been examined and passed around.
I'll refer to the stackoverflow above, because the answers here are better than the peer review. On the whole, sites like Rose India are not on, and the answers are ridiculously poor quality. If you like inquisitive, look at the number of spelling mistakes (class names and jargon) or incorrect remarks in an article above. One reason for these problems is that there is no effective feedback mechanism to correct these errors.
For you to recommend some Java interview questions:
The most valuable 50-way Java face test for access to a Java programmer
10 Classic Java Main method face test
Explore the most common 10-way questions in Java (Super Classic)
10-way XML face test for Java programmers Fresh baked
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.