Java interview question set (3)

Source: Internet
Author: User
Tags xml parser ssl connection

61. servlet Lifecycle
The Web container loads the servlet and starts its lifecycle. Call the servlet Init () method to initialize the servlet. You can call the service () method to call different do *** () methods based on different requests. End the service. The Web Container calls the Servlet's destroy () method.
62. How to Implement servlet single-thread mode
<% @ Page isthreadsafe = "false" %>
63. Methods for transferring objects between pages
Request, session, application, Cookie, etc.
64. What are the similarities and differences between JSP and Servlet, and what are their relationships?
JSP is an extension of Servlet technology. It is essentially a simple servlet method, with more emphasis on the external expression of the application. After JSP compilation, it is "servlet-like ". The main difference between Servlet and JSP is that the application logic of servlet is in the Java file and is completely separated from the HTML in the presentation layer. In JSP, Java and HTML can be combined into a file with the extension. jsp. JSP focuses on views. servlet is mainly used for control logic.
65. Four session tracking technologies
Description of the session scope servletsjsp page
Page No indicates the objects and attributes related to a page. A page is represented by a compiled Java Servlet class (which can contain any include command but has no include action. This includes both Servlet and JSP pages compiled into servlet.
A request is an object and attribute related to a request sent by a Web Client. A request may span multiple pages and involves multiple Web Components (due to the relationship between the forward instruction and the include action)
A session is an object and attribute associated with a user experience for a Web Client. A web session can also frequently span requests from multiple clients.
Application represents the objects and attributes related to the entire web application. This is essentially a global scope that spans the entire web application, including multiple pages, requests, and sessions
66. Main Methods of the request object:
Setattribute (string name, object): Set the parameter value of the request whose name is name.
Getattribute (string name): returns the property value specified by name.
Getattributenames (): returns the name set of all attributes of the request object. The result is an enumerated instance.
Getcookies (): return all cookie objects on the client. The result is a cookie array.
Getcharacterencoding (): returns the character encoding method in the request.
Getcontentlength (): returns the length of the Request body.
Getheader (string name): Get the file header defined by HTTP
Getheaders (string name): returns all the values of the request header with the specified name. The result is an enumerated instance.
Getheadernames (): returns the name of the Request Header. The result is an enumerated instance.
Getinputstream (): returns the input stream of the request to obtain data in the request.
Getmethod (): method for obtaining data transmitted from the client to the server
Getparameter (string name): Get the parameter value specified by name sent from the client to the server.
Getparameternames (): obtains the names of all parameters sent from the client to the server. The result is an enumerated instance.
Getparametervalues (string name): obtains all values of the parameter specified by name.
Getprotocol (): gets the protocol name on which the client transmits data to the server.
Getquerystring (): Get the query string
Getrequesturi (): obtains the client address of the request string.
Getremoteaddr (): obtains the IP address of the client.
Getremotehost (): Get the client name
Getsession ([Boolean create]): returns the session associated with the request.
Getservername (): Get the server name
Getservletpath (): Get the path of the script file requested by the client
Getserverport (): Get the server port number
Removeattribute (string name): deletes an attribute in a request.
67. Is J2EE a technology, a platform, or a framework?
J2EE is a standard, a standard platform for enterprise distributed application development.
J2EE is also a framework, including JDBC, JNDI, RMI, JMS, EJB, JTA and other technologies.
68, we often encounter the output of some encoding characters in the Web application development process, such as iso8859-1, how to output a certain encoding string?
Public String translate (string Str ){
String tempstr = "";
Try {
Tempstr = new string (Str. getbytes ("ISO-8859-1"), "GBK ");
Tempstr = tempstr. Trim ();
}
Catch (exception e ){
System. Err. println (E. getmessage ());
}
Return tempstr;
}
69. Briefly describe the differences between logical operations (&, |, ^) and conditional operations (&, |.
There are two main differences: A. Conditional operations can only operate on the boolean type, while logical operations can operate not only on the boolean type, but also on the numeric type.
B. logical operations will not generate short circuits
70. How many forms are defined in XML documents? What are the essential differences between them? How can I Parse XML documents?
A: Two forms of DTD schema. B: essential difference: the schema itself is XML and can be parsed by the XML Parser (this is also the fundamental purpose of developing the schema from the DTD). C: dom, sax, Stax, etc.
DOM: when processing large files, its performance drops sharply. This problem is caused by the DOM tree structure. This structure occupies a large amount of memory and the Dom must load the entire file into the memory before parsing the file, which is suitable for Random Access to XML.
Sax: it does not exist in Dom. Sax is an event-driven XML parsing method. It reads XML files sequentially without loading the entire file at a time. When a file starts with a file, the document ends, or the tag starts with a tag, it triggers an event. You can write the processing code in the callback event to process the XML file, suitable for sequential access to XML
Stax: streaming API for XML (Stax)
71. What are the similarities and differences between synchronized and Java. util. Concurrent. locks. Lock?
The main point is that lock can complete all functions implemented by synchronized.
Major difference: Lock has more precise thread semantics and better performance than synchronized. Synchronized Automatically releases the lock, which must be manually released by the programmer and must be released in the finally clause.
72. EJB roles and three objects
A complete EJB-based Distributed Computing structure consists of six roles, which can be provided by different developers. Each role must follow the EJB specifications provided by Sun, to ensure compatibility between them. These six roles are EJB component developer (enterprise Bean provider), application aggreger (Application aggreger), deployer (deployer), and EJB Server Provider (EJB Server Provider), EJB container provider, System Administrator)
The three objects are remote (local) interface, Home (localhome) interface, and Bean class.
73. Services provided by the EJB container
It mainly provides declarative cycle management, code generation, continuity management, security, transaction management, lock and release management services.
74. What operations are prohibited in ejbs In the EJB specification?
1. the thread and thread APIs cannot be operated (the thread API refers to methods of non-thread objects, such as notify and wait. AWT cannot be operated, 3. cannot implement server functions. 4. cannot survive the static genus. you cannot use Io operations to directly access the file system. 6. the local database cannot be loaded ., 7. you cannot use this as a variable or return value. it cannot be called cyclically.
75. Main Functions of the remote interface and home interface
The remote interface defines the business method used by the EJB client to call the business method.
The home interface is used by the EJB factory to create and remove EJB instances.

76. Bean instance Lifecycle
Stateless Session Bean, Entity Bean, and message driven bean are generally managed by the buffer pool, while Entity Bean and statefull Session Bean are managed by cache, which usually includes instance creation, set the context, create an EJB object (create), call a business method, and remove. For beans with buffer pool management, the instance is not cleared from the memory after create, instead, the buffer pool scheduling mechanism is used to repeatedly reuse instances. For beans with Cache Management, the activation and deactivation mechanisms are used to maintain the bean status and limit the number of instances in the memory.
77. EJB activation mechanism
Taking stateful Session Bean as an example: the cache size determines the number of bean instances that can coexist in the memory. According to the MRU or NRU algorithm, instances are migrated between the activation and deactivation statuses, the activation mechanism is that when the client calls a business method of an EJB instance, if the corresponding EJB object finds that it is not bound to the corresponding bean instance, it will activate bean storage from it (storage instance through serialization mechanism) reply (activate) this instance. The corresponding ejbactive and ejbpassivate methods are called before the status changes.
78. EJB types
Session Bean, Entity Bean message-driven Bean
Session beans can be divided into stateful and stateless.
Entity beans can be divided into two types: bean management continuity (BMP) and container management continuity (CMP ).
79. Basic Steps for client to call an EJB object
Set the properties of the JNDI service factory and the JNDI service address system, find the home interface, call the create method from the home interface to create a remote interface, and call its business method through the remote interface.
80. How do I specify the memory size for WebLogic?
In the Weblogic STARTUP script (startservername located in the directory of the corresponding domian server), add set mem_args =-xms32m-xmx200m. You can adjust the minimum memory to 32 MB and the maximum memory to 200 MB.
81. How to set the Weblogic hot start mode (Development Mode) and product release mode?
You can change the Startup Mode of the corresponding server to one of the development or product modes on the console. Or modify the Service Startup File or commenv file and add set production_mode = true.
82. How do I not need to enter the user name and password at startup?
Modify the Service Startup File and add the wls_user and wls_pw items. You can also add encrypted user names and passwords to the boot. properties file.
83. In the Weblogic Management Console, After configuring JMS, EJB, connection pool, and other related information for an application domain (or a website or domain), what files are actually stored in?
The config. xml file stored in this domain is the core configuration file of the server.
84. What is the default directory structure of a domain in WebLogic? For example, a simple helloworld. under the directory where JSP is put, you can enter http: // host: Port Number // helloword in the browser. can JSP view the running result? Another example is how to use a self-written JavaBean?
Domain directory/Server Directory/applications, where the application directory can be accessed as an application. If it is a Web application, the application directory must meet the web application directory requirements, JSP files can be directly placed in the application directory, JavaBean needs to be placed in the application directory of the WEB-INF directory of the classes directory, set the Server default application will be able to achieve in the browser without entering the application name.
85. configuration files required for deploying EJB in WebLogic
Different types of EJB involve different configuration files, all involve configuration files including ejb-jar.xml, weblogic-ejb-jar.xmlCMP entity beans generally also need weblogic-cmp-rdbms-jar.xml
86. How to perform SSL configuration and client authentication configuration in WebLogic or discuss how to configure SSL in J2EE (standard )?
Demoidentity is used in the default installation. jks and demotrust. to implement SSL in jks keystore, You need to configure the server to use Enable SSL and configure its port. In product mode, you need to obtain the private key and digital certificate from the CA, and create the identity and trust keystore, load the obtained key and digital certificate. You can configure whether the SSL connection is unidirectional or bidirectional.
87. How do I view the published ejbs in WebLogic?
You can use the console to view all published ejbs in its deployment.
88. What is CORBA? What is the purpose?
The Common Object Request Broker Architecture is a Common Object Request Broker Architecture, which is standardized by Object Management Group (OMG. It is composed of an Interface Definition Language (IDL), a language binding (binding: also translated as associated encoding), and a protocol that allows interoperation between applications. The objective is to use different programming languages to run in different processes and develop different operating systems.
89. How many common J2EE modes do you know or have heard? And some opinions on the Design Model
Session Facade Pattern: Use sessionbean to access entitybean
Message Facade Pattern: asynchronous call
EJB Command pattern: replace sessionbean with command JavaBeans for Lightweight Access
Data transfer object Factory: Using DTO factory to simplify entitybean data provision features
Generic attribute access: the attibuteaccess interface simplifies entitybean data provision features
Business interface: Use Remote (local) interfaces and bean classes to implement the same interface and standardize business logic consistency
The design of the EJB architecture directly affects the system performance, scalability, maintainability, component reusability, and development efficiency. The more complex the project, the larger the project team, the more important the design is.
90. Differences between persistent and non-persisten when sending a message Bean in WebLogic
The persistent MDB ensures the reliability of message transmission, that is, if an error occurs in the EJB container and the JMS server still sends the message when the MDB is available, non-persistent messages are discarded.

91. Which of the following methods are generally implemented during servlet execution?
Public void Init (servletconfig config)
Public servletconfig getservletconfig ()
Public String getservletinfo ()
Public void Service (servletrequest request, servletresponse response)
Public void destroy ()
92. Common J2EE design patterns? Describe the factory model.
23 Design Patterns in Java:
Factory (factory mode), Builder (construction mode), factory method (Factory method mode ),
Prototype (original model mode), Singleton (Singleton mode), facade (facade mode ),
Adapter (adapter mode), bridge (Bridge Mode), composite (merging mode ),
Decorator, flyweight, proxy ),
Command (command mode), Interpreter (Interpreter mode), visitor (visitor mode ),
Iterator, mediator, memento ),
Observer (Observer mode), State (State mode), Strategy (Policy mode ),
Template Method (template method mode), chain of responsibleity (responsibility chain mode)
Factory mode: The factory mode is a frequently used mode. Classes implemented based on the factory mode can generate instances of a class in a group based on the provided data, generally, this group of classes has a common abstract parent class that implements the same method, but these methods perform different operations on different data. First, you need to define a base class. The subclass of this class implements the methods in the base class through different methods. Define a factory class. The factory class can generate different subclass instances according to the conditions. After obtaining the subclass instance, developers can call the methods in the base class without having to consider which subclass instance is returned.
93. Does EJB need to directly implement its business interface or home interface? Please briefly describe the reasons.
The remote interface and home interface do not need to be implemented directly. Their implementation code is generated by the server. The corresponding implementation class in the program running will be used as an instance of the corresponding interface type.
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. In addition, 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 use of stop () is opposed because it is insecure. 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 objects in 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. 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.

Related Article

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.