Oreilly upload source components

  Abstract: Oreilly upload source components 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> upload open source components.    Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ Back 

Chinese Version jdom2.5 source jive

  Abstract: Chinese Version jdom2.5 source jive 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> learning jsp Forum production and design patterns classical source.    </ Td> </ tr> <tr> 

  ↑ Back 

JSP source holy message boards

  Abstract: holy JSP source message board 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="362" height="86" align="center" valign="top"> 

  JSP source holy message boards 

  Win2k Server procedures Resin + + + Mysql J2sdk Below passed. 

  Lyb to copy the folder to your virtual directory. 
  Chclyb copy the folder to X: \ mysql \ data \ Below. 
  Class class_lyb copied to the folder Below, at the same time changed its name to lyb 

  Operation http://127.0.0.1:8080/lyb/ 

  See! 

  If you have any problems please contact 
  Chen_shengjie@tom.com 

  PS: There is no copyright. 

  </ Td> <td width="377" valign="top"> </ td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> 

  </ Td> </ tr> <tr> 

  ↑ Back 

Javabean automatically to the source

  Abstract: javabean automatically to the source 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="338" height="86" align="left" valign="top"> 

  Following is the source java 

ReturnTo.java

  Package examples; 
  Import java.io. *; 
  Import java.util .*; 
  Import javax.servlet .*; 
  Import javax.servlet.http .*; 
  / * 
  Automatic steering javabean 
  * / 
  Public class ReturnTo extends HttpServlet 
  ( 
  Private String Msg; 
  Private String Rurl; 
  Private boolean isA; 

  </ Td> <td width="346" valign="top"> </ td> </ tr> </ table> 

  Public void setMsg (String inMsg) ( 
  This.Msg = inMsg; 
  ) 

  Public void setRurl (String inRurl) ( 
  This.Rurl = inRurl; 
  ) 

  Public void setIsA (boolean inisA) ( 
  This.isA = inisA; 
  ) 

  Public String getMsg () ( 
  Return this.Msg; 
  ) 

  Public String getRurl () ( 
  Return this.Rurl; 
  ) 

  Public boolean getIsA () ( 
  Return this.isA; 
  ) 

  Public void go (HttpServletResponse response) throws IOException, ServletException ( 
  PrintWriter out = response.getWriter (); 
  Out.print ( "<script language='javascript'>"); 
  If (this.isA) ( 
  Out.print ( "alert ( '" + + "!');"); Msg 
  ) 
  Out.print ( "location.href = '" + Rurl +"';"); 
  Out.print ( "</ script>"); 
  ) 
  ) 

  Application test.jsp 

  <% @ Page contentType = "text / html; GBK charset ="%> 

<%
  String Msg = "automatic shift in …."; 
  String Url = "http://www.java3z.com"; 
  We.setMsg (Msg); 
  We.setRurl (Url); 
  We.setIsA (true); 
  We.go (response); 
%>

  Notes: 

  1: Save the file position 

  ReturnTo.class ===> web-inf/classes/examples / 

  Test.jsp arbitrary position 

  2, wrote this page is not too many of javascript code:) simply frivolous. 

  3, in testing jdk1.5 tomcat + + win2k3 through. 

  </ Td> </ tr> <tr> 

  ↑ Back 

Access to a database with Struts source

  Abstract: Access to a database with Struts source 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> 
  First, preparation work 
  Create a database in access eBookStore.mdb and table book (download from the Site), and in the windows control panel set up good data source page 

  <table Width="681" height="24" border="0"> <tr> <td width="412"> at eBookStore.mdb.    Three other needs jar documents: 

  1, commons-dbcp-1.2.1.jar 
  Download Address: http://apache.linuxforum.net/dist/jakarta/commons/dbcp/binaries/ 

  2, struts-legacy.jar 
  Download Address: http://apache.linuxforum.net/dist/jakarta/struts/struts-legacy/ 

  3, commons-pool-1.2.jar 
  Download Address: http://apache.linuxforum.net/dist/jakarta/commons/pool/binaries/ 

  Second, struts-config.xml configuration 
  <? Xml version = "1.0" encoding = "ISO-8859-1"> </ td> <td width="259"> </ td> </ tr> </ table> 
  Struts-config PUBLIC 
  "- / / Apache Software Foundation / / DTD Struts Configuration 1.2 / / EN" 
  "Http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> 




















<form-beans>
  </ Form-beans> 












  3. Action categories: DataSourceAction.java 

  Package page; 
  Import org.apache.struts.action .*; 
  Import javax.servlet.http .*; 

  Import java.util .*; 
  Import javax.sql .*; 
  Import java.sql .*; 

  Public class DataSourceAction extends Action ( 

  Public DataSourceAction () () 

  Public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, 
  HttpServletResponse response) throws Exception ( 
  Try ( 
  This.getDataSource DataSource ds = (request, "dataSource"); 
  Connection con = ds.getConnection (); 
  Statement stmt = con.createStatement (); 
  String sql = "SELECT * FROM book"; 
  ResultSet rs = stmt.executeQuery (sql); 
  Request.setAttribute ( "result", rs); 
  ) Catch (Exception e) ( 
  E.printStackTrace (); 
  System.out.println ( "Database Connection unusual"); 
  ) 



  Return (mapping.findForward ( "success")); 
  ) 
  ) 

  Fourth, the test page: testpage.jsp 

  <% @ Page contentType = "text / html; charset = gb2312" language = "java"%> 
  <% @ Page import = "java.sql .*"%> 

<%
  ResultSet rs = (ResultSet) request.getAttribute ( "result"); 
  While (rs.next ()) ( 
  Out.println (rs.getString ( "name ")+"—–"); 
  Out.println (rs.getString ( "author") + " 
");
  ) 
%>

  OK!! 

  5.    Test: 
  Test Site downloaded from the directory structure TestPage Add tomcat the webapps directory in the browser, type: 
  Http://127.0.0.1:8080/TestPage/page.do 
  Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ Back 

Hanoi Tower animation demo source

  Abstract: Hanoi Tower animation demo source 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="255" height="86" align="center" valign="top"> </ td> <td width="429" valign="top"> 
  Hanoi Tower animation demo source. 

  Hanoi Tower Yuanyou from ancient India, the legend is a temple, which is the centre of the universe.    Placed in a temple above inserted three long peg with the wood, in which a peg, top-down of the 64 have been placed in ascending from the diameter circular metal sheets.    Ancient Hindu god instructed its 64 monks will go to the metal in the three peg on which one.    During each of the provisions in the mobile, can only remove a metal piece, and in the process must be maintained pieces of metal from the top diameter is ascending order, in other words, regardless of which one peg, the circular Metal films are smaller in diameter was placed on top.    Until one day, monks can be 64 to the metal in accordance with the rules specified peg from the root of all mobile peg to another, then, that subsequent to the end of the world, and all the world will eventually be destroyed, everything are approaching the World of Ultimate Bliss. 

  </ Td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> 

  Procedures diagram: 

  Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ Back 

AbstractList source analysis

  Abstract: The source of AbstractList 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="457" height="86" align="center" valign="top"> 

  List AbstractList to provide a framework to achieve, which the statement is as follows: 
  Public abstract class AbstractList extends AbstractCollection implements List 
  Below look at the way in this category 

  Public boolean add (Object o) ( 
  Add (size (), o); 
  Return true; 
  ) 
  Directly call methods add (int index, Object o) at the end inserted into a data 

  Abstract public Object get (int index); 
  The method of achieving 

  Public Object set (int index, Object element) ( 
  Throw new UnsupportedOperationException (); 
  ) 
  The method unsupported 

  Public void add (int index, Object element) ( 
  Throw new UnsupportedOperationException (); 
  ) 
  The method is not supported, this is a direct impact on the above public boolean add (Object o) method. 

  Public Object remove (int index) ( 
  Throw new UnsupportedOperationException (); 
  ) 
  The method unsupported 

  Public int indexOf (Object o) ( 
  ListIterator e = listIterator (); 
  If (o == null) ( 
  While (e.hasNext ()) 
  If (e.next () == null) 
  Return e.previousIndex (); 
  Else () 
  While (e.hasNext ()) 
  If (o.equals (e.next ())) 
  Return e.previousIndex (); 
  ) 
  Return -1; 
  ) 
  The method was designated in the list of elements in the index, positive search and find is a minimum. 
  It will not return to the 1, the situation will not traverse the entire list. 

  Public int lastIndexOf (Object o) ( 
  ListIterator ListIterator e = (size ()); 
  If (o == null) ( 
  While (e.hasPrevious ()) 
  If (e.previous () == null) 
  Return e.nextIndex (); 
  Else () 
  While (e.hasPrevious ()) 
  If (o.equals (e.previous ())) 
  Return e.nextIndex (); 
  ) 
  Return -1; 
  ) 

  </ Td> <td width="227" valign="top"> </ td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> 

xmlns:dc=”http://purl.org/dc/elements/1.1/”

xmlns:trackback=”http://madskills.com/public/xml/rss/module/trackback/”>

rdf:about=”http://blog.csdn.net/treeroot/archive/2004/09/14/104743.aspx”

dc:identifier=”http://blog.csdn.net/treeroot/archive/2004/09/14/104743.aspx”

dc:title=”AbstractList源码分析”

trackback:ping=”http://tb.blog.csdn.net/TrackBack.aspx?PostId=104743″ />   Document.write (""); 

  This method is almost the same as above, but from the front after facing only to find, is an index to find the maximum. 

  Public void clear () ( 
  RemoveRange (0, size ()); 
  ) 
  Clearly between the two indexing all the elements, including the beginning, not including the end, see removeRange methods. 

  Public boolean addAll (int index, Collection c) ( 
  Boolean modified = false; 
  Iterator e = c.iterator (); 
  While (e.hasNext ()) ( 
  Add (index + +, e.next ()); 
  Modified = true; 
  ) 
  Return modified; 
  ) 
  This method calls through the cycle add methods to achieve, because each method call add the following elements must complete the shift, a mobile needs 
  C.size (), and relatively low efficiency.    Sub-category will generally cover this method. 

  Public Iterator iterator () ( 
  Return new Itr (); 
  ) 
  There is a category within Itr, see the following definition. 

  Public ListIterator listIterator () ( 
  Return listIterator (0); 
  ) 
  Back to the default list iteration, starting position in the forefront. 

  Public ListIterator listIterator (final int index) ( 
  If (index <0 | | index> size ()) 
  Throw new IndexOutOfBoundsException ( "Index:" + index); 
  Return new ListItr (index); 
  ) 
  Check cross-border, also has an internal ListItr category, see the following definition. 

  Following is the definition of Itr: 
  The Iterator interface: http://blog.csdn.net/treeroot/archive/2004/09/11/101589.aspx 

  Private internal category 
  Private class Itr implements Iterator ( 
  Int cursor = 0; 
  Records of the cursor position 

  Int lastRet = -1; 
  Last call next () or previous () Index, in fact no definition of previous Iterator (). 

  Int expectedModCount = modCount; 
  Revised record number in AbstractList modCount defined in the List for structural change in the number of words. 
  Here to visit the Iterator ListIterotor List, and a concurrent visit, we discussed this issue back again. 

  Public boolean hasNext () ( 
  Return cursor! = Size (); 
  ) 
  If the cursor does not mean that the current set of size (0 to less certain size () -1 of a value) that are under a value. 
  Size () is the method of AbstractList. 

  Public Object next () ( 
  Try ( 
  Object next = get (cursor); 
  CheckForComodification (); 
  LastRet = cursor + +; 
  Return next; 
  ) Catch (IndexOutOfBoundsException e) ( 
  CheckForComodification (); 
  Throw new NoSuchElementException (); 
  ) 
  ) 
  Comparison of hate here is a call AbstractList get in the way (int index), where a system to capture anomalies (which may not capture the abnormal) IndexOutOfBoundsException.    In any case first made the visit with abnormal ConcurrentModificationException 
  (If any).    Under normal circumstances the current cursor and the last visit have been added to an index. 

  Public void remove () ( 
  If (lastRet == -1) 
  Throw new IllegalStateException (); 
  CheckForComodification (); 
  Try ( 
  AbstractList.this.remove (lastRet); 
  If (lastRet <cursor) 
  Cursor -; 
  LastRet = -1; 
  ExpectedModCount = modCount; 
  ) Catch (IndexOutOfBoundsException e) ( 
  Throw new ConcurrentModificationException (); 
  ) 
  ) 
  If last visit index is 1 (Iterator has just been such that when the time), dished out IllegalStateException anomaly. 
  Otherwise the deletion of the elements, if the elements in the current cursor before the cursor value to advancement.    Iterator change because it is the structure of the List, 
  Here, we must amend expertedModCount value.    If the deletion of time here when cross-border, it is revising the other places in the List, 
  So dished out to visit with abnormal.    NOTE: To set up here to lastRet -1, and at this time can not call ListIterator remove the add, set the method. 

  Final void checkForComodification () ( 
  If (modCount! = ExpectedModCount) 
  Throw new ConcurrentModificationException (); 
  ) 
  ) 
  If the two local record number of amendments are not the same, that there are other places in revising the List. 
  ) 

  Following is the definition of ListItr: 
  The ListIterator Interface: http://blog.csdn.net/treeroot/archive/2004/09/14/104608.aspx 

  Internal private category 
  Private class ListItr extends Itr implements ListIterator ( 
  ListItr (int index) ( 
  Cursor = index; 
  ) 
  Constructor function, initialize the current cursor position. 

  Public boolean hasPrevious () ( 
  Return cursor! = 0; 
  ) 
  0 current cursor that is not in front element. 

  Public Object previous () ( 
  Try ( 
  Int i = cursor - 1; 
  Object previous = get (i); 
  CheckForComodification (); 
  LastRet = cursor = i; 
  Return previous; 
  ) Catch (IndexOutOfBoundsException e) ( 
  CheckForComodification (); 
  Throw new NoSuchElementException (); 
  ) 
  ) 
  Back to the current cursor before an element of the cursor and the last visit index has changed, the reference concurrency control Itr 

  Public int nextIndex () ( 
  Return cursor; 
  ) 
  Under an element of the same index and the current cursor. 

  Public int previousIndex () ( 
  Return cursor-1; 
  ) 
  Needless to say 

  Public void set (Object o) ( 
  If (lastRet == -1) 
  Throw new IllegalStateException (); 
  CheckForComodification (); 
  Try ( 
  AbstractList.this.set (lastRet, o); 
  ExpectedModCount = modCount; 
  ) Catch (IndexOutOfBoundsException e) ( 
  Throw new ConcurrentModificationException (); 
  ) 
  ) 
  Calling the set of external, concurrency control in reference Itr remove an explanation of the methodology. 

  Public void add (Object o) ( 
  CheckForComodification (); 
  Try ( 
  AbstractList.this.add (cursor + + o); 
  LastRet = -1; 
  ExpectedModCount = modCount; 
  ) Catch (IndexOutOfBoundsException e) ( 
  Throw new ConcurrentModificationException (); 
  ) 
  ) 
  Itr remove reference in an explanation of the methodology. 
  ) 

  Back to the method AbstractList 
  Public List subList (int fromIndex, int toIndex) ( 
  Return (this instanceof RandomAccess? 
  New RandomAccessSubList (this, fromIndex, toIndex): 
  New SubList (this, fromIndex, toIndex)); 
  ) 
  If the List has RandomAccess interface, a new return RandomAccessSubList example, 
  Otherwise return a SubList example, the two categories defined in the back. 

  Public boolean equals (Object o) ( 
  If (o == this) 
  Return true; 
  If (! (O instanceof List)) 
  Return false; 

  ListIterator e1 = listIterator (); 
  ListIterator e2 = ((List) o). ListIterator (); 
  While (e1.hasNext () & & e2.hasNext ()) ( 
  Object o1 = e1.next (); 
  Object o2 = e2.next (); 
  If (! (O1 == null? O2 == null: o1.equals (o2))) 
  Return false; 
  ) 
  Return! (E1.hasNext () | | e2.hasNext ()); 
  ) 
  Comparison of this method is simple and traverse through the list to compare the two, only two elements of the list, as well as the same sequence is exactly the same as before. 

  Public int hashCode () ( 
  Int hashCode = 1; 
  Iterator i = iterator (); 
  While (i.hasNext ()) ( 
  Object obj = i.next (); 
  HashCode hashCode * = 31 + (obj == null? 0: obj.hashCode ()); 
  ) 
  Return hashCode; 
  ) 
  This method can be fully guaranteed: List equal to two hashCode also their equal. 

  Protected void removeRange (int fromIndex, int toIndex) ( 
  ListIterator it = listIterator (fromIndex); 
  For (int i = 0, n = toIndex-fromIndex; i    It.next (); 
  It.remove (); 
  ) 
  ) 
  Adopted here iterators to delete the specified elements, and iterators remove method is called, so the efficiency of this method is not high. 

  Protected transient int modCount = 0; 
  Fenwick said that the revision of the List was the number of concurrent purpose is to control access. 

  AbstractList the end of the content, but we also used two categories: RandomAccessList and SubList. 
  SubList look at the definition: 
  (Class SubList extends AbstractList 
  Private AbstractList l; 
  Private int offset; 
  Private int size; 
  Private int expectedModCount; 

  SubList (AbstractList list, int fromIndex, int toIndex) ( 
  If (fromIndex <0) 
  Throw new IndexOutOfBoundsException ( "fromIndex =" + fromIndex); 
  If (toIndex> list.size ()) 
  Throw new IndexOutOfBoundsException ( "toIndex =" + toIndex); 
  If (fromIndex> toIndex) 
  Throw new IllegalArgumentException ( "fromIndex (" + + fromIndex 
  ")> ToIndex (" + + ")"); toIndex 
  L = list; 
  Offset = fromIndex; 
  Size = toIndex - fromIndex; 
  ExpectedModCount = l.modCount; 
  ) 

  Public Object set (int index, Object element) ( 
  RangeCheck (index); 
  CheckForComodification (); 
  Return l.set (index + offset, element); 
  ) 

  Public Object get (int index) ( 
  RangeCheck (index); 
  CheckForComodification (); 
  Return l.get (index + offset); 
  ) 

  Public int size () ( 
  CheckForComodification (); 
  Return size; 
  ) 

  Public void add (int index, Object element) ( 
  If (index <0 | | index> size) 
  Throw new IndexOutOfBoundsException (); 
  CheckForComodification (); 
  L.add (index + offset, element); 
  ExpectedModCount = l.modCount; 
  Size + +; 
  ModCount + +; 
  ) 

  Public Object remove (int index) ( 
  RangeCheck (index); 
  CheckForComodification (); 
  Object result = l.remove (index + offset); 
  ExpectedModCount = l.modCount; 
  Size -; 
  ModCount + +; 
  Return result; 
  ) 

  Protected void removeRange (int fromIndex, int toIndex) ( 
  CheckForComodification (); 
  L.removeRange (fromIndex + offset, toIndex + offset); 
  ExpectedModCount = l.modCount; 
  Size -= (toIndex-fromIndex); 
  ModCount + +; 
  ) 

  Public boolean addAll (Collection c) ( 
  Return addAll (size, c); 
  ) 

  Public boolean addAll (int index, Collection c) ( 
  If (index <0 | | index> size) 
  Throw new IndexOutOfBoundsException ( 
  "Index:" + index + ", Size:" + size); 
  Int cSize = c.size (); 
  If (cSize == 0) 
  Return false; 

  CheckForComodification (); 
  L.addAll (offset + index, c); 
  ExpectedModCount = l.modCount; 
  Size + = cSize; 
  ModCount + +; 
  Return true; 
  ) 

  Public Iterator iterator () ( 
  Return listIterator (); 
  ) 

  Public ListIterator listIterator (final int index) ( 
  CheckForComodification (); 
  If (index <0 | | index> size) 
  Throw new IndexOutOfBoundsException ( 
  "Index:" + index + ", Size:" + size); 

  Return new ListIterator () ( 
  Private ListIterator i = l.listIterator (index + offset); 
  Public boolean hasNext () ( 
  Return nextIndex () <size; 
  ) 
  Public Object next () ( 
  If (hasNext ()) 
  Return i.next (); 
  Else 
  Throw new NoSuchElementException (); 
  ) 
  Public boolean hasPrevious () ( 
  Return previousIndex ()> = 0; 
  ) 
  Public Object previous () ( 
  If (hasPrevious ()) 
  Return i.previous (); 
  Else 
  Throw new NoSuchElementException (); 
  ) 
  Public int nextIndex () ( 
  Return i.nextIndex () - offset; 
  ) 
  Public int previousIndex () ( 
  Return i.previousIndex () - offset; 
  ) 
  Public void remove () ( 
  I.remove (); 
  ExpectedModCount = l.modCount; 
  Size -; 
  ModCount + +; 
  ) 
  Public void set (Object o) ( 
  I.set (o); 
  ) 
  Public void add (Object o) ( 
  I.add (o); 
  ExpectedModCount = l.modCount; 
  Size + +; 
  ModCount + +; 
  ) 
  ); 
  ) 

  Public List subList (int fromIndex, int toIndex) ( 
  Return new SubList (this, fromIndex, toIndex); 
  ) 

  Private void rangeCheck (int index) ( 
  If (index <0 | | index> = size) 
  Throw new IndexOutOfBoundsException ( "Index:" + + index 
  "Size:" + size); 
  ) 

  Private void checkForComodification () ( 
  If (l.modCount! = ExpectedModCount) 
  Throw new ConcurrentModificationException (); 
  ) 
  ) 
  This class inheritance AbstractList basically well understood, but there are several major needs: 
  1. Attention l.modCount, modCount, expectedModCount difference between modCount is inherited domain SubList 
  ExpectedModCount SubList is to prevent the visit with the new Canadian domain l.modCount certainly understandable. 
  2.public ListIterator listIterator (final int index) method used an anonymous category. 
  3. Attention SubList only one of the constructor function requires three parameters belt, but only a SubList view, modify SubList 
  It is amended in the list of parameters. 

  Finally, there is RandomAccessSubList 
  Class RandomAccessSubList extends SubList implements RandomAccess ( 
  RandomAccessSubList (AbstractList list, int fromIndex, int toIndex) ( 
  Super (list, fromIndex, toIndex); 
  ) 

  Public List subList (int fromIndex, int toIndex) ( 
  Return new RandomAccessSubList (this, fromIndex, toIndex); 
  ) 
  ) 
  This class is not something, but is not the same type and SubList it (because one more RandomAccess interface). 

  Analysis here is the realization of this type, there is no evaluation of this class design is good or bad, but I hate nested class is more (especially nested class can call the method category external), the return of another SubList is a view, rather than a fully independent List, so in the end好不well? 

  Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=104743 


  </ Td> </ tr> <tr> 

  ↑ Back 

A BASIC language interpreter (with source code)

  Abstract: A BASIC language interpreter (with source code) 

  </ Td> </ tr> <tr> <td width="470" height="35" valign="top" class="ArticleTeitle"> This is a java with a simple preparation of the BASIC language interpreter, only explain the following keywords: 
  PRINT INPUT IF THEN FOR NEXT 
  TO GOTO GOSUB RETURN END 
  Support digital, variable (A to Z), the operator (+-*/^=()<>>=<=<>), See Demo: 

  (Class SBDemo 
  Public static void main (String args []) 
  ( 
  If (args.length! = 1) ( 
  System.out.println ( "Usage: sbasic  ");
  Return; 
  ) 

  Try ( 
  SBasic ob = new SBasic (args [0]) / / input from the command line BASIC language source of 

  File name 
  Ob.run (); / / explain operation 
  ) Catch (InterpreterException exc) ( 
  System.out.println (exc); 
  ) 
  ) 
  ) 

  Run: 

  C: \ java> java SBDemo TEST2.BAS 
  This program demonstrates nested GOSUBs. 
  Enter a number: 9 
  9.0 18.0 27.0 36.0 45.0 54.0 63.0 72.0 81.0 
  C: \ java> 

  Below are the BASIC language source: TEST2.BAS 
  PRINT "This program demonstrates nested GOSUBs." 
  INPUT "enter a number:" I 
  GOSUB 100 

END

  100 FOR T = 1 TO I 
  X = X + I 
  GOSUB 150 
NEXT
RETURN

  150 PRINT X; 
  RETURN function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document.getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> <td width="214" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

ArrayList source analysis

  Abstract: ArrayList source analysis 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="474" height="86" align="center" valign="top"> 

  Finally can begin analysis of a specific category, we should be very familiar to ArrayList, and regardless of whether you understand how it is achieved, but we are used to it everywhere. 
  The following statement: 
  Public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable, java.io.Serializable 

   The AbstractList:  
   Http://blog.csdn.net/treeroot/archive/2004/09/14/104743.aspx  
   The List:  
   Http://blog.csdn.net/treeroot/archive/2004/09/14/104638.aspx  
   The RandomAccess:  
   Http://blog.csdn.net/treeroot/archive/2004/09/14/104538.aspx  
   The Cloneable:  
   Http://blog.csdn.net/treeroot/archive/2004/09/07/96936.aspx  
   The java.io.Serializeable: The main target for the sequence of.  

  Private static final long serialVersionUID = 8683452581122892189L; 
  Version Control 

  Private transient Object elementData []; 
  Internal structure, the original is an array, there is no serial of it. 

  Private int size; 
  The size of the list, which is the number of elements. 

  Public ArrayList (int initialCapacity) ( 
  Super (); 
  If (initialCapacity <0) 
  Throw new IllegalArgumentException ( "Illegal Capacity:" + initialCapacity); 
  This.elementData = new Object [initialCapacity]; 
  ) 
  Constructor function, internal array initialization for a specified size, the attention of the list is empty. 

  Public ArrayList () ( 
  This (10); 
  ) 
  Default if the initial internal array size 10, why is 10 is not justified, it may be more appropriate. 

  Public ArrayList (Collection c) ( 
  Size = c.size (); 
  / / Allow room for growth of 10% 
  ElementData = 
  New Object [(int) Math.min ((size * 110L) / 100, Integer.MAX_VALUE)]; 
  C.toArray (elementData); 
  ) 
  Adoption of a set of initial words to the ArrayList, internal array applications space than c, mainly for the purpose of improving efficiency.    Noting c.toArray (elementData) method call, this certainly will not generate new array If elementData = c.toArray () many of the poor efficiency.    Besides the Math here call the static method min to get smaller value. 

  Public void trimToSize () ( 
  ModCount + +; 
  Int oldCapacity = elementData.length; 
  If (size <oldCapacity) ( 
  Object oldData [] = elementData; 
  ElementData = new Object [size]; 
  System.arraycopy (oldData, 0, elementData, 0, size); 
  ) 
  ) 
  This method to remove excess space, so that the size of an array of internal ArrayList exactly equivalent to the size (), this method need to reallocate space, it needs a copy of the array (arraycopy is a native method, and use more), general under this approach rarely was called. 

  </ Td> <td width="210" valign="top"> </ td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> 

  Public void ensureCapacity (int minCapacity) ( 
  ModCount + +; 
  Int oldCapacity = elementData.length; 
  If (minCapacity> oldCapacity) ( 
  Object oldData [] = elementData; 
  Int newCapacity = (oldCapacity * 3) / 2 + 1; 
  If (newCapacity <minCapacity) 
  NewCapacity = minCapacity; 
  ElementData = new Object [newCapacity]; 
  System.arraycopy (oldData, 0, elementData, 0, size); 
  ) 
  ) 
  This method of the ArrayList to expand capacity, it can accommodate at least minCapacity elements, if array capacity greater than the value of what not to do.    Otherwise, according to a 
  Algorithm (1.5 doubly 1) increase, if not minCapacity large, it would set minCapacity.    In this method and add addAll method should call, 
  Why is set to public here?    Because every time the redistribution of space are more time consuming (even arrayCopy new operation), if the size could be expected to be 
  So, this approach will compare flexibility.    Although the expansion of the operator has been relatively good, but can, through their own or control efficiency, the method for programmers 
  Bring convenience. 
  Eg1: 
  ArrayList al = new ArrayList (); 
  For (int i = 0; i <100; i + +) ( 
  Object obj = new Object (); 
  Al.add (obj); 
  ) 
  Eg2 (more efficient): 
  ArrayList al = new ArrayList (100); 
  For (int i = 0; i <100; i + +) ( 
  Object obj = new Object (); 
  Al.add (obj); 
  ) 
  Or 
  ArrayList al = new ArrayList (); 
  Al.ensureCapacity (100); 
  For (int i = 0; i <100; i + +) ( 
  Object obj = new Object (); 
  Al.add (obj); 
  ) 

  Public int size () ( 
  Return size; 
  ) 
  Back to size 

  Public boolean isEmpty () ( 
  Return size == 0; 
  ) 
  It is empty 

  Public boolean contains (Object elem) ( 
  Return indexOf (elem)> = 0; 
  ) 
  It contains an element, called the indexOf () method. 

  Public int indexOf (Object elem) ( 
  If (elem == null) ( 
  For (int i = 0; i <size; i + +) 
  If (elementData [i] == null) 
  Return i; 
  Else () 
  For (int i = 0; i <size; i + +) 
  If (elem.equals (elementData [i])) 
  Return i; 
  ) 
  Return -1; 
  ) 
  This method Ergodic List (0 .. array size-1) 

  Public int lastIndexOf (Object elem) ( 
  If (elem == null) ( 
  For (int i = size-1; i> = 0; i -) 
  If (elementData [i] == null) 
  Return i; 
  Else () 
  For (int i = size-1; i> = 0; i -) 
  If (elem.equals (elementData [i])) 
  Return i; 
  ) 
  Return -1; 
  ) 
  This method and above the basic, just not the same sequence. 

  Public Object clone () ( 
  Try ( 
  ArrayList v = (ArrayList) super.clone (); 
  V.elementData = new Object [size]; 
  System.arraycopy (elementData, 0, v.elementData, 0, size); 
  V.modCount = 0; 
  Return v; 
  ) Catch (CloneNotSupportedException e) ( 
  / / This shouldn't happen, since we are Cloneable 
  Throw new InternalError (); 
  ) 
  ) 
  The coverage Object clone () method, clone, attention here is a shallow copy, two ArrayList in the array element 
  Is the same, because System.arraycopy is shallow copy. 

  ToArray public Object [] () ( 
  Object [] result = new Object [size]; 
  System.arraycopy (elementData, 0, result, 0, size); 
  Return result; 
  ) 
  Back to the elements of an array ArrayList, although here the attention of a new generation of the array, the array elements and the elements in the pool is shared, 
  Collection interface is safe to say that this is not strict, the following examples demonstrate this effect. 
  Eg1: 
  ArrayList al = new ArrayList (); 
  Al.add (new StringBuffer ( "hello")); 
  Object [] = a al.toArray (); 
  StringBuffer sb = (StringBuffer) a [0]; 
  Sb.append ( "changed"); / / change the array element also changes in the original elements of the ArrayList 
  System.out.println (al.get (0)); 
  String will not be used here to replace StringBuffer because String constants. 

  Public Object [] toArray (Object a []) ( 
  If (a.length <size) 
  A = (Object []) java.lang.reflect.Array.newInstance (a.getClass (). GetComponentType (), size); 
  System.arraycopy (elementData, 0, a, 0, size); 
  If (a.length> size) 
  A [size] = null; 
  Return a; 
  ) 
  This approach might not generate new array, an array that if a capacity overload, the only size set to null. 

  Public Object get (int index) ( 
  RangeCheck (index); 
  Return elementData [index]; 
  ) 
  Random Access can be seen efficiency is very high, and the array index visit is the same as the way the design to the index value will check. 

  Public Object set (int index, Object element) ( 
  RangeCheck (index); 
  Object oldValue = elementData [index]; 
  ElementData [index] = element; 
  Return oldValue; 
  ) 
  Update the value of the designated location, and visit the original value. 

  Public boolean add (Object o) ( 
  EnsureCapacity (size + 1) / / Increments modCount! 
  ElementData [size + +] = o; 
  Return true; 
  ) 
  Adding a new element to the end, the front said the new method should first call ensureCapacity method, there is no call add (size, o) method. 

  Public void add (int index, Object element) ( 
  If (index> size | | index <0) 
  Throw new IndexOutOfBoundsException ( "Index:" + index + ", Size:" + size); 
  EnsureCapacity (size +1); / / Increments modCount! 
  System.arraycopy (elementData, index, elementData, index + 1, the size - index); 
  ElementData [index] = element; 
  Size + +; 
  ) 
  Inserted in the position specified elements behind specific elements and the elements after shift. 

  Public Object remove (int index) ( 
  RangeCheck (index); 
  ModCount + +; 
  Object oldValue = elementData [index]; 
  Int numMoved = size - index - 1; 
  If (numMoved> 0) 
  System.arraycopy (elementData, index +1, elementData, index, numMoved); 
  ElementData [- size] = null; / / Let gc do its work 
  Return oldValue; 
  ) 
  Delete the specified location of the elements, elements behind the forward and return to the deleted elements here to the attention of the elementData [- size] = null this statement, 
  If this does not happen, then it may cause memory leaks, because the object has been of no use, but also one of its internal use, if we do not set 
  As null, GC will not be able to recall this space, and accumulated more could lead to memory leaks, and here only possible, but not certain. 

  Public void clear () ( 
  ModCount + +; 
  / / Let gc do its work 
  For (int i = 0; i <size; i + +) 
  ElementData [i] = null; 
  Size = 0; 
  ) 
  This code comparison efficient, here also must be set to empty cited reasons Ibid. 

  Public boolean addAll (Collection c) ( 
  ModCount + +; 
  Int numNew = c.size (); 
  EnsureCapacity (size + numNew); 
  Iterator e = c.iterator (); 
  For (int i = 0; i <NUMNEW; i + +) 
  ElementData [size + +] = e.next (); 
  Return numNew! = 0; 
  ) 
  Set c add elements to ArrayList in the end, add the successful return true if the set is empty c, returns false. 

  Public boolean addAll (int index, Collection c) ( 
  If (index> size | | index <0) 
  Throw new IndexOutOfBoundsException ( "Index:" + index + ", Size:" + size); 
  Int numNew = c.size (); 
  EnsureCapacity (size + numNew); / / Increments modCount! 
  Int numMoved = size - index; 
  If (numMoved> 0) 
  System.arraycopy (elementData, index, elementData, index + numNew, numMoved); 
  Iterator e = c.iterator (); 
  For (int i = 0; i <NUMNEW; i + +) elementData [index + +] = e.next (); 
  Size + = numNew; 
  Return numNew! = 0; 
  ) 
  Insert in the designated spots in the pool all the elements, and above a basic method similar elements and designated spots after shifting to the future. 

  Protected void removeRange (int fromIndex, int toIndex) ( 
  ModCount + +; 
  Int numMoved = size - toIndex; 
  System.arraycopy (elementData, toIndex, elementData, fromIndex, numMoved); 
  / / Let gc do its work 
  Int newSize = size - (toIndex-fromIndex); 
  While (size! = NewSize) 
  ElementData [- size] = null; 
  ) 
  This is a protection method to delete the specified location fromIndex toIndex elements, including the front does not include behind. 

  Private void RangeCheck (int index) ( 
  If (index> = size | | index <0) 
  Throw new IndexOutOfBoundsException ( "Index:" + index + ", Size:" + size); 
  ) 
  Not explained. 

  Private synchronized void writeObject (java.io.ObjectOutputStream s) throws java.io.IOException ( 
  / / Write out element count, and any hidden stuff 
  S.defaultWriteObject (); 
  / / Write out array length 
  S.writeInt (elementData.length); 
  / / Write out all elements in the proper order. 
  For (int i = 0; i <SIZE; i + +) s.writeObject (elementData [i]); 
  ) 
  Private synchronized void readObject (java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException ( 
  / / Read in size, and any hidden stuff 
  S.defaultReadObject (); 
  / / Read in array length and allocate array 
  Int arrayLength = s.readInt (); 
  ElementData = new Object [arrayLength]; 
  / / Read in all elements in the proper order. 
  For (int i = 0; i <SIZE; i + +) 
  ElementData s.readObject [i] = (); 
  ) 
  This is in order to achieve two of the serial, which is, we should pay attention to a few points here: 
  1. Java.io.Serializable two methods is not defined in the method, marking only Serializable interface. 
  2. Serial object when the first checks whether the two ways to achieve this, if they realized the call, and if not we will call the default method. 
  As for why can call the object's private methods is not clear to me, the issue is rather strange, if we can target the private visit, it 
  Too much of the insecurity. 
  3. Statement because elementData for transient, and of the need to manually serial. 

  Summary: 
  1.ArrayList methods are not synchronized, so multi-threading is unsafe and must be their own pace and ArrayList many ways statement for multi-threaded operation 
  Are not stipulated, that is the result unpredictable. 
  2.toArray () method returns and the original list is the same object, that is to say: 
  ArrayList.toArray () [0] == arrayList.get (0) to return to the true (assuming arrayList not empty). 
  3.clone () method is a shallow copy. 
  4. EnsureCapacity can, through their own call () improve efficiency. 

  </ Td> </ tr> <tr> 

  ↑ Back 

A simple web browser source code

  Abstract: a simple web browser source code 

  - Source    <link> Href ="../../ css / index.css "rel =" stylesheet "type =" text / css "> </ head> function valiform () (if (document.form2.keyword.value = =""){ alert ( "Please enter keywords!"); document.form2.keyword.focus (); return false;)) function valiform1 () (if (document.form5.pinjianame.value =="") (alert ( "Please enter names!"); document.form5.pinjianame.focus (); return false;) if (document.form5.pinjiacontent.value ==""){ alert ( "Please enter evaluation of the content!") ; document.form5.pinjiacontent.focus (); return false;)) <body bgcolor="#FFFFFF" background="../../images/background.gif" leftmargin="0" topmargin="0"> <table width="756" height="1146" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="LTR"> <tr> <td width = "754" height = "78"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width = "19%" height = "65" > </ td> <td width="81%"> <table width = "94%" height = "53" border = "0" align = "center" cellpadding = "0" cellspacing = "0" class = " LTR "> <tr> <td height="53"> 

  </ Td> </ tr> </ table> </ td> </ tr> </ table> </ td> </ tr> <tr> <td height="20" class="ArticleTeitle"> <table width = "100%" height = "25" border = "0" cellpadding = "0" cellspacing = "0" bgcolor = "# 3399FF"> <tr> <td width="29%"> size of your position {{{{{{{{{{{{{{{{{{{{{{{{ â–¡ {{{{{{{{{{{{{{{{{{{{{{{{ â–¡ Release Date {{{{{{{{{{{{{{{{{{{{{{{{ â–¡ View 
  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="739" border="0"> <tr> <td width = " 733 "> </ td> </ tr> </ table> <table width="97%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width =" 47 "height = "265" align = "center" valign = "top"> </ td> <td width="705" valign="top"> 
  <table Width="624" border="0"> <tr> <td width="377"> This is a simple web browser, forward, rewind functions.    Below is the chart: </ td> <td width="237"> </ td> </ tr> </ table> 

  </ Td> </ tr> <tr> <td height="44" colspan="2"> 

  </ Td> </ tr> </ table> 

  <script> Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore" ); document.getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ Back 

keep looking »