Java interview series 11

Source: Internet
Author: User

Question no: 1 publicclass Test1 {publicstaticvoid changeStr (String str) {str = "welcome";} publicstaticvoid main (String [] args) {String str = "1234 "; changeStr (str); System. out. println (str) ;}/// output result: 1234 // although this is a static method, the variable in it is a local variable, // This is not because it is a static method. I mistakenly believe that the variable in it is also a static variable. QUESTION NO: 2 publicclass Test2 {staticboolean foo (char c) {System. out. print (c); returntrue;} publicstaticvoid main (String [] argv) {in T I = 0; // for (65; 88 & (I <2); 67) for (foo ('A'); foo ('B ') & (I <2); foo ('C') {I ++; foo ('D') ;}}/* What is the result? A. ABDCBDCBB. ABCDABCDC. compilation fails. d. an exception is thrown at runtime. // The output result is: ABDCBDCB analysis: the conditions in the FOR loop must be true. It has nothing to do with your regular expression. It is like here, although it is a printed letter, but it is not false, so you can execute the first loop: foo ('A') to print the letter A. (Note: if it is not false, the default condition is true) foo ('B') print the letter B, I = 0, compare (I <2), the condition is true, perform the loop body, foo ('D ') print Dfoo ('C') print letter C second loop: foo ('B') print B, I = 1, compare (I <2) is true, carry out the loop body, foo ('D') print Dfoo ('C') print letter C third cycle: foo ('B') print letter B, I = 2, comparison (I <2) false. Exit the loop. The result is */question no.: 3 1. class A {2. protected int method1 (int a, int B) {return 0;} 3.} Which two are valid in a class that extends class? (Choose two). 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 ;} publicclass B extends A {/*** @ paramargs * // can not reduce the visibility of the inherited method from A // the method that cannot be used to continue from Class visibility Lower // private int method1 (int a, int B) {return 0 ;} // This static method cannot hide the instance method from A // the static method cannot hide the instance that inherits from A // static protected int method1 (int a, int B) {return 0;} // The return type is inconsistent with the method in A // public short method1 (int a, int B) {return 0;}/*** summary: in class inheritance, if you want to reload the parent class method, you must be consistent with the return type, visibility, and so on in the parent class * otherwise, the program will report an error. The subclass must follow the parent class principle. * The answer I selected was privateintmethod1 and staticprotectedint. * The reason why I chose the first one was that it was originally protected, if I set this parameter to public, the original visibility is extended. * It is originally invisible to the outside of the package and is now visible to the outside of the package, so I chose private *. The second error is that all of them are protected. Here it is changed to static. * // here I wrote an overload method, because the parameter types are inconsistent, privateint method1 (int a, long B) {return 0;} // The visibility can be increased but cannot be reduced. Correct publicint method1 (int, int B) {return 0;} publicstaticvoid main (String [] args) {// TODO Auto-generated met Hod stub} question no: 4 1. public class Outer {2. public void someOuterMethod () {3. // Line 34 .} 5. public class Inner {} 6. public static void main (String [] argv) {7. outer o = new Outer (); 8. // Line 89 .} 10 .} which instantiates an instance of Inner? A. new Inner (); // At line 3B. new Inner (); // At line 8C. new o. inner (); // At line 8D. new Outer. inner (); // At line 8 // new Outer (). new Inner () Answer: publicclass Outer {publicvoid someOuterMethod () {// Line 3 new Inner (); // No error is reported here} publicclass Inner {} publicstaticvoid main (String [] argv) {Outer o = new Outer (); // Line 8 // o cannot be interpreted as a type, error // new o. inner ();/*** the following error is reported for both of the following usage: * Noenclosinginst AnceoftypeOuterisaccessible. * Mustqualifytheallocationwithanenclosinginstance * oftypeOuter (e. g. x. newA () wherexisaninstanceofOuter) * // new Outer. inner (); // 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? That method is used by servlet to insert its session ID into a url, which is written to the servlet response output stream.). 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). <% = 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 Re 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 wi Th 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 1. describe the Struts architecture? What are the main development tasks of each part? Struts is an implementation of MVC. It uses Servlet and JSP tags (belonging to the J2EE specification) as part of the implementation. Struts inherits various MVC features and makes corresponding changes and extensions based on J2EE features. The architecture and working principle of Struts are shown in Figure 2: 1) Model (Model) in the Struts architecture, the Model is divided into two parts: the internal status of the system and the operations (transaction logic) that can change the status ). The internal status is usually represented by a group of Actinform beans. Depending on the design or application complexity, these beans can be self-contained and continuous, or only obtain data (from a database) as needed ). Large applications typically encapsulate transaction logic (Operations) within a method, which can be called by bean with state information. For example, the shopping cart bean has the information of the purchased items, and the checkOut () method may be used to check the user's credit card and send the order information to the warehouse. In small programs, operations may be embedded in the Action class, which is part of the controller role in the struts framework. This method is suitable when the logic is simple. We recommend that you separate the transaction logic (what to do) from the role played by the Action class (what to do. 2) The View is mainly created by JSP. struts contains the TagLib, which simplifies the process of creating a completely internationalized user interface. Currently, tag libraries include Bean Tags, HTML tags, Logic Tags, Nested Tags, and Template Tags. 3) Controller in struts, the basic Controller component is the instance servelt in the ActionServlet class. The actually used servlet is mapped by a group in the configuration file (described by the ActionMapping class). Operations on business logic are mainly completed by the Action, ActionMapping, and ActionForward components. Action acts as the real implementer of business logic, actionMapping and ActionForward specify the operation direction of different business logic or processes. Struts-config.xml file configuration controller. 2. What are the explanations and differences of XML? Including: DOM (Document Object Modal) Document Object Model, SAX (Simple API for XML ). DOM reads the entire document into the memory at a time. If the document is small and the file is read into the memory, the operation speed can be greatly improved. However, if the document is large, this will be difficult. At this time, the SAX application was born, instead of reading the entire document into the memory at a time, which is more powerful for processing large documents. 3. What built-in objects and actions does JSP have? What are their functions? JSP has the following nine basic built-in components: request client requests, this request will contain the response page of the response Parameter response from the GET/POST request to the user. The response pageContext page attribute is used to manage the out of the content being executed by the application servlet during the session related to the request. send Response output config servlet framework Part page JSP page itself exception for the error page, common uncaptured components: request, response, out, session, application, exception 4. SQL Q & A SELECT * FROM TABLE AND SELECT * FROM TABLE WHERE NAME LIKE '%' AND ADDR LIKE '%' AND (1_ADDR LIKE '%' OR 2_ADDR LIKE '%' OR 3_ADDR LIKE '%' OR 4_ADDR LIKE '%') Why is the retrieval result different? A: I did a test. In ACCESS, I used it for query. This will be different from MYSQL. You may try it, I used SQL query in ACCESS yesterday. The result is blank, that is, no records. In MYSQL, records with null conditions are not displayed, and others are displayed. 5. SQL Q & A table structure: 1. Table Name: g_cardapply field (field name/type/length): g_applyno varchar 8; // Application Form Number (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; // applicant's name g_idcard varchar 18; // applicant's ID card number g_state varchar 2; // application status where the join fields of the two tables are application form numbers. Question: 1. query the application date of ID card number 440401430103082 Select g_cardapply.g _ applydate from g_cardapply, g_cardapplydetail where g_cardapplydetail.g_idcard = ''and g_cardapply.g_applyno = numbers. query ID card numbers and number of records with more than two records for the same ID card number. 3. Apply for records with ID card number 440401430103082 in two tables. the status is changed to 07 Update g_cardapply. g_state = '07', g_cardapplydetail. g_state 4. Delete all records surnamed Li in the g_cardapplydetail table ------------------------ ******* test ******* ----------------- create database mianshi use mianshi; create table g_cardapply (g_applyno varchar (8), g_applydate bigint, g_state varchar (20) gocreate table g_cardapplydetail (g_applyno varchar (8), g_name varchar (30 ), g_idcard varchar (18), g_state varchar (20 )) 1. select a1.g _ applydate from g_cardapply as a1 inner join g_cardapplydetail a2 ona1.g _ applyno = a2.g _ applyno where a2.g _ idcard = "123"; 2. select g_idcard, count (g_idcard) from g_cardapplydetail group by g_idcard having count (g_idcard)> = 2; 3. update g_cardapply set g_state = 603 from g_cardapply as g_d inner join g_cardapplydetail as g_c ong_d.g_applyno = g_c.g_applyno and g_idcard = '000000 '; update g_state update g_cardapplydetail set g_state = 603 where g_idcard = '000000' in the first table ';

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.