1. What is the difference between error and exception? ErrorA serious problem that indicates that recovery is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such situations. Exception represents a design or implementation issue. That is, it means that if the program runs normally, it never happens.
2. The simple principle and application of exception handling mechanism in Java. An exception is an abnormal condition or error that occurs when a Java program is run (not compiled), and Java uses an object-oriented approach to handle an exception, which encapsulates each exception that occurs in the program to an object that contains information about the exception. Java classifies exceptions, different types of exceptions are represented by different Java classes, the root class for all exceptions is java.lang.Throwable, and the throwable below derives two subclasses: Error and Exception, error Represents a serious problem that the application itself cannot overcome and recover, for example, to say a memory overflow. Exception said that the program can also overcome and restore the problem, which is divided into system anomalies and common anomalies, system anomalies are the defects of the software itself caused by problems, that is, the software developers to consider the problem caused by poor, software users can not overcome and restore this problem, But in this case the software system can continue to run or let the software die, for example, null pointer exception. Ordinary exception is the operating environment changes or anomalies caused by the problem, is the user can overcome problems, such as network disconnection, hard disk space is not enough, after such an exception, the program should not die. Java provides a different solution for system exceptions and common exceptions, and the compiler enforces common exceptions that must try: Catch processing or using the throws declaration continues to be thrown to the upper call method processing, so the common exception is also called the checked exception, and the system exception can be handled or not handled, so the compiler does not enforce with try. catch processing or declaration with throws, so system exceptions are also known as unchecked exceptions.3.
Please write down the 5 runtime exception you are most familiar with . ClassCastException, ArithmeticException, NullPointerException, Stringindexoutofboundsexception, Negativearraysizeexception.
4. The difference between String and StringBufferCommon denominator: You can store and manipulate strings. Different points: The String class provides a string with numeric values that cannot be changed, and string implements the Equals method and the Hashcode method. The StringBuffer class dynamically constructs character data, provides string modifications, and StringBuffer does not implement the Equals method and Hashcode method. The problem occurs when you store a StringBuffer object in a Java collection class.
5. Does the array have the length () method? Does string have the length () method? The array does not have the length () method, which has the length property. String has the length () method.
6, the following statement altogether created how many objects: strings= "A" + "B" + "C" + "D";The Javac compilation can be optimized for expressions that add directly to string constants without having to wait for the runtime to do addition processing, but rather to compile with the plus sign removed, compiling it directly into a result of these constants. The s variable in the title is equivalent to a string that defines a "ABCD" directly, so the above code should only create a string object.
7. The difference between ArrayList and vectorsA: Common: Both implement the List interface, is an ordered set. Different points: ArrayList is not safe, vector is thread-safe, if only one line routines access to the collection, it is best to use ArrayList, because it does not consider thread safety, efficiency is higher, if there are multiple lines routines access to the collection, it is best to use Vector, because we don't need to think about and write thread-safe code ourselves. When the set length is not enough, the ArrayList increases the original 0.5 times times, the vector increases the original one times, the vector can also set the growth space size, and ArrayList does not provide the method to set the growth space.
8. The difference between HashMap and HashtableCommon points: All completed the map interface differences: HASHMAP is a lightweight implementation of Hashtable, hashmap allow null (NULL) key value (key), HashMap Hashtable method of contains removed, changed to Contai Nsvalue and ContainsKey. HashMap is not secure, and Hashtable is thread-safe.
9. What is the difference between List and Map?List is a collection of data stored in a single column, the stored data is in order, and allows duplicate map is the storage of keys and values such as two-column data collection, the stored data is not sequential, its key is not repeatable, its value can be duplicated.
10, try {} has a return statement, then immediately after this try finally{} code will not be executed,When is it executed, before or after the return? Return, but to be more granular, in the middle of return, see the following program code running results: public class Test {Public static void Main (string[] args) {SYSTEM.OUT.PRINTLN (new test (). Test ());; } static int Test (){int x = 1; try{return x; }finally{++x; }}}---------execution results---------1 ———————————— Description: The running result is 1, the main function calls the child function and obtains the result of the process, like the main function prepares an empty jar, when the child function to return the result, first put the result in the jar, and then return the program logic back to The main function. The so-called return, that is, the sub-function said, I do not run, your main function to continue to run it, there is no result, the result is to say this before put into the jar.
11, Final,finally, finalize the difference. Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable. Finally is part of the exception-handling statement structure, which indicates that it is always executed. Finalize is a method of the object class that, when executed by the garbage collector, invokes the Finalize method of a reclaimed object, and can override this method to provide additional resource recycling when garbage collection occurs, such as closing a file. The JVM does not guarantee that this method is always called
12. What are the similarities and differences between abnormal operation and general anomaly? An exception represents an unhealthy state that may occur during a program's run, and a run-time exception that represents an exception that may be encountered in a typical operation of a virtual machine is a common run error. The Java compiler requires that a method must declare a non-runtime exception that might occur, but does not require that an uncaught run-time exception be declared to be thrown
13, Strings = "Hello"; s= s + "world!"; After these two lines of code executes, does the content in the original string object change to the bottom? No. Because string is designed as an immutable class, all its objects are immutable objects. In this code, s originally pointed to a string object, the content is "Hello", then we have a + operation on S, then, S does not point to the original object, and pointed to another string object, the content is "Hello world!", the original object is still in memory , just s This reference variable no longer points to it. So if you use string to make a lot of changes to the string, or if the unpredictable changes can cause a lot of memory overhead. Because a string object cannot be changed after it is established, a string object is required for each different string. At this point, you should consider using the StringBuffer class, which allows you to modify instead of creating a new object for each different string. Also, the conversion of these two kinds of objects is very easy. For string constants, if the content is the same, Java considers them to represent the same string object. Calling the constructor with the keyword new always creates a new object, regardless of whether the content is the same.
14. Can I inherit the string class?The string class is the final class and cannot be inherited.
15. Strings =new String ("xyz"); How many stringobject are created? What's the difference between the two? Two or one, "xyz" corresponds to an object, which is placed in a string constant buffer, and the constant "XYZ" is the one in the buffer, no matter how many times it occurs. New string every time it is written, it creates an object that, if previously used ' XYZ ', does not create "XYZ" itself, and takes it directly from the buffer------additional interview tips. If during the interview you feel like you can, the last interviewer asks you what you have to ask, and you can try to answer:
If you have the privilege of entering your company, do I need to prepare for pre-work in advance? So there's a chance to improve yourself get an offerOh!
Java Common interview Topics ___ <java Interview >