1. Object-oriented features
Abstract:
Abstraction is a factor that is irrelevant to the current target in a topic, while fully considering the relevant content. Abstract cannot solve all problems in the target. You can only select one part and ignore other parts. Abstract: Process abstraction and data abstraction.
Inheritance
Inheritance is a hierarchical model of connected classes. It allows reuse of encouraged classes and provides a clear and common method. A new class of an object can be derived from an existing class, which is called class inheritance. The new class is called the derived class or subclass of the original class, and the original class is called the base class or parent class of the new class. Sub-classes can inherit the methods and implementation variables of the parent class from the parent class, but allow new classes to add and modify new methods to meet their needs.
Encapsulation
Encapsulation is to enclose the process and data. Access to data is only allowed through the defined interface. Object-oriented is based on this concept, that is, the real world can be described as a series of fully autonomous and encapsulated objects that access other objects through fixed protected interfaces.
Polymorphism
Polymorphism means that different types of objects correspond to the same request. Polymorphism includes parameter polymorphism and inclusion polymorphism. Polymorphism languages have the advantages of flexibility, abstraction, behavior sharing, and code sharing. It solves the problem of the same name in the application.
2. What is the difference between int and integer?
Java provides two types: reference type and original type (built-in type ). Int Is the original data type of Java, and integer is the encapsulation class provided by Java for int.
Java provides its own encapsulation class for each data type:
Original data type encapsulation class
Int integer
Boolean
Char character
Byte byte
Short short
Long long
Float float
Double double
The behavior of the reference type and the original type is completely different, and they have different semantics. The reference type and the original type have different features and usage, they include: size and speed problems, which type of data structure is used for storage? The default value is set when the reference type and the original type are used as instance data of a class. The default value of the object application instance variable is null, and the default value of the original type instance variable is related to their type.
3. Differences between final, finally, and finalize
Final is a declared attribute, its role and class, method, and variable. The final modified variable value cannot be changed, and the final modification aspect cannot be overwritten, final-modified classes cannot be inherited.
Finally is a part of the exception handling statement, indicating that it is always executed.
Finalize is a sub-Method of the object class. The Garbage Collector calls this method to recycle objects. This method can be overwritten to collect other resources when resources are collected. For example, close the file.
4. Differences between heap and stack
Stack is an existing structure. Its adding and deleting elements should be completed in the same segment, and the stack should be processed in a later manner.
Heap is an element of stack.
5. Basic Data Types
Byte, Int, long, double, Char, Boolean, float, short
String is not a basic data type. java. util. string is a final class. Therefore, this class cannot be modified or inherited.
To save space and improve efficiency, we should use stringbuffer.
6. When will assert be used?
Assertion is a common debugging method used in software development. Many programming 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 the value is false, the system will give a warning or exit when the maze program is in an incorrect state. Generally, assertion is used to ensure the most basic and critical correctness of the program. The assertion check is usually started during development and testing. To improve efficiency, the assertion check is usually closed after the software is released.
7. What is GC? Why does GC exist?
GC is the meaning of garbage collection (gabage collection). The memory processor is a place where programmers are prone to problems. Forgetting or wrong memory collection leads to unstable programs or systems or even crashes, java's GC function can automatically monitor whether the object exceeded the scope to automatically recycle the memory. Java does not provide a Russian display operation to release the allocated memory.
8. Does the startup thread use run () or start ()?
Start a thread using the START () method to make the virtual processor represented by the thread in a running state, which means it can be scheduled and executed by JVM (Java Virtual Machine, this does not mean that the thread will be executed immediately. The run () method can generate the exit sign to stop a thread.
9. Can constructor be overwritten?
The constructor (override) cannot be inherited, so overriding cannot be overwritten, but overloading can be overloaded.
10. After an object is passed as a parameter to a method, this method can give the property of this object and return the changed result, so here is the transfer of values or the transfer of references?
Is worth passing.
In Java, only values are transmitted as 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 object content can be changed in the called method, but the object reference will never change.
11. Advantages of the garbage collection mechanism, and two recycling mechanisms are considered.
A notable feature of Java is the introduction of the garbage collection mechanism, which helps C ++ programmers solve the most headache in memory management, he makes it unnecessary for Java programmers to consider the internal profit management issue when writing the course of study. Because of the garbage collection mechanism, the objects in Java do not have the concept of "Scope, it is only available when the object is referenced. Garbage collection can effectively prevent memory leakage and effectively use available memory.
The garbage collector is usually used as a separate low-level thread to clear and recycle objects in the memory heap that have died or are not used for a long time, it is promised that a wishing programmer cannot call several recyclers to recycle a certain object or all objects in real time. The recycling mechanism involves several recyclers, marked garbage collection, and incremental garbage collection.
12. Can a single Chinese character be stored in a char variable? Why?
A Chinese character can be stored.
Because Java uses unicode encoding and a char occupies 16 bytes, it is no problem to put more than Chinese characters.
13. embedded objects in JSP
Request -- indicates the httpservletrequest object. It contains information about browser requests and provides several swimming methods for obtaining cookie, header, and session data.
Response -- indicates the httpservletresponse object. It provides several methods (such as Cookie header information) for setting the response to the browser ).
Out -- the object is an instance of Java. jsp. jspwriter. It provides several methods for you to return output results in a browser.
Pagecontext -- indicates a javax. servlet. jsp. pagecontext object. It is used to facilitate access to various namespaces and servlet-Related Object APIs, and encapsulates common servlet-related functions.
Session: indicates the javax. servlet. http. httpsession object of a request. session can be used to display the status information of mutual users.
Application -- indicates a javax. servlet. servletcontext object, which helps you find information about the servlet engine and Servlet environment.
Config -- indicates a javax. servlet. servletconfig object, which is used to access the initialization data of the servlet instance.
Page -- indicates a servlet instance generated from the page.
14. What are the similarities and differences between JSP and Servlet? What is the connection between them?
JSP is an extension of Servlet technology. It is essentially a simple servlet method, emphasizing application performance and expression. After JSP compilation, it is a "servlet-like". The main difference between Servlet and JSP is that, the servlet application logic is in a Java file and is completely separated from the HTML in the presentation layer. In JSP, Java and HTML can be combined into a file extension. JSP files, JSP focuses on views, servlet is mainly used to control the logic.
15. Can an anonymous internal class inherit from other classes and implement interfaces?
It can inherit other classes or complete other interfaces. This method is often used in swing programming.
16. Differences between hashmap and hashtable
Hashmap is a lightweight Implementation of hashtable (non-thread-safe implementation). All of them have completed the map interface. The main difference is that hashmap allows null key values (KEYS) and is not thread-safe, the efficiency may be higher than that of hashtable.
17. String S = new string ("ABC"); how many objects are created?
Two objects are created: "ABC" and S object pointing to the "ABC" object.
18. 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 return method returns a long integer closest to the parameter. After the parameter is added to 1/2, the floor is required.
19. What is the difference between sleep () and wait?
Sleep is a thread method. This thread suspends the execution at a certain time, giving the execution opportunity to other threads, but the monitoring status remains unchanged. Then, the thread automatically replies and calls sleep without releasing the object lock.
Wait is a method of the object class. The wait method issued by this object causes this thread to discard the object lock and enter the lock pool waiting for this object in ancient times. Only the notify method (or notifyall) is issued for this object) then this thread enters the object lock pool and prepares to get the object lock and enters the running state.
20. Does the array have the length () method? Does string have the length () method?
The array does not have the length () method. The length method is available.
String has the length () method.
21. Differences between overload and override. Can the overloaded method change the type of the returned value?
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 overload Overloading is a manifestation of the polymorphism in a class,
If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten (voerriding ). When a subclass object uses this method, it calls the definition in the subclass. For it, the definition in the parent class is blocked. If multiple methods with the same name are defined in a class, they may have different numbers of parameters or different parameter types, which are called overriding. The overriding method can change the type of return values.
22. Can the elements in the Set be repeated? What method can be used to distinguish whether the elements are repeated or not? Use = or equals ()? What are their differences?
The elements in the set cannot be repeated, so the iterator () method is used to identify whether the elements are repeated or not. The equals () method is used to determine whether two sets are equal.
The equals () and = Methods Determine whether the reference value points to the same object. Equals () is overwritten in the class, so that when the content and type of the two separated objects match, returns the true value.
23. Differences between error and exception
Error indicates that the restoration is not an impossible but difficult case. For example, memory overflow cannot be expected to be processed by the program.
Exception indicates a design or implementation problem. That is to say, if the program runs normally, it will never happen.
24. What is the difference between abstract class and interface? (Differences between abstract classes and interfaces)
The existence of a declarative method does not implement its class. It is called an abstract class. It is used to create a class that reflects certain basic behaviors and declare a method for this class, however, this class cannot be implemented at the end of the class, and an abstract class instance cannot be created. However, you can create a variable whose type is an abstract class and point it to an instance of a specific subclass. Abstract constructor or abstract static methods are not allowed. The subclasses of abstract classes provide implementation for all abstract methods in their parent classes. Otherwise, they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can implement these methods in the class.
An interface is a variant of an abstract class. In an interface, all methods are abstract. Multi-inheritance can be achieved by implementing such an interface. All methods in the interface are abstract, and no program body exists. The interface can only define static final member variables. The implementation of the interface is similar to that of the subclass, except for an implementation class, the behavior cannot be inherited from the interface definition. When a class implements a special interface, it defines (that is, the program will give) the same interface, it can call the interface method on any object of the class that implements this interface. Because of the abstract class, it allows the interface name as the type of the application variable. Normally, dynamic Association editing takes effect. The reference can be converted to the interface type or from the interface type conversion. The instanceof operator can be used to determine whether the class of an object implements the interface.
25. can abstract methods be both static, native, and synchronized?
None
26. What are the jump methods on the JSP page? What is the difference?
There are two types:
<JSP: Include page = "jjj. jsp" fresh = "true">
<JSP: Forward page = "nextpage. jsp">
Differences:
The former page does not switch to the page referred to by include, but only displays the results of this page. The home page is still the original page and will return after execution, which is equivalent to a function call and can contain parameters, the back refers to completely switching to a new page and will not come back. It is equivalent to a GOTO statement.
27. What is the difference between forward () and redirect () in Java Servlet APIs?
The former is only the redirection of control in the container, and the redirection address is not displayed in the address bar of the client browser. The latter is a complete jump, and the browser will get the jump address, and re-send the request link. In this way, you can see the link address after the jump from the browser's address bar, more than million, more efficient. While the former can meet the needs, try to use the forward () method, and this helps to hide the actual link. In some cases, for example, you need to jump to the resources of other browsers, the sendredeirct () method must be used.
28. What parsing technologies does XML provide? What is the difference?
Dom, sax, Stax, etc.
DOM: the performance of processing large files is greatly reduced. This problem is caused by the DOM tree structure, which occupies a large amount of memory, in addition, Dom must load the entire file into memory before parsing the file, which is suitable for Random Access to XML. Sax: not present, Dom, And sax are event-driven XML parsing methods, he reads XML files sequentially without loading all the positive files himself. When the beginning of a document, the document ends, or the tag is opened and ends, he triggers an event, it is used to process XML files by writing processing code in the callback event, and is suitable for sequential access to XML.
Stax: streaming API for XML (Stax ).
29. What built-in objects does JSP have? What are their roles?
JSP contains 9 built-in components,
Request: a client request that contains parameters from the get/POST request;
Response: response from the webpage to the client.
Pagecontext: The page property is managed here
Session: session related to the request
Application: servlet content being executed
Out: the output used to pass the response.
Config: servlet framework
Page JSP page itself
Exception: For an incorrect webpage. Uncaptured exceptions.
30. Programming Using Java to parse XML
Parse XML using the sax method. XML is as follows:
<? XML version = 1.0 encoding = gb2312? >
James
Information Institute
6258113
Male, 1955, Doctor, transferred to Hainan University in 94 years
Event Callback class saxhandler. Java
Import java. Io .*;
Import java. util. hashtable;
Import org. xml. Sax .*;
Public class saxhandler extends handlerbase
{
Private hashtable table = new hashtable ();
Private string currentelement = NULL;
Private string currentvalue = NULL;
Public void settable (hashtable table)
{
This. Table = table;
}
Public hashtable gettable ()
{
Return table;
}
Public void startelement (string tag, attributelist attrs)
Throws saxexception
{
Currentelement = tag;
}
Public void characters (char [] CH, int start, int length)
Throws saxexception
{
Currentvalue = new string (CH, start, length );
}
Public void endelement (string name) throws saxexception
{
If (currentelement. Equals (name ))
Table. Put (currentelement, currentvalue );
}
}
Source code of JSP content display, saxxml. jsp:
<% @ Page errorpage = errpage. jsp contenttype = text/html; charset = gb2312 %>
<% @ Page import = java. Io. * %>
<% @ Page import = java. util. hashtable %>
<% @ Page import = org. W3C. Dom. * %>
<% @ Page import = org. xml. Sax. * %>
<% @ Page import = javax. xml. parsers. saxparserfactory %>
<% @ Page import = javax. xml. parsers. saxparser %>
<% @ Page import = saxhandler %>
<% @
File file = new file (C: \ people. XML );
Filereader reader = new filereader (File );
Parser;
Saxparserfactory SPF = saxparserfactory. newinstance ();
Saxparser sp = SPF. newsaxparser ();
Saxhandler handler = new saxhandler ();
Sp. parse (New inputsource (Reader), Handler );
Hashtable = handler. gettable ();
Out. println ();
Out. println (
+ );
Out. println (
+ );
Out. println (
+ );
Out. println (
+ );
Out. println (
Instructor information table
| Name |
+
(String) hashtable. Get (new string (name) + |
| School |
+
(String) hashtable. Get (new string (college) + |
| Phone number |
+
(String) hashtable. Get (new string (telephone) + |
| Remarks |
+
(String) hashtable. Get (new string (notes) + |
);
>
31. Differences between EJB and JavaBean
Javabean is a reusable component that does not have strict specifications on JavaBean. Theoretically, any Java class can be a bean, but generally, because Javabean is built by containers (such as Tomcat. Therefore, JavaBean should have a parameter constructor. In addition, JavaBean usually needs to implement the serializable interface for bean persistence. Javabean is actually equivalent to the COM component in the local process in the Microsoft COM model, it cannot be accessed by exaggerated processes. enterorise Javabean is equivalent to DCOM, which is a distributed component. It is developed based on Java's RMI technology, therefore, ejbs can be remotely accessed (cross-Inbound, cross-computer), but ejbs must be deployed in containers such as websoere and weblogic. EJB customers never directly access the real EJB components, instead, it is accessed through its container. The EJB container is a proxy established by EJB, And the EJB component is created and managed by the container. The customer accesses the real EJB component through the container.