Talking about Final, Finally, Finalize Final-Modifier (Keyword) If a class is declared as final, it means that it cannot be derived from new subclasses and cannot be inherited as a parent class. Therefore, a class cannot be declared as Abstract, and it is declared as final. Declaring variables or methods to Final, ensuring that they are not changed in use. Variables that are declared for final must give initial values at the time of declaration, and only read in future references, cannot be modified. The method that is declared as final is also available, can not be overloaded
Finally- provides a Finally block when processed. If you throw an exception, then the matching catch clause will execute, and then the control will enter the Finally block (if any).
Finalize-method name. Java technology allows the use of the Finalize () method to make the object to clear the object from the memory before making the necessary cleanup work. This method is called by the garbage collector when it is determined that this object is not referenced. It is defined in the Object class, so all classes have inherited it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called by this object before the garbage collector deletes the object.
Is an Anonymous Inner Class (anonymous internal class) can be extends other classes, can IMPLEMENTS INTERFACE (interface)?
The anonymous internal class is an internal class without a name. You cannot extends other classes, but an internal class can be implemented as an interface, and is implemented by another internal class.
Static Nested Class and Inner Class are different, the more you say, the better (the interview question is very popular)
NESTED CLASS (generally C statement), Inner Class (typically Java said). The maximum difference between Java internal classes and C nested classes is whether there is a reference to the outside.
Note: Static Inner Class means 1 creation of an object of a Static internal class, does not require an external class object, 2 cannot access an external class object from an object of a Static internal class
& And &&'s difference
& Is a bit operator. && is the Boolean logic operator.
Differences between HashMap and HashTable
Both of the MAP interface, implement the unique key to a specific value.
The HashMap class is not classified or sorted. It allows a NULL key and multiple NULL values.
Hashtable is similar to HashMap, but NULL keys and NULL values are not allowed. It is also slower than HashMap because it is synchronized.
The difference between Collection and Collectes
Collections is a class under java.util that contains a variety of static methods related to the collection.
Collection is an interface under java.util, which is a parent interface of a variety of collections.
When is the ASSERT assert, it is a statement containing a Boolean expression that assumes that the expression is TRUE when performing this statement. If the expression is calculated as false, then the system will report an AssertionError. It is used to debug purposes:
Assert (a> 0); // throws an assertionerror if a <= 0
There are two forms of assertions:
Assert Expression1; Assert Expression1: Expression2;
Expression1 should always produce a Boolean value.
Expression2 can be any expression that draws a value. This value is used to generate a String message displaying more debugging information. As default, it is disabled by default. To enable assertions while compiling, you need to use Source 1.4 tags:
Javac -Source 1.4 Test.java
To enable assertion at runtime, you can use the -enableassertions or the -ea tag.
To disable assertion at runtime, you can use the -DA or the -disableAssertions tag.
To enable assertion in the system class, you can use the -esa or -dsa tag. You can also enable or disable assertions on the basis of the package.
An assertion can be placed at any position that is not reached in normal conditions. As an assertation can be used to verify the parameters passing to the private method. However, assertions should not be used to verify parameters passing to the public method, as there is no matter whether it is enabled, the public method must check its parameters. However, it can be used in public methods or in a non-public method to use asserts to test the post condition. In addition, the assertion should not change the status of the program in any way.
What is GC? Why do you have a GC? (Foundation)
GC is a garbage collector. Java programmers don't have to worry about memory management because the garbage collector will automatically manage. To request garbage collection, you can call one of the following methods:
System.gc () runtime.getRuntime (). Gc ()
String s = new string ("xyz"); created a few String Object?
Two objects, one is "XYX", one is a reference object S pointing to "XYX".
Math.Round (11.5) is equal to? Math.Round (-11.5)?
Math.Round (11.5) Returns (long) 12, Math.Round (-11.5) Returns (long) -11;
Short S1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong?
Short S1 = 1; S1 = S1 1; error, S1 is the short type, S1 1 is INT type, cannot explicitly convert to a SHORT type. Can be modified to S1 = (Short) (S1 1). Short S1 = 1; S1 = 1 is correct.
What is the difference between SLEEP () and WAIT ()? Make a thread
The SLEEP () method is to stop the thread to stop a period of time. After the SLEEP time interval is full, the thread does not necessarily resume it immediately. This is because at that moment, other threads may be running and are not scheduled to give up execution unless (a) "wake up" thread has a higher priority; (b) is running because of other reasons
Wait () is a thread interaction if the thread issues a wait () call, the thread is suspended, the object is adjusted to the waiting state until it is awake or waiting time.
Is there goto in Java?
The reserved word in Goto-Java is not used in Java.
Are there any length () method? String has a length () method?
The array does not have Length () method, with the properties of the length.
String has a length () method.
The difference between OverLoad and Override. Can OVERLOADED methods change the type of return value?
The method of rewriting Overriding and overloading overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. If a method is defined in the subclass with the same name and parameters as its parent class, we say that this method is overriddled. When the subject of subclass uses this method, the definition of the subclass will be called. For it, the definition in the parent class is like "shielded". If a plurality of the same names are defined in a class, they or have different parameters or different parameter types, called overloading. The way OVERLOADED is to change the type of return value. The elements in the set cannot be repeated. What method is used to distinguish whether it is repeated? Is it == or equals ()? What is the difference?
The elements in the set cannot be repeated, then use the iterator () method to distinguish whether you are repeated. Equals () is the judgment of whether two SETs are equal.
Equals () and == Method Decide whether the reference value points to the same object Equals () override in the class, which is the true value of the content and type of two separate objects.
Give me a Runtime Exception you most often
ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException,
ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFORMatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException
What is the difference between ERROR and EXCEPTION?
Error indicates a serious problem that recovery is not impossible but difficult. For example, memory is overflow. It is impossible to expect the program to handle this situation.
Exception represents a design or implementation problem. That is, it means that if the program runs normally, it will never occur.
List, SET, MAP inherits from the Collection interface? List, set is
MAP is not
What is the difference between Abstract Class and Interface?
The presence of a declaration method does not implement its class called abstract class, which is used to create a class that reflects certain basic behavior and declares the class, but cannot implement this class in this class. Case. An instance of the Abstract class cannot be created. However, you can create a variable, which is an abstract class and let it point to an instance of the specific subclass. There is no abstract constructor or abstract static method. Subclasses of the Abstract class provide implementation for all abstraction methods in their parent class, otherwise they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can be implemented in the class. Interface is a variant of an abstract class. In the interface, all methods are abstract. Multiple inheritance can be obtained by achieving such an interface. All methods in the interface are abstract, no probabilities. The interface can only define the Static Final member variable. The implementation of the interface is similar to the subclass, except that the implementation class cannot inherit behavior from the interface definition. When the class implements a special interface, it defines the method of all such an interface (that is, the program body is given). Then, it can call the interface to call the interface on any object of the class of the interface. Because there is an abstract class, it allows the interface name as the type of reference variable. The usual dynamic cable will take effect. The reference can be converted to an interface type or a slave interface type, and the InstanceOf operator can be used to determine whether an object is implemented.
Whether the method of Abstract is simultaneous to be static, whether it can be native at the same time, is it SYNCHRONIZED?
both are not
Does the interface be inherited? Is the abstract class enable (IMPLEMENTS) interface? Does the abstract class can inherit the physical classes (Concrete Class)?
The interface can inherit the interface. Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor.
Start a thread with Run () or start ()?
Starting a thread is to call the start () method so that the virtual process representing the thread is in operation, which means it can be scheduled and executed by the JVM. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread.
Is the constructor CONSTRUCTOR can be Override?
The constructor constructor cannot be inherited, so Overriding cannot be overridden, but Overloading can be overloaded.
Can I inherit the String class?
The String class is that the final class cannot be inherited.
Other methods of other threads can enter this object when a thread enters an Synchronized method of an object?
No, a Synchronized method of an object can only be accessed by one thread.
There is a Return statement in Try {}, so the code in finally {} after this try is not executed, when is executed, before returnome or after?
Will be executed, execute before return.
Program: Two multiply 8 equal to a few with the most efficient method?
Programmers with C background especially like to ask this question.
2 << 3
The two object values are the same (x.equals (y) == true), but there is a different Hash Code, this sentence is wrong?
No, there is the same Hash Code.
When an object is passed as a parameter to a method, this method can change the properties of this object and return the resulting result, then here is the value delivery or reference delivery?
It is a value transfer. The Java programming language is only passed by the value. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change.
Whether SWTICH can act on byte, whether it can act on long, can it function on String? Switch (expr1), expr1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH.
Program: Write a Singleton out.
The main role of the Singleton mode is to ensure that only one example exists in a Java application.
General Singleton mode usually has several forms:
The first form: Define a class, its constructor is private, it has a type of PRIVATE for a Static, an instantimeter of the class initialization, get a reference to it through a public GetInstance method, then call it Methods.
Public class singleton {private singleton ()} // define one instance in itself, is it very strange? / Note This is private only for internal calling private static singleton instance = new singleton (); // here provides a static method for external access to this Class, you can directly access public static singleton getInstance () {return instance;}}
The second form:
Public class singleton {private static singleleton instance = null; public static synchronized singleton getInstance () {// This method has been improved above, and does not have to generate an object each time, it is only the first time // uses instances, improved effectiveness! IF (instance == null) instance = new singleleton (); return instance;}}
Other forms:
Define a class, its constructor is private, all methods are static.
It is generally considered that the first form is more secure.
Hashtable and havehmap
HashTable inherits from the Dictionary class, and HashMap is an implementation of Map Interface introduced by Java1.2.
Hashmap allows null as a key or value of Entry, and hashtable is not allowed
Also, Hashmap removes the HashTable's Contains method, changed to ContainsValue and Containskey. Because the Contains method is easy to cause misunderstandings.
The biggest difference is that the HashTable method is Synchronize, and HashMap is not, when accessed HashTable, does not need to be synchronized for its method, and HashMap must provide external synchronization.
Hash / rehash algorithms used by HashTable and Hashmap are probably, so performance will not have a big difference.
Practical question 1.
Abstract class name {private string name; public abstract boolean isstupidName (String name) {}}}
What is wrong?
Answer: wrong. Abstract Method must end with a semicolon and do not bring a curly bracket.
2.
Public class something {void dosomething () {private string s = ""; int L = s.length ();}} Is it wrong?
Answer: wrong. Any access modifier (private, PUBLIC, and Protected) cannot be placed before the local variable. Final can be used to modify partial variables
(Final is like Abstract and Strictfp, all non-access modifiers, stricTFP can only modify Class and Method rather than variable).
3.
Abstract class something {private abstract string dosomething ();
It seems that there is nothing wrong?
Answer: wrong. Abstract Methods cannot be modified in private. Abstract Methods is the specific details of the subclass item, how can I use Private to block Abstract Method? (Similar to the confstract method, Final cannot be added).
4.
Public Class Something {Public Int Add (Final INT X) {Return x;}}
This is more obvious.
Answer: wrong. INT X is modified to Final, meaning X cannot be modified in Addone Method.
5.
Public class new {= new}; new thing (}) {o);}; Other {public Int i;}
It is very similar to the above, it is about Final problem, is this wrong?
Answer: Correct. In Addone Method, the parameter O is modified into final. If we modified O's Reference in Addone Method
(Such as: o = new other ();), then the question is also wrong as the above example. But this is modified here that the MEMBER VAIRABLE (member variable) of O, while the REFERENCE does not change.
6.
Class Something {INT I; Public Void Dosomething () {system.out.println ("i =" i);}}
Is there anything wrong? I can't see it.
Answer: Correct. The output is "i = 0". INT i belongs to Instant Variable (instance variable, or a member variable). Instant variable has default value. INT's default value is 0.
7.
Class Something {Final Int i; public void dosomething () {system.out.println ("i =" i);}}
There is only one place with one of the above questions, that is, there is a final. Is this wrong?
Answer: wrong. Final INT i is a Final's Instant Variable (instance variable, or a member variable). Final Instant Variable No default value must be given a clear value before the constructor ends. Can be modified to "Final INT I = 0;".
8.
Public class nemething {public static void main (string [] args) {Something s = new something (); system.out.println ("s.dosomething () returns" DOSMETHING ());} public string dosomething ()} Return "Do Something ...";}} It looks perfect.
Answer: wrong. It seems that there is no problem in main dosomething in main, after all, two Methods are in the same class. But look carefully, main is static. Static Method can't directly call Non-Static Methods. It can be changed to "S.DOSMETHING () Returns" S.DOSomething ()); ". Similarly, Static Method cannot access Non-Static Instant Variable.
9.
Here, the file name of the Something class is called Othershing.java
Class Something {Private Static Void Main (String [] Something_to_do) {system.out.println ("Do Something ...";}}
This seems to be obvious.
Answer: Correct. No one has said that the Java's Class name must be the same as its file name. But the name of the public class must be the same as the file name.
10.
The hardest question today:
interface Playable {void play ();} interface Bounceable {void play ();} interface Rollable extends Playable, Bounceable {Ball ball = new Ball ( "PingPang");} class Ball implements Rollable {private String name; public String getName ( ) {RETURN Name;} public ball (string name) {this.name = name;} public void play () {ball = new ball ("football"); system.out.println (ball.getname ());} }
This error is not easy to find.