1, final, finally, Finalize the difference between final: modifier (keyword) if a class is declared final, No child classes can be Inherited. therefore, A class cannot be declared abstract and declared Final. Declaring variables or methods as final ensures that they are not changed in Use. A variable declared final must be given an initial value at the time of declaration and cannot be modified Later. A method that is declared final can also be used only and cannot be overloaded with finally: a finally block is provided to perform any cleanup operations when the exception is Handled. If an exception is thrown, the matching catch clause executes, and the control enters the finally block, if Any. Finalize: Method Name. Java technology allows the use of the Finalize () method to do the necessary cleanup before the garbage collector clears objects from Memory. 2, Anonymous Inner class (anonymous inner Class) can extends (inherit) other classes, whether implements (implement) interface (interface) Anonymous inner class is an inner class without a Name. Other classes cannot be extends (inherited), but an inner class can be implemented as an interface by another inner class. The difference between 3, & and &&. & is a bitwise OPERATOR. && is a boolean logical Operator. && left is true right is not executed,& has been executed. The difference between 4, HashMap and Hashtable. are classes that belong to the map interface and store the data in the form of Key-value Pairs. HashMap unordered, It allows for an empty hashtable similar to HashMap, but does not allow nulls, and it is slower than HashMap because it is synchronous. 5, arraylist, and vector differences in synchronization: vector is thread-safe, that is, synchronous, and ArrayList is not a secure line program, not synchronous data growth: when the need to grow, vector by default growth of the original, But the ArrayList is the original half 6, Collection and collections Difference. Collections is a Java.util class that contains a variety of static methods related to collection Operations. Collection is the ancestor interface of the collection class, and the main interface for inheriting it is set and List. What is 7 and gc? Why do you have a gc? GC is a garbage collector. Java ProgramsDon't worry about memory management, because the garbage collector is automatically managed. The GC functionality provided by Java can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory. To request garbage collection, you can call one of the following methods: System.GC () runtime.getruntime (). GC ()
System.GC (); Runtime.getruntime (). GC ();
8, string s = new string ("xyz"), and several string Object created?
Two objects, one is "xyx", and the other is a reference object pointing to "xyx" S.
9, Math.Round (11.5) How much? Math.Round (-11.5) How much? Math.Round (11.5) returns (long) 12,math.round (-11.5) returns (long) -11; 10, short S1 = 1; S1 = S1 + 1; What's wrong? Short S1 = 1; S1 + = 1; What's wrong? short S1 = 1; S1 = S1 + 1; error, S1 is a short type, s1+1 is an int type, cannot be converted to short type explicitly. Can be modified to S1 = (short) (s1 + 1). Short S1 = 1; S1 + = 1 Correct. What is the difference between 11, sleep () and wait ()? the difference between them is: sleep () does not release the sync lock, wait () releases the sync lock The difference between the usage is: sleep (milliseconds) You can use the time specified to make him wake up automatically, if the time is less than you can only call Interreput () to forcibly interrupt, wait () can be directly aroused with notify (). sleep is a static method of the thread class. Wait is the method of object, which means that you can call the wait method on any object, and calling the wait method will suspend the Caller's thread until another thread calls the same Object's notify method to reactivate the caller 12, the array has no length () This 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. The difference between 13, overload, and Override. Can the overloaded method change the type of the return value? the overridden overriding and overloaded overloading of a method are different manifestations of Java Polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called the Method's weight (overloading).the overloaded method is to change the type of the return Value. 14. What is the difference between "= =" and equals method? The = = operator is specifically used to compare the values of two variables, that is, whether the value stored in the memory used to compare the variables is the same, to compare two basic types of data or two reference variables equal, only with the = = Operator. If the data that a variable points to is an object type, then this time involves two blocks of memory, the object itself occupies a chunk of memory (heap memory), and the variable occupies a chunk of memory, such as objet obj = new object (); The variable obj is a memory, and new object () is another memory, At this point, the value stored in the memory of the variable obj corresponds to the first address of the memory that the object Occupies. For variables that point to the object type, if you want to compare whether the two variables point to the same object, that is, to see if the values in memory for the two variables are equal, then you need to compare them with the = = Operator. The Equals method is used to compare the contents of two separate objects, as compared to two people whose looks are the same, compared to the two objects that are independent of each other. For example, for the following code: string A=new string ("foo"); String B=new string ("foo"), Two new statement creates two objects, and then a/b variable points to one of the objects, which is two different objects, their first address is different, that is, the values stored in a and B are not the same, so the expression a== b returns false, and the contents of the two objects are the same, so the expression a.equals (b) returns True. What is the difference between 15, error, and exception? error indicates a serious problem that is difficult to recover. For example, Memory overflow. It is impossible to expect the program to handle such situations. Exception represents a design or implementation Issue. In other words, it means that if the program is running normally, it will never happen exception the exception that the program needs to catch and handle; Error indicates system-level errors and programs do not need to be processed. 16, List, Set, map inherit from collection interface? list,set is map is not 17, abstract class and interface what is the difference? The class that declares the existence of a method and does not implement it is called an abstract class, which declares only that it is not implemented in Subclasses. You can have an implemented method and a private METHOD) interface (interface) is a variant of an abstract class. All the methods in the interface are abstract, without a program body。 An interface can only define static final member Variables. When a class implements an interface, it must implement all the methods in the Interface. 1. Abstract classes can have construction methods, and interfaces cannot have Constructors. 2. There can be ordinary member variables in the abstract class, there is no ordinary member variable 3 in the Interface. abstract classes can contain non-abstract ordinary methods, all the methods in the interface must be abstract, not non-abstract ordinary methods. 4. The access type of an abstract method in an abstract class can be public,protected and default, but the abstract method in an interface is only of the public type, and the default is the public abstract type. 5. Abstract classes can contain static methods, and interfaces cannot contain static method 6. Both abstract classes and interfaces can contain static member variables, and the access types of static member variables in an abstract class can be arbitrary, but the variables defined in the interface can only be public static final types, and the public static final type is the Default. 7. A class can implement multiple interfaces, but can inherit only one abstract class. 18, interface can inherit interface? is an abstract class achievable (implements) interface? Can an abstract class inherit an entity class (concrete class)? interfaces can inherit Interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, but only if the entity classes must have explicit constructors. 19, whether the constructor constructor can be overridden, the constructor constructor cannot be inherited, and therefore cannot override overriding, but can be overloaded with overloading. 20, can I inherit the string class? The string class is final and cannot be Inherited. 21, when a thread enters a synchronized method of an object, does the other thread have access to other methods of this object? no, an synchronized method of an object can be accessed only by a single thread. There is a return statement in 22, try {}, then the code in the finally {} immediately after the try will not be executed, when executed, before or after the return, executes before the Return. 23, two objects of the same value (x.equals (y) = = true), but can have different hash code, this sentence is not? wrong, there is the same hash code. (first Judge Hashcode if hashcode equals again, so equal equals so hashcode oneEqual) 24, When an object is passed as a parameter to a method, this method can change the properties of the object and return the changed result, is it a value pass or a reference pass? is the value pass. The Java programming language has only value-passing Parameters. When an object instance is passed as a parameter to a method, the value of the parameter is a reference to the Object. The contents of the object can be changed in the called method, but the Object's reference is never Changed. Whether 25, Swtich can function on a byte, whether it can function on a long, whether it can function on a string? switch (expr1), expr1 is an integer expression. So the arguments passed to the switch and case statements should be int, short, char, or Byte. Long,string can not act on Swtich. The difference between 26, string and Stringbuffer. The length of the string is immutable, and the length of the StringBuffer is Variable. StringBuffer content can be modified, and a string is a non-modifiable modification that results in a new object. If you are frequently manipulating the contents of a string, especially if the content is to be modified, use stringbuffer, and if you need a string at the end, use the ToString () method of Stringbuffer. 1. If you want to manipulate a small amount of data with String2. single-threaded operation string Buffers operate a large number of data StringBuilder3. multi-threaded operation string buffers operate a large amount of data stringbuffer (thread-safe, slower than stringbuilder) What's the difference between 27, int, and Integer Java provides two different types: reference type and primitive type (or built-in type), int is Java's raw data type, and Integer is the wrapper class provided by Java for Int. Reference types and primitive types have different characteristics and usages, including: size and speed issues, The default value of the object reference instance variable is null, and the default value of the original type instance variable is related to their type 28, say arraylist,vector, LinkedList storage performance and features ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement. So the index data is fast and the insertion data is slow, vector due to the use of the Synchronized method (thread safety), usually performanceCompared with arraylist, while LinkedList uses the bidirectional linked list to implement storage, index data by ordinal need forward or backward traversal, but inserting data only need to record the Item's front and rear items, so the insertion speed is faster. What's the difference between 29, heap, and stack? the space of the stack is automatically allocated and freed by the operating system, the heap is manually applied and freed, and the heap is commonly assigned with the new Keyword. Stack space is limited, and the heap space is a large free zone. In java, If you just declare an object, it is assigned an address space in the stack memory, and if you instantiate it again, it is assigned an address in heap memory. Such as: Object a =null; Allocate space only in stack memory object b =new Object (); What is the difference between allocating space 30, static variables, and instance variables in heap memory? static i = 10; Constant class A a; a.i =10;//variable 31, What is Java serialization, How do I implement Java serialization? Serialization is a mechanism for dealing with the flow of objects, so-called object flow is the flow of the Object's Contents. It is possible to read and write to a fluidized object, or to transfer the streamed object between the Networks. Serialization is a problem that is raised when reading and writing to an object Stream. Serialization implementation: implement the Serializable interface for the class that needs to be serialized, there is no method to implement it, implements Serializable just to annotate that the object is serializable, and then use an output stream ( Such as: Fileoutputstream) to construct a objectoutputstream object, followed by the WriteObject (object Obj) of the ObjectOutputStream object method to write out (that is, save its State) the object with the parameter obj, and the input stream to Restore. 32, There are several types of streams in java? The JDK provides some abstract classes for inheritance for each type of stream, tell me what classes they are. Byte stream, character Stream. The byte stream inherits from the InputStream outputstream, and the character stream inherits from the InputStreamReader Outputstreamwriter. There are many other streams in the java.io package, mainly to improve performance and ease of use. What are the similarities and differences between 33, synchronization, and asynchrony, and under what circumstances are they used separately? An example is Described. If the data will be shared between THREADS. For example, you are writingData may later be read by another thread, or the data being read may have been written by another thread, then the data is shared and must be accessed synchronously. When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the method to be returned, it should use asynchronous programming, which is often more efficient in many cases with asynchronous approaches. 34, please say the thread synchronization method you know. Wait (): causes a thread to be in a wait state and releases the lock of the object it holds. Sleep (): makes a running thread sleep, is a static method that calls this method to catch the Interruptedexception Exception. Notify (): wakes up a waiting thread, noting that when this method is called, it does not actually wake up a waiting state thread, but is determined by the JVM to wake up which thread, and not by Priority. Allnotity (): wakes all the threads that are in the waiting state, noting that they do not give all the wake-up threads an object lock, but instead let them compete. 35, multi-threaded there are several ways to achieve, what is it? there are several ways to implement synchronization, and there are two ways to implement multithreading, namely, inheriting the thread class and implementing the Runnable interface, there are two implementations of synchronization, namely synchronized, The relationship between wait and notify 36, the basic concept of threads, the basic state of threads, and the state of the thread refers to the ability to execute an execution unit of program code during program execution, at least one thread per program, that is, the program itself. There are four types of threads in Java: run, ready, suspend, End 37, Briefly describe the similarities and differences between synchronized and Java.util.concurrent.locks.Lock: lock can accomplish the main differences in all the functions implemented by Synchronized: Lock has more precise line semantics and better performance than Synchronized. The synchronized automatically releases the lock, and lock must require the programmer to release it manually, and must be released in the finally Clause. What is the basic principle of 38 and garbage collector? Can the garbage collector reclaim memory right away? Is there any way to proactively notify a virtual machine for garbage collection? for gc, when a programmer creates an object, the GC starts to monitor the address, size, and usage of the Object. typically, a GC uses a graph to record and manage all objects in the HEAP. In this way, you determine which objects are "accessible" and which objects are "unreachable." When the GC determines that some objects are unreachable, it is the responsibility of the GC to reclaim those memory Spaces. OK. RideThe sequencer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will Execute. Similarities and differences between 39, Runtime exceptions and general exceptions Java provides two main types of Exceptions: runtime exception and checked Exception. The checked exception is the IO exception that we often encounter, and the SQL exception is the Exception. For this exception, the Java compiler enforces that we must catch the exceptions that Occur. so, in the face of such anomalies whether we like it or not, we can only write a lot of catch blocks to deal with possible exceptions. But another exception: runtime exception, also known as runtime exception, we can not handle. When such an exception occurs, it is always taken over by the virtual Machine. For Example: no one has ever dealt with a nullpointerexception exception, which is a run-time exception, and this exception is one of the most common exceptions. When a Run-time exception occurs, the system throws the exception all the way to the top and continues to experience processing Code. If there is no processing block, to the topmost level, if it is multithreading is thrown by Thread.run (), if it is a single thread is thrown by main (). Once thrown, the thread exits if it is a thread. If the exception is thrown by the main program, then the entire program Exits. Runtime exceptions are subclasses of the exception, and there are general exceptions that can be handled by catch blocks. It's just that we're not dealing with Him. That is, if you do not handle a run-time exception, then a run-time exception occurs, either the thread aborts or the main program Terminates. The simple principle and application of exception handling mechanism in   40 and Java when a Java program violates the semantics of Java rules, the Java Virtual machine represents the error that occurs as an Exception. There are 2 cases of violating semantic rules. One is the semantic check built into the Java class Library. For example, array subscript is out of bounds, indexoutofboundsexception is thrown, and N ullpointerexception is thrown when an object that accesses Null. Another scenario is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose when to throw exceptions with the throw Keyword. All exceptions are subclasses of Java.lang.Thowable. 41, Programming Questions: Write a singleton Out. The main purpose of the singleton mode is to ensure that only one instance of a class is present in a Java Application. The general singleton pattern usually has several forms: the first form:
1 public class Singleton {2 Private Singleton () {} 3 Private Static New Singleton (); 4 public Static Singleton getinstance () {5return instance; 6 }}
View CodeThe second form Of:
1 public classSingleton {2 Private StaticSingleton instance =NULL;3 4 public Static synchronizedSingleton getinstance () {5 if(instance==NULL)6Instance=NewSingleton ();7 returninstance; 8 }9}View Code
Basic knowledge of Java interviewing (1)