JAVA basics-full explanation of Java BASICS (2)

Source: Internet
Author: User
Tags websphere application server

20. What is the difference between EJB and java bean?
Java Bean is a reusable component and there is no strict specification for Java Bean. Theoretically, any Java class can be a Bean. However, since Java Beans are created by containers (such as Tomcat), Java Beans should have a constructor without parameters. In addition, generally, Java Bean must implement the Serializable interface to realize Bean persistence. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model. It cannot be accessed across processes. Enterprise Java Bean is equivalent to DCOM, which is a distributed component. It is based on Java remote method call (RMI) technology, so EJB can be remotely accessed (cross-process, cross-computer ). However, EJB must be deployed in containers such as Webspere and WebLogic. The EJB client never directly accesses the real EJB component but accesses it through its container. The EJB container is the proxy of the EJB component. The EJB component is created and managed by the container. The customer accesses the real EJB component through the container.

[B/] 21. Differences between Static Nested Class and Inner Class. [/B]
Static Nested Class is an internal Class declared as static. It can be instantiated without relying on external Class instances. In general, internal classes must be instantiated before they can be instantiated.

22. What is the difference between dynamic INCLUDE and static INCLUDE in JSP?
Implement Dynamic INCLUDE with jsp: include action It always checks changes in the contained files and is suitable for containing dynamic pages and can contain parameters.
Static INCLUDE is implemented using the include pseudo code, and changes to the included files are not checked. This applies to static pages containing <% @ include file = "included.htm" %>


23. When to use assert.
Assertion is a common debugging method in software development. Many development languages support this mechanism. In implementation, assertion is a statement in the program. It checks a boolean expression. A correct program must ensure that the value of this boolean expression is true. If this value is false, if the program is in an incorrect state, the system will give a warning or exit. Generally, assertion is used to ensure the most basic and critical correctness of the program. The assertion check is usually enabled during development and testing. To improve performance, the assertion check is usually disabled after the software is released.


24. What is GC? Why does GC exist?
GC is the meaning of garbage Collection (Gabage Collection). Memory Processing is a place where programmers are prone to problems. Forgetting or wrong memory Collection can lead to instability or even crash of programs or systems, the GC function provided by Java can automatically monitor whether the object exceeded the scope to automatically recycle the memory. the Java language does not provide a display operation to release the allocated memory.

 
25. short s1 = 1; s1 = s1 + 1; what is the error? Short s1 = 1; s1 + = 1; what is the error?
Short s1 = 1; s1 = s1 + 1; (the s1 + 1 operation results in int type, which requires forced conversion)
Short s1 = 1; s1 + = 1; (it can be compiled correctly)


26. How much is Math. round (11.5? Math. round (-11.5) and so on? 
Math. round (11.5) = 12
Math. round (-11.5) =-11
The round method returns a long integer closest to the parameter. After the parameter is added to 1/2, the floor is obtained.


27. String s = new String ("xyz"); how many String objects are created?
Two


28. Design four threads, two of which increase 1 to j each time, and the other two reduce 1 to j each time. Write the program.
The following programs use internal classes to implement threads, and do not consider the sequence when j is added or subtracted.
Public class ThreadTest1 {
Private int j;
Public static void main (String args []) {
ThreadTest1 tt = new ThreadTest1 ();
Inc inc = tt. new Inc ();
Dec dec = tt. new Dec ();
For (int I = 0; I <2; I ++ ){
Thread t = new Thread (inc );
T. start ();
T = new Thread (dec );
T. start ();
}
}
Private synchronized void inc (){
J ++;
System. out. println (Thread. currentThread (). getName () + "-inc:" + j );
}
Private synchronized void dec (){
J --;
System. out. println (Thread. currentThread (). getName () + "-dec:" + j );
}
Class Inc implements Runnable {
Public void run (){
For (int I = 0; I <100; I ++ ){
Inc ();
}
}
}
Class Dec implements Runnable {
Public void run (){
For (int I = 0; I <100; I ++ ){
Dec ();
}
}
}
}


29. Is there a goto in Java?
Reserved Words in java, which are not currently used in java.


30. Do I use run () or start () to start a thread ()?
When a thread is started, the start () method is called to make the virtual processor represented by the thread in a running state, which means that it can be scheduled and executed by JVM. This does not mean that the thread will run immediately. The run () method can generate the exit sign to stop a thread.


31. EJB includes (SessionBean, EntityBean) indicating their lifecycle and how to manage transactions?
SessionBean: the lifecycle of Stateless Session Bean is determined by the container. When the client sends a request to create a Bean instance, the EJB container does not have to create a new Bean instance for the client to call. Instead, it finds an existing instance and provides it to the client. When the client calls a Stateful Session Bean for the first time, the container must immediately create a new Bean instance on the server and associate it with the client, when this client calls the Stateful Session Bean method later, the container will dispatch the call to the Bean instance associated with this client.
EntityBean: Entity Beans can survive for a relatively long time, And the status is continuous. As long as the data in the database exists, Entity beans will survive. It is not based on the application or service process. Even if the EJB container crashes, Entity beans survive. Entity Beans can be managed by containers or Beans themselves.
EJB uses the following technical management practices: OTS of Object Management Organization (OMG), Transaction Service (JTS) of Sun Microsystems, and Java Transaction API (JTA ), the XA interface of the Development Group (X/Open.


32. What are the application servers?
BEA WebLogic Server, IBM WebSphere Application Server, Oracle9i Application Server, jBoss, Tomcat


33. Give me the most common runtime exception.
Except, ArrayStoreException, except, failed, CannotRedoException, CannotUndoException, ClassCastException, cmcmexception, except, DOMException, EmptyStackException, except, failed, ImagingOpException, failed, MissingResourceException, failed, failed, nullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException


34. CAN interfaces be inherited? Can an abstract class implement the (implements) interface? Can an abstract class inherit a concrete class )?
Interfaces can inherit interfaces. Abstract classes can be implemented (implements) interfaces, and whether abstract classes can inherit object classes, provided that object classes must have clear constructors.


35. Does List, Set, and Map inherit from the Collection interface?
List, Set is, Map is not


36. What is the working mechanism of the data connection pool?
When the J2EE server is started, a certain number of pool connections will be established, and a certain number of pool connections will be maintained. When the client program needs to connect, the pool driver returns an unused pool connection and logs its table as busy. If no idle connection exists, the pool driver creates a certain number of connections. The number of new connections is determined by the configuration parameters. When the pool connection call is completed, the pool driver records the connection table as idle, and other calls can use the connection.


37. can abstract methods be both static, native, and synchronized?
None


38. Does the array have the length () method? Does String have the length () method?
The array does not have the length () method. It has the length attribute. String has the length () method.


39. The elements in the Set cannot be repeated. How can we identify whether the elements are repeated or not? Is = or equals () used ()? What are their differences?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.