Interview Series - 2019 125 common pen java interview questions summary (b)

26, when to use assert. 
assertion (assertion) is a common debug mode in software development languages support this mechanism for many developers. In the implementation, assertion is a statement in the program, it checks a boolean expression, a program must ensure that the correct boolean expression evaluates to true; if the value is false, explain procedures already in a bad state , the system will give a warning or quit. Generally speaking, assertion assurance procedures for basic and critical correctness. assertion checking is usually open during development and testing. To improve performance, after the software release, assertion checking is usually closed.

27, GC What is? Why should there be GC? 
GC is a garbage collection means (Gabage Collection), memory handling is where programmers prone to problems, and forget or false memory recovery program will lead to instability or even system crashes, Java GC function provides automatic monitoring of the object exceeds the scope so as to achieve the purpose of automatic recovery of memory, Java language does not provide a method of operating the display release allocated memory.

28, short s1 = 1; s1 = s1 + 1; there is nothing wrong with short s1 = 1;? S1 + = 1; there anything wrong? 
Short s1 = 1; s1 = s1 + 1; (s1 + 1 operation result is int type, you need to type cast)
Short s1 = 1; s1 + = 1; (compile correctly)

29, Math.round (11.5) is equal to the number of Math.round (-11.5) equals how much?? 
 Math.round (11.5) = 12 is =
Math.round (-11.5) == -. 11
round method returns the nearest long integer parameter, the parameter is increased by seeking the floor 1/2.

30, String s = new String ( "xyz"); created several String Object? 
Two

31, EJB, including (SessionBean, EntityBean) say their life cycle, and how to manage the affairs?
SessionBean: Stateless Session Bean's life cycle is determined by the container when the client makes a request to create an instance of a Bean, EJB containers do not have to create a new instance of the Bean for client calls, but now easily find a some examples are provided to the client. When a client first call a Stateful Session Bean, the container must be created immediately in the server a new Bean instance, and related to the client, the client calls after this when Stateful Session Bean method will call dispatch to the container Bean instance associated with this client.
EntityBean: Entity Beans can survive for a relatively long time, and the state is continuing. As long as the database data exist, Entity beans have been alive. Not the application process for the program or service. Even if the EJB container crashes, Entity beans also survived. Lifecycle Entity Beans Beans can be container or manage their own.
EJB technology through the following management practices: Object Management Group (OMG) object Practice Services (OTS), Sun  Microsystems's Transaction Service (JTS), Java Transaction API (JTA), the development group (X / Open) XA Interface.

32, application servers have those?
BEA WebLogic Server,IBM WebSphere Application Server,Oracle9i Application Server,jBoss,Tomcat

33、给我一个你最常见到的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

34, the interface is inheritable interfaces? Are abstract class can implement (implements) the interface? Abstract class is inheritable entity class (concrete class)?
Interfaces can be inherited interfaces. Abstract class can implement (implements) interface abstract class is inheritable entity class, but only if the entity class must have explicit constructor.

35, List, Set, Map whether inherited from the Collection interface?
List, the Set Shi, Map not

36, what data connection pooling mechanism to say that?
The J2EE  server startup will establish a pool certain number of connections, the number has been maintained and number of pool connections thereto. Needs to connect client program, the pool driver returns a pool of unused connection and denoted as busy. If no connection is idle, the driver on the new pool certain number of connections, the number of new connections have configuration parameters decision. When the call is completed using a connection pool, pool table driver this connection referred to as idle, other calls can use this connection.

37, abstract whether the method is also static, it also is a native, it is also synchronized?
Can not be

38, the array has no length () this method? String has no length () this method?
Arrays are not length () this method, length attributes. String with a length () this method.

)? How do they 39, Set in the element is not repeated, then the method used to distinguish whether or not repeat it? Is == or equals (the difference?
The Set, the elements are not repeated, then use the iterator () A method to distinguish whether or not repeated. equals () is the interpretation of whether the two Set for equality.
equals () == method and value at the decision point to the same object equals () is covered in the class, and the type of the content when two separate objects match it returns a true value. 

40, whether Constructor constructor can be override?
Constructor constructor can not be inherited and can not rewrite Overriding, but can be overridden Overloading.

41, can inherit String class?
String class is final class can not inherit it.

42, swtich on whether the role of the byte, whether in the role on the long, whether in the role on a String?
Switch (expr1) in, expr1 is an integer expression. Therefore, the parameters passed to the switch and case statements should be int, short, char or byte. long, string can not act on the swtich.

43, try {} there is a return statement, then followed by code in finally after this try {} there will not be executed, when executed, the return before or after?
Is executed, executed before return.

44, the programming problem: 2 by multiplying 8 the most efficient method of calculating equal to a few? 
2 <<. 3

45, the values of two identical objects (x.equals (y) == true) , but it may have different hash code , this sentence right?
No, have the same hash code.

46, when an object is passed as a parameter to a method, this method can change the properties of this object, and returns the result of changes in, then in the end is passed by reference or value transfer here? 
Is passed by value. Java  programming language only pass parameters value. When a method is passed to the object instance as a parameter, the value of the parameter is a reference to the object. Contents of the object may change in the method is called, but the object reference will never change.

47, when a thread enters a synchronized method of an object, other threads can access this object other methods?
No, an object of a synchronized method can only be accessed by a thread.

48, the programming problem: to write out a Singleton.
Singleton pattern major role is to ensure that a Java application, a Class of only one instance of existence.
General Singleton pattern usually have several different forms: The
first form: define a class, its constructor is private, it has a private static class variables, examples, then, through a public initialization in the class of getInstance the method of obtaining a reference to it, which in turn calls a method.

public  class Singleton {
 Private Singleton () {}
     // define themselves in their own internal one instance, is not it strange?
    // Note that this is private for internal calls 
    private  static the Singleton instance = new new the Singleton ();
     // there is provided a method for static external access to the class, can directly access 
    public  static the Singleton the getInstance () {
     return instance;
    } 
}  

 

The second form: 

public  class the Singleton { 
  Private  static the Singleton instance = null ;
  public  static  the synchronized the Singleton the getInstance () {
    // This method is somewhat than the above improvements, not to generate each subject, only the first 
    // create instances used to improve the effectiveness! 
    IF (instance == null )
      instance=new Singleton();
      return instance;   
    }   }
}

 

 Other forms:
define a class, its constructor is private, all of the static method.
The first form is generally considered to be more secure some 

49, Java interfaces and C ++ the same and different from the virtual class.
Because Java does not support multiple inheritance, there is a possibility of a class or object to use each method or property in a few classes or objects inside the existing single inheritance mechanism can not meet the requirements. Compared with the inheritance, interfaces have greater flexibility, because the interface does not contain any implementation code. When a class implements the interface after the implementation of the interface class to which all of the methods and properties, and the properties of the interface which is the default state following public static, default, all methods is public. A class can implement multiple interfaces.

50, simple principle and application of exception handling mechanisms in Java.
When the JAVA program violates the semantic rules of JAVA, JAVA virtual machine error will occur is expressed as an exception. Violation of semantic rules include two cases. One is the JAVA class libraries built semantic checks. For example, cross-border array subscript, will trigger IndexOutOfBoundsException; access will trigger NullPointerException null object. In other cases, JAVA allows programmers to extend this semantic checks, programmers can create their own unusual and freedom to choose when to throw an exception with the throw keyword. All exceptions are subclasses of java.lang.Thowable.

Guess you like

Origin www.cnblogs.com/juihai/p/11102142.html