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 Different defaults to Friendly2, ArrayList and Vector Difference A: ARRAYLIST and Vector are mainly from two aspects. 1. Synchronization: Vector is a thread safe, that is, synchronization, ArrayList is an unsafe of the line program. Data growth: Data growth: When you need to grow, the vector has grown to the original training, but 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, can the CHAR type variable can not store a Chinese Chinese character? 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 implementations, what is it? Synchronize several implementation methods, what is it? A: Multi-thread has two implementation methods, inheriting the THREAD class and implementing the implementation of the Runnable interface synchronization Synchronized, WAIT and Notify5, inherited the execution order problem, generally a choice question, ask you how to print? A: Parent Class: Package Test; Public Class Fatherclass {PUBLIC FatherClass () {System 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 of the class a: sample code is as follows: 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 d ouble d1 = 1.0; // insert code here} You need to insert an inner class declaration at line 3. Which two inner class declarations arevalid A class InnerOne {public static double methoda () {return d1? (Choose two.).; }} B. Public class innerone {static double methoda () {return D1;}} c. Private class innerone {double methoda () {return D1;}} d. Static class innerone {protected double methoda () {Return D1; }} E. Abstract class innerone {public abstract double methoda (); 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, E7, garbage recycling mechanism, how to optimize the program? I hope everyone will make up, thank you 8, FLOAT float f = 3.4 is correct? A: incorrect. The accuracy is not accurate, it should be converted with a mandatory type, as shown below: float f = (float) 3.49, introduce the Collection Framework in Java (including how to write your own data structure)? A: Collection Framework as follows: Collection├List│├LinkedList │ ├ARRAYLIST│ └Vector│ └STACK etSETMAP ├WeakHashmapCollection is the most basic set interface, a collection represents a group of object, ie the Collection Map provides mapping 10, Java is abnormal Processing mechanism, event mechanism? 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 display? A: Server side 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 (1000); while (True) {socket = ss.accept (); string remoteip = socket.getinetaddress (). gethostaddress (); string remoteport = ":" socket.getlocalport (); system.out .println ( "A client come in IP:!" RemoteIP RemotePort); in = new BufferedReader (newInputStreamReader (socket.getInputStream ())); String line = in.readLine (); System.out.println ( "cleint Send is: " line); out = new printwriter (socket.getputstream (), true); 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 server: package test; import java. IO. *; import java.net. *; public class client {socket socket; bufferedreader in; printwriter out; public client () {try {system.out.println ("try to connection 127.0.0.1:10000" ); socket = new socket ("127.0.0.1", 1000); System.out.Println ("The Server Connected!"); System.out.Println ("please enter some character:"); bufferedReader line = new bufferedReader (newInputStreamReader (System.in)); out = new PrintWriter (socket.getOutputStream (), true); out.println (line.readLine ()); in = new BufferedReader (new InputStreamReader (socket.getInputStream ())); System.Out.println (in.readline ()); out.close (); in .close (); socket.close ();} catch (ioException e) {Out.println ("WRONG");
}}} public static void main (string [] args) {new client ();}}; 14 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 A: The code is 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 ) / Splitbyte 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 DD text DSAF in male big 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 aspect 1, what built-in objects do you have? A: 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 the parameter page of the Get / POST request response to the user's response to the pageContext page The attribute is the content of the session period Application Servlet is being managed here. The contents of the session period Application Servlet is used to transmit the response. 2, what do you have? What is the action? A: JSP has the following six basic action JSP: include: 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 tags based on the browser type to the Java plugin 3, Dynamic INCLUDE and Static Include in JSP? A: Dynamic include uses JSP: include Page = "incrude.jsp" flush = "true" /> It always checks the changes in the file included, suitable for using dynamic pages, and can bring The parameter static include uses the incrude pseudo code, which does not check the changes in the file included, suitable for use in the static page <% @ include file = "incruded.htm"%> 4, what is the two types of jump mode? What is it? Difference? A: There are two kinds, which are: 4, Servlet basic structure public class ServletName extends HttpServlet {public void doPost (HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {} public void doGet (HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {}} Jdbc, Jdo aspect 1, may Will 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; resulttSet RS = null; public jdbc () {Try {class.forname (" Oracle.jdbc. . driver.OracleDriver ") newInstance (); c = DriverManager.getConnection (dbUrl, theUser, thePw); conn = c.createStatement ();} 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.PrintStac KTrace ();} return}} public void close (); c.close ();} catch (exception e) {E.PrintStackTrace ();}} public static void main (String [] args) {resultSet RS; JDBC conn = new jdbc (); rs = conn.executeQuery ("select * from test"); try {whele (rs.next ()) {system.out.println (rs.getstring ("ID")); system.out.println (});}}}}} catch (exception e) {E.PrintStackTrace ();}}} 2, Class.Forname role? Use? A: Call the access to return an object that is specified by a string specified class name. 3. What is JDO? A: JDO is a new specification for the Java object persistence, which is a referred to as Java Data Object, and 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: One page method <% int i = 1; int number = 14; string pages = request.getParameter ("page"); int currentpage = 1; currentpage = (Pages == NULL)? (1): {Integer .PARSEINT (PAGES)} SQL = "SELECT Count (*) from Tables"; ResultSet RS = DBLINK.EXECUTEQUERY (SQL); while (rs.next ()) i = rs.Getint (1); int intelectCount = 1; ? intPageCount = (i% numPages == 0) (i / numPages) :( i / numPages 1); int nextPage; int upPage; nextPage = currentPage 1; if (nextPage> = intPageCount) nextPage = intPageCount; upPage = CurrentPage-1; if (UPPage <= 1) UPPAGE = 1; rs.close (); SQL = "Select * from Tables"; rs = dblink.executeQuery (SQL); i = 0; While ((i 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, which aspects do you use to use XML technology? How to implement? A: 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 solve Chinese problems when using JDOM to resolve the Chinese problem? How to resolve? A: Look at the following code, use the encoding method to 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 I ")); 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.setOutputProperty (javax.xml.transform.OutputKeys.INDENT, "yes"); transformer.transform (new javax.xml.transform.dom.DOMSource (doc) Newjavax.xml.transform.Stream.StreamResult (outfile);} catch (exception e) {system.out.println (E.getMessage ());}}} 4, programming Java parsing XML method. A: The XML file is parsed in SAX, the XML file is as follows: XML Version = "1.0" encoding = "GB2312"?> 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: