Problem and answers when Java written test

xiaoxiao2021-03-06  88

Some time ago Because of the need to participate in a written test, two articles about the written test topic were found during the preparation period. One of the articles for the << Excited: Applicable to the Java written test, there is a question, there is another one, read I was deeply inspired. In the process of looking for these answers, I recorded the relevant answers, and formed these things. It is necessary to have the following answers that there are many incomplete or even mistakes. You need to correct it and improve it, don't throw my eggs. I hope this article can help the colleagues who are going to the written test site, and more people want more people to join these work that collects the test and the improvement of the answer, and make a better acquisition opportunity to make a better contribution. I would like to thank the authors of the authors of the written test topic. If you have any comments and suggestions, please contact me by QQ: 6045306, mail: huijunzi@21cn.com. Java foundation:

1, the scope public, private, protected, and the difference in not writing A: Differences are as follows: Scope Current classpublic √ √ √ √Protected √ √ × Friendly √ √ × × private √ × × × × × private × × × × × × privat Do not write, default is Friendly

2. ARRAYLIST and VECTOR differences, the difference between HashMap and HashTable: ARRAYLIST and Vector are mainly from the second aspect. I. Synchronization: Vector is a thread safe, that is, the synchronization, and arraylist is the line program. Safe, not synchronized two. Data growth: When you need to grow, Vector default growth is the original training, and ArrayList is the original half of Hashmap and HashTable mainly from three aspects. I. Historical reasons: HashTable is an implementation of the old Dictionary class. Hashmap is an implementation of the MAP interface introduced by Java 1.2. Synchronism: HashTable is the thread security, that is, HashMap is not safe. What is not synchronized. Value: Only HashMap allows you to take null values ​​as a key or value of a table.

3, CHAR type variables can not be stored in Chinese Chinese characters why A: It is possible to define a Chinese, because Java is encoded in Unicode, a char accounts for 16 bytes, so putting a Chinese is no problem.

4, many threads have several implementation methods, what is the synchronization of several implementation methods, what is the answer: Multi-thread has two implementation methods, which are two kinds in the implementation of THREAD classes and the implementation of Runnable interface synchronization. Synchronized, Wait and Notify, respectively

5, inherited the execution order problem, generally a choice question, ask you what answer will be printed: Parent Class: Package Test; Public Class FatherClass {PUBLIC FatherClass () {System.out.Println ("FatherClass Create" );}} subclasses: package test; import test.FatherClass; public class ChildClass extends FatherClass {public ChildClass () {System.out.println ( "ChildClass Create");} public static void main (String [] args) { FatherClass fc = new FatherClass (); ChildClass cc = new ChildClass ();}} the output: C: /> java test.ChildClassFatherClass CreateFatherClass CreateChildClass Create6, the internal implementation class a: the following sample code: package test; public class OuterClass {private class InterClass {public InterClass () {System.out.println ( "InterClass Create");}} public OuterClass () {InterClass ic = new InterClass (); System.out.println ( "OuterClass Create");} public static void main (String [] args) {OuterClass oc = new OuterClass ();}} The output: C: /> java test / OuterClassInterClass CreateOuterClass Create a further example: public class OuterClass {private double d1 = 1.0; // INSERT CODE Here} you need to inse Rt An Inner Class Declaration At line 3. Which Two Inner Class Declarations Are

Valid (Choose Two.) A. Class Innerne {Public Static Double Methoda () {Return D1;}} B. Public Class Inner ' {RETURN D1;}} D. static class innerone {protected Double methoda () {Return D1;}} E. Abstract Class Inner '};}; And non-statically internal classes cannot have static members. Therefore, A, B is wrong. Non-static members of static internal classes can access the external class static variables, and the unstatic variables of the external class; RETURN D1 error.

Therefore, D is not three. Non-static members of non-static internal classes can access unstatic variables of external classes. Therefore, C is correct. The answer is C, E

7, garbage collection mechanism, how to optimize the program, I hope everyone will make up, thank you 8, FLOAT type float f = 3.4 is correct answer: incorrect. The accuracy is not accurate, and it should be converted with a mandatory type, as shown below: float f = (float) 3.4

9. Introduction of Collection Framework in Java (including how to write your own data structure) Answer: Collection Framework as follows: Collection├List│├LINKEDLIST│├ARRAYLIST│ └Vector│ └stack └STMAP├HASHTABLOLESHMAP└WEAKHASHMAPCOLLECTION is the most basic Collecting interface, a collection represents a group of object, ie the element of Collection (Elements) MAP provides mapping of Key to Value

10. Abnormal handling mechanism, event mechanism in Java?

11. Proffles and inheritance in Java? I hope everyone will make up, thank you.

12, abstract class and interface? A: Abstract class and interface are used for abstraction, but the abstract class (Java) can have its own partial implementation, and the interface is completely an identifier (both multiple inheritance functions).

13, Java communication programming, programming questions (or question and answer), programming, read servers several characters, and write to local displays in Java Socket? A: Server end program: package test; import java.net. *; Import java.io. *;

public class Server {private ServerSocket ss; private Socket socket; private BufferedReader in; private PrintWriter out; public Server () {try {ss = new ServerSocket (10000); while (true) {socket = ss.accept (); String RemoteIP = Socket.Getinetaddress (). gethostaddress (); string remotEport = ":" Socket.getlocalPort (); system.out.println ("a client com in! ip:" remoteip remoteport); in = new buffredReader New

InputStreamReader (Socket.GetinputStream ()); string line = in.readline (); system.out.println ("Cleint Send IS: line); OUT = New PrintWriter (socket.getputstream (); OUT .println ("Your Message Received!"); out.close (); in .close (); socket.close ();}}} catch (ooException e) {Out.println ("WRONG");}} public static Void Main (String [] args) {new server ();}}; client side program: package test; import java.io. *; import java.net. *;

Public class client {socket; buffredreader in; printwriter out; public client () {try {system.out.println ("try to connection 127.0.0.1:10000); socket = new socket (" 127.0.0.1 ", 10000); System.out.println ( "! The Server Connected"); System.out.println ( "Please enter some Character:"); BufferedReader line = new BufferedReader (newInputStreamReader (System.in)); out = new PrintWriter (Socket.getputStream (), true); out.println (line.readline ()); in = new buffreme (new input.getinputstream ()); system.out.println (In.Readline ()); Out.close (); in.close (); socket.close ();} catch (ooException e) {outputln ("wrong");}} public static void main (String [] args) {new client }};

14. Use Java to achieve a method of sorting, Java class to realize serialization (two)? As in the Collection framework, what kind of interface is to be achieved? A: Sort by the insertion method is as follows Package Test; import java.util. *; Class insertsort {arraylist al; public insertsort (int Num, int mod) {al = new arraylist (num); random rand = new random () System.out.println ("The ArrayList Sort Before:"); for (INT i = 0; i {al.add (new integer (math.abs (rand.nextint ())% mod 1)); system .out.println ("Al [" i "] =" al.get (i));}} public void sortit ()}} public void sortit () {integer tempint; int maxSize = 1; for (int i = 1; i {tempint = (Integer) Al.Remove (i); if (Tempint.intValue ()> = ((Integer) Al.Get (MaxSize-1)). INTVALUE ()) {Al.Add (MaxSize, Tempint); maxSize ; System.out.println (Al.Tostring ());} else {for (int J = 0; J {IF

((Integer) Al.Get (j)). INTVALUE ()> = Tempint.intValue ()) {al.add (j, tempint); maxSize ; system.out.println (al.tostring ()); break }}}} System.out.println ("The arraylist sort after:"); for (int i = 0; i {system.out.println ("Al [" i "] =" Al.Get ( i);}} public static void main (string [] args) {INSERTSORT IS = New INSERTSORT (10,100); is.sortit ();}}} Java class implementation method is to implement java.io.Serializable interface In the Collection Framework, you can implement the comparable interface and the Comparator interface 15. Program: Write a function that intercept strings, input to a string and byte, the output is a string that is intercepted by byte. But to ensure that the Chinese characters are not It is halfway, such as "I am ABC" 4, it should be "I AB", enter "I am ABC Han DEF", 6, should output "I am ABC" instead of "half of my ABC Han". Answer: Code As follows: package test;

class SplitString {String SplitStr; int SplitByte; public SplitString (String str, int bytes) {SplitStr = str; SplitByte = bytes; System.out.println ( "The String is: '" SplitStr "'; SplitBytes =" SplitByte } Public void splitit () {int loopcount;

LoopCount = (splitstr.length ()% splitbyte == 0) (splitstr.length () / splitbyte) :( splitstr.length () / split

BYTE 1); System.out.Println ("Will Split INTO" LoopCount; for (int i = 1; i <= loopcount; i ) {if (i == loopcount) {

System.out.println (splitstr.substring ((i-1) * splitbyte, splitstr.length ()));} else {

System.out.println (splitstr.substring ((i-1) * splitbyte, (i * splitbyte)));}}} public static void main (STRING [] args) {splitstring ss = new splitstring ("TEST DDD Wen DSAF Chinese Men 3443N China 43 Chinese

0ewldfls = 103 ", 4); ss.splitit ();}}

16, Java multi-thread programming. Write a multi-thread program with Java, such as writing four threads, two plus 1, two to one variable minus one, output. I hope everyone will make up, thank you 17, String and StringBuffer. A: The length of String is invisible, and the length of StringBuffer is variable. If you use the content in the string, especially when you want to modify, use StringBuffer, if you finally need String, use StringBuffer's toString () method

JSP

1, what built-in objects in JSP is the answer: JSP has the following 9 basic built-in components (can correspond to the six internal components of the ASP): Request User Request, this request will contain parameters from Get / POST request Response web page Reconsive User's Responding to the PageContext page The properties of the page are here to manage the session and requests related session period Application Servlet is executing the contents of the output of the response to the response. Config servlets. Capture exception

2. What are the action effects of JSP A: JSP has the following six basic action JSP: include: Introduction: Introducing a file when the page is requested. JSP: Usebean: Find or instantiate a JavaBean. JSP: setProperty: Sets the properties of JavaBean. JSP: getProperty: Outputs the properties of a JavaBean. JSP: Forward: Turn the request to a new page. JSP: Plugin: Generate Object or Embed tag according to the browser type.

3, Dynamic INCLUDE and Static Include in JSP? Answer: Dynamic include uses JSP: Include action to implement it to check the changes in the file included in the file, suitable for inclusion of dynamic pages, and can be implemented with the parameter static include 码 码, customize the change of the file included Applicable to include static pages

4, what is the difference between the two jump methods: There are two kinds, respectively: The frontier page does not turn to include the page referred to in INCLUDE, just display the result of the page, the main page is still the original page. It will come back later, which is equivalent to the function call. And can be used with parameters. The latter is completely turned to a new page and will not come back. Equivalent to the GO TO statement.

Servlet

1. Say the life cycle of the servlet: servlet has a good definition of life, including loading and instantiation, initialization, processing request, and service end. This survival period is expressed by the init, service, and destroy method of the javax.servlet.servlet interface.

2, the alternative to the servlet version (forgot what two versions of the question) I hope everyone will make up, thank you

3, the difference between forward () and redirect () in the Java Servlet API? A: The former is only the steering of the control of control in the container. It does not show the turn-behind address in the client browser address bar; the latter is completely jump, the browser will get the address of the jump, and re-re- Send a request link. Thus, the link address after the jump is seen from the address bar of the browser. Therefore, the former is more efficient, and when the former can meet the needs, try to use the forward () method, and this also helps to hide the actual link. In some cases, for example, you need to jump into a resource on a further server, you must use the sendRedirect () method. 4, Servlet basic structure public class ServletName extends HttpServlet {public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {} public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}}

JDBC, JDO

1, you may let you write a JDBC even Oracle program and implement data queries. A: The program is as follows: package hello.ant; import java.sql. *; Public class jdbc {string dburl = "JDBC: Oracle: Thin: @ 127.0.0.1: 1521: ORCL "; string theuser =" admin "; string thepw =" manager "; connection c = null; statement conn; result set = null; public jdbc () {Try {class.forname (" Oracle .jdbc.driver.racledriver "). Newinstance (); c = drivermanager.getConnection (DBURL, THEUSER, THEPW); conn = c.createment ();} catch (exception e) {E.PrintStackTrace ();}} PUBLIC boolean executeUpdate (String sql) {try {conn.executeUpdate (sql); return true;} catch (SQLException e) {e.printStackTrace (); return false;}} public ResultSet executeQuery (String sql) {rs = null; try {RS = Conn.executeQuery (SQL);} catch (sqlexception e) {E.PrintStackTrace ();} return} public void close ()} public void close (); c.close ();} catch (EXCEPTION E) {E.PrintStackTrace ();}} public static void main (string [] AR GS) {RSULTSET RS; JDBC conn = new jdbc (); rs = conn.executeQuery ("SELECT * from test"); try {whele (rs.next ()) {system.out.println (rs.getstring " ID ")); system.out.println (Rs.getString (" name "));}} catch (exception e) {E.PrintStackTrace ();}}} 2, the role of Class.Forname is using: Calling this access Returns an object of a class that specifies a class name with a string.

3, JDO is what A: JDO is a new norm of Java object persistence, for Java Data Object, is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage, so that the developer does not require additional code (such as the JDBC API). These cumbersome routines have been transferred to the JDO product provider, so that developers are freed out to concentrate on time and energy logically. In addition, JDO is flexible because it can run on any data underlayer. JDBC is just more common to relational database (RDBMS) JDO, providing storage capabilities of any data underlying, such as relational database, file, xml, and object database (ODBMS), etc., make it stronger to apply portability. 4. Subject solution in Oracle's large amount of data. Generally, the ID method is used, and there is a three-layer nested method. A: A paging method

// Output content // Output page Tour connection total: / first

HREF = "list.jsp page ="> Previous

[]

Next page last page

XML aspect

1, what are the analysis of the analysis of the technical differences: Dom, SAX, Stax and other DOM: It is very powerful when processing large files. This problem is caused by the tree structure of the DOM. This structure is more memory, and the DOM must load the entire document into memory before parsing the file, suitable for the random access of XML SAX: not now in Dom, SAX is Event drive type XML parsing method. It sequentially reads the XML file, and does not need to load all files all. When encountered at the beginning of the file, the end of the document, or the label is ended, it triggers an event, the user handles the XML file by writing processing code in its callback event, suitable for the order of XML, Streaming API For XML (stax)

2. You use what aspects of XML technology in the project answer: use data storage, information configuration two aspects. When doing a data exchange platform, the data that cannot be data sources cannot be assembled into an XML file, and then the XML file is compressed and encrypted, and then transmitted to the recipient through the network, and the decryption is decryled and decompressed and the related information is reduced in the XML file. When doing software configuration, it is easy to use XML, and the various configuration parameters of the software are stored in the XML file.

3. How to resolve Chinese issues when using JDom to resolve the Chinese problem, how to resolve the answer: see the following code, solve the package test; import java.io. *; Public class domtest {private string infile = "c: // people. XML "; private string outfile =" c: //people.xml "; public static void main (string args [) {new domtest ();} public domtest () {try {javax.xml.parsers.DocumentBuilder Builder =

javax.xml.parsers.DocumentBuilderFactory.newInstance () newDocumentBuilder ();. org.w3c.dom.Document doc = builder.newDocument (); org.w3c.dom.Element root = doc.createElement ( "teacher"); org .w3c.dom.Element Wang = doc.createElement ("King"); org.w3c.dom.Element Liu = Doc.createElement ("Liu"); wang.Appendchild (Doc.createTextNode ("I am Teacher Wang") ); root.appendChild (wang); doc.appendChild (root); javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory.newInstance () newTransformer ();. transformer.setOutputProperty (javax.xml.transform .Outputkeys.encoding, "gb2312"); transformer.setputProperty (javax.xml.transform.outputkeys.indent, "yes"); Transformer.Transform (New javax.xml.transform.dom.dom, new

Javax.xml.transform.Stream.StreamResult (outfile);} catch (exception e) {system.out.println (E.getMessage ());}}}

4, programming with Java to parse XML way. A: Use SAX mode to parse XML, XML files are as follows:

Wang Xiaoming Information School 6258113 Male, 1955, Ph.D., 95 years to Hainan University Event Return class saxhandler.java import java.io. *; import java.util.hashtable; import org.xml.sax. *; Public class saxhandler Extends HandlerBase {private Hashtable table = new Hashtable (); private String currentElement = null; private String currentValue = null; public void setTable (Hashtable table) {this.table = table;} public Hashtable getTable () {return table;} public void startElement (String tag, AttributeList attrs) throws SAXException {currentElement = tag;} public void characters (char [] ch, int start, int length) throws SAXException {currentValue = new String (ch, start, length);} public void endElement (String name) THROWS SAXEXCEPTION {IF (Currentelement.equals (name)) Table.put (Currentelement, CurrentValue);}} JSP content display source code, SAXXML.JSP: EJB

1. What are the difference between EJB 2.0 and EJB 1.0 and EJB1.1: Specification includes bean provider, application assembly, EJB container, EJB configuration tool, EJB service provider, system management member. In this regard, the EJB container is the core of EJB. The EJB container manages EJB creation, undo, activation, deactivation, and the database connection, etc. Important work. JSP, Servlet, EJB, JNDI, JDBC, JMS .....

2, the difference between EJB and Java Bean? A: Java bean is a reused component, which does not have a strict specification for Java Bean. In theory, any Java class can be a bean. In general, since the Java bean is created (such as Tomcat) by the container, the Java Bean should have a 11-free constructor, in addition, the Java Bean also implements the Serializable interface to implement the persistence of beans. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model, which cannot be accessed across the process. Enterprise Java Bean is equivalent to DCOM, ie distributed components. It is based on Java-based remote method call (RMI) technology, so EJB can be remotely accessed (cross processes, cross-computers). But EJB must be deployed in a container such as WebSpere, WebLogic, and EJB customers never access true EJB components, but access them through their container. The EJB container is an agent of EJB components, and the EJB component is created and managed by the container. The client accesses the real EJB component through the container. 3, EJB A basic structure: an EJB comprises three parts: Code package Beans Remote Interface interface; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Add extends EJBObject {// some method declare} Home Code package Beans Interface interface; import java.rmi.RemoteException; import jaax.ejb.CreateException; import javax.ejb.EJBHome; public interface AddHome extends EJBHome {// some method declare} EJB class code package Beans; import java. RMI.RemoteException; import javax.ejb.sessionBean; import javx.ejb.sessionContext; public class addbean imports sessionbean {// some method Declare}

J2EE, MVC

1. Each of the MVC has those technologies to achieve how to implement the answer: MVC is the shortcoming of Model-View-Controller. "Model" is the application's business logic (implemented by javabean, ejb component), "view" is the application's representation surface (generated by JSP page), "Controller" is a process control (generally a servlet) The application logic, processing procedure, and display logic are achieved by this design model into different components. These components can interact and reuse.

2, the difference between application servers and web server? I hope everyone will make up, thank you.

3, what is J2EE? A: JE22 is a multi-dimi-Diered, distributed, distributed, component-based, based on Component-Base, in which an application system can follow Function is divided into different components that can be on different computers and are in the corresponding hierarchy (TIER). The hierarchies are included in the ClientN Tier components, web layers, and components, Business layers, and components, and corporate information systems (EIS) layers. 4. Web service noun explanation. JSWDL development package. JAXP, JAXM explanation. SOAP, UDDI, WSDL Explanation. A: Web Service Description Language WSDL SOAP, Simple Object Access Protocol, is a lightweight protocol for exchange XML encoding information. The purpose of UDDI is to establish standards for e-commerce; UDDI is a web-based, distributed, implementation standard specification provided by the information registry for Web Service, and also includes a group of web services that can provide themselves. Register to achieve the implementation of the access protocols that other companies can discover.

5, links and differences between BS and CS. I hope everyone will make up, thank you.

6, Struts Application (such as Struts Architecture) A: Struts is a Framework that uses Java Servlet / JavaServer Pages technology to develop web applications. The Struts can develop an application architecture based on MODEL-View-Controller design mode. Struts has the following main functions: I contain a controller servlet to send the user's request to the corresponding Action object. II.Jsp Free Tag Library and provide association support in the Controller Servlet to help developers create interactive form applications. 3. Provide a series of practical objects: XML processing, automatically handle JavaBeans properties, international tips and messages through Java Reflection APIs.

Design mode

1. In the development of the design mode, what is used in what is used: Each mode describes a problem that has emerged in our environment and then describes the core of the solution. In this way, you can use the existing solutions countlessly without counting the same job. Mainly used in the design pattern of MVC. Used to develop JSP / Servlet or J2EE related applications. Simple factory model, etc.

2, UML Answer: Standard Modeling Language UML. Model example, static map (including class diagram, object map, and package), behavioral map, interaction map (sequential diagram, cooperation map), implementation diagram,

JavaScript

1. How to verify digital VAR RE = / ^ / d {1, 8} $ | /. / D {1, 2} $ /; var str = document.form1.all (i) .value; var r = Str.match (re); if (r == null) {siGN = -4; Break;} else {document.form1.all (i) .value = parsefloat (str);}

CORBA

1, what is the use of CORBA A: CORBA standard is a common object request agency structure, which is standardized by the object management organization (Object Management Group, abbreviated as OMG). Its composition is the interface definition language (IDL), language binding (binding: also translated into a cable) and an agreement to interoperate interoperability. Its purpose is to use different programming languages ​​to write in different processes to develop in different processes.

Linux

转载请注明原文地址:https://www.9cbs.com/read-104749.html

New Post(0)