Java Basics
1. What data types are available?
Java defines 8 simple types: Byte, short, int, long, char, float, double, and Boolean.
2. Object-oriented language features
Encapsulation, inheritance, polymorphism
3, there are several access mechanisms?
4. How object-oriented polymorphism is implemented 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. Suppose you define a method in a subclass that has the same name and number of parameters as its parent class. We say that the method is rewritten (overriding). When an object of a subclass uses this method, the definition in the subclass is called, for it. The definition in the parent class is "masked". Suppose you define more than one method with the same name in a class that either has a different number of parameters or has a different parameter type. is called a method's overload (overloading). Overloaded method is able to change the return value
5. Differences between character stream and byte stream in Java I/O
A byte stream is an integer that passes 0~255, and some (such as Unicode code) in Java cannot use a character stream, which is a special byte stream.
6, say Arraylist,vector, LinkedList storage performance and Characteristics
Both ArrayList and vectors store data using arrays, which are larger than the actual stored data for adding and inserting elements. They all agree to index elements directly by ordinal, but inserting elements involves memory operations such as array element movement. So the index data is fast and the insertion data is slow, vector because of the use of synchronized method (thread safety), usually the performance of the ArrayList poor, and LinkedList using a doubly linked list for storage, indexed by ordinal data need to forward or back traversal, However, inserting the data only needs to record the item's front and rear items, so the insertion speed is faster.
7. Differences between Hashtable and HashMap
There are three important differences between the Hashtable and the HashMap class. The first difference is mainly historical reason, Hashtable is based on the old Dictionary class, and HashMap is an implementation of the map interface introduced by Java1.2
The method of Hashtable is synchronous, and the method of HashMap is not, which means. Although you can use a hashtable in a multithreaded application with no matter what you do, you have to provide external synchronization equally for HashMap, and a convenient way is to take advantage of the static Synchronizedmap () method of the collection class. It creates a thread-safe map object and returns it as a encapsulated object that allows you to synchronize access to potential hashmap, the structure of which is that when you do not need to synchronize, you cannot cut off synchronization in Hashtable (for example, in a single-threaded application) And synchronization adds a lot of processing costs.
The third difference is. Only HashMap can let you empty values as a table of entries and keys and Value,hashmap only one record can be a blank key. But a random number of entries can be blank value.
This means that if a search is not found in a table, or if a search key is found, it is a null value. Then get () will return NULL, assuming it is necessary. Use the Containkey () method to discriminate between the two cases.
8. Whether the HTTP protocol is a long connection or a short link
The HTTP protocol is a stateless connection, so it is a segment connection.
9. What are the basic data types of Java, string is not the basic type
Boolean,int,byte,char,short,long,float,double,void,
String is not a base type.
10. Differences between String and StringBuffer
The length of the string is immutable. The length of the StringBuffer is variable. Assuming you are working on the contents of a string frequently, especially if the content is to be changed, then use StringBuffer, assuming that the last string is required. Then use the ToString () method of StringBuffer
11. What are the similarities and differences between exception and general exception when executing?
An exception represents an unhealthy state that may occur during program execution. Execution-time exceptions represent exceptions that may be encountered in a typical operation of a virtual machine. is a common execution error. The Java compiler requires the method to declare a non-execution-time exception that might occur. However, it is not required to declare an uncaught execution-time exception to be thrown.
12. Say some of the frequently used classes, packages, interfaces, please give 5
Frequently used classes:
BufferedReader bufferedwriter filereader filewirter String Integer
Frequently used packages: Java.lang java.awt java.io java.util java.sql
Frequently used interfaces: Remote List Map Document NodeList
13, how to avoid multiple sockets read and write blocking, jdk1.4 new ways to solve the problem?
In the JDK1.4 version number, to avoid blocking occurs, there are two ways to do the following:
Using multithreading to handle different socket operations, assume that a thread is processing a read, a processing write.
Use a third-party library, Non-jdk method.
NiO was introduced into the JDK1.4 and later version numbers, and non-blocking sockets were introduced to enable network operation without blocking.
14. The life cycle of the servlet
(1) Loading/instantiation:
The servlet container finds and loads all the servlet classes. When the servlet engine starts or when the client HTTP request is committed, an instance of Servle or multiple servlet classes
(2) initialization
Here, the init () method is used to initialize the client before it requests to entrust the agent.
(3) Request processing
The client HTTP request is then processed when the initialization is complete. This method of service () is used here to complete and pass it as a reference, where the number of references includes HttpServletRequest () and HttpServletResponse (). Two methods corresponding to the request and response they will also throw servletexception and IOException and then target different HTTP requests (four said above, Get,post,put,head) by Doget (), DoPost (), DoPut (), Dohead (), these four different methods block the processing unit to deal with ...
(4) Delete Sevlet
Sometimes it is necessary to delete the servlet instance in the Sevlet container for some reason, then the Destroy () method can be called, and after this method is executed, Sevlet can no longer execute the request of the other client ... And then it becomes the garbage collector of Java Recycling Object!
15. What are the redirection methods in JSP, and what are their differences?
<jsp:forward page=”url”/><jsp:include file=”url”/>
The former redirects the current page to the page of the specified URL, which is the page that includes the specified URL in the current page.
16. What are the built-in objects of JSP? What is the role of each?
Request: Client requests, this request will include the number of references from the Get/post request
GetParameter (), SetAttribute (), getattribute (), reponse (): Feedback from the Web page back to the client
Encode (), Sendredirect (), SETCONTEXTF (), PageContext: The properties of the Web page are managed here
Getservletcontext (), Getsessin (), SetAttribute (), session: Conversation period related to the request
GetAttribute (), SetAttribute (), invalidate (), application (): What the servlet is doing
SetAttribute (), GetAttribute (): The architecture part of the config servlet
Getservletcontext (), Getservletname (), Getinitparameter (): Out output used to transmit the response (used to output data to the client)
println () \ Flush (), Close (): Page JSP Web page itself
Exception exceptions (exceptions) for error pages, not captured
17. What are the actions of JSP? What are their roles?
The JSP collectively has the following 6 actions:
Jsp:include:: Introduce a file when the webpage is requested
Jsp:usebean: Finding or instantiating a JavaBean
Jsp:setproperty: Setting the properties of a JavaBean
Jsp:getproperty: Output Properties of a JavaBean
Jsp:forward: Move the request to a new page.
Jsp:plugin: Based on browser type Java plugin or generate object or embed tag
18. What is the difference between a dynamic include and a static include in a JSP?
Dynamic include is implemented with Jsp:include action
It always checks for changes in the included files, is suitable for including dynamic pages, and is able to take a number of parameters
Static include is not checked with the include pseudo-code implementation. Changes to the included files, applicable to include static pages
19. What are the solution technologies for XML? What's the difference?
There are DOM. Sax. STAT
The DOM's performance drops very badly when it handles large files.
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. Random Interview FOR XML
Sax is a different DOM document-driven type, and 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 you encounter the beginning of a file, the document ends, or the label begins with the end of the label. It will trigger an event.
The user passes in its callback event. The user processes the XML file by writing the processing code in its callback event, which is suitable for sequential access to XML
Stax:streamingapi for XMl (STAX)
20. What aspects of XML technology do you use in your project? How is it achieved?
Use of data storage, information configuration two aspects
When doing a data exchange platform. Assembles the data source data into an XML file. The XML file is then compressed and packaged and encrypted over the network to receive, receive decryption and name decompression, and then the XML file to restore the relevant information processing.
The use of XML can be very handy when it comes to software configuration. Software and a variety of configuration parameters are stored in the XML file.
21, how to solve the connection pool, what are the advantages?
WORKAROUND: Establish sufficient database connections at application startup and make these connections a pool of connections. Applications are dynamically applied to the connection in the pool by the application. Use. and release.
For concurrent requests for connection pooling, you should queue up in the request queue. And the application can dynamically add or decrease the number of connections in the pool based on the usage of the connections in the pool.
Advantage, and reuse as much of the resources of the sand-consuming memory as possible, greatly saving memory. Improves server service efficiency and can support many other customer services by using connection pooling. Will greatly improve the efficiency of program execution. At the same time, we are able to monitor the number of databases through its own management mechanism. Usage and so on.
22. The JDBC Process
(1) Loading the JDBC driver
Class.forName ("Com.mysql.jdbc.Driver");//mysql loading the JDBC driver method
Class.forName ("Org.postgresql.Driver");//postgresql
Class.forName ("Oracle.jdbc.driver.OracleDriver");//oracle
Class.forName ("Com.ibm.db2.jdbc.net.DB2Driver");//db2
Class.forName ("Com.sybase.jdbc2.jdbc.SybDriver");//sybase
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");//sqlserver
(2) establishing a database connection
How to establish a connection to the MySQL database:
Connectioncon=drivermanager.getconnection ("Jdbc:mysql://mydbcomputernameorip:3306/mydbname", ID,PWD);
How to establish a connection to the PostgreSQL database:
Connectioncon=drivermanager.getconnection ("Jdbc:postgresql://mydbcomputernameorip:3306/mydbname", ID,PWD);
How to establish a connection to an Oracle database:
Connectioncon=drivermanager.getconnection ("Jdbc:oracle:thin: @MyDbComputerNameOrIP: 1521:orcl", id,pwd);
How to establish a connection to the Sybase database:
Connectioncon=drivermanager.getconnection ("jdbc:sybase:tds:mydbcomputernameorip:2638", ID,PWD);
How to establish a connection to a SQL Server database:
Connectioncon=drivermanager.getconnection ("Jdbc:microsoft:sqlserver://mydbcomputernameorip:1433;databasename= Master ", id,pwd);
How to establish a connection to the DB1 database:
Connectioncon=drivermanager.getconnection ("Jdbc:db2://mydbcomputernameorip/mydbname", ID,PWD);
(3) Creating and executing SQL statements
Use the Connection.createstatement () method to create a statement object. The statement object executes a query and returns a ResultSet object that includes the result of the response from the DBMS.
(4) Processing data returned from the DBMS
The query results received from the DBMS are assigned to the Java.sql.ResultSet object after query processing. The object includes methods for getting data from the result set to the Java variable for further processing.
(5) Closing the database connection
The memory consumed by database-related objects is very large, so close the database connection in a timely manner after the database access is complete, and also close the contents returned in connection at the same time. Includes statement objects and ResultSet objects.
"Interview written Test" Java Common interview written summary