Java Face question Summary 1 (continuous update)

Source: Internet
Author: User

1. What are the similarities and differences between runtime exceptions and general exceptions?

Answer: An exception indicates an unhealthy state that may occur during a program run, and a run-time exception that represents an exception that may be encountered in a virtual machine's usual operation 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.

2. Differences between stored procedures and functions
Answer:
From the return of the parameter:

It is best to use a stored procedure if you return multiple parameter values, and you can use a function if there is only one return value.

In terms of invocation:

If you call in a SQL statement (DML or select) it must be a stored function or stored package function can not be stored procedures, but call storage functions there are a lot of restrictions and the level of purity of the function of the problem, if it is called in a procedural statement, it depends on what kind of function you want to implement. Functions are typically used to calculate and return a calculation and stored procedures are typically used to complete specific data operations (such as modifying, inserting database tables, or executing certain DDL statements, etc.), so although they are syntactically similar, the functionality that users need to do when they use them is mostly different.

3. What are the three basic characteristics of a class? What are the advantages of each feature?

Solution: Classes have encapsulation, inheritance, and polymorphism.

What is the difference between 4.Collection and collections?

Solution: Collection is the interface under Java.util, which is the parent interface of various collections, and the interfaces that inherit from it are mainly set and list Collections is a Java.util class, a helper class for collections that provides a series of static methods for searching, sorting, threading, and so on for various collections.

What is the difference between 5.HashMap and treemap?

Answer: HashMap quickly find its content through hashcode, and all elements in TreeMap are kept in a fixed order, and if you need to get an ordered result you should use TREEMAP (the order of the elements in HashMap is not fixed).

What is the difference between 6.ArrayList and vector?

Answer: The synchronization: vector is thread-safe, that is, synchronous, and ArrayList is thread insecure, not synchronous; Data growth: When growth is needed, vectors grow by default to the original, while ArrayList is half the original.

What is the difference between 7.HashMap and Hashtable?

Answer: HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all implement the map interface, the main difference

Is that HASHMAP allows null (NULL) key values (key), which is more efficient than Hashtable due to non-thread safety. 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 HasTable method is synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide synchronization.

8. Please say Arraylist,vector, LinkedList storage performance and features

Answer: Both ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly. Vector because of the use of the Synchronized method (thread-safe), usually performance is worse than ArrayList, and LinkedList using a doubly linked list for storage, index data by ordinal need to be forward or backward traversal, but when inserting data only need to record the item before and after items can be , so the insertion speed is faster.

9. List the JDK packages that you commonly use.

Answer: JDK Common package

Java.lang: This is the basic class of the system, such as string, etc. are inside, this package is the only one can be used without import package

Java.io: This is all the input and output related classes, such as file operation, etc.

Java.net: This is a network-related class, such as Url,urlconnection.

Java.util: This is the system auxiliary class, especially the collection class Collection,list,map and so on.

java.sql: This is the database operation class, Connection, Statememt,resultset, etc.

What are the characteristics of 10.List, MAP, set three interface storage elements?

Answer:

1) List is an ordered collection, using this interface to precisely control where each element is inserted. The user is able to access the elements in the list using an index (where the element is positioned in the list, similar to an array subscript), similar to an array of java.

2) set is a collection that contains no duplicate elements, that is, any two elements E1 and E2 have E1.equals (E2) =false,set have a maximum of one null element.

3) Map Interface: Note that map does not inherit the collection interface, and map provides a key-to-value mapping

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

Solution: 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, or they are abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these methods in the class. An interface (interface) is a variant of an abstract class. The new multi-inheritance can be achieved by implementing such an interface. All methods in an interface are abstract, and all member variables are public static final. A class can implement multiple interfaces, and when a class implements an interface, all methods of the interface must be implemented. Abstract classes represent a single-inheritance relationship in the Java language, which is not required for interface, and does not require that the interface and interface definitions be consistent in concept, but only the contract that implements the interface definition. Abstract classes can define their own member variables, can also contain non-abstract methods, and in the interface can only have static constants, all methods must be abstract, the implementation of the abstract class can only implement some of the methods, and if you implement an interface, you must implement all the abstract methods in this interface.

What are the methods for passing parameters between 12.JSP pages?

Answer:

1) Request

2) session

3) Application

4) Submit the form

5) Hyperlinks
6) hiding the form

The difference between 13.forward and redirect

Answer: Forward is the control in the container of the steering, is the server request resources, the server directly access the URL of the destination address, the URL of the response to read the content, and then send the content to the browser, the browser does not know where the server sent the content from, So its address bar is still the original address. redirect is the server based on logic, send a status code, tell the browser to request the address again, generally speaking, the browser will use all the parameters just requested, and from the browser's address bar can see the link address after the jump. the former is more efficient, when the former can satisfy the need, try to use the forward () method, and this also helps to hide the actual link ; In some cases, such as the need to jump to a resource on a different server, you must use Sendredirect ( Method

What is the effect of 14.Java reflection mechanism?

Solution: The role of the Java Reflection mechanism is:

1) Determine the class to which any object belongs at run time.

2) Constructs an object of any class at run time.

3) Determine the member variables and methods that any one class has at run time.

4) method of invoking any object at run time

15. How do you understand the generics of Java?

Solution: In the case of Java SE 1.5, without generics, by referring to the type object to implement the "arbitrariness" of the parameter, the disadvantage of "arbitrariness" is to do explicit coercion of type conversion, which requires the developer to the actual parameter type can be predicted. in the case of coercion of type conversion errors, the compiler may not prompt for an error and an exception occurs at run time, which is a security risk.

Generics are a new feature of Java SE 1.5, and the nature of generics is a parameterized type, meaning that the data type being manipulated is specified as a parameter. This type of parameter can be used in the creation of classes, interfaces, and methods, called generic classes, generic interfaces, and generic methods, respectively.

The benefit of generics is that it checks for type safety at compile time, and all casts are automatic and implicit , increasing the rate of reuse of the code.

16.AVA If multiple classes can be included in the source file, what are the limitations

Answer: A Java source file can contain multiple classes, each source file has at most one public class, if any, then the source file must be the same name. If there is no public class in the source file, the source file can be any name, but it is better to have a specific meaning so that you do not remember what is written in it.

17. Please explain the Distributed transaction management?

Solution: A distributed transaction is a contributor to a transaction, a server that supports transactions, a resource server, and a transaction manager on different nodes of a different distributed system. In order to implement a distributed transaction, you need to use the two-phase commit protocol described below. Phase one: Start sending pre-submission information to all resources involved in the transaction. At this point, the resources involved in the transaction have the last chance to end the transaction unexpectedly. If either resource determines an unexpected end transaction, the entire transaction is canceled and the resource is not updated. Otherwise, the transaction will execute normally unless a catastrophic failure occurs. To prevent a catastrophic failure, updates to all resources are written to the log. These logs are permanent, so these logs are spared and can be re-updated for all resources after a failure. Stage Two: Only occurs when the stage is not at the end of an exception. At this point, all resource managers that can be located and individually controlled will begin to perform real data updates. In the distributed transaction two phase commit protocol, there is a primary transaction manager responsible for acting as the Distributed Transaction Coordinator. The transaction Coordinator is responsible for the entire transaction and makes it work with other transaction managers in the network. In order to implement a distributed transaction, it is necessary to use a protocol to pass transaction context information between the various actors of the distributed transaction, IIOP the protocol. This requires that transaction participants developed by different developers must support a standard protocol in order to achieve distributed transactions.

18.String, the difference between StringBuffer StringBuilder.
Answer: The length of the string is immutable, the length of the StringBuffer is variable, if you are working on the contents of the string frequently, especially when the content is to be modified, then use StringBuffer, if the last string is required, Then use the ToString () method of StringBuffer; thread-safe; StringBuilder is starting with JDK 5, which complements the equivalence class used by a single thread for StringBuffer class; StringBuilder classes should usually be preferred , because it supports all the same operations, but because it does not perform synchronization, it is faster.

19. Please write out 5 common runtime exception.

Answer:

NullPointerException: This error occurs when you manipulate a null reference.

NumberFormatException: This exception occurs when there is a problem with the data format conversion.

ClassCastException: This exception occurs when coercion type conversion types do not match.

ArrayIndexOutOfBoundsException: Array subscript is out of bounds when this exception occurs when using an array subscript that does not exist.

ArithmeticException: This exception occurs when math runs incorrectly

20. Does the array have the length () method? Does string have the length () method?

Answer: The array does not have the length () method and it has the length property

String has the length () method.

21. In Java, List is an interface, what is the difference between a class that implements a list interface?

Answer: ArrayList is to store data in an array way, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly.

LinkedList uses two-way linked lists for storage, index data by ordinal requires forward or backward traversal, but when inserting data, you only need to record the item's front and rear items, so the insertion speed is faster.

What 3 types of beans are included in 22.EJB

Solution: Session bean (conversation bean), Entity bean (solid bean), message bean

Java objects in 23.hibernate have several states, how they relate (differentiate and convert to each other).

Answer: In hibernate, there are three states of the object: temporary, persistent, and free. Temporary state: When new is a physical object, the object is in a temporary state, that is, an area of memory that holds temporary data, and if no variable references the object, it is reclaimed by the JRE garbage collection mechanism . The data stored by this object has nothing to do with the database, unless the temporary object is associated with the database through save or saveorupdate of the session and the data is inserted or updated into the database, the object is converted to a persistent object;

Persistent state: an instance of a persisted object has a corresponding record in the database and has a persistent representation (ID). After a delete operation on a persisted object, the corresponding record in the database is deleted, and the persisted object no longer has a corresponding relationship with the database record, and the persisted object becomes a temporary state.

After the persisted object is modified, it is not synchronized to the database immediately until the database transaction commits. The persisted object is dirty (Dirty) before synchronization.

Free State: When the session is closed, clear, or evict, the persisted object has a persistent identifier and a value consistent with the database corresponding record, but because the session has disappeared, the object is not within persistent management, so it is in a Free State (also

Called: off-tube State). An object with a free state is very similar to a temporary state object, except that it also contains persistent identities.

What is the difference between 24.error and exception?

Answer:
Error indicates system-level errors and exceptions that the program does not have to handle, a serious problem in situations where recovery is not impossible but difficult, such as memory overflow, which cannot be expected to be handled by the program; exception represents an exception that needs to be captured or handled by a program, which is a design or implementation issue In other words, it means that if the program runs normally, it never happens.

25. Describe the differences between JSP and servlet, the common denominator, and the scope of their respective applications

Answer: JSPs are essentially servlets, but they are not created the same way. The servlet is completely Java program code composition, good at process control and transaction processing, It is not intuitive to generate dynamic Web pages through Servlets. JSP is made up of HTML code and JSP tags, which makes it easy to write dynamic Web pages. Therefore, the servlet is used to control the business process in the actual application, and the JSP is used to generate the Dynamic Web page.

26. What is the difference between int and Integer in the Java language

Answer: Int is the basic data type, integer is the wrapper class for int, and is a reference type

27. Describe the similarities and differences between synchronized and Java.util.concurrent.locks.Lock?

Answer: The main similarities: lock can accomplish all the main features of the synchronized implementation: 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.

Java Face question Summary 1 (continuous update)

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.