Java based on the knowledge that 32 points

  Java based on the knowledge that 32 points 

  Java is the whole basis of the knowledge to do two points must be 
  1, a clear distinction must be reached, mastering, Lanshu at heart, and to the extent of the census form 
  2, we must at any time, any place, under any circumstances accurately answer these questions 

   First, talk about the final, finally, finalize distinction.  
   The most commonly asked.  

   Second, Anonymous Inner Class (anonymous internal) can extends (succession) Other categories can implements (realization) interface (interface)?  

   Third, Static Nested Class Inner Class and the different, to put it better (face some very general questions).  

   Fourth, and & & & distinction.  
   Asked a little of this.  

   Fifth, the HashMap and Hashtable distinction.  
   Chang asked.  

   Sixth, Collection and Collections distinction.  
   You should never say one is a single number is plural.  

   Seventh, when used assert.  
   API-level technical personnel may be asked this.  

   8, GC? GC Why do we need?  
   Basis.  

   Ninth, String s = new String ( "xyz"); created several String Object? (See also "java basis - String")  

   10, Math.round (11.5) equal to how many? Math.round (-11.5) mean?  

   11, short s1 = 1; s1 = s1 + 1; What is wrong? Short s1 = 1; s1 + = 1; What is wrong?  
   Face questions are very abnormal, it is necessary to do a good job for abused.  

   12, sleep () and wait () What is the difference?  
   Engage threads favorite.  

   13, Java has goto?  
   13 is the issue, if the interviews which asked this question, I advise you into this or other companies.  

   14, have an array length () This method? Have String length () This method?  

   15, Overload and Override distinction.      Overloaded whether the method can change the type of return value?  
   Chang asked.  

   16, Set, the elements are not repeated, then the method used to distinguish whether or not to repeat? Use == or equals ()? What is the difference between them?  

   17, the most to me you see a runtime exception.  
   If your answer to interview people will think you do not have the actual programming experience.  

   18, error and exception What is the difference?  

   19, List, Set, whether inherited from the Map Collection Interface?  

   20th, the abstract class and interface What is the difference? (See also "in-depth understanding of Abstract Class and Interface")  
   Chang asked.  

   21, the abstract whether the method is static at the same time, whether at the same time is native, can be synchronized at the same time?  

   22, the interface Gejicheng interface? Abstract class can be realized if (implements) interface? Abstract class is Gejicheng entity class (concrete class)?  

   23, the thread is used to launch a run () or the start ()?  

   24, the constructor may be whether Constructor override?  

   25, can inherit String class?  

   26, when a thread into a target of a synchronized method, the other threads can access this object other methods?  

   27, () try in a return statement, then try keeping up with this after finally () in the code will be executed, when executed, in return before or after?  

   28, programming and that: The most efficient method calculated by multiplying 2 equivalent to several 8?  
   C programmers with backgrounds like to ask this particular question.  

   29, the two targets of the same value (x.equals (y) == true), but it may have different hash code, this sentence right?  

   30, when an object to be used as a parameter transmission methods, this method can change the object's properties, and return the result of changes in, then here in the end is passed by reference or value transfer? (This question can be answered please See "java parameter transmission in the end is passed by reference or value transfer")  

   31, it can swtich role in the byte, whether in the long role, whether in the role of String?  

   32, programming that: write a Singleton out.  

  Below are the answers 

  First, talk about the final, finally, finalize distinction. 

  Final-Xiuchifu (keyword) If a class was for the final statement, implies that it will not send another unexpected new sub-category, was not a father of succession.    Thus, a class could not be both abstract of the statement, the statement was the final.    Will be variable or method statement for the final, can guarantee that they will not be in use change.    By the final statement of variables must be given in the initial statement, and in the future can only be used in the reader, can not be amended.    For the final statement was also the only method used, can not override 

  Exception Handling-to finally provide finally block to the implementation of any clearing operation.    If dished out an exception, then the match will be the implementation of the catch clause, then control will finally enter the block (if any). 
  - Finalize method name.    Java technology allows the use finalize () method in the refuse collection will be targeted for removal from memory before doing the necessary cleanup work.    This method is by garbage collectors in determining the object was not invoked when the object of the call.    It is the definition of the Object class, so all classes are inherited it.    Subclass coverage finalize () method to tidy up system resources or perform other cleanup work.    Finalize () method in the refuse collection target for the deletion of the object before calling. 

  Second, Anonymous Inner Class (anonymous internal) can extends (succession) Other categories can implements (realization) interface (interface)? 

  Anonymous is the internal name of the internal category.    Not extends (succession) Other category, but a class can be used as an internal interface, the internal category by another realization. 

  Third, Static Nested Class Inner Class and the different, to put it better (face some very general questions). 
  Nested Class (typically C + + view), Inner Class (that is generally JAVA).    Internal Java and C + + class category nested The biggest difference lies in whether there is a point on the external references.    Concrete, visible http://www.frontfree.net/articles/services/view.asp?id=704&page=1 
  Note: internal static type (Inner Class) means a creation of a category of static internal targets, does not require an external object type, not from a static 2 within a category of object access an external object class 

  Fourth, and & & & distinction. 
  & Is bitwise.    & & Is Boolean logic operators. 

  Fifth, the HashMap and Hashtable distinction. 
  Map Interface belong to the category, will be achieved only keys mapped to specific values. 
  HashMap no classification or category ranking.    It allows a bond and a number of null null value. 
  Hashtable HashMap similar, but not null-and null values.    It is also slower than the HashMap because it is synchronized. 

  Sixth, Collection and Collections distinction. 
  Collections is a java.util under the category, which includes the operation of the various sets of static methods. 
  Collection is a java.util under the interface, it is the father of a set of interface structure. 

  Seventh, when used assert. 
  Assertion is a Boolean expressions containing the statement in the implementation of the sentence, assuming that the expression is true.    If the formula for calculating false, then the system will report a Assertionerror.    It is used for debugging purposes: 
  Assert (a> 0) / / throws an Assertionerror if a <= 0 
  Asserted that there are two forms: 
  Assert Expression1; 
  Assert Expression1: Expression2; 
  Expression1 should always produce a boolean value. 
  Expression2 can reach an arbitrary value of the expression.    This value is used to generate information indicates that more String debugging information. 
  Assertion is in default under the disabled.    To compile the opening, that the need to use the source 1.4 Tags: 
  Javac-source 1.4 Test.java 
  In the opening run, that can be used - enableassertions or - ea marker. 
  Run-time option to disable, that can be used - or da - disableassertions marker. 
  System category to the opening, that can be used - esa or - dsa marker.    Also in the package can be on the basis of opening or disable assertion. 
  Can be expected under normal circumstances would not arrive at any location on the assertion.    Asserted that can be used to validate the method of transfer to the private parameters.    However, the assertion should not be used to validate the method of transmission parameters to the public, because whether or not opened, that the public methods to check its parameters.    However, both methods can be in the public domain as well as in the use of non-means tested assertion home conditions.    In addition, the assertion should not in any way change the status of procedures. 

  8, GC? Why do we need GC (base). 
  GC is garbage collectors.    Java programmers do not have to worry about memory management, garbage collectors will be automatically managed.    To request garbage collection, which could be called one of the following methods: 
  System.gc () 
  Runtime.getRuntime (). Gc () 

  Ninth, String s = new String ( "xyz"); created several String Object? 
  Two objects, one is "xyx," one refers to "xyx" s object references. 

  10, Math.round (11.5) equal to how many? Math.round (-11.5) mean? 
  Math.round (11.5) return (long) 12, Math.round (-11.5) return (long) 11; 

  11, short s1 = 1; s1 = s1 + 1; What is wrong? Short s1 = 1; s1 + = 1; What is wrong? 
  Short s1 = 1; s1 = s1 + 1; wrong, s1 is short type, type int s1 +1 is not explicit into short type.    Can be adapted to s1 = (short) (s1 + 1).    Short s1 = 1; s1 + = 1 correctly. 

  12, sleep () and wait () What is the difference? Engage threads favorite 
  Sleep () method is to stop for a period of time threading methods.    Sleep in the time interval expires, not necessarily an immediate resumption of the implementation of threads.    This is because, in that moment, other threads may be running and has not been abandoned for the implementation of scheduling, unless (a) "woke up" threads have higher priority 
  (B) the threads are running for other reasons obstruction. 
  Wait () is threaded interactive, and if a thread synchronization object x send a wait () call, the thread will be suspended, had been re-enter the wait state object, or wait until they were awakened time. 

  13, Java has goto? 
  Goto-java in the reserved words, there is no use in java. 

  14, have an array length () This method? Have String length () This method? 
  Arrays are not length () This method, length attributes. 
  String with a length () This method. 

  15, Overload and Override distinction.    Overloaded whether the method can change the type of return value? 
  Overriding method of rewriting and Heavy Overloading is the polymorphism of different Java performance.    Overriding rewrite of the father and son is like between a polymorphism of performance, heavy-duty category Overloading is a polymorphism of a performance.    If the definition of a category of methods and his father have the same name and parameters, we say that the methods have been rewritten (Overriding).    Sub-category of objects using this method, called sub-category will be the definition of it, the father category, as was the definition of "shield".    If a definition in a number of the same name, they may have different parameters or the number of different types of parameters, the method is referred to as the heavy-duty (Overloading).    Overloaded method can change the type of the return value. 

  16, Set, the elements are not repeated, then the method used to distinguish whether or not to repeat? Use == or equals ()? What is the difference between them? 
  Set in the elements can not be duplicated, then using iterator () method to distinguish whether or not to repeat.    Equals () Set two is whether the same interpretation. 
  Equals () == method and the value at the decision to use the same object equals () in the category was covered, as is the subject of two separate types of content and match it back to the true value. 

  17, the most to me you see a runtime exception. 
  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 

  18, error and exception What is the difference? 
  Restoration of error that is difficult but not impossible situation of a serious problem.    For example, memory overflow.    Not expect procedures to deal with such cases. 
  Exception that a design problem or to achieve.    In other words, it said that if the normal operating procedures, the situation will not happen. 

  19, List, Set, whether inherited from the Map Collection Interface? 
  List, is Set 

  Map is not 

  20th, the abstract class and interface What is the difference? 
  Statement instead of the existence of methods to achieve its category called abstract class (abstract class), which used to create an embodiment of some of the basic category, as well as such a statement, but these can not be achieved in such a situation.    Can not create abstract instance of the class.    However, you can create a variable, the type is an abstract class and subclass it at a specific example.    Constructor function is not abstract or abstract static method.    Abstract of the sub-class for their father to all of the means for achieving the abstract, it is an abstract class for them.    Instead, in the category of achieving this method.    Know the behavior of other classes can be achieved in the category of these methods. 
  Interface (interface) is a variant of the abstract category.    In the interface, all methods are abstract.    More can be inherited through the realization of this interface and access.    Interface methods are all abstract, not in a procedure.    Interface can only definition of static final variables.    Interface with the realization of similar type, in addition to the realization of the interface definition can not inherit behavior.    When the realization of the special type interface, which defines (forthcoming process of giving) all such interface methods.    Then, it can be achieved in the interface of any object method call interface.    As an abstract class, which allows the use of interface were cited as the type of a variable.    Usually the dynamic of the series will come into force.    Can be converted to use interface type or from the interface type conversion, instanceof operator can be used to determine whether a particular object of achieving the interface. 

  21, the abstract whether the method is static at the same time, whether at the same time is native, can be synchronized at the same time? 
  Can 

  22, the interface Gejicheng interface? Abstract class can be realized if (implements) interface? Abstract class is Gejicheng entity class (concrete class)? 
  Interface interface can be inherited.    An abstract class can be achieved (implements) interface, abstract class is Gejicheng entity categories, but the precondition is that such entities must have a clear structure function. 

  23, the thread is used to launch a run () or the start ()? 
  Start a thread is called start () method, represented by the thread of virtual processors can be run at the state, which means it can be JVM scheduling and implementation.    This does not mean that thread will be immediately operational.    Run () method can be generated from the signs to stop a thread. 

  24, the constructor may be whether Constructor override? 
  Constructor constructor can not be inherited, it is not rewriting Overriding, but can be heavy-duty Overloading. 

  25, can inherit String class? 
  String class is the final category is not inherited. 

  26, when a thread into a target of a synchronized method, the other threads can access this object other methods? 
  Not, an object of a synchronized method can only visit by a thread. 

  27, () try in a return statement, then try keeping up with this after finally () in the code will be executed, when executed, in return before or after? 
  Will be implemented, in return before implementation. 

  28, programming and that: The most efficient method calculated by multiplying 2 equivalent to several 8? 
  C programmers with backgrounds like to ask this particular question. 

  2 <<3 

  29, the two targets of the same value (x.equals (y) == true), but it may have different hash code, this sentence right? 
  Not have the same hash code. 

  30, when an object to be used as a parameter transmission methods, this method can change the object's properties, and return the result of changes in, then here in the end is passed by reference or value transfer (see also "java is transfer or use of transfer ") 
  Is the value of transmission.    Java programming language only by passing a parameter value.    When an object instance is passed as a parameter to the method, the value of parameter is the object.    The contents of the object can be called by the change, but the object is invoked never change. 

  31, it can swtich role in the byte, whether in the long role, whether in the role of String? 
  Switch (expr1), expr1 is an integral expression.    Therefore transmitted to the switch statement and the case should be the parameters int, short, or char byte.    Long, in the role of string can swtich. 

  32, programming that: write a Singleton out. 
  Singleton pattern major role is to ensure that a Java application, a Class of only one instance of existence. 
  General Singleton pattern usually there are several different forms: 
  The first forms: a class definition, and its constructor function for the private, and it has a static variable of such a private, in the case of initialization, through a public access to the getInstance method used it, and then Calling these methods. 
  Public class Singleton ( 
  Private Singleton () () 
  / / Define themselves in their own internal An example is not very strange? 
  / / Note that this is private internal calls only private static Singleton instance = new Singleton (); 
  / / Here's a visit to the class for external static methods can be direct access to public static Singleton getInstance () ( 
  Return instance; 
  ) 
  ) 
  The second form: 
  Public class Singleton ( 
  Private static Singleton instance = null; 
  Public static synchronized Singleton getInstance () ( 
  / / This method than the above improvements, not to generate each object is the first time / / create an instance when the use of improved efficiency! 
  If (instance == null) 
  Instance = new Singleton (); 
  Return instance;) 
  ) 
  Other forms: 
  Definition of a category, and its constructor function for the private, all the static method. 
  General considers that the form should be some more security 

  Hashtable and HashMap 
  Hashtable inherited from the Dictionary category, and the introduction of Java1.2 HashMap is a realization Map interface 

  HashMap allowed as a null entry will be the key or value, and not Hashtable 

  There is, the HashMap the Hashtable contains methods removed, and replaced containsvalue containsKey.    Because contains methods easily lead to misunderstanding. 

  The biggest difference is that the method is Synchronize Hashtable, and HashMap not, in a number of threads visit Hashtable, it does not require its own method for synchronization, and HashMap 
  Provided, it must be synchronized. 

  Hashtable and HashMap used hash / algorithms are probably rehash the same, so there will not be much of the difference. 

  Posted on 2007-03-28 17:20 chengjie Reading (25) Comments (0) edit collections cited 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply