125 common java interview pen questions Summary 5

Source: Internet
Author: User
94. What are the methods for sorting? List. Use JAVA to implement a fast sorting.
The sorting methods include insert sorting (direct insertion sorting and Hill sorting), exchange sorting (Bubble sorting and quick sorting), select sorting (Direct selection sorting and heap sorting), and merge sorting, sort allocation (Box sorting and base sorting)
Pseudo code for fast sorting.
// Use the quick sorting method to sort a [0: n-1]
Select an element from a [0: n-1] As m I d l e, which is the fulcrum
Divide the remaining elements into two left and r I g h t, so that the elements in l e f t are less than or equal to the fulcrum, and the elements in right are greater than or equal to the Fulcrum.
Recursively sort left by using the quick sorting method
Recursively sort right using the quick sorting method
The result is l e f t + m I d l e + r I g h t.

95. Please explain (or briefly describe) the terms commonly used in J2EE below)
Web Container: provides an environment for the application components (JSP and SERVLET) in the container, so that JSP and SERVLET can directly interact with the environment variable interfaces in the container, so that you do not have to pay attention to other system problems. It is mainly implemented by WEB servers. For example, TOMCAT, WEBLOGIC, and WEBSPHERE. The interface provided by the container strictly complies with the web application standard in J2EE specifications. We call the WEB server that complies with the above standards the WEB Container in J2EE.
EJB container: Enterprise java bean container. More industry-specific characteristics. It provides various management functions for the component EJB running in it. As long as the EJB meeting the J2EE specification is put into the container, it will be managed efficiently by the container immediately. And system-level services can be obtained through ready-made interfaces. For example, mail service and transaction management.
JNDI :( Java Naming & Directory Interface) JAVA Naming Directory service. The main function is to provide a directory system that allows applications from other places to leave their own indexes on it to quickly find and locate distributed applications.
JMS :( Java Message Service) JAVA Message Service. Communication between applications. Including point-to-point and broadcast.
JTA :( Java Transaction API) JAVA Transaction service. Provides various distributed transaction services. An application only needs to call the interfaces it provides.
JAF :( Java Action FrameWork) JAVA security authentication FrameWork. Provides some security control frameworks. Developers can implement their own personalized security control policies through various deployment and customization.
RMI/IIOP: (Remote Method Invocation/internet object request mediation protocol) They are mainly used to call services remotely. For example, if a program runs on a remote computer that provides the Stock Analysis Service, we can directly call it on a local computer. Of course, this requires certain specifications to communicate between heterogeneous systems. RMI is unique to JAVA.

96. How to handle exceptions in JAVA? What are the meanings of keywords: throws, throw, try, catch, and finally? Can I throw an exception in the try block?
Java uses object-oriented methods to handle exceptions, classify various exceptions, and provides good interfaces. In Java, each exception is an object, which is an instance of the Throwable class or other subclass. When a method encounters an exception, an exception object is thrown. The object contains the exception information. The method that calls this object can capture the exception and handle it. Java exception handling is implemented through five keywords: try, catch, throw, throws, and finally. Generally, try is used to execute a program. If an exception occurs, the system throws an exception. In this case, you can catch it by its type, or finally (finally) is handled by the default processor.
Use try to specify a program to prevent all "exceptions. The catch clause should be followed by the try program to specify the type of the "exception" you want to capture.
Throw statements are used to explicitly throw an "exception ".
Throws is used to indicate various "exceptions" that a member function may throw ".
Finally ensures that a piece of code is executed no matter what "exception" occurs.
You can write a try statement outside a member function call, and write another try statement inside the member function to protect other code. Every time a try statement is encountered, the framework of "exception" is placed on the stack until all try statements are completed. If the try statement at the next level does not process an "exception", the stack will be opened until a try statement that handles this "exception" is encountered.

97. Can a ". java" source file contain multiple classes (not internal classes )? What are the restrictions?
Yes. Only one class name must be the same as the file name.

98. What technologies are used to implement MVC? How to implement it?
MVC is short for Model-View-Controller. "Model" indicates the business logic of the application (implemented by the JavaBean and EJB components), and "View" indicates the application surface (generated by the JSP page ), "Controller" provides application processing process control (generally a Servlet). This design model divides the application logic, processing process and display logic into different components for implementation. These components can be used for interaction and reuse.

99. How can I implement a thread in java? What keywords are used to modify the synchronization method? Why is the stop () and suspend () methods not recommended?
There are two implementation methods: Inheriting the Thread class and implementing the Runnable interface.
Use the synchronized keyword to modify the synchronization method
The opposite uses stop () because it is not safe. It unlocks all the locks obtained by the thread, and if the object is in an inconsistent state, other threads can check and modify them in that state. It is difficult to check the real problem. The suspend () method is prone to deadlocks. When suspend () is called, the target thread stops, but still holds the lock obtained before that. At this time, no other thread can access the locked resources, unless it is "suspended" the thread resumes running. For any thread, if they want to restore the target thread and attempt to use any locked resource, it will cause a deadlock. Therefore, you should not use suspend (), but set a flag in your Thread class to indicate whether the Thread should be active or suspended. If the flag indicates that the thread should be suspended, use wait () to enter the waiting state. If the flag indicates that the thread should be recovered, restart the thread with a notify.

100. How many types of streams are available in java? JDK provides some abstract classes for each type of stream for inheritance. which classes are they?
Byte stream: bytes stream. Byte streams are inherited from InputStream OutputStream, and bytes streams are inherited from InputStreamReader OutputStreamWriter. There are many other streams in the java. io package, mainly to improve performance and ease of use.

101. Is there any memory leakage in java? Please briefly describe it.
Yes. For example: int I, i2; return (i-i2); // when I is a positive number large enough, i2 is a negative number large enough. The result may cause overflow and errors.

102. What is the mechanism for implementing polymorphism in java?
Overriding and Overloading are different manifestations of Java polymorphism. Overriding is a manifestation of the polymorphism between the parent class and the Child class, and Overloading is a manifestation of the polymorphism in a class.

103. What is the basic principle of the garbage collector? Can the Garbage Collector recycle memory immediately? Is there any way to proactively notify virtual machines to recycle garbage?
For GC, when a programmer creates an object, GC starts to monitor the address, size, and usage of the object. Generally, GC records and manages all the objects in the heap by Directed Graphs. This method is used to determine which objects are "reachable" and which objects are "inaccessible ". When GC determines that some objects are "inaccessible", GC has the responsibility to recycle the memory space. Yes. Programmers can manually execute System. gc () to notify the GC to run, but the Java language specification does not guarantee that GC will be executed.

104 what are the differences between static variables and instance variables?
Static I = 10; // constant
Class A a; a. I = 10; // variable

105. What is java serialization and how to implement java serialization?
Serialization is a mechanism for processing object streams. Object streams are called object streams that stream object content. You can perform read and write operations on Streaming objects, or transfer streaming objects between networks. Serialization aims to solve the problems caused by read/write operations on Object streams.
Serialization implementation: implement the Serializable interface for the class to be serialized. There is no implementation method for this interface. implements Serializable is only to mark that the object can be serialized, then, an output stream (such as FileOutputStream) is used to construct an ObjectOutputStream (Object stream) Object. Then, the writeObject (Object obj) of the ObjectOutputStream Object is used) method, you can write the object whose parameter is obj (that is, save its status). To restore the object, use the input stream.

106 can a non-static method be called from inside a static method?
No. If it contains the method () of the object, object initialization is not guaranteed.

107 When writing the clone () method, there is usually a line of code. What is it?
Clone has a default action. super. clone () is responsible for generating the correct size of space and copying data by bit.

108. in JAVA, how does one jump out of the current multi-nested loop?
Use the break; return method.

109. What are the features of the interfaces List, Map, and Set when accessing elements?
A List holds elements in a specific order, and can contain duplicate elements. Set cannot have repeated elements and can be sorted internally. Map stores the key-value, which can be multiple values.

110. What is J2EE?
J2EE is a multi-layer (multi-diered), distributed (distributed), component-based enterprise-level application model (enterpriese application model) proposed by Sun ). in such an application system, different components can be divided by function. These components can be located on different computers and at the corresponding level (tier. The hierarchy includes the Client layer (clietn tier) components, web layer and components, Business layer and components, and Enterprise Information System (EIS) layer.

111 UML
Standard Modeling Language (UML. Use case diagram, static diagram (including class diagram, object diagram, and package diagram), behavior diagram, and interaction diagram (sequence diagram, cooperation diagram) to implement the diagram.

112. You can name five common classes, packages, and interfaces.
Common classes: BufferedReader BufferedWriter FileReader FileWirter String Integer
Common packages: java. lang java. awt java. io java. util java. SQL
Common interfaces: Remote List Map Document NodeList

113 what design patterns are used in development? In what scenarios?
Each mode describes a problem that is constantly emerging in our environment, and then describes the core of the solution to the problem. In this way, you can use existing solutions countless times without repeating the same work. The MVC design mode is mainly used. Used to develop JSP/Servlet or J2EE applications. Simple factory mode.

114. What actions does jsp have? What are their roles?
JSP has the following 6 basic actions: include: Introduce a file when the page is requested. Jsp: useBean: Find or instantiate a JavaBean. Jsp: setProperty: Set attributes of JavaBean. Jsp: getProperty: outputs the attributes of a JavaBean. Jsp: forward: Transfers requests to a new page. Jsp: plugin: generate the OBJECT or EMBED tag for the Java Plug-in based on the browser type.

115 can Anonymous Inner Class (Anonymous internal Class) be extends (inherited) other classes, or implements (implemented) interface (interface )?
It can inherit other classes or complete other interfaces. This method is often used in swing programming.

116 what is the difference between an application SERVER and a web server?
Application Servers: Weblogic, Tomcat, and Jboss
Web server: IIS, Apache

117. Relationship and difference between BS and CS.
C/S is the abbreviation of Client/Server. Servers generally use high-performance PCs, workstations, or minicomputers, and large database systems such as Oracle, Sybase, Informix, or SQL Server. The client must install dedicated client software.
B/S is the abbreviation of Brower/Server. to install a Browser on a client, such as Netscape Navigator or Internet Explorer, the Server installs Oracle, Sybase, Informix, SQL Server, and other databases. In this structure, the user interface is fully implemented through the WWW browser. Some transaction logic is implemented at the front end, but the main transaction logic is implemented at the server end. The browser interacts with the database through the Web Server.
Differences between C/S and B/S:
1. Different hardware environments:
C/S is generally built on a dedicated network. In a small network environment, the LAN provides connection and data exchange services through dedicated servers.
B/S is built on a wide area network. It does not need to be a dedicated network hardware environment, such as accessing the Internet over the phone and renting equipment. information management. it has a stronger adaptability than C/S. Generally, only the operating system and browser are available.
2. Different security requirements
C/S is generally oriented to relatively fixed user groups and has strong information security control capabilities. generally, the C/S structure is suitable for highly confidential information systems. some public information can be published through B/S.
B/S is built on a wide area network, which has relatively weak security control capabilities and may be intended for unknown users.
3. Different program Architectures
The C/S program can focus more on processes, perform multi-level permission verification, and minimize the system running speed.
B/S's multiple considerations for security and access speed are based on the need for more optimization. higher requirements for B/S architecture than C/S is a development trend, from MS. net series of BizTalk 2000 Exchange 2000 and so on, fully support the system built by network components. the JavaBean Component Technology pushed by SUN and IBM makes B/S more mature.
4. Different Software Reuse
The reusability of components is not as good as that of components under B/S requirements.
The multiple structures of B/S pairs require relatively independent components and can be reused relatively well. You can purchase a dining table instead of a stone table on the wall.
5. Different system maintenance
Due to the integrity of the C/S program, it is necessary to make an overall investigation to solve the problems and system upgrades. Upgrading is difficult. It may be necessary to create a new system.
B/S components, which can be replaced individually to achieve seamless system upgrade. The system maintenance overhead is minimized. Users can download and install the components online to achieve the upgrade.
6. Different handling problems
The C/S program can fix the user surface and meet high security requirements in the same region. It is related to the operating system and should be the same system.
B/S is built on the Wide Area Network. It targets different user groups and is scattered across regions. This is what C/S cannot do. It has the least relationship with the operating system platform.
7. Different user interfaces
C/S is mostly built on Windows platforms, with limited performance methods and high requirements on programmers.
B/S is built on a browser, with richer and more vivid expressions to communicate with users, and most of the difficulties are reduced to reduce development costs.
8. Different information flows
C/S programs are generally typical centralized mechanical processing, with relatively low interaction.
B/S information flow to changeable, B-B B-C B-G and other information, flow changes, more like the transaction center.

118. LINUX thread and GDI class explanation.
LINUX implements the "one-to-one" thread model based on the core lightweight process. A thread entity corresponds to a core Lightweight Process, and management between threads is implemented in the off-core function library.
The GDI class is the image device programming interface class library.

119 STRUTS applications (such as STRUTS Architecture)
Struts is an open source framework that uses Java Servlet/JavaServer Pages technology to develop Web application programming. Struts can be used to develop an application architecture based on the Model-View-Controller design pattern. Struts has the following main functions: 1. It includes a controller servlet that can send user requests to corresponding Action objects. II. the JSP free tag Library provides Association support in the controller servlet to help developers create interactive form applications. 3. provides a series of practical objects: XML processing, automatic processing of JavaBeans attributes through Java reflection APIs, and International prompts and messages.

120. What is Jdo?
JDO is a new specification for Java object persistence. It is short for java data object and is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage. Therefore, for developers, no additional code (such as the use of JDBC APIs) is required to store data objects ). These tedious routine work has been transferred to the JDO product provider, freeing developers to concentrate their time and effort on business logic. In addition, JDO is flexible because it can run on any data underlying layer. JDBC is more common to Relational Database Service (RDBMS) JDO and provides underlying storage functions for any data, such as relational databases, files, XML, and Object Database Service (ODBMS, makes applications more portable.

121 can an internal class reference its members in the class? Are there any restrictions?
An internal class object can access the content of its external Class Object

122. web service terminology. JSWDL Development Kit introduction. JAXP and JAXM. SOAP, UDDI, and WSDL.
Web ServiceWeb Service is a network-based, distributed modular component that executes specific tasks and complies with specific technical specifications. These specifications Enable Web Service to interoperate with other compatible components.
JAXP (Java API for XML Parsing) defines a common interface for using DOM, SAX, and XSLT in Java. In this way, you only need to use these universal interfaces in your program, and you do not need to modify the code when you need to change the specific implementation.
JAXM (Java API for XML Messaging) is an API that provides access methods and transmission mechanisms for SOAP communication.
WSDL is an XML format used to describe network services as a group of endpoints that operate on messages that contain document-oriented or process-oriented information. This format first abstracts the operation and message, and then binds it to a specific network protocol and Message format to define the endpoint. The specific endpoints are combined into abstract endpoints (services ).
SOAP is the Simple Object Access Protocol. It is a lightweight Protocol used to exchange XML encoding information.
The purpose of UDDI is to establish standards for e-commerce. UDDI is a set of Web-based, distributed, and standard standards for implementing information registration centers for Web Services, it also contains a set of access protocols that enable enterprises to register their own Web services so that other enterprises can discover.

 

123. Design four threads, two of which increase 1 for j each time, and the other two reduce 1 for 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 ();
}
}
}
}

124. Does Java have a goto?
Reserved Words in java, which are not currently used in java.

125 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.

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.