Java Surface Examination Questions Daquan (II.)

Source: Internet
Author: User
Tags xml parser

41. Can I inherit the String class?
The string class is the final class and cannot be inherited.
42, whether the Swtich can function on a byte, whether it can function on a long, whether it can function on a string?
Switch (EXPR1), expr1 is an integer expression. So the arguments passed to the switch and case statements should be int, short, char, or byte. Long,string can not act on Swtich.
43, try{} There is a return statement, then immediately after the try of the finally {} code will not be executed, when executed, before or after return?
Executes before the return.
44, programming problems: the most efficient way to calculate 2 times 8 and so on?
2 << 3
45, two object values are the same (x.equals (y) = = true), but can have different hashcode, this sentence right?
No, there's the same hashcode.

46, when an object is passed as a parameter to a method, this method can change the properties of the object, and can return the changed results, then this is the value of the pass or reference pass?
is a value pass. The Java programming language has only value-passing parameters. When an object instance is passed as a parameter to a method, the value of the parameter is a reference to the object. The contents of the object can be changed in the called method, but the object's reference is never changed.
47. When a thread enters an synchronized method of an object, does the other thread have access to other methods of this object?
No, an synchronized method of an object can only be accessed by one thread.
48, Programming Problem: Write a singleton out.
The main purpose of the singleton mode is to ensure that only one instance of a class is present in a Java application.
The general singleton pattern usually has several forms:
The first form: Defines a class whose constructor is private, and it has a static private class variable that, when the class is initialized, gets a reference to it through a public getinstance method, and then calls the method in it.
public class Singleton {
Private Singleton () {}
Is it strange to define an instance of yourself within yourself?
Note that this is private only for internal calls
private static Singleton instance = new Singleton ();
This provides a static method for external access to this class, which can be accessed directly
public static Singleton getinstance () {
return instance;
}
}
The second form of:
public class Singleton {
Privatestatic Singleton instance = null;
Publicstatic synchronized Singleton getinstance () {
This method is better than the above, and does not have to be generated every time, just the first time
Generate an instance when used, improve the efficiency!
if (instance==null)
Instance=new Singleton ();
return instance; }
}
Other forms:
Defines a class whose constructor is private, and all methods are static.
The first form is generally considered to be more secure.
49, Java interface and C + + virtual class of the same and different places.
Because Java does not support multiple inheritance, it is possible for a class or object to use a method or property that is within several classes or objects, and the existing single-inheritance mechanism cannot satisfy the requirement. The interface has more flexibility than inheritance because there is no implementation code in the interface. When a class implements an interface, the class implements all the methods and properties in the interface, and the properties inside the interface are publicstatic by default, and all methods are public by default. A class can implement multiple interfaces.
50. The simple principle and application of exception handling mechanism in Java.
When a Java program violates the semantics of Java rules, the Java virtual machine will represent the error that occurred as an exception. There are 2 cases of violating semantic rules. One is the semantic check built into the Java class library. For example, array subscript is out of bounds, indexoutofboundsexception is thrown, and NullPointerException is thrown when a null object is accessed. Another scenario is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose when to throw exceptions with the throw keyword. All exceptions are subclasses of java.lang.Thowable.
51, the advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms.
A notable feature of the Java language is the introduction of a garbage collection mechanism, which makes it possible for the C + + programmer to solve the most troublesome memory management problems, which makes it unnecessary for Java programmers to consider memory management when writing programs. Because there is a garbage collection mechanism, objects in Java no longer have a "scope" concept, and only references to objects are scoped. Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is typically run as a separate low-level thread, unpredictable and clear and recyclable for objects that have died in the heap or that have not been used for a long time, and the programmer cannot call the garbage collector in real time for garbage collection of an object or all objects. The recycling mechanism has generational replication garbage collection and token garbage collection, incremental garbage collection.
52. Please say the thread synchronization method you know.
Wait (): causes a thread to be in a wait state and releases the lock of the object it holds.
Sleep (): Makes a running thread sleep, is a static method that calls this method to catch the interruptedexception exception.
Notify (): Wakes up a waiting thread, noting that when this method is called, it does not actually wake up a waiting state thread, but is determined by the JVM to wake up which thread, and not by priority.
Allnotity (): Wakes all the threads that are in the waiting state, noting that they do not give all the wake-up threads an object lock, but instead let them compete.
53. What are the collection classes you know? The Main method?
The most common collection classes are list and map. The specific implementation of the list includes ArrayList and vectors, which are variable-sized lists that are more appropriate for building, storing, and manipulating any type of object. List is useful for cases where elements are accessed by numeric indexes.
MAP provides a more general method of storing elements. The Map collection class is used to store element pairs (called "Keys" and "values"), where each key is mapped to a value.
54. Describe the principle mechanism of the JVM loading class file?
The loading of classes in the JVM is implemented by ClassLoader and its subclasses, and Javaclassloader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.
55. Can I store a Chinese character in char type?
Can be defined as a Chinese, because in Java encoding in Unicode, a char accounted for 16 bytes, so put a Chinese is no problem
56, multi-threaded there are several ways to achieve, what is it? How are there several implementations of synchronization?
There are two ways to implement multithreading, namely, inheriting the thread class and implementing the Runnable interface.
There are two implementations of synchronization, namely Synchronized,wait and notify
57, JSP's built-in objects and methods.
The request represents the HttpServletRequest object. It contains information about browser requests and provides several useful ways to get Cookie,header, and session data.
Response represents the HttpServletResponse object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)
The Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser.
PageContext represents a Javax.servlet.jsp.PageContext object. It is an API for easy access to a wide range of namespaces, servlet-related objects, and a way to wrap generic servlet-related functionality.
The session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's status information
Applicaton represents a Javax.servle.ServletContext object. This helps to find information about the servlet engine and the servlet environment
Config represents a Javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance.
Page represents a servlet instance that is generated from this page
58. Basic concepts of threads, the basic state of threads, and the relationship between states
A thread is an execution unit that executes a program's code during the execution of a program, and each program has at least one thread, the program itself.
There are four types of threads in Java: Run, ready, suspend, end.
59. Common directives of JSP
<% @pageLanguage= "java" contentype= "text/html;charset=gb2312" session= "true" buffer= "64KB" autoflush= "true" isthreadsafe= " True "info=" text "errorpage=" error.jsp "iserrorpage=" true "iselignored=" true "pageencoding=" gb2312 "import=" java.sql . * "%>
Iserrorpage (whether the exception object can be used), iselignored (whether or not to ignore the expression)
<% @includefile= "FileName"%>
<% @taglibPrefix= "C" uri= "http://..."%>
60, under what circumstances call Doget () and Dopost ()?
The method property in the form tag in the JSP page is called doget () when it is get, and Dopost () is called when it is post.

61. The life cycle of the servlet
The Web container loads the servlet, beginning with the life cycle. The servlet is initialized by calling the servlet's init () method. By invoking the service () method implementation, different do*** () methods are called depending on the request. To end the service, the Web container invokes the servlet's Destroy () method.
62, how to live servlet single-threaded mode
<%@ page isthreadsafe= "false"%>
63. How to transfer objects between pages
Request,session,application,cookie, etc.
64. What are the similarities and differences between JSP and servlet, and what are their connections?
JSP is the extension of servlet technology, which is essentially a simple way for servlets to emphasize the appearance of application. The JSP is compiled with a "class servlet". The main difference between Servlets and JSPs is that the application logic of the servlet is in the Java file and is completely detached from the HTML in the presentation layer. The case for JSP is that Java and HTML can be combined into a file with a. jsp extension. JSPs focus on Views, and Servlets are used primarily for control logic.
65. Four kinds of conversation tracking technology
Session Scope servletsjsp Page description
Page no is a representation of the objects and properties associated with a page. A page is represented by a compiled Java Servlet class (which can have any include directives, but no include actions). This includes both Servlets and JSP pages that are compiled into Servlets
Request is an object and property that represents a request that is made to a Web client. A request may span multiple pages, involving multiple Web components (due to the relationship of the forward directive and the include action)
A session is a representation of objects and properties that are related to a user experience for a Web client. A web session can and will often be requested across multiple clients
Application is a representation of objects and properties 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. The main method of the Request object:
SetAttribute (String name,object): Sets the parameter value of the request named name
GetAttribute (String name): Returns the property value specified by name
Getattributenames (): Returns a collection of names of all properties of the request object, resulting in an instance of an enumeration
GetCookies (): Returns all cookie objects for the client, as a result of a cookie array
Getcharacterencoding (): Returns the character encoding in the request
Getcontentlength (): Returns the length of the requested body
GetHeader (String name): Gets the file header information defined by the HTTP protocol
Getheaders (String name): Returns all values of the Requestheader of the specified name, resulting in an instance of an enumeration
Getheadernames (): Returns the name of the Requestheader so that the result is an instance of an enumeration
getInputStream (): Returns the requested input stream for obtaining the data in the request
GetMethod (): Obtaining a client's way of transmitting data to the server side
GetParameter (String name): Gets the parameter value specified by the client that is passed to the server side by name
Getparameternames (): Gets the name of all parameters that the client sends to the server side, and the result is an instance of the enumeration
Getparametervalues (String name): Gets all values that have the parameter specified by name
Getprotocol (): Gets the protocol name on which the client transmits data to the server
GetQueryString (): Get query string
Getrequesturi (): Gets the client address that issued the request string
GETREMOTEADDR (): Gets the IP address of the client
Getremotehost (): Gets the name of the client
GetSession ([Boolean create]): Returns and requests the relevant session
getServerName (): Gets the name of the server
Getservletpath (): Gets the path of the script file requested by the client
Getserverport (): Gets the port number of the server
RemoveAttribute (String name): Delete One of the properties in the request
67. Is it a technology or a platform or a framework?
The Java EE itself is a standard, a standard platform for the development of enterprise distributed applications.
The Java EE is also a framework, including JDBC, JNDI, RMI, JMS, EJB, JTA and other technologies.
68, we often encountered in the Web application development process output some kind of encoded characters, such as iso8859-1, how to output a certain encoding of the 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. Brief description of logical operation (&,|,^) and condition operation (&&,| |) The difference.
The difference between the main answer two: a. Conditional operations can only operate on Boolean, while logical operations not only manipulate Boolean, but also manipulate numeric types
B. Logical operation does not cause a short circuit
70. There are several forms of XML document definition. What are the essential differences between them? What are the different ways to parse an XML document?
A: Two forms of DTD schema,b: The essential difference: The schema itself is XML and can be parsed by the XML parser (which is also the fundamental purpose of developing schema from the DTD), C: dom,sax,stax, etc.
DOM: When working with large files, its performance drops very badly. This problem is caused by the tree structure of the DOM, which takes up more memory, and the DOM must load the entire document into memory before parsing the file, which is appropriate for random access to the XML
SAX: Not present in Dom,sax is an event-driven XML parsing method. It reads the XML file sequentially and does not need to load the entire file at once. When it encounters a file beginning with a document ending, or the beginning of a label with the end of the label, it triggers an event that the user processes the XML file by writing the processing code in its callback event, which is appropriate for sequential access to the XML
Stax:streaming API for XML (STAX)
71, briefly describe the similarities and differences between synchronized and Java.util.concurrent.locks.Lock?
Main similarities: Lock can complete all functions implemented by synchronized
Main differences: Lock has more precise line semantics and better performance than synchronized. The synchronized automatically releases the lock, and lock must require the programmer to release it manually, and must be released in the finally clause.
72. EJB role and three objects
A complete EJB-based distributed computing architecture consists of six roles, six of which can be provided by different developers, and each role must work in accordance with the EJB specifications provided by Sun to ensure compatibility with each other. These six roles are EJB component Developer (Enterprise Beanprovider), application composition (Applicationassembler), Deployer (Deployer), EJB server provider (EJB Provider), EJB container provider (EJB containerprovider), System Administrator (Systemadministrator)
The three objects are the remote (Local) interface, the Home (Localhome) interface, the Bean class
73. Services provided by the EJB container
It mainly provides services such as claim cycle management, code generation, continuity management, security, transaction management, lock and release management.
74. What is the EJB specification that prohibits operations in EJBS?
1. Cannot manipulate threads and threading API (thread API refers to non-threaded objects such as notify,wait, etc.), 2. awt,3 cannot be operated. Server functions cannot be implemented, 4. Cannot be used for static genus, 5. You cannot access the file system directly using IO operations, 6. The local library cannot be loaded., 7. This cannot be used as a variable and returned, 8. Cannot be called loop.
75, remote interface and home interface main role
The remote interface defines the business method used by the EJB client to invoke the business method.
The home interface is used by the EJB factory to create and remove lookup EJB instances

76. Life cycle of Bean instances
Buffer pool management exists for stateless session bean, entity Bean, messagedriven bean, and cache management for Entity Bean and statefull session bean. Typically includes creating instances, setting contexts, creating EJB Object (Create), business method calls, remove, and so on, for beans that have buffer pool management, the instance is not purged from memory after create, and the instance is constantly reused using the buffer pool scheduling mechanism. For cache-managed beans, the state of the bean is maintained and the number of instances in memory is limited by activating and deactivating the mechanism.
77. EJB Activation mechanism
Take the stateful Session bean as an example: its cache size determines the number of Bean instances that can exist concurrently in memory, and depending on the MRU or NRU algorithm, the instance is migrated between the activation and deactivation states, and the activation mechanism is when the client invokes an EJB instance business method. If the corresponding EJB object finds itself not bound to the corresponding bean instance, it activates the Bean store (through the serialization mechanism storage instance) to reply (activate) This instance. The corresponding ejbactive and Ejbpassivate methods are called before the state changes.
78, several types of EJB
Session bean, Entity bean message-driven (msg driven) bean
The session bean can also be divided into stateful (Stateful) and stateless (stateless) two
Entity beans can be divided into bean management Persistence (BMP) and container management persistence (CMP) Two kinds
79. Several basic steps of invoking EJB object on customer service side
Set the Jndi service Factory and Jndi service address system Properties, look for the home interface, call the Create method from the home interface for creating the remote interface, and invoke its business methods through the remote interface.
80, how to give WebLogic to specify the size of memory?
In the script that launches WebLogic (Startservername in the corresponding server directory of the Domian), the set mem_args=-xms32m-xmx200m can be adjusted, the minimum memory is 32M, the maximum 200M
81, how to set the WebLogic hot start Mode (development mode) and product release mode?

Java Surface Examination Questions Daquan (II.)

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.