Java Face question Collection

Source: Internet
Author: User

1. The difference between String, StringBuffer, and StringBuilder.

(1) String: A string that stores values that cannot be changed

(2) StringBuffer: variable character sequence, thread safety, low efficiency

(3) StringBuilder: variable character sequence, thread insecure, high efficiency


2. Final, finally, finalize the difference.

(1) The final modified class cannot be inherited, the decorated method cannot be overridden by the quilt class, and the decorated property is constant. Once initialized, the value cannot be assigned again. Customary, constant

expressed in uppercase characters.

(2) Finally is a part of the exception handling statement structure that is always executed.

(3) Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, which can override this method when it provides garbage collection

He recycles resources, such as closing files.


3. The difference between HashMap and Hashtable. (both complete the map interface)

(1) HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation) with high efficiency, while Hashtable is thread-safe and less efficient.

(2) Hashtable is not allowed to use NULL as key and value, while HashMap can.

(3) Hashtable method is synchronize, and HashMap is not, when multiple threads access Hashtable, do not need to implement their own methods to synchronize, and

HashMap must provide external synchronization for it.


4. What is the difference between abstract class and interface?

(1) Abstract classes differ from interface definitions:

Abstract class, interface interface

(2) An interface can contain only abstract methods, not methods that have already been implemented, and abstract classes can completely contain common methods.

(3) Static methods cannot be defined in interfaces; Abstract classes can define static methods

(4) Only static constant attributes can be defined in an interface, and ordinary properties cannot be defined; Abstract classes define both normal and static constants.

(5) The interface does not contain constructors, and abstract classes can contain constructors, and constructors in abstract classes are not used to create objects, but rather to have their subclasses invoke these constructor functions

Number to complete the initialization of the abstract class.

(6) An interface does not contain an initialization block, but an abstract class can contain an initialization block.

(7) A class can have at most one direct parent class, including an abstract class, but a class may implement multiple interfaces directly, by implementing multiple interfaces to compensate for Java's single inheritance

Insufficient


The difference between 5.Overload (reload) and override (override). Can the overloaded method change the type of the return value? (yes)
(1) method overloading means that in a class, the method names of multiple methods are the same, but the parameter list is different, and the corresponding method is called according to different parameters.

(2) A method override occurs between a parent class and a subclass and must have the same method name, argument list, and return value type as the overridden method. Subclasses of the object use this method

, the definition in the child class is called, and the definition in the parent class is overwritten.


6. The difference between Collection and collections

(1) collection is the ancestor interface of the collection class, and the main interface of inheriting with him is set and list.

(2) Collections is a helper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections.


7.Java anomalies (including exception and error) are categorized as checked exceptions and non-checked exceptions (unchecked exceptions).

(1) can be checked for exceptions (compiler requirements must be disposed of exceptions)

(2) Non-checked exceptions (compiler does not require mandatory disposition of exceptions)


8. What is the difference between error and exception?

ERROR:JVM System Internal errors, resource exhaustion and other serious situations//uncontrollable, not processing

Exception: Other general problems caused by programming errors or accidental external factors are the procedure itself can handle. For example: null pointer access, attempting to read a nonexistent

Files and so on.


9. Say Arraylist,vector, LinkedList storage performance and features

(1) both ArrayList and vectors store data using arrays, and the number of elements in the array is greater than the actual data stored in order to increment and insert the element, allowing the index to be indexed directly by ordinal

element, but inserting elements involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly.

(2) vector due to the use of the Synchronized method (thread safety), the performance is usually more ArrayList poor.

(3) LinkedList uses the bidirectional linked list to implement the storage, index data by ordinal need to be forward or backward traversal, but insert the data only need to record the item before and after the item is

, so the insertion speed is faster.


10. The difference between redirection and forwarding
(1) Redirect: two requests. Forward: One request, one response.

(2) Redirect: The URL of the address bar changes to the URL that is directed.

Forwarding: The URL of the address bar does not change.

(3) Redirect: Executes on the client, so it can be on a different server. Redirection speed is slow.

Forwarding: Executed on the server side, so it must be on the same server. Forwarding speed is fast.

(4) Redirect: the variables stored in the previous request are all invalidated and enter a new request scope.

Forwarding: The variables stored in the previous request are not invalidated, just like putting two of pages together.


Can you store a Chinese character in a char variable?

Only one Chinese character can be stored, because Java is encoded in Unicode, a char is 2 bytes, and the space allocated for the char type in the computer is 16 bits, which is 2 bytes, so it is no problem to put a Chinese.


The built-in objects and methods of JSP.
(1) The request represents the HttpServletRequest object. It contains information about the browser request and provides several useful ways to get the cookie, header, and session data.

(2) Response represents the HttpServletResponse object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)

(3) An Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser.

(4) PageContext represents a Javax.servlet.jsp.PageContext object. It is used to facilitate access to various scopes of namespaces, servlet-related objects

API, and wraps the methods of common servlet-related functionality.

(5) The session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's status information

(6) Applicaton represents a Javax.servle.ServletContext object. This helps to find information about the servlet engine and the servlet environment

(7) config represents a Javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance.

(8) page represents a servlet instance that is generated from this page

(9) Exception represents the exception object that is generated when the JSP file is run

13. Advantages and disadvantages of creating an index

Advantages:

Creating an index can greatly improve the performance of your system:
(1) by creating a unique index, you can guarantee the uniqueness of each row of data in a database table.
(2) can greatly speed up the retrieval of data, which is the most important reason for creating indexes.
(3) The connection between tables and tables can be accelerated, particularly in terms of the referential integrity of the data.
(4) When using grouping and sorting clauses for data retrieval, you can also significantly reduce the time to group and sort in queries.
(5) by using the index, you can improve the performance of the system by using the optimized hidden device during the query process.

Disadvantages:
(1) It takes time to create indexes and maintain indexes, and this time increases as the amount of data increases.
(2) The index needs to occupy the physical space, in addition to the data table to occupy the data space, each index also occupies a certain amount of physical space, if you want to establish a clustered index, then the space will be larger.
(3) When the data in the table is added, deleted and modified, the index should be maintained dynamically, thus reducing the maintenance speed of the data.

14.sleep and wait method differences

(1) Sleep is a threading class (thread) method that causes this thread to pause execution for the specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored when it is time. Calling sleep does not release the object lock.
(2) Wait is a method of the object class that calls the wait method on this to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify method (or Notifyall) is issued for this object the thread enters the object lock pool ready to get the object lock into the running state.


15. Why can't I use abstract to modify properties, private methods, constructors, static methods, final methods
A: Abstract can be used to modify classes (abstract classes: Non-instancing) and methods (abstract methods: No method body)
(1) Abstract is simply a declaration that the attribute is directly defined by the system assignment initial value.
(2) constructors cannot be overridden
(3) Subclasses cannot override private adornment methods (private methods)
(4) Static Modification method (class method) can be called directly through the class, and the method of the abstract modification has no method body, can not be called, the two contradictions
(5) The final modified method cannot be overridden

Java Face question Collection

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.