Detailed explanation of Huawei Java Huawei interview questions (transferred from suningin, I added some questions for reference)

Source: Internet
Author: User
Tags websphere application server

Java
1. What are the aspects of object-oriented features?
1. Abstraction:
Abstraction is to ignore those aspects irrelevant to the current target in a topic, so that you can pay more attention to the aspects related to the current target. Abstraction is not intended to understand all the problems, but to select a part of the problem. Abstract: Process abstraction and data abstraction.
2. Inheritance:
Inheritance is a hierarchical model that connects classes and allows reuse of encouraging classes. It provides a way to clearly express commonalities. A new class of an object can be derived from an existing class. This process is called class inheritance. The new class inherits the features of the original class. The new class is called the derived class (subclass) of the original class, and the original class is called the base class (parent class) of the new class ). A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more suitable for special needs.
3. encapsulation:
Encapsulation is to enclose the process and data. Data access can only be performed through the defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of completely autonomous and encapsulated objects that access other objects through a protected interface.
4. Polymorphism:
Polymorphism allows different types of objects to respond to the same message. Polymorphism includes parameterized polymorphism and inclusion polymorphism. The polymorphism language has the advantages of flexibility, abstraction, behavior sharing, and code sharing, which effectively solves the same name problem of application functions.


2 is string the most basic data type?
No, it is an object

3 what is the difference between int and integer?
Java provides two different types: The reference type and the original type (or the built-in type ). Int Is the original data type of Java, and integer is the encapsulation class provided by Java for int

4 differences between string and stringbuffer
The length of string is unchangeable, and the length of stringbuffer is variable. If you often operate on the content in the string, especially when the content is to be modified, use stringbuffer. If the string is needed at last, use the tostring () method of stringbuffer.

5. What are the differences between runtime exceptions and general exceptions?
An exception indicates an abnormal state that may occur during the running of the program. An exception indicates an exception that may occur during common operations on the virtual machine. It is a common running error. The Java compiler requires that methods must declare and throw possible non-runtime exceptions, but do not require that they throw uncaptured runtime exceptions.

6. You can name five common classes, packages, and interfaces.
Common classes: bufferedreader bufferedwriter filereader filewirter string integer
Common packages: Java. Lang java. AWT java. Io java. util java. SQL
Common interfaces: Remote list map document nodelist

7. Specify the storage performance and features of arraylist, vector, and sorted list.
Both arraylist and vector use arrays to store data. The number of elements in the array is greater than that in the actual data storage to add and insert elements. They allow the element to be indexed by serial number directly, however, inserting elements involves memory operations such as array element movement, so index data is fast and data insertion is slow. Because vector uses the Synchronized Method (thread-safe), its performance is generally inferior to that of arraylist, the sorted list uses a two-way linked list for storage. Data indexed by serial number needs to be traversed in the forward or backward direction. However, when inserting data, you only need to record the items before and after this item, so the insertion speed is fast.
8. Design four threads. Two of them increase 1 to J each time, and the other two threads decrease 1 to J each time. Write the program.
The following programs use internal classes to implement threads, and do not consider the sequence when J is added or subtracted.
Public class threadtest1 {
Private Int J;
Public static void main (string ARGs []) {
Threadtest1 TT = new threadtest1 ();
INC Inc = TT. New Inc ();
Dec dec = TT. New Dec ();
For (INT I = 0; I <2; I ++ ){
Thread t = new thread (INC );
T. Start ();
T = new thread (DEC );
T. Start ();
}
}
Private synchronized void Inc (){
J ++;
System. Out. println (thread. currentthread (). getname () + "-Inc:" + J );
}
Private synchronized void Dec (){
J --;
System. Out. println (thread. currentthread (). getname () + "-Dec:" + J );
}

Class Inc implements runnable {
Public void run (){
For (INT I = 0; I <100; I ++ ){
INC ();
}
}
}
Class dec implements runnable {
Public void run (){
For (INT I = 0; I <100; I ++ ){
Dec ();
}
}
}
}

9. built-in JSP objects and methods.
Request request indicates the httpservletrequest object. It contains information about browser requests and provides several useful methods for obtaining cookie, header, and session data.

Response response indicates the httpservletresponse object, and provides several methods (such as cookies and header information) for setting the response to the browser)

The out object is an instance of javax. jsp. jspwriter. It provides several methods for sending output results to the 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 session indicates a requested javax. servlet. http. httpsession object. Session can store user status information

Application applicaton indicates a javax. servle. servletcontext object. This helps you find information about the servlet engine and Servlet environment.

Config config indicates a javax. servlet. servletconfig object. This object is used to access the initialization parameters of the servlet instance.

Page page indicates a servlet instance generated from this page.

10. Write the communication between the client and the server using socket communication. The client must be able to echo the same data after sending the data.
See the socket communication example in the course.

11. Tell the servlet lifecycle and the difference between Servlet and CGI.
After the servlet is instantiated by the server, the container runs its init method, runs its service method when the request arrives, and the service method automatically dispatches the doxxx method (doget, dopost) corresponding to the request, etc, the destroy method is called when the server decides to destroy the instance.
The difference with CGI is that the servlet is in a server process and runs its service method in multi-thread mode. An instance can serve multiple requests, and its instance is generally not destroyed, CGI generates a new process for each request. After the service is completed, it is destroyed, so the efficiency is lower than that of servlet.
12. What technologies are EJB implemented based on? And the difference between sessionbean and entitybean, and the difference between statefulbean and statelessbean.

13. EJB includes (sessionbean, entitybean) telling about their lifecycle and how to manage transactions?
Sessionbean: the lifecycle of stateless Session Bean is determined by the container. When the client sends a request to create a bean instance, the EJB container does not have to create a new bean instance for the client to call. Instead, it finds an existing instance and provides it to the client. When the client calls a stateful Session Bean for the first time, the container must immediately create a new bean instance on the server and associate it with the client, when this client calls the stateful Session Bean method later, the container will dispatch the call to the bean instance associated with this client.
Entitybean: entity beans can survive for a relatively long time, And the status is continuous. As long as the data in the database exists, entity beans will survive. It is not based on the application or service process. Even if the EJB container crashes, entity beans survive. Entity beans can be managed by containers or beans themselves.

EJB uses the following technical management practices: ots of Object Management Organization (OMG), Transaction Service (JTs) of Sun Microsystems, and Java transaction API (JTA ), the Xa interface of the Development Group (x/open.

14. What is the working mechanism of the data connection pool?
When the J2EE server is started, a certain number of pool connections will be established, and a certain number of pool connections will be maintained. When the client program needs to connect, the pool driver returns an unused pool connection and logs its table as busy. If no idle connection exists, the pool driver creates a certain number of connections. The number of new connections is determined by the configuration parameters. When the pool connection call is completed, the pool driver records the connection table as idle, and other calls can use the connection.

15. Synchronization and Asynchronization have similarities and differences. Under what circumstances should they be used separately? Examples.
If data is shared among threads. For example, if the data being written may be read by another thread or the data being read may have been written by another thread, 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 return of the method, asynchronous programming should be used, in many cases, adopting asynchronous channels is often more efficient.

16. What are the app servers?
BEA WebLogic Server, IBM WebSphere Application Server, Oracle9i Application Server, JBoss, Tomcat

17 what are the collection classes you know? What are the main methods?
The most common collection classes are list and map. The specific implementation of list includes arraylist and vector, which are variable-size lists and are suitable for building, storing, and operating the list of elements of any type of object. List is applicable to accessing elements by Numerical index.

Map provides a more general method for storing elements. The Map Collection class is used to store element pairs (called "keys" and "values"). Each key maps to a value.

18 here is one for you: Driver A, data source name B, user name C, password D, database table T. Please use JDBC to retrieve all data in table t.

19. How are pages displayed on the JSP page?
Save the following parameters on the page:
Total number of rows: obtain the total number of rows based on SQL statements.
Number of lines per page: Set Value
Current page number: Request Parameters
The page calculates the number of rows in the first row of the current page based on the current page number and number of rows per page, locates the result set to this row, and retrieves the rows of the number of lines displayed on each page.

Database:

1. Differences between stored procedures and functions
A stored procedure is a collection of user-defined SQL statements involving tasks of a specific table or other objects. You can call the stored procedure. A function is usually a database-defined method, it receives parameters and returns some type of values, and does not involve specific user tables.
2. What is a transaction?
A transaction is a series of operations performed by a logical unit. A logical unit of work must have four attributes, called acid (atomicity, consistency, isolation, and persistence) attributes, only in this way can we become a transaction:
Atomicity
A transaction must be an atomic unit of work. modifications to its data must either be performed in all or not.
Consistency
When the transaction is completed, all data must be consistent. In related databases, all rules must be applied to transaction modifications to maintain the integrity of all data. At the end of the transaction, all internal data structures (such as B-tree indexes or two-way linked lists) must be correct.
Isolation
Modifications made by a concurrent firm must be isolated from those made by any other concurrent firm. The status of the data when the transaction is viewing the data is either the status before the transaction is modified or the status after the transaction is modified. The transaction does not view the data in the intermediate status. This is called serializability because it can reload the starting data and replays a series of transactions so that the State at the end of the data is the same as that of the original transaction execution.
Durability
After the transaction is completed, its impact on the system is permanent. This modification will be maintained even if a system failure occurs.

3. What is the role of a cursor? How do I know that the cursor has reached the end?
The cursor is used to locate the rows in the result set. by determining the global variable @ fetch_status, you can determine whether the result set is reached. Generally, this variable is not equal to 0, indicating that an error or the result set is reached.


4. triggers are divided into pre-trigger and post-trigger. There are differences between these two triggers. What is the difference between statement-level triggering and row-level triggering.
The trigger runs before the trigger event occurs, and the trigger runs after the trigger event. The trigger can obtain the new field values before the event.
A statement-Level Trigger can be executed before or after the statement is executed, and a row-Level Trigger is triggered once for each row affected by the trigger.

Question No: 1
1. Public class test {
Public static void changestr (string Str ){
STR = "welcome ";
}
Public static void main (string [] ARGs ){
String STR = "1234 ";
Changestr (STR );
System. Out. println (STR );
}
}
Please write the output result:
1234
Question No: 2
1. Public class test {
2. Static Boolean Foo (char c ){
3. system. Out. Print (C );
4. Return true;
5 .}
6. Public static void main (string [] argv ){
7. Int I = 0;
8. For (FOO ('A'); Foo ('B') & (I <2); Foo ('C ')){
9. I ++;
10. Foo ('D ');
12 .}
13 .}
14 .}
What is the result?
A
A. abdcbdcb
B. abcdabcd
C. Compilation fails.
D. An exception is thrown at runtime.

Question No: 3
1. Class {
2. Protected int Method1 (int A, int B) {return 0 ;}
3 .}
Which two are valid in a class that extends Class? (Choose two)
A. Public int Method1 (int A, int B) {return 0 ;}
B. Private int Method1 (int A, int B) {return 0 ;}
C. Private int Method1 (int A, long B) {return 0 ;}
D. Public short Method1 (int A, int B) {return 0 ;}
E. Static protected int Method1 (int A, int B) {return 0 ;}

Question No: 4
1. Public class Outer {
2. Public void someoutermethod (){
3. // line 3
4 .}
5. Public class inner {}
6. Public static void main (string [] argv ){
7. Outer o = new outer ();
8. // line 8
9 .}
10 .}
Which instantiates an instance of inner?
A. New inner (); // At line 3
B. New inner (); // At line 8
C. New O. Inner (); // At line 8
D. New outer. Inner (); // At Line 8 // new outer (). New inner ()

Question No: 5
Which method is used by a servlet to place its session ID in a URL that is written to the Servlet's response output stream?
A. The encodeurl method of the httpservletrequest interface.
B. The encodeurl METHOD OF THE httpservletresponse interface.
C. The rewriteurl method of the httpservletrequest interface.
D. The rewriteurl method of the httpservletresponse interface.

Question No: 6
Which two are equivalent? (Choose two)
A. <% = yoshibean. Size %>
B. <% = yoshibean. getsize () %>
C. <% = yoshibean. getproperty ("size") %>
D. <JSP: getproperty id = "yoshibean" Param = "size"/>
E. <JSP: getproperty name = "yoshibean" Param = "size"/>
F. <JSP: getproperty id = "yoshibean" property = "size"/>
G. <JSP: getproperty name = "yoshibean" property = "size"/>

Question No: 7
Which of the following statements regarding the lifecycle of a session bean are correct?
1. java. Lang. illegalstateexception is thrown if sessioncontext. getejbobject () is invoked when a stateful Session Bean instance is passivated.
2. sessioncontext. getrollbackonly () does not throw an exception when a session bean with bean-managed transaction demarcation is activated.
3. An exception is not thrown when sessioncontext. getusertransaction () is called in the afterbegin method of a bean with container-managed transactions.
4. JNDI access to Java: COMP/ENV is permitted in all the sessionsynchronization methods of a stateful session bean with container-managed transaction demarcation.
5. Accessing resource managers in the sessionsynchronization. afterbegin method of a stateful session bean with bean-managed transaction does not throw an exception.

Part 2: Concept questions
1. Describe the struts architecture? What are the main development tasks of each part?

 

 

 

 

 

 

2. What are the explanations and differences of XML?

 

 

3. What built-in objects and actions does JSP have? What are their functions?

 

 

 

 

 

 

4. SQL Q &
Select * from table
And
Select * from table
Where name like '%' and ADDR like '%'
And (incluaddr like '%' or 2_addr like '%'
Or 3_addr like '%' or 4_addr like '% ')
Why are different search results?

 

5. SQL Q &
Table Structure:
1. Table Name: g_cardapply
Field (field name/type/length ):
G_applyno varchar 8; // application Ticket No. (keyword)
G_applydate bigint 8; // application date
G_state varchar 2; // Application Status
2. Table Name: g_cardapplydetail
Field (field name/type/length ):
G_applyno varchar 8; // application Ticket No. (keyword)
G_name varchar 30; // requester name
G_idcard varchar 18; // requester ID card No.
G_state varchar 2; // Application Status
The joined fields of the two tables are the application form numbers.
Question:
1. query the application date with ID card number 440401430103082
2. query the ID number and number of records with more than two records for the same ID card number
3. Change the application status of the 440401430103082 ID card in both tables to 07.
4. Delete all records surnamed Li in the g_cardapplydetail table

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.