[Interview]-Java face question 3

Source: Internet
Author: User

the difference between overload and override. can the overloaded method change the type of the return value?
The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The overloaded method is to change the type of the return value.
What is the mechanism for polymorphism in Java?
The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class.

MVC English is Model-view-controller, that is, an application of input, processing, output process according to model, view, Controller to separate the way, such an application is divided into three layers-model layer, view layer, control layer. The view represents the user interface, which can be generalized as an HTML interface for Web applications, but it can be XHTML, XML, and applets. With the complexity and scale of the application, the processing of the interface becomes challenging. An application may have many different views, the MVC design pattern is limited to the processing of the view's data collection and processing, and the user's request, not including the business process on the view. The processing of business processes is delivered to the model. For example, an order view only accepts data from the model and is displayed to the user, as well as passing input data and requests from the user interface to the control and model.

lists hold elements in a particular order, and can have repeating elements. Set cannot have duplicate elements, internal ordering. Map holds the Key-value value, and value can be multivalued.

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.

forward is the server requests the resource, the server directly accesses the URL of the destination address, reads the response content of that URL, and then sends the content to the browser, the browser does not know where the server sends the content from, so its address bar is the original address. Redirect is the server based on logic, send a status code, tell the browser to request the address again, in general, the browser will use all the parameters just requested again, so the session,request parameter can be obtained

A class that declares the existence of a method and does not implement it is called an abstract class , which is used to create a class that embodies some basic behavior, declares a method for that class, but does not implement the class in that class. An instance of the abstract class cannot be created. However, you can create a variable whose type is an abstract class that points to an instance of a specific subclass. Cannot have abstract constructors or abstract static methods. The subclasses of the abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these method interfaces (interface) in a class are variants of abstract classes. In an interface, all methods are abstract. Multiple inheritance can be obtained by implementing such an interface. All the methods in the interface are abstract, without a program body. An interface can only define static final member variables. The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit the behavior from the interface definition. When a class implements a special interface, it defines the method (which is given by the program body) to all such interfaces. It can then invoke the interface's method on any object that implements the interface's class. Because of an abstract class, it allows you to use the interface name as the type of the reference variable. The usual dynamic binder will take effect. A reference can be converted to an interface type or converted from an interface type, and the instanceof operator can be used to determine whether an object's class implements an interface

the JSP has the following 9 basic built-in components (which correspond to the 6 internal components of ASP):

Request client requests, this request will contain parameters from the Get/post request
Response Web page back to the client's response
The properties of the PageContext Web page are managed here
Session period associated with the request
What the application servlet is doing
Output used to transmit a response
Config Servlet's architectural parts
Page JSP webpage itself
Exception exceptions for error pages, not captured

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

Dead lock
Deadlock in multi-threaded synchronization, is a very annoying problem. It was because of his uncertainty that it became a very difficult problem to solve. Because there may never be a deadlock, but if a deadlock happens, you know exactly when the next time the deadlock will occur, there is no way to start. First, let's look at what a deadlock is, when a thread waits for another thread, and then waits for the other thread, waiting until the thread on the chain waits for the first thread to release the lock. This gets a continuous loop between threads waiting for each other, and no thread can continue, which is called a deadlock. Breaking the deadlock method is also simple, as long as it destroys his loop waiting on the line. If in the above program, only need to destroy this loop chain to avoid deadlocks, but the most difficult to solve the deadlock problem is the discovery of deadlocks. This requires programmers to be very cautious in designing multi-threading, and be sure not to trust any assumptions made on multithreading!

Thread synchronization
What is called synchronization. The word "synchronous" cannot be understood by literal means. Because this is likely to cause misunderstanding. For example, like the bank's savings and money. If you use synchronization, you will only be able to withdraw money after you have saved, and these two actions are a kind of synchronization. If it's asynchronous, that means saving and taking money can be done at the same time. The Synchronized keyword is provided in Java to keep the threads in sync. There are two ways to synchronize operations, method synchronization, and code block synchronization. When the Synchronized keyword is added to a method or block of code, it means that when a thread executes here, the object's lock is obtained first, and if the object is not locked, the thread adds a lock to the object and continues execution. While other threads are executing here, because the object is already locked, these threads will only wait for the lock on that object to be released. This will allow the threads executing here to remain synchronized. There are two forms of synchronous operations: Method synchronization and code block synchronization.

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.

What is the rationale behind the garbage collector? Can the garbage collector reclaim memory right away? Is there any way to proactively notify a virtual machine for garbage collection?
For GC, when a programmer creates an object, the GC starts to monitor the object's address, size, and usage. Typically, a GC uses a graph to record and manage all objects in the heap. In this way, you determine which objects are "accessible" and which objects are "unreachable." When the GC determines that some objects are unreachable, it is the responsibility of the GC to reclaim those memory spaces. OK. The programmer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will execute.

What happens when doget () and Dopost ()are called?
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.

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.

What are the similarities and differences between JSP and servlet, and what is the connection between them?
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.

Is the EE 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.

What are the similarities and differences between synchronous and asynchronous , and under what circumstances are they used separately? An example is described.
If the data will be shared between threads. For example, the data being written may be read by another thread later, or the data being read may have been written by another thread, then the data is shared and must be accessed synchronously.
When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the method to be returned, it should use asynchronous programming, which is often more efficient in many cases with asynchronous approaches.

What are the similarities and differences between run-time exceptions and general exceptions?
An exception represents an unhealthy state that may occur during a program's run, and a run-time exception that represents an exception that may be encountered in a typical operation of a virtual machine is a common run error. The Java compiler requires the method to declare a non-runtime exception that might occur, but does not require that a runtime exception that is not caught to be thrown must be declared.

EJB includes (Sessionbean,entitybean) say their life cycle, and how to manage the transaction?
The lifecycle of the sessionbean:stateless Session Bean is determined by the container, and when the client makes a request to establish an instance of the bean, the EJB container does not have to create a new instance of the bean for the client to invoke. Instead, find an existing instance to provide to the client. When a client invokes a statefulsession bean for the first time, the container must immediately create a new bean instance in the server and associate it to the client, which in the future calls the stateful Session bean method, the container assigns the call to the bean instance associated with the client.
Entitybean:entity beans can survive for a relatively long time, and the state is persistent. As long as the data in the database exists, Entity beans has survived. Not according to the application or service process. Even if the EJB container crashes, the Entity beans is alive. The Entity beans life cycle can be managed by the container or beans itself.
EJB is managed by the following technologies: Object Management Organization (OMG), Transaction Service (JTS), Java Transaction API (JTA), Development Group (x/), Microsystems Services (OTS) Open) of the XA interface.

What are the similarities and differences between JSP and Servlet , and what is the connection between them?
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.

The difference between String and StringbuffeR
The Java platform provides two classes: string and StringBuffer, which can store and manipulate strings, which are character data that contain multiple characters. This string class provides a string of values that cannot be changed. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know that character data is going to change. Typically, you can use Stringbuffers to dynamically construct character data.

the difference between HashMap and Hashtable.
HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), because of non-thread security, the efficiency may be higher than Hashtable.
HashMap allows NULL to be used as a entry key or value, and Hashtable is not allowed.
HashMap hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding.
Hashtable inherits from the dictionary class, and HashMap is an implementation of the map interface introduced by Java1.2.
The biggest difference is that the Hashtable method is synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide external synchronization. The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.

What is the difference between EJB and Java bean?
Java beans are reusable components, and there is no strict specification for Java beans, and in theory, any Java class can be a Bean. In general, however, because Java beans are created by containers (such as Tomcat), Java beans should have a parameterless constructor, and in addition, Java beans typically implement the serializable interface to implement Bean persistence. Java beans are actually equivalent to the local in-process COM component in the Microsoft COM model, which cannot be accessed across processes. Enterprise Java beans are equivalent to DCOM, which is distributed components. It is a Java-based remote method invocation (RMI) technology, so EJBS can be accessed remotely (across processes, across computers). However, EJBS must be in containers such as Webspere, WebLogic, and EJB clients never directly access real EJB components, but are accessed through their containers. The EJB container is the proxy for the EJB component, and the EJB component is created and managed by the container. The customer accesses the real EJB component through the container.

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.

[Interview]-Java face question 3

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.