Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:java

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
becki:linux:java [2009-04-28 10:10]
becki
becki:linux:java [2010-10-19 12:50] (aktuell)
becki
Zeile 1: Zeile 1:
 ====== Java == ====== Java ==
-===== Links ==+===== Related Pages ==
  
-[[sunkurs]] [[comparison table]]+<​pagelist>​ 
 +  * [[java plumbing]]  
 +  * [[java web programming]] 
 +  * [[apache click]] 
 +  * [[apache tomcat]] 
 +  * [[jrunscript]] 
 +</​pagelist>​
  
 ===== Java Versions and Compatibility == ===== Java Versions and Compatibility ==
Zeile 78: Zeile 84:
 </​code>​ </​code>​
  
-===== Applets == +===== Rich Internet Applications == 
-==== Requirements ​==+ 
 +FIXME Whole secton is obsoete. See [[java plumbing]] instead! 
 + 
 +==== Java Web Start == 
 + 
 +This might help: http://​www.developer.com/​java/​web/​article.php/​3828811 
 + 
 +==== Applets == 
 +=== Embedding in HTML == 
 + 
 +Easiest is to use the [[javatut>​uiswing/​components/​applet.html#​plugin|applet tag]] 
 + 
 +See also: 
 + 
 +  * [[http://​www.developer.com/​java/​article.php/​3841566/​|Java ARchive (JAR) Files]] tutorial 
 +  * [[javaref>​technotes/​guides/​plugin/​developer_guide/​using_tags.html|Using applet, object and embed Tags]] 
 +  * [[http://​java.sun.com/​products/​plugin/​versions.html|Encountering OBJECT, EMBED, and APPLET Tags With Different Plug-in Versions and Browsers]] 
 +  * The CODEBASE-attribute of the applet-tag has a different meaning of the CODEBASE-attribute of the object-tag! 
 +  * [[javaref>​technotes/​guides/​plugin/​developer_guide/​java_js.html|Java-to-Javascript Communication]] (needs plugin.jar) 
 + 
 +=== Code Template == 
 + 
 +It is [[javatut>​deployment/​applet/​|recommended]] to use ''​JAppled''​ instead of ''​Applet''​. Therefore the rest of this section is obsolete. An example for the use of ''​JAppled''​ is provided [[java#​deploy_both_as_applet_and_jws|below]].
  
 <code java> <code java>
Zeile 95: Zeile 123:
   - inherited from java.awt.Container   - inherited from java.awt.Container
 see also Java Tutorial Sun: Lesson: Overview of Applets see also Java Tutorial Sun: Lesson: Overview of Applets
- 
-==== Embedding in HTML == 
- 
-see: 
-  * [[javatut>​uiswing/​components/​applet.html#​plugin|Sun Java Tutorial -> Swing -> Applets]] and continuative links 
-  * [[javaref>​technotes/​guides/​plugin/​developer_guide/​using_tags.html|Using applet, object and embed Tags]] 
-  * [[http://​java.sun.com/​products/​plugin/​versions.html|Encountering OBJECT, EMBED, and APPLET Tags With Different Plug-in Versions and Browsers]] 
-  * The CODEBASE-attribute of the applet-tag has a different meaning of the CODEBASE-attribute of the object-tag! 
-  * [[javaref>​technotes/​guides/​plugin/​developer_guide/​java_js.html|Java-to-Javascript Communication]] (needs plugin.jar) 
  
 ===== Events == ===== Events ==
Zeile 166: Zeile 185:
 String s= ""​+ 4711; String s= ""​+ 4711;
 String s= new Integer(4711).toString();​ String s= new Integer(4711).toString();​
 +String s= String.valueOf(4711);​
 </​code>​ </​code>​
  
Zeile 265: Zeile 285:
 </​code>​ </​code>​
  
-===== Threads ​====== +===== Collections ​== 
-==== Thread States ​======+==== Overview == 
 + 
 +[[javatut>​reallybigindex.html#​collections|Chapter in the Java tutorial]] 
 + 
 +|  //​[[javaref>​api/​java/​util/​Collection.html|Collection]]// ​ ||||  //​[[javaref>​api/​java/​util/​Map.html|Map]]// ​ || 
 +|  //​[[javaref>​api/​java/​util/​Set.html|Set]]// ​ ||  //​[[javaref>​api/​java/​util/​List.html|List]]// ​ |  //​[[javaref>​api/​java/​util/​Queue.html|Queue]]// ​ |  || 
 +|  |  //​[[javaref>​api/​java/​util/​SortedSet.html|SortedSet]]//​ |  |  |  |  //​[[javaref>​api/​java/​util/​SortedMap.html|SortedMap]]// ​ | 
 +| HashSet LinkedHashSet | TreeSet | LinkedList Vector ArrayList | LinkedList, PriorityQueue | HashTable LinkedHashMap HashMap | TreeMap | 
 + 
 +==== Implementations ​== 
 + 
 +  * [[javatut>​collections/​implementations/​|Overview]] 
 +  * [[http://​www.developer.com/​java/​article.php/​3829891|Selecting the Best Java Collection Class for Your Application]] 
 +  * [[javatut>​collections/​implementations/​map.html|General purpose map implementations]] 
 + 
 +==== Methods == 
 + 
 +<code java> 
 +// important methods of List: 
 +boolean add(E e) 
 +void add(int index, E element) 
 +boolean contains(Object o) 
 +E get(int index) 
 +int indexOf(Object o) 
 +Iterator<​E>​ iterator() 
 +E remove(int index) 
 +boolean remove(Object o) // Removes the first occurrence 
 +Object[] toArray() 
 +<T> T[] toArray(T[] a) 
 + 
 +// important methods of Map 
 +boolean containsKey(Object key) 
 +boolean ​ containsValue(Object value) 
 +V get(Object key) 
 +Set<​K>​ keySet() // Returns a set of the keys 
 +V put(K key, V value) // there is no add! 
 +V remove(Object key) 
 + 
 +// important methods of Queue: 
 +boolean offer(E o) // Inserts the specified element at the end; also add() possible 
 +E peek() // Retrieves, but does not remove, 
 +E poll() // Retrieves and removes from the beginning; remove() also possible 
 +</​code>​ 
 + 
 +  * Set: has no special order and no duplicates are permitted, not indexed; methods ar a subset of List (no index operations) 
 +  * List: ordered, duplicates are permitted, indexed 
 +  * Map does not implement the collection interface 
 +  * '​Sorted'​ is a subset of '​Ordered'​ 
 +  * Ordering: 
 +    * //Lists// are always ordered by index 
 +    * //Linked// collections are always ordered by insertion or last access 
 +    * //Tree// collections are always sorted 
 +  * List can made thread-save by Collections.synchronizedList() 
 +  * Tutorial: Vector is a legacy class; API: Vector is a normal class; Hashtable is similar; Vector also implements List 
 +  * HashSet & LinkedHashSet:​ Overwrite hashCode() so that equal objects provide the same hashcode 
 +  * LinkedList implements //List// and //Queue// 
 +  * //Queue// has Fifo (not stack) behaviour! 
 +  * All Interfaces have a size() method 
 +  * PriorityQueue sorts Elements by natural order using Comparable 
 +  * Elements for SortedSet/​TreeSet,​ SortedMap/​TreeMap 
 + 
 + ​PriorityQueue must implement the Comparable interface! 
 +  * String implements interface Comparable<​String>​ and Integer implements Comparable<​Integer>​ -> Trying to add both Types to any untyped (old style) Tree-Container results in a ClassCastException 
 +  * Whereas adding only the same Type (eg Strings) works but gives a compiler warning. (I assume the type is detected at run time by reflection and the Object to compare is casted to String before compareTo() is called.) 
 + 
 +==== Sorting and Searching == 
 +=== Sorting with the Comparable Interface == 
 + 
 +To sort a //List// (eg ArrayList) or an array use: 
 +<code java> 
 +static void Collections.sort(List<​T>​ list); 
 +static void Arrays.sort(allPrimitivesAndObject[] a); 
 +</​code>​ 
 +The List interface has no sort method! All elements in the List or array must implement the Comparable interface:​ 
 + 
 +<code java> 
 +Interface Comparable<​T>​ { 
 +    int compareTo(T o); 
 +
 +</​code>​ 
 +Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Keep in mind that compareTo accepts Type T (the generic of the List) wheras equals always only accepts type Object! 
 + 
 +=== Sorting with the Comparator Interface == 
 + 
 +<code java> 
 +static void Collections.sort(List<​T>​ list, Comparator<?​ super T> c); 
 +static void Arrays.sort(T[] a, Comparator<?​ super T> c); // T is an Object, no primitives! 
 + 
 +Interface Comparator<​T>​ { 
 +    int compare(T o1, T o2); 
 +
 +</​code>​ 
 + 
 +=== Searching == 
 + 
 +<code java> 
 +static int Collections.binarySearch(List<​T>​ list, T key[, Comparator<?​ super T> c]); 
 +static int Arrays.binarySearch(allPrimitivesAndObject[] a, allPrimitivesAndObject key); 
 +static int Arrays.binarySearch(T[] a, T key, Comparator<?​ super T> c); 
 +</​code>​ 
 +Call binarySearch() with the array or List as first param, the key as second, and, if not all items implement the Comparable interface, provide a Comparator as 3rd parameter. List or array has to be sorted before binarySearch can be called, otherwise the result is not predictable! If the element is not found, binarySearch returns -length-1 
 + 
 +===== Threads == 
 +==== Basics == 
 + 
 +A thread owns the locks on one or more objects. The lock of an object can only have one thread as owner. 
 + 
 +Only one thread can access the code in a syncronized method or code block at one time. ''​syncronized''​ refers always to an object, not to code; the lock is acquired per object. 
 + 
 +==== Thread States ​==
  
 <​code>​ <​code>​
Zeile 275: Zeile 404:
 Verify: As a rule of thumb, only the current thread can bring itself from state Running to another state, other threads can't. Verify: As a rule of thumb, only the current thread can bring itself from state Running to another state, other threads can't.
  
-==== Creating a Thread ​======+==== Creating a Thread ==
  
 Two techniques for providing a run method for a thread: Two techniques for providing a run method for a thread:
Zeile 376: Zeile 505:
 Got exception in HelloThread! Got exception in HelloThread!
 Good bye from SlaveThread! Good bye from SlaveThread!
-</​code>​ 
- 
-=== Open ==== 
- 
-<code java> 
-ThreadGroup getThreadGroup() // ? Returns the thread group to which this thread belongs. 
-isAlive() 
 </​code>​ </​code>​
  
Zeile 474: Zeile 596:
 ==== Misc == ==== Misc ==
  
 +  * Possibly useful: [[ibm>​java/​library/​j-javadev2-7.html|Kilim]] //actors// instead of threads for concurrent programming
   * [[http://​www.developer.com/​design/​article.php/​3680701|Thread local static variables]] (Threads Versus The Singleton Pattern)   * [[http://​www.developer.com/​design/​article.php/​3680701|Thread local static variables]] (Threads Versus The Singleton Pattern)
   * Possibly useful: Simple thread control with [[http://​www.developer.com/​java/​article.php/​3713031|CountDownLatch]]   * Possibly useful: Simple thread control with [[http://​www.developer.com/​java/​article.php/​3713031|CountDownLatch]]
Zeile 677: Zeile 800:
         t1.state= Tribool.State.FALSE;​ t0.state= Tribool.State.FALSE;​         t1.state= Tribool.State.FALSE;​ t0.state= Tribool.State.FALSE;​
         System.out.println((t0.and(t1)).toString());​         System.out.println((t0.and(t1)).toString());​
- 
     }     }
 } }
 </​code>​ </​code>​
  
-===== open questions ​todo ======+===== Further Reading ​2do ==
  
 +  * Intro to the [[ibm>​java/​library/​j-5things9.html|Java Scripting API]] with [[jrunscript]]
 +  * Doc general Java strategy: Use [[Apache Pivot]] for the GUI, [[JUnit]] for testing, [[Apache Ant]] for building, JWS for distribution and [[Groovy]] for coding
 +  * [[http://​www.linux-magazin.de/​Heft-Abo/​Ausgaben/​2008/​08/​Reiches-Angebot|Webentwicklung mit Java]]: An Overview (german)
 +  * [[http://​www.ibm.com/​developerworks/​opensource/​library/​os-lombok/​|Eliminate Java verbosity with  Lombok]]
 +  * REST (with AJAX):
 +    * Wink is a framework for building RESTful Web services
 +      * [[ibm>​web/​library/​wa-aj-jackson/​|Wink with Jackson]], a [[http://​jackson.codehaus.org/​|Java JSON-processor]]
 +      * [[ibm>​web/​library/​wa-aj-richjava/​|Build rich Java Web applications with Apache Wink and Ajax]]
 +      * [[ibm>​web/​library/​wa-apachewink1/​|RESTful Web services with Apache Wink]]
 +    * [[http://​www.developer.com/​article.php/​3843846|JAX-RS]]:​ The Java API for RESTful Web Services
 +    * [[http://​www.developer.com/​article.php/​3841046|Real World REST]] using Jersey, AJAX and JSON
 +  * [[http://​www.developer.com/​java/​article.php/​3837316/​|Non-Blocking I/O Made Possible in Java]]
   * Dick Wall [[http://​www.developer.com/​java/​ent/​print.php/​10933_3813031_1|recommends]] to create a reusable genericized ''​Pair''​ (and ''​Triple''​) class (like in the C++ Standard Library) for the main purpose of being able to conveniently and typsave return more values at once from a method.   * Dick Wall [[http://​www.developer.com/​java/​ent/​print.php/​10933_3813031_1|recommends]] to create a reusable genericized ''​Pair''​ (and ''​Triple''​) class (like in the C++ Standard Library) for the main purpose of being able to conveniently and typsave return more values at once from a method.
-  * Do have to make classes final to optimize? see [[http://​www.ibiblio.org/​javafaq/​javafaq.html#​xtocid1902957]]+  ​* [[http://​www.developer.com/​java/​ent/​print.php/​3623781|Internationalization in Java]] using string resource referencesis better than ResourceBundle'​s (?) 
 +  ​* Do we have to make classes final to optimize? see [[http://​www.ibiblio.org/​javafaq/​javafaq.html#​xtocid1902957]]
becki/linux/java.1240913445.txt.gz · Zuletzt geändert: 2009-04-28 10:10 von becki

Impressum - Datenschutzerklärung