2D array is quite similar to 1D [[array]]. The first "number of arrays" portion will have an array of pointers to other arrays, that will either contain the actual values if primitive or references to objects.\n<html><pre>\n type [] [] array_name; // This creates the array identifier\n array_name = new type [number of arrays] [length]; // This creates the array object, the array itself.\n array_name[array index] [index]= value; // This is to place values in the array. Index starts at zero.\n\n sales[0][4] = 42;\n</pre></html>
config.options.chkHttpReadOnly = false;\n
Here is an example of ArrayList:\n<HTML><PRE>\n List<String> list = new ArrayList<String>(c);\n</PRE></HTML>
When using [[Generics]] you can restrict what parameters are allowed, sending a wrong type will cause a [[Checked]] error. In the following example, we only allow Number types.\n<html><pre>\n public <U extends Number> void inspect(U u){ ...\n// So something like the following will throw an exception:\n somename.inspect("some text"); \n</pre></html>
Boxing or autoboxing and unboxing operations are used to convert from/to primitives to/from objects (aka wrappers). Autoboxing would convert int to Integer. There are 8 primitives. Java with [[Generics]] automatically does un/boxing where needed.
''Checked'' and ''Unchecked'' refer to Java exceptions. All exceptions are subclasses from the ''Throwable'' class.\n*''Checked'' exceptions are those that can be checked by the compiler. They have to be either caught in a [[try]] statement or thrown by a [[throws]] clause in the [[method]] header. Exceptions are mostly derived from the [[Exception]] class and its many subclasses, but not from the Exception.RuntimeException class.\n*''Unchecked'' exceptions are those not ''checked'' by the compiler. These are usually severe problems or program bugs. Fatal exceptions are represented by the [[Error]] class. Other unchecked exceptions are from the Exception.RuntimeException class..\nSerious failures like VM errors the Java program should not be captured. \n
The Collection (see [[Collection Framework]]) interface is the root of the collection hierarchy. It represents in a general way a collection of objects called [[Elements]]. Think of it like a container. It is the lowest common denominator needed to implement and use collections. For more specific handling (like no duplicate data, ordered data) there are two sub-interfaces: [[Set]] and [[List]]. There is no concrete implementation of Collection, it is an interface, defined lie:\n<html><pre>\n public interface Collection <E> ...\n</pre></html>So a Collection is generic, it accepts any type. You can use the [[for-each]] and [[Iterator]] to traverse the collection.\n
The Collection Framework is an architecture (standard way) for representing and manipulating collections. The framework contains three things:\n*Interfaces - abstract types to represent collections\n*Implementation - concrete mplementations of interfaces\n*Methods/algorithms.\nCollections are used to manipulate data. It can be thought of as a container - that groups related data together. The two top level interfaces are:\n*[[Collection]] hierarchy: [[Set]], [[SortedSet]], [[List]] and [[Queue]]. \n*[[Map]] hierarchy: [[SortedMap]]. ([[Map]] is considered a collection, but not a true one.) \n\nThe Collections interface has standard methods that are available to all that instantiate it. Examples are:\n|!Signature|!Description|\n|boolean isEmpty();|determines if empty|\n|boolean add(Element);|Adds an element|\n|boolean addAll(Collection<? extends E> c);|Adds lots.|\n|Iterator<E>|Iterator over elements. The syntax ''<E>'' tells you the interface is [[Generics]].|\n\nCollections hold objects as type "Object". So placing an object into a collection means that the object loses their actual type. When they are retrieved from the collection, they have be be cast back to their original type, which is a source of errors. This is where [[Generics]] come in handy.\nCollections can use [[Iterator]] to iterate thru a collection. You can also use [[for-each]].\n
A ''Comparator'' is an interface that allows you to sort objects. It is often used in the [[collections|Collection]]. Basically - it compares two objects (arguements) returns:\n* -1 for o1 < o2\n* 0 for o1 = o2\n* 1 for o1 > o2\nThrows a ClassCastException if something is amiss.\n<html><pre>\npublic interface Comparator<T> {\n int compare(T o1, T o2);\n}\n</pre></html>\n
This is a big topic, so summarizing as best as possible. Concurrency using [[multithreading]].\nConcurrency involves using \n*[[Thread]]\n*[[Runnable]]
To create a constant, a field that cannot change,we use ''static final''.\n<html><pre>\n static final int ANSWER2LIFE = 42;\n</pre></html>\n\n
A constructor is called first in a Java method - it has the same name of the class, and have the same name as the class and do not return a value. They are only executed once, unlike regular methods that can be called many times. To call other constructors from within a constructor, use ''this()''. to call the superclass constructor use ''super()''.\n<html><pre>\n public class SomeName\n \n [modifiers] SomeName ( [arguements] ) { // Constructor Name is SomeName \n ...code ...\n }\n }\n</pre></html>\nTechnically you always call a constructor when creating an object. Even if you don't make one, a default one is created for you. A constructor can be overloaded.
[[Introduction]]\n[[TiddlyWiki]]
''Encapsulation'' refers to keeping all the related members (variables and methods) together in an object. This is important for integrity and security. We can make sure values are correct and acceptable and that other processes cannot alter them incorrectly.
Here is Enumeration to print out a [[vector]].\n<html><pre>\n Enumeration drivesEnum = drives.elements(); \n while(drivesEnum.hasMoreElements()) \n System.out.print(drivesEnum .nextElement() + " "); \n</pre></html>
Erasure (a little misnomer) removes parameters at runtime but then adds\ncasts. Types like List<Integer> and List<String> at runtime are represented\nby the same type: [[List]].\n\nErasure also keeps generics simple to read and does not add anything that \nis not already in java. There is only one implementation of List, not one \nversion for each type. And both generic & nongeneric code translates to\nthe *same* bytecode! So legacy non-generic code is fine in Java1.5 and up.
The ''Error'' class is a subclass of Throwable and is an [[Unchecked|Checked]] exception. As well, under [[Exception]] there is ~RuntimeException (and all subclasses of it) which is also [[Unchecked|Checked]]. An common example is the ~NullPointerException. Typically this is caused by something external to the application, like trying to read a file that is not there.
''Exception'' a subclass of Throwable. All subclasses of Exception are [[Checked]] exceptions. \nIf you can extend this class, this will be a [[Checked]] exception. If you extend it off of the RunTime class then it is an [[Unchecked|Checked]] exception.\nAn exception is caught by a either a\n*[[try-catch]] construct. \n*[[throws]] clause in a method.
The ''File'' object is used to create & modify & delete files. This class does not actually read into or out of a file, we'll use something else (like [[FileReader]] or [[FileWriter]]) for that. Creating an object is simple:\n<html><pre>\n File variable-name = new File(<directory-name>, <file-name>);\n</pre></html>
The ''FileReader'' object will open a file. It will read in chunks of information, but if we are handling human readable information, it makes sense to read in complete lines, so In the following example we are using ~BufferedReader. This class has the method ''~ReadLine'' to read in a line (ie terminated by a \sn) of entered text. The following will be in a [[try]] block.\n<html><pre>\n File file = new File("someFileName.ext");\n BufferedReader in = new BufferedReader(new FileReader(file));\n String s;\n s = in.readLine();\n while (s != null) {\n System.out.println("Read: " + s);\n s = in.readLine();\n }\n in.close();\n\n</pre></html>
We use ''FileWriter'' to write to files, the following example will by in a [[try]] block.\n<html><pre>\n File file = new File("something.txt");\n InputStreamReader isr = new InputStreamReader(System.in);\n BufferedReader in = new BufferedReader(isr);\n\n // Could also use the BufferedWriter.\n PrintWriter out = new PrintWriter(new FileWriter(file));\n String s;\n System.out.println("Enter something:");\n System.out.println("Enter cntl-z to exit.");\n\n while ((s = in.readLine()) != null) {\n out.println(s);\n }\n in.close();\n out.close();\n\n</pre></html>
Generics enable compile-time type-safety with classes that work on arbitrary types. [[Collections]] is a great example of something that generics has made simplier and safer to use. Generics use generic type or [[parameterized type]] invocation.\n<html><pre>\n ArrayList<Integer> list = new ArrayList<Integer>();\n list.add(new Integer(13));\n int total = list.get(0).intValue();\n list.add("test"); // Error: Will not compile!\n</pre></html>\nYou can also restrict what parameters are allowed using [[Bounded Type Parameters]].\nBe careful of subtyping generics, its not like regular classes. \n*An Integer is-a Number and a Double is-a Number, ie Integer is a subtype of Number.\n*A Box<Integer> is ''not'' a subtype of Box<Number> .\nWhy? Because generics are containers, a container for Integers cannot hold a container built for Doubles.\n
Is the best performing [[Set]] implementation, but makes no guarantees for the order of iteration.
Hashtable is a concrete implementation.
Java ''IO'' classes are all under the ''java.io'' package. There are two types of IO classes, binary & character.\n*''Binary'' classes all descend from the abstract ''InputStream'' and ''OutputStream'' classes.\n*''Character'' classes all descend from the abstract [[Reader]] and [[Writer]] classes.\n\nThere are many types of streams, files, memory and pipes. Terms to know:\n*''Stream'' - a flow of data, typically binary data.\n*''Source'' - starts flow of data. A byte stream is [[InputStream]] and a character stream is a [[Reader]].\n*''Sink'' - terminates a flow of data. A byte stream is [[OutputStream]] and a character stream is a [[Writer]].\n*''Standard Input'' - access via ''system.in'' used to read keyboard data, as a byte stream only.\n*''Standard Output'' - access via ''system.out'' used to write data to screen.\n*''Standard Error'' - access via ''system.err'' used to write error messages to screen.\n
Here are the ''IO Classes'' - which are either Character or Byte streams.\n\nHere are the classes used:\n|!Type|!Character Streams|!Byte Streams|\n|File|FileReader|FileInputStream|\n|File|FileWriter|FileoutputStream|\n|Memory Array|CharArrayReader|ByteArrayInputStream|\n|Memory Array|CharArrayWriter|ByteArrayOutputStream|\n|Memory String|StringReader|n/a|\n|Memory String|StringWriter|n/a|\n|Pipe|PipedReader|PipedInputStream|\n|Pipe|PipedWriter|PipedoutputStream|\n|Buffering|BufferedReader|BufferedInputStream|\n|Buffering|BufferedWriter|BufferedOutputStream|\n|Object Serialization|n/a|ObjectInputStream|\n|Object Serialization|n/a|ObjectOutputStream|\n\nUse ''~InputStreamReader'' to translate ''Standard Input'' byte stream data to string (unicode) data, see [[FileReader]] example.\nUse ''~BufferedReader'' to convert unbuffered data to buffered data. You can do this manually too with the ''Reader'' class.\nUse ''~DataInputStream'' to convert low level (raw) binary stream to convert to primitive data & string type.\n\n
Identifiers are the names that we give [[Constants]], [[variables]], [[method]]s and [[class]]es. They typically start with:\n*a letter\n*$ (dollar sign)\n*_ (underscore)\nand can contain numbers and letters. Case is important.
There are two types of Inheritance, Interface & Implementation. Interface inheritance is the preferred method, following a "is-a" relationship. Bike is-a Vehicle. Implementation is a "has-a" relationship. Bike has-a ~FrontWheel.\nInheritance uses the [[extend]] keyword. It is uni-directional.\n\n''Implementation (aka class inheritance):''\nThis type is where a class inherits functionality from the parent class. This is something already implemented. You can only inherit from one superclass. This is rigid, and if changes are done to the superclass, this means that all subclasses will need to be checked so that they don't break. This uses [[abstract]] classes and the [[extends]] keyword.\n \n''Interface (aka type inheritance or subtyping)''\nThis allows unrelated classes to have a relationship. This reduces the tight coupling of the above method, you program to the interface not the implementation. This method allows multiple inheritance. This uses [[interface]]s and the [[implements]] keyword.\n\nTrue multiple inheritance is not possible in Java.\n
The ''InputStream'' is an abstract class that allows us to read byte data as well as close the stream. We will typically use the [[FileInputStream]] class, to read bytes from files.
Instance variables are created whenever a class is instantiated.
Java is an [[object oriented|OO]] programming language. It has [[multithreading]] and [[Networking]] capabilities as well as automatic garbage collection lotsa other cool things. Bytecode is created by compilation and can run on any JVM on any platform. Here are some starting points:\n*[[The Basics]]\n*[[Collection Framework]]\n*[[Generics]]\n*[[IO]]\n\n
There are two ways to traverse collections: \n*with the [[for-each]] construct \n*using [[Iterators]].
An ''Iterator'' is a class that allows you to iterate thru a collection. Here is an example:\n<html><pre>\n List aList = new ArrayList();\n // Populate aList.\n Iterator iter = aList.iterator();\n while (iter.hasNext()) {\n // So something with iter.next()!\n }\n</pre></html>
An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired. You get an Iterator for a collection by calling its iterator method. The following is an example of a polymorphic, which means it works for any collection:\n<HTML><PRE>\nstatic void filter(Collection<?> c) {\n for (Iterator<?> it = c.iterator(); it.hasNext(); )\n if (!cond(it.next()))\n it.remove();\n}\n</PRE></HTML>
[[abstract]]\n[[assert]]\n[[array]]\n[[Bounded Type Parameters]].\n[[Boxing]]\n[[Checked]]\n[[class]]\n[[class variables|Static Variables]]\n[[Comparator]]\n[[Collection]]\n[[Collection Framework]]\n[[Concurrency]]\n[[conditional operator]]\n[[Constants]]\n[[Constructor]]\n[[Encapsulation]]\n[[enum]]\n[[Enumeration]]\n[[equality]]\n[[Erasure]]\n[[Error]]\n[[exception]]\n[[Exception]]\n[[exam questions]]\n[[extends]]\n
[[final]]\n[[File]]\n[[FileReader]]\n[[FileWriter]]\n[[for loop|for-each]]\n[[for-each]]\n[[Generics]]\n[[Identifiers]]\n[[implements]]\n[[Inheritance]]\n[[interface]]\n[[import]]\n[[InputStream]]\n[[instance]]\n[[Instance Variables]]\n[[instanceof]]\n[[IO]]\n[[IO Classes]]\n[[Iteration]]\n[[java.lang]] \n[[HashSet]]\n[[Hashtable]]\n[[LinkedHashSet]]\n[[List]]\n[[Map]]\n[[Math]]\n[[memory]]\n[[method]]\n[[modifiers]]\n[[multithreading]]
[[Networking]]\n[[NullPointerException]]\n[[Object]]\n[[OO]]\n[[OutputStream]]\n[[Overloading]]\n[[Overriding]]\n[[package]]\n[[Polymorphism]]\n[[primitive]]\n[[println]]\n[[process]]\n[[Queue]]\n[[Reader]]\n[[Reify]]\n[[Runnable]]\n[[runtime exceptions]]
[[Scanner]]\n[[Set]]\n[[static]]\n[[Static Initializers]]\n[[Static Methods]]\n[[Static Variables]]\n[[subclass]]\n[[substring]]\n[[super]]\n[[synchronized]]\n[[System]]\n[[Thread]]\n[[thread safety]]\n[[throws]]\n[[TreeSet]]\n[[try-catch]]\n[[Unchecked|Checked]]\n[[UML]]\n[[URL]]\n[[utility class]]\n[[varag]]\n[[variables]]\n[[vector]]\n[[Wrapper Class]]\n[[Writer]]\n[[2D array]]\n[[==|equality]]\n[[?|conditional operator]]
/***\n|''Name:''|LegacyStrikeThroughPlugin|\n|''Description:''|Support for legacy (pre 2.1) strike through formatting|\n|''Version:''|1.0.1|\n|''Date:''|Jul 21, 2006|\n|''Source:''|http://www.tiddlywiki.com/#LegacyStrikeThroughPlugin|\n|''Author:''|MartinBudden (mjbudden (at) gmail (dot) com)|\n|''License:''|[[BSD open source license]]|\n|''CoreVersion:''|2.1.0|\n|''Browser:''|Firefox 1.0.4+; Firefox 1.5; InternetExplorer 6.0|\n\n***/\n\n//{{{\n\n// Ensure that the LegacyStrikeThrough Plugin is only installed once.\nif(!version.extensions.LegacyStrikeThroughPlugin)\n {\n version.extensions.LegacyStrikeThroughPlugin = true;\n\nconfig.formatters.push(\n{\n name: "legacyStrikeByChar",\n match: "==",\n termRegExp: /(==)/mg,\n element: "strike",\n handler: config.formatterHelpers.createElementAndWikify\n});\n\n} // end of "install only once"\n//}}}\n
This implementation of [[Set]] is a hash table with a linked list. It orders its elements based on the order they are inserted into the set. It is almost as fast as HashSet, but spares a "chaotic" ordering by [[HashSet]].\nA list has:\n*Positional access: can manipulate elements based on position.\n*Search: finds specified objectand returns its position.\n*Iteration: extends [[Iterator]].\n*Range-view: performs arbitrary range operations.
A List is an ordered [[Collection]]. It is an [[interface]]. It can contain duplicates. There is precise control over data placement, as well as insert, access and delete elements based on position. One can also iterate.\n\n[[Vector]] (a concrete implementation) has been retrofitted to implement List.\n\nThere are two List implementations. \n - [[ArrayList]]: usually better-performing to random access but slow to insert/delete from middle of list..\n - [[LinkedList]]: optimal sequential access, inexpensive insertions & deletions from middle of list.\n\n
[[Introduction]]\n[[Java A-E]]\n[[Java F-M]]\n[[Java N-R]]\n[[Java S-Z]] \n\n[[JSF Notes|http://jsf.rtfm.tiddlyspot.com]]\n[[JSP Notes|http://jsp.rtfm.tiddlyspot.com]]\n[[J2EE Notes|http://j2ee.rtfm.tiddlyspot.com]]\n[[Swing|http://swing.rtfm.tiddlyspot.com/]]\n\n''Other Sites''\n[[Ruby Notes|http://ruby.rtfm.tiddlyspot.com]]\n[[JRuby Notes|http://jruby.rtfm.tiddlyspot.com]]\n[[Rails Notes|http://rails.rtfm.tiddlyspot.com]]\n[[Rails 3 Notes|http://rails3.rtfm.tiddlyspot.com]]\n[[PHP Notes|http://php.rtfm.tiddlyspot.com]]\n[[Ajax Notes|http://ajax.rtfm.tiddlyspot.com]]\n[[Javascript Notes|http://javascript.rtfm.tiddlyspot.com]]\n[[CSS Notes|http://css.rtfm.tiddlyspot.com]]\n[[Drupal Notes|http://drupal.rtfm.tiddlyspot.com]] \n[[Python|http://python.rtfm.tiddlyspot.com/]]\n[[gae|http://gae.rtfm.tiddlyspot.com/]]\n[[linux|http://linux.rtfm.tiddlyspot.com/]]\n[[nsis|http://linux.rtfm.tiddlyspot.com/]]\n\nOther Java sites: \n*[[Jane|http://www.janeg.ca/index.html]]\n*[[Javamex|http://www.javamex.com/]]\n*[[Java2s|http://www.java2s.com/Tutorial/Java/CatalogJava.htm]]\n*[[Leepoint|http://www.leepoint.net/notes-java/]]\n
A Map is a [[Collection]] that maps keys to values. It is an interface. Each key maps to only one value. Therefore, there are no duplicate keys. Maps provide a safe way to remove elements during iteration. Similar to a hash table, but with added bonus of being able to iterate key/value pairs.\nMap has three implementations:\n*HashMap - allows nulls and is unsynchronised.\n*TreeMap - self balanced binary tree, uses natural ordering or define your own [[Comparator]]. Not synchronised.\n*LinkedHashMap - like HashMap but iterates a predictable order. \n\nThe sub-interface is: [[SortedMap]]. Perfect for a dictionary.\n
The ''java.Math'' class has nothing but static methods and attributes. Math.PI has the constant value of pi. Has a random() method. Go nuts.
Java has networking capabilities and can use both [[application and transport]] layers. Communication between two computers is done by the use of [[sockets]]. A socket will have two [[streams|IO]] - an input stream and an output stream.\nTo connect to another machine you need two things:\n#Address of the machine - 32 bit IP address.\n#Port number (0-65535, 16 bit) Port numbers below 1024 are reserved for predefined services.\n''The Steps''\n#The server will use the ServerSocket class to listen on a port for a connection request.\n#The client uses the [[Socket]] class to attempt to connect - using ''Socket(host, port)''\n#The server will ''~ServerSocket.accept()'' the connection request and be passed the ''Socket'' class to communicate.\n#The file [[IO]] classes are used to communicate within the socket. \n#To terminate the connection, both client & server must ''Socket.close()'' the connection.\nThe server can handle connection & communication to many different clients on the same port.
Object Oriented Programming (OOP) has many advantages over other languages. The basic three are: [[Polymorphism]], [[Inheritance]] and [[Encapsulation]].
An object is a way of modeling the real world, by using state and behaviour. Or data (aka fields, variables) and methods (aka functions).\nWe access objects in Java by reference. For an object variable, the [[variable|The Basics]] can only have a reference to an object, whereas in a variable for a [[primitive]] we store the actual variable. So, for an object \n<html><pre>\n Vehicle fury; // This creates a variable named "fury" that can only have a reference value.\n fury = new Vehicle(); // Now the "new" operator create an object in memory and return a reference to the object.\n // The variable "fury" now has a reference to the object we have just created.\n</pre></html>\nTo access attributes or methods in an object, we use the dot notation:\n<html><pre>\n fury.wheelCount = 4; // Set the variable "wheelCount"\n String colour = fury.getColour(); // Access the method "getColour()".\n</pre></html>
The ''OutputStream'' allows us to write out byte data. We will typically use the [[FileOutputStream]] class, to read bytes from files.
[[Method]]s can be ''overloaded''. To overload a method simply have a different argument signature. The return-value has to be the same, otherwise it is a different method and not overloaded.
''Overriding'' methods.You can override methods by [[extend]]ing classes and using the same method signature. \nIf you override a method that throws exceptions, you can do one of three things:\n#Throw the same exception\n#Throw a subclass of the exception\n#Throw no exception at all.\nYou cannot do these two things:\n#Throw a parent of the original exception.\n#Throw an exception of a different type.
POJO - stands for Plain Old Java Object
''Polymorphism'' means "one object, many forms". This means that an object can be treated differently based on what object called it, This is usually done by such things as method [[overloading|Overloading]] and method overriding. and means that a superclass variable can refer to a subclass object. \n\n\nthe ability of a single variable of a given type to be used to reference objects of different types, and automatically call the method that is specific to the type of object the variable references. This means it is very easy to add new classes without breaking calling code. This is done using [[interface]]s.
A Queue is a [[Collection]] used to hold multiple elements in a queue. A Queue also provides insertion, deletion and inspection capabilities.\nQueues typically order elements as FIFO. Priority queues are non-FIFO. Each queue must specify its ordering properties.\n\nA call to remove or inspect a queue accesses the head. In a FIFO queue, all new elements are inserted at the tail. Non-FIFO queues can use \ndifferent placement rules.\n\n
The ''Reader'' class is abstract, and is used to read characters. All higher level reading functions descend from here. We will use the [[FileReader]] class, to read files.
[[Generics]] reifies array component types but does not reify [[element types]]. \n\nWhen we issue:\n\n new String[size]\n\nan array is allocated and stores info that the components are type String.\n\nWhen we issue:\n\n new ArrayList<String>()\n \na list is allocated but there is no indication of the element type. So we\nsay that Java does not reify list element types, but it does reify \ncomponent types.
Runnable is an interface with defines only the one method "run()". It allows you to create a [[Thread]] and extend it if you wish. It is preferred to use of a new [[Thread]], which if you extend - you are changing the behaviour of threads, not something you want to do.
The java.util class has a method ''Scanner'' that provides a formatted input function. That is, reading in data from keyboard as well as from network streams.
The ''ServerSocket'' class uses [[TCP|application and transport]] to communicate.\n
Set is a sub-interface of [[Collection]] and provides more specific handling of data. There are six concrete implementations of this set. A set cannot contain duplicate elements. This interface models mathematical sets and is used to represent such things as: phone numbers, poker hands...\n\nThere are three implementations of Set, in order of common use: [[HashSet]], [[TreeSet]], and [[LinkedHashSet]].\n\nThere is a sub-interface of this: [[SortedSet]]. Perfect for a membership list.
rob richards' various miscellaneous mumblings
Java Notes
A ''SortedMap'' is a sub interface of [[Map]] and is a [[Collection]] interface.Its mappings are in ascending key order. This is the Map analog of [[SortedSet]]. Sorted maps are used for naturally ordered collections of key/value pairs, such as dictionaries and telephone directories.
The ''SortedSet'' is a sub interface of [[Set]] and is a [[Collection]] interface. It keeps its elements in ascending order. Several additional operations are provided to take advantage of the ordering. Sorted sets are used for naturally ordered sets, like word and membership lists.
These are chunks of code that are only *ever* executed once, even before constructors, when the class is initially loaded.\n<html><pre>\n public static final int A = 42;\n public static final int B;;\n...\n static {\n if (A == 8) B = 99;\n else B = 13; }\n</pre></html>\nIf a method has no need to access an instance variable it may be a good candidate for being static. A static variable is useful to have only one value of something, like an object creation count! Or a count of how many times something is done - so it does not matter what particular object (all from same class) calls it, but that it was called.
''Static Methods'' aka ''Class Methods'' are methods that belong to the class, not an instance. So each instance has access to the method that is only in one spot (to be shared) in memory. As opposed to [[instance methods]] where each instance has its own copy in memory of the method. They are made like:\n<html><pre>\n static int getTheBikeCount() { return numberOfBikes; } // Declared\n ...\n Bike.getTheBikeCount() // Called like this ...\n</pre></html>
Static variables (aka ''Class Variables'') are used to have a common variable across all created objects. They are associated with the class and not the instantiated object. These variables and methods can be accessed right away, even before the object is created. If this is important, then it is right to make it static. There will only ever be one variable and one method if they are declared ([[modified|modifiers]]) as ''static''.\nThere are many built in classes that have static variables and methods like the [[Math]] class and the [[System]] class.
The ''System'' class has many [[Static Methods]] as well as [[Overloaded|Overloading]] methods, like [[println]]. Important ones are:\n|!Static Class|!I/O|!Description|\n|System.out|Standard output|Writes|\n|System.in|Standard input|Reads from keyboard.|\n|System.err|Standard error|Writes|\n
Java source files end with ''.java''. Each file typically should (but not required) have to contain, in this order:\n*[[Package|package]] declaration\n*[[Import|import]] statements\n*[[Class|class]] definitions\nJava has many keywords, like [[class]], [[foreach]], [[static]] and so forth. Identifiers are variables and must start with either a letter, underscore or a dollar sign. Identifiers cannot be a keyword. They are case sensitive.\nThere are [[primitive]] types as well as [[other]] types.\n
A ''Thread'' is a lightweight [[process]] that runs in a [[multithreading]] environment. Each thread (which is an instance of class Thread) in a process has access to all the resources of that process. The following are ''Thread'' methods:\n|!Method|!Description|\n|start()|This starts a thread, don't use run()!|\n|isAlive()|Is the thread still alive?|\n|getName() |Get the thread name. There is also set method.|\n|getPriority()|Get thread priority. There is also set method.|\n|sleep()|Puts thread in a suspended state. Must be in [[try-catch]] block. Not guaranteed to be accurate.|\n|[[interrupt()]]|This will halt the execution of a thread. A thread can interrupt itself.|\n|yield()|Let someone else use time if needed.|\n|join()|This will cause a thread to finish processing before moving on.|\n|wait()|Will cause a thread to suspend, releasing any locks it has, therefore only in [[synchronized]] code.|\n|notify()|Will notify (or wake up) a thread that is waiting for that object.|\n|yield()|Yield control to another thread.|\nFor java it is simplier to extend from the Thread class. Otherwise, you implement the Runnable interface, which is better OO design.\n
Java Notes\nhttp://www.leepoint.net/notes-java/
Is an implementation of [[Set]], slower then [[HashSet]] but orders its data based on the value. \n
UML notation for Java:\n|!Symbol|!Description|\n|#|Protected [[modifier|modifiers]].|\n|-|Private modifier.|\n|+|Public modifier.|\nUnderlines variables and methods are [[static]].\nDashed lines joining objects means implements an interface.\nSolid lines joining objects means inherits (extands) a class.
A Uniform Resource Locator or ''URL'' is a reference to locate data on the internet. The URL class provides many methods for getting port, host, ref etc information from the URL. In java to create a URL object:\n<html><pre>\n URL rtfm = new URL("http://rtfm.ca/"); // Absolute\n URL rtfmPix = new URL(rtfm, "pictures.html"); // Relative\n</pre></html>\n\n
| !date | !user | !location | !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |\n| 16/11/2006 11:41:25 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 16/11/2006 13:51:35 | rob | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 16/11/2006 13:51:35 | rob | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/4/2007 14:36:21 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 15:46:17 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:20:36 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:22:26 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:24:43 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:26:3 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:28:3 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:32:58 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/4/2007 16:34:1 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/4/2007 16:36:17 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/4/2007 16:37:10 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/4/2007 16:38:32 | rvr | [[/|http://rtfm.tiddlyspot.com/#]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/4/2007 0:7:11 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/4/2007 0:7:30 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 10/4/2007 1:53:50 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/4/2007 1:59:49 | rvr | [[rtfm(3).html|file:///C:/Documents%20and%20Settings/RobRichards/Desktop/rtfm(3).html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 10/4/2007 2:3:18 | rvr | [[rtfm(3).html|file:///C:/Documents%20and%20Settings/RobRichards/Desktop/rtfm(3).html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/4/2007 16:10:21 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 11/4/2007 0:28:5 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 11/4/2007 23:46:40 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 28/4/2007 21:9:40 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 11/5/2007 2:10:52 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/1/2008 18:27:58 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 8/1/2008 20:36:34 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/1/2008 23:9:3 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/1/2008 23:10:5 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/1/2008 23:13:52 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 20/1/2008 17:54:9 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 21/1/2008 21:38:32 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 24/2/2008 22:58:5 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 24/3/2008 18:26:57 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 11/9/2008 15:27:38 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 28/1/2009 19:26:0 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 28/1/2009 22:25:30 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 4/2/2009 19:24:25 | YourName | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/2/2009 19:10:5 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/2/2009 23:34:4 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 11/2/2009 19:40:2 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 14/2/2009 23:48:44 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 15/2/2009 14:1:23 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 15/2/2009 14:20:15 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 15/2/2009 16:58:59 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 15/2/2009 17:18:45 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/2/2009 23:26:5 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 25/2/2009 0:9:46 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 25/2/2009 0:13:15 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 25/2/2009 14:42:54 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 25/2/2009 16:28:52 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 4/3/2009 14:32:41 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 4/3/2009 17:25:29 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 4/3/2009 23:53:35 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 5/3/2009 1:20:45 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 6/3/2009 20:40:36 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/3/2009 19:7:59 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html#IO]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 11/3/2009 16:35:27 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/3/2009 23:14:7 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 1/4/2009 23:24:49 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 1/4/2009 23:27:11 | rvr | [[rtfm.html|file:///C:/Docs/notes/programming/tiddly/rtfm.html]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 1/6/2009 10:28:53 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 14/6/2009 11:40:49 | YourName | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/9/2009 14:18:16 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 23/11/2009 22:0:56 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 24/2/2010 10:48:25 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 10/8/2010 23:42:45 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 14/8/2010 10:2:41 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 15/8/2010 23:12:44 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 16/8/2010 21:52:6 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 17/8/2010 20:33:54 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 17/8/2010 20:58:13 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 17/8/2010 21:24:18 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 18/8/2010 22:44:15 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 19/8/2010 0:41:31 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 19/8/2010 19:18:42 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 19/8/2010 22:39:29 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 19/8/2010 23:38:47 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 20/8/2010 1:19:8 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 20/8/2010 10:21:8 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 20/8/2010 10:24:1 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 20/8/2010 23:11:23 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 21/8/2010 22:18:7 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 23/8/2010 20:59:13 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 24/11/2010 15:25:17 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 8/12/2010 21:28:58 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 28/2/2011 1:49:8 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 12/7/2011 10:45:43 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 12/7/2011 10:45:55 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 17/8/2011 21:22:15 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 17/8/2011 21:23:33 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 4/9/2011 22:5:30 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . | Ok |\n| 5/9/2011 23:34:37 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 12/9/2011 18:19:39 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 14/9/2011 1:16:17 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 27/9/2011 13:52:3 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |\n| 3/11/2011 21:52:51 | rvr | [[/|http://rtfm.tiddlyspot.com/]] | [[store.cgi|http://rtfm.tiddlyspot.com/store.cgi]] | . | index.html | . |
/***\n|''Name:''|UploadPlugin|\n|''Description:''|Save to web a TiddlyWiki|\n|''Version:''|3.4.4|\n|''Date:''|Sep 30, 2006|\n|''Source:''|http://tiddlywiki.bidix.info/#UploadPlugin|\n|''Documentation:''|http://tiddlywiki.bidix.info/#UploadDoc|\n|''Author:''|BidiX (BidiX (at) bidix (dot) info)|\n|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|\n|''~CoreVersion:''|2.0.0|\n|''Browser:''|Firefox 1.5; InternetExplorer 6.0; Safari|\n|''Include:''|config.lib.file; config.lib.log; config.lib.options; PasswordTweak|\n|''Require:''|[[UploadService|http://tiddlywiki.bidix.info/#UploadService]]|\n***/\n//{{{\nversion.extensions.UploadPlugin = {\n major: 3, minor: 4, revision: 4, \n date: new Date(2006,8,30),\n source: 'http://tiddlywiki.bidix.info/#UploadPlugin',\n documentation: 'http://tiddlywiki.bidix.info/#UploadDoc',\n author: 'BidiX (BidiX (at) bidix (dot) info',\n license: '[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D]]',\n coreVersion: '2.0.0',\n browser: 'Firefox 1.5; InternetExplorer 6.0; Safari'\n};\n//}}}\n\n////+++!![config.lib.file]\n\n//{{{\nif (!config.lib) config.lib = {};\nif (!config.lib.file) config.lib.file= {\n author: 'BidiX',\n version: {major: 0, minor: 1, revision: 0}, \n date: new Date(2006,3,9)\n};\nconfig.lib.file.dirname = function (filePath) {\n var lastpos;\n if ((lastpos = filePath.lastIndexOf("/")) != -1) {\n return filePath.substring(0, lastpos);\n } else {\n return filePath.substring(0, filePath.lastIndexOf("\s\s"));\n }\n};\nconfig.lib.file.basename = function (filePath) {\n var lastpos;\n if ((lastpos = filePath.lastIndexOf("#")) != -1) \n filePath = filePath.substring(0, lastpos);\n if ((lastpos = filePath.lastIndexOf("/")) != -1) {\n return filePath.substring(lastpos + 1);\n } else\n return filePath.substring(filePath.lastIndexOf("\s\s")+1);\n};\nwindow.basename = function() {return "@@deprecated@@";};\n//}}}\n////===\n\n////+++!![config.lib.log]\n\n//{{{\nif (!config.lib) config.lib = {};\nif (!config.lib.log) config.lib.log= {\n author: 'BidiX',\n version: {major: 0, minor: 1, revision: 1}, \n date: new Date(2006,8,19)\n};\nconfig.lib.Log = function(tiddlerTitle, logHeader) {\n if (version.major < 2)\n this.tiddler = store.tiddlers[tiddlerTitle];\n else\n this.tiddler = store.getTiddler(tiddlerTitle);\n if (!this.tiddler) {\n this.tiddler = new Tiddler();\n this.tiddler.title = tiddlerTitle;\n this.tiddler.text = "| !date | !user | !location |" + logHeader;\n this.tiddler.created = new Date();\n this.tiddler.modifier = config.options.txtUserName;\n this.tiddler.modified = new Date();\n if (version.major < 2)\n store.tiddlers[tiddlerTitle] = this.tiddler;\n else\n store.addTiddler(this.tiddler);\n }\n return this;\n};\n\nconfig.lib.Log.prototype.newLine = function (line) {\n var now = new Date();\n var newText = "| ";\n newText += now.getDate()+"/"+(now.getMonth()+1)+"/"+now.getFullYear() + " ";\n newText += now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+" | ";\n newText += config.options.txtUserName + " | ";\n var location = document.location.toString();\n var filename = config.lib.file.basename(location);\n if (!filename) filename = '/';\n newText += "[["+filename+"|"+location + "]] |";\n this.tiddler.text = this.tiddler.text + "\sn" + newText;\n this.addToLine(line);\n};\n\nconfig.lib.Log.prototype.addToLine = function (text) {\n this.tiddler.text = this.tiddler.text + text;\n this.tiddler.modifier = config.options.txtUserName;\n this.tiddler.modified = new Date();\n if (version.major < 2)\n store.tiddlers[this.tiddler.tittle] = this.tiddler;\n else {\n store.addTiddler(this.tiddler);\n story.refreshTiddler(this.tiddler.title);\n store.notify(this.tiddler.title, true);\n }\n if (version.major < 2)\n store.notifyAll(); \n};\n//}}}\n////===\n\n////+++!![config.lib.options]\n\n//{{{\nif (!config.lib) config.lib = {};\nif (!config.lib.options) config.lib.options = {\n author: 'BidiX',\n version: {major: 0, minor: 1, revision: 0}, \n date: new Date(2006,3,9)\n};\n\nconfig.lib.options.init = function (name, defaultValue) {\n if (!config.options[name]) {\n config.options[name] = defaultValue;\n saveOptionCookie(name);\n }\n};\n//}}}\n////===\n\n////+++!![PasswordTweak]\n\n//{{{\nversion.extensions.PasswordTweak = {\n major: 1, minor: 0, revision: 3, date: new Date(2006,8,30),\n type: 'tweak',\n source: 'http://tiddlywiki.bidix.info/#PasswordTweak'\n};\n//}}}\n/***\n!!config.macros.option\n***/\n//{{{\nconfig.macros.option.passwordCheckboxLabel = "Save this password on this computer";\nconfig.macros.option.passwordType = "password"; // password | text\n\nconfig.macros.option.onChangeOption = function(e)\n{\n var opt = this.getAttribute("option");\n var elementType,valueField;\n if(opt) {\n switch(opt.substr(0,3)) {\n case "txt":\n elementType = "input";\n valueField = "value";\n break;\n case "pas":\n elementType = "input";\n valueField = "value";\n break;\n case "chk":\n elementType = "input";\n valueField = "checked";\n break;\n }\n config.options[opt] = this[valueField];\n saveOptionCookie(opt);\n var nodes = document.getElementsByTagName(elementType);\n for(var t=0; t<nodes.length; t++) \n {\n var optNode = nodes[t].getAttribute("option");\n if (opt == optNode) \n nodes[t][valueField] = this[valueField];\n }\n }\n return(true);\n};\n\nconfig.macros.option.handler = function(place,macroName,params)\n{\n var opt = params[0];\n if(config.options[opt] === undefined) {\n return;}\n var c;\n switch(opt.substr(0,3)) {\n case "txt":\n c = document.createElement("input");\n c.onkeyup = this.onChangeOption;\n c.setAttribute ("option",opt);\n c.className = "txtOptionInput "+opt;\n place.appendChild(c);\n c.value = config.options[opt];\n break;\n case "pas":\n // input password\n c = document.createElement ("input");\n c.setAttribute("type",config.macros.option.passwordType);\n c.onkeyup = this.onChangeOption;\n c.setAttribute("option",opt);\n c.className = "pasOptionInput "+opt;\n place.appendChild(c);\n c.value = config.options[opt];\n // checkbox link with this password "save this password on this computer"\n c = document.createElement("input");\n c.setAttribute("type","checkbox");\n c.onclick = this.onChangeOption;\n c.setAttribute("option","chk"+opt);\n c.className = "chkOptionInput "+opt;\n place.appendChild(c);\n c.checked = config.options["chk"+opt];\n // text savePasswordCheckboxLabel\n place.appendChild(document.createTextNode(config.macros.option.passwordCheckboxLabel));\n break;\n case "chk":\n c = document.createElement("input");\n c.setAttribute("type","checkbox");\n c.onclick = this.onChangeOption;\n c.setAttribute("option",opt);\n c.className = "chkOptionInput "+opt;\n place.appendChild(c);\n c.checked = config.options[opt];\n break;\n }\n};\n//}}}\n/***\n!! Option cookie stuff\n***/\n//{{{\nwindow.loadOptionsCookie_orig_PasswordTweak = window.loadOptionsCookie;\nwindow.loadOptionsCookie = function()\n{\n var cookies = document.cookie.split(";");\n for(var c=0; c<cookies.length; c++) {\n var p = cookies[c].indexOf("=");\n if(p != -1) {\n var name = cookies[c].substr(0,p).trim();\n var value = cookies[c].substr(p+1).trim();\n switch(name.substr(0,3)) {\n case "txt":\n config.options[name] = unescape(value);\n break;\n case "pas":\n config.options[name] = unescape(value);\n break;\n case "chk":\n config.options[name] = value == "true";\n break;\n }\n }\n }\n};\n\nwindow.saveOptionCookie_orig_PasswordTweak = window.saveOptionCookie;\nwindow.saveOptionCookie = function(name)\n{\n var c = name + "=";\n switch(name.substr(0,3)) {\n case "txt":\n c += escape(config.options[name].toString());\n break;\n case "chk":\n c += config.options[name] ? "true" : "false";\n // is there an option link with this chk ?\n if (config.options[name.substr(3)]) {\n saveOptionCookie(name.substr(3));\n }\n break;\n case "pas":\n if (config.options["chk"+name]) {\n c += escape(config.options[name].toString());\n } else {\n c += "";\n }\n break;\n }\n c += "; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/";\n document.cookie = c;\n};\n//}}}\n/***\n!! Initializations\n***/\n//{{{\n// define config.options.pasPassword\nif (!config.options.pasPassword) {\n config.options.pasPassword = 'defaultPassword';\n window.saveOptionCookie('pasPassword');\n}\n// since loadCookies is first called befor password definition\n// we need to reload cookies\nwindow.loadOptionsCookie();\n//}}}\n////===\n\n////+++!![config.macros.upload]\n\n//{{{\nconfig.macros.upload = {\n accessKey: "U",\n formName: "UploadPlugin",\n contentType: "text/html;charset=UTF-8",\n defaultStoreScript: "store.php"\n};\n\n// only this two configs need to be translated\nconfig.macros.upload.messages = {\n aboutToUpload: "About to upload TiddlyWiki to %0",\n backupFileStored: "Previous file backuped in %0",\n crossDomain: "Certainly a cross-domain isue: access to an other site isn't allowed",\n errorDownloading: "Error downloading",\n errorUploadingContent: "Error uploading content",\n fileLocked: "Files is locked: You are not allowed to Upload",\n fileNotFound: "file to upload not found",\n fileNotUploaded: "File %0 NOT uploaded",\n mainFileUploaded: "Main TiddlyWiki file uploaded to %0",\n passwordEmpty: "Unable to upload, your password is empty",\n urlParamMissing: "url param missing",\n rssFileNotUploaded: "RssFile %0 NOT uploaded",\n rssFileUploaded: "Rss File uploaded to %0"\n};\n\nconfig.macros.upload.label = {\n promptOption: "Save and Upload this TiddlyWiki with UploadOptions",\n promptParamMacro: "Save and Upload this TiddlyWiki in %0",\n saveLabel: "save to web", \n saveToDisk: "save to disk",\n uploadLabel: "upload" \n};\n\nconfig.macros.upload.handler = function(place,macroName,params){\n // parameters initialization\n var storeUrl = params[0];\n var toFilename = params[1];\n var backupDir = params[2];\n var uploadDir = params[3];\n var username = params[4];\n var password; // for security reason no password as macro parameter\n var label;\n if (document.location.toString().substr(0,4) == "http")\n label = this.label.saveLabel;\n else\n label = this.label.uploadLabel;\n var prompt;\n if (storeUrl) {\n prompt = this.label.promptParamMacro.toString().format([this.toDirUrl(storeUrl, uploadDir, username)]);\n }\n else {\n prompt = this.label.promptOption;\n }\n createTiddlyButton(place, label, prompt, \n function () {\n config.macros.upload.upload(storeUrl, toFilename, uploadDir, backupDir, username, password); \n return false;}, \n null, null, this.accessKey);\n};\nconfig.macros.upload.UploadLog = function() {\n return new config.lib.Log('UploadLog', " !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |" );\n};\nconfig.macros.upload.UploadLog.prototype = config.lib.Log.prototype;\nconfig.macros.upload.UploadLog.prototype.startUpload = function(storeUrl, toFilename, uploadDir, backupDir) {\n var line = " [[" + config.lib.file.basename(storeUrl) + "|" + storeUrl + "]] | ";\n line += uploadDir + " | " + toFilename + " | " + backupDir + " |";\n this.newLine(line);\n};\nconfig.macros.upload.UploadLog.prototype.endUpload = function() {\n this.addToLine(" Ok |");\n};\nconfig.macros.upload.basename = config.lib.file.basename;\nconfig.macros.upload.dirname = config.lib.file.dirname;\nconfig.macros.upload.toRootUrl = function (storeUrl, username)\n{\n return root = (this.dirname(storeUrl)?this.dirname(storeUrl):this.dirname(document.location.toString()));\n}\nconfig.macros.upload.toDirUrl = function (storeUrl, uploadDir, username)\n{\n var root = this.toRootUrl(storeUrl, username);\n if (uploadDir && uploadDir != '.')\n root = root + '/' + uploadDir;\n return root;\n}\nconfig.macros.upload.toFileUrl = function (storeUrl, toFilename, uploadDir, username)\n{\n return this.toDirUrl(storeUrl, uploadDir, username) + '/' + toFilename;\n}\nconfig.macros.upload.upload = function(storeUrl, toFilename, uploadDir, backupDir, username, password)\n{\n // parameters initialization\n storeUrl = (storeUrl ? storeUrl : config.options.txtUploadStoreUrl);\n toFilename = (toFilename ? toFilename : config.options.txtUploadFilename);\n backupDir = (backupDir ? backupDir : config.options.txtUploadBackupDir);\n uploadDir = (uploadDir ? uploadDir : config.options.txtUploadDir);\n username = (username ? username : config.options.txtUploadUserName);\n password = config.options.pasUploadPassword; // for security reason no password as macro parameter\n if (!password || password === '') {\n alert(config.macros.upload.messages.passwordEmpty);\n return;\n }\n if (storeUrl === '') {\n storeUrl = config.macros.upload.defaultStoreScript;\n }\n if (config.lib.file.dirname(storeUrl) === '') {\n storeUrl = config.lib.file.dirname(document.location.toString())+'/'+storeUrl;\n }\n if (toFilename === '') {\n toFilename = config.lib.file.basename(document.location.toString());\n }\n\n clearMessage();\n // only for forcing the message to display\n if (version.major < 2)\n store.notifyAll();\n if (!storeUrl) {\n alert(config.macros.upload.messages.urlParamMissing);\n return;\n }\n // Check that file is not locked\n if (window.BidiX && BidiX.GroupAuthoring && BidiX.GroupAuthoring.lock) {\n if (BidiX.GroupAuthoring.lock.isLocked() && !BidiX.GroupAuthoring.lock.isMyLock()) {\n alert(config.macros.upload.messages.fileLocked);\n return;\n }\n }\n \n var log = new this.UploadLog();\n log.startUpload(storeUrl, toFilename, uploadDir, backupDir);\n if (document.location.toString().substr(0,5) == "file:") {\n saveChanges();\n }\n var toDir = config.macros.upload.toDirUrl(storeUrl, toFilename, uploadDir, username);\n displayMessage(config.macros.upload.messages.aboutToUpload.format([toDir]), toDir);\n this.uploadChanges(storeUrl, toFilename, uploadDir, backupDir, username, password);\n if(config.options.chkGenerateAnRssFeed) {\n //var rssContent = convertUnicodeToUTF8(generateRss());\n var rssContent = generateRss();\n var rssPath = toFilename.substr(0,toFilename.lastIndexOf(".")) + ".xml";\n this.uploadContent(rssContent, storeUrl, rssPath, uploadDir, '', username, password, \n function (responseText) {\n if (responseText.substring(0,1) != '0') {\n displayMessage(config.macros.upload.messages.rssFileNotUploaded.format([rssPath]));\n }\n else {\n var toFileUrl = config.macros.upload.toFileUrl(storeUrl, rssPath, uploadDir, username);\n displayMessage(config.macros.upload.messages.rssFileUploaded.format(\n [toFileUrl]), toFileUrl);\n }\n // for debugging store.php uncomment last line\n //DEBUG alert(responseText);\n });\n }\n return;\n};\n\nconfig.macros.upload.uploadChanges = function(storeUrl, toFilename, uploadDir, backupDir, \n username, password) {\n var original;\n if (document.location.toString().substr(0,4) == "http") {\n original = this.download(storeUrl, toFilename, uploadDir, backupDir, username, password);\n return;\n }\n else {\n // standard way : Local file\n \n original = loadFile(getLocalPath(document.location.toString()));\n if(window.Components) {\n // it's a mozilla browser\n try {\n netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");\n var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]\n .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);\n converter.charset = "UTF-8";\n original = converter.ConvertToUnicode(original);\n }\n catch(e) {\n }\n }\n }\n //DEBUG alert(original);\n this.uploadChangesFrom(original, storeUrl, toFilename, uploadDir, backupDir, \n username, password);\n};\n\nconfig.macros.upload.uploadChangesFrom = function(original, storeUrl, toFilename, uploadDir, backupDir, \n username, password) {\n var startSaveArea = '<div id="' + 'storeArea">'; // Split up into two so that indexOf() of this source doesn't find it\n var endSaveArea = '</d' + 'iv>';\n // Locate the storeArea div's\n var posOpeningDiv = original.indexOf(startSaveArea);\n var posClosingDiv = original.lastIndexOf(endSaveArea);\n if((posOpeningDiv == -1) || (posClosingDiv == -1))\n {\n alert(config.messages.invalidFileError.format([document.location.toString()]));\n return;\n }\n var revised = original.substr(0,posOpeningDiv + startSaveArea.length) + \n allTiddlersAsHtml() + "\sn\st\st" +\n original.substr(posClosingDiv);\n var newSiteTitle;\n if(version.major < 2){\n newSiteTitle = (getElementText("siteTitle") + " - " + getElementText("siteSubtitle")).htmlEncode();\n } else {\n newSiteTitle = (wikifyPlain ("SiteTitle") + " - " + wikifyPlain ("SiteSubtitle")).htmlEncode();\n }\n\n revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");\n revised = revised.replaceChunk("<!--PRE-HEAD-START--"+">","<!--PRE-HEAD-END--"+">","\sn" + store.getTiddlerText("MarkupPreHead","") + "\sn");\n revised = revised.replaceChunk("<!--POST-HEAD-START--"+">","<!--POST-HEAD-END--"+">","\sn" + store.getTiddlerText("MarkupPostHead","") + "\sn");\n revised = revised.replaceChunk("<!--PRE-BODY-START--"+">","<!--PRE-BODY-END--"+">","\sn" + store.getTiddlerText("MarkupPreBody","") + "\sn");\n revised = revised.replaceChunk("<!--POST-BODY-START--"+">","<!--POST-BODY-END--"+">","\sn" + store.getTiddlerText("MarkupPostBody","") + "\sn");\n\n var response = this.uploadContent(revised, storeUrl, toFilename, uploadDir, backupDir, \n username, password, function (responseText) {\n if (responseText.substring(0,1) != '0') {\n alert(responseText);\n displayMessage(config.macros.upload.messages.fileNotUploaded.format([getLocalPath(document.location.toString())]));\n }\n else {\n if (uploadDir !== '') {\n toFilename = uploadDir + "/" + config.macros.upload.basename(toFilename);\n } else {\n toFilename = config.macros.upload.basename(toFilename);\n }\n var toFileUrl = config.macros.upload.toFileUrl(storeUrl, toFilename, uploadDir, username);\n if (responseText.indexOf("destfile:") > 0) {\n var destfile = responseText.substring(responseText.indexOf("destfile:")+9, \n responseText.indexOf("\sn", responseText.indexOf("destfile:")));\n toFileUrl = config.macros.upload.toRootUrl(storeUrl, username) + '/' + destfile;\n }\n else {\n toFileUrl = config.macros.upload.toFileUrl(storeUrl, toFilename, uploadDir, username);\n }\n displayMessage(config.macros.upload.messages.mainFileUploaded.format(\n [toFileUrl]), toFileUrl);\n if (backupDir && responseText.indexOf("backupfile:") > 0) {\n var backupFile = responseText.substring(responseText.indexOf("backupfile:")+11, \n responseText.indexOf("\sn", responseText.indexOf("backupfile:")));\n toBackupUrl = config.macros.upload.toRootUrl(storeUrl, username) + '/' + backupFile;\n displayMessage(config.macros.upload.messages.backupFileStored.format(\n [toBackupUrl]), toBackupUrl);\n }\n var log = new config.macros.upload.UploadLog();\n log.endUpload();\n store.setDirty(false);\n // erase local lock\n if (window.BidiX && BidiX.GroupAuthoring && BidiX.GroupAuthoring.lock) {\n BidiX.GroupAuthoring.lock.eraseLock();\n // change mtime with new mtime after upload\n var mtime = responseText.substr(responseText.indexOf("mtime:")+6);\n BidiX.GroupAuthoring.lock.mtime = mtime;\n }\n \n \n }\n // for debugging store.php uncomment last line\n //DEBUG alert(responseText);\n }\n );\n};\n\nconfig.macros.upload.uploadContent = function(content, storeUrl, toFilename, uploadDir, backupDir, \n username, password, callbackFn) {\n var boundary = "---------------------------"+"AaB03x"; \n var request;\n try {\n request = new XMLHttpRequest();\n } \n catch (e) { \n request = new ActiveXObject("Msxml2.XMLHTTP"); \n }\n if (window.netscape){\n try {\n if (document.location.toString().substr(0,4) != "http") {\n netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');}\n }\n catch (e) {}\n } \n //DEBUG alert("user["+config.options.txtUploadUserName+"] password[" + config.options.pasUploadPassword + "]");\n // compose headers data\n var sheader = "";\n sheader += "--" + boundary + "\sr\snContent-disposition: form-data; name=\s"";\n sheader += config.macros.upload.formName +"\s"\sr\sn\sr\sn";\n sheader += "backupDir="+backupDir\n +";user=" + username \n +";password=" + password\n +";uploaddir=" + uploadDir;\n // add lock attributes to sheader\n if (window.BidiX && BidiX.GroupAuthoring && BidiX.GroupAuthoring.lock) {\n var l = BidiX.GroupAuthoring.lock.myLock;\n sheader += ";lockuser=" + l.user\n + ";mtime=" + l.mtime\n + ";locktime=" + l.locktime;\n }\n sheader += ";;\sr\sn"; \n sheader += "\sr\sn" + "--" + boundary + "\sr\sn";\n sheader += "Content-disposition: form-data; name=\s"userfile\s"; filename=\s""+toFilename+"\s"\sr\sn";\n sheader += "Content-Type: " + config.macros.upload.contentType + "\sr\sn";\n sheader += "Content-Length: " + content.length + "\sr\sn\sr\sn";\n // compose trailer data\n var strailer = new String();\n strailer = "\sr\sn--" + boundary + "--\sr\sn";\n //strailer = "--" + boundary + "--\sr\sn";\n var data;\n data = sheader + content + strailer;\n //request.open("POST", storeUrl, true, username, password);\n try {\n request.open("POST", storeUrl, true); \n }\n catch(e) {\n alert(config.macros.upload.messages.crossDomain + "\snError:" +e);\n exit;\n }\n request.onreadystatechange = function () {\n if (request.readyState == 4) {\n if (request.status == 200)\n callbackFn(request.responseText);\n else\n alert(config.macros.upload.messages.errorUploadingContent + "\snStatus: "+request.status.statusText);\n }\n };\n request.setRequestHeader("Content-Length",data.length);\n request.setRequestHeader("Content-Type","multipart/form-data; boundary="+boundary);\n request.send(data); \n};\n\n\nconfig.macros.upload.download = function(uploadUrl, uploadToFilename, uploadDir, uploadBackupDir, \n username, password) {\n var request;\n try {\n request = new XMLHttpRequest();\n } \n catch (e) { \n request = new ActiveXObject("Msxml2.XMLHTTP"); \n }\n try {\n if (uploadUrl.substr(0,4) == "http") {\n netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");\n }\n else {\n netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");\n }\n } catch (e) { }\n //request.open("GET", document.location.toString(), true, username, password);\n try {\n request.open("GET", document.location.toString(), true);\n }\n catch(e) {\n alert(config.macros.upload.messages.crossDomain + "\snError:" +e);\n exit;\n }\n \n request.onreadystatechange = function () {\n if (request.readyState == 4) {\n if(request.status == 200) {\n config.macros.upload.uploadChangesFrom(request.responseText, uploadUrl, \n uploadToFilename, uploadDir, uploadBackupDir, username, password);\n }\n else\n alert(config.macros.upload.messages.errorDownloading.format(\n [document.location.toString()]) + "\snStatus: "+request.status.statusText);\n }\n };\n request.send(null);\n};\n\n//}}}\n////===\n\n////+++!![Initializations]\n\n//{{{\nconfig.lib.options.init('txtUploadStoreUrl','store.php');\nconfig.lib.options.init('txtUploadFilename','');\nconfig.lib.options.init('txtUploadDir','');\nconfig.lib.options.init('txtUploadBackupDir','');\nconfig.lib.options.init('txtUploadUserName',config.options.txtUserName);\nconfig.lib.options.init('pasUploadPassword','');\nsetStylesheet(\n ".pasOptionInput {width: 11em;}\sn"+\n ".txtOptionInput.txtUploadStoreUrl {width: 25em;}\sn"+\n ".txtOptionInput.txtUploadFilename {width: 25em;}\sn"+\n ".txtOptionInput.txtUploadDir {width: 25em;}\sn"+\n ".txtOptionInput.txtUploadBackupDir {width: 25em;}\sn"+\n "",\n "UploadOptionsStyles");\nconfig.shadowTiddlers.UploadDoc = "[[Full Documentation|http://tiddlywiki.bidix.info/l#UploadDoc ]]\sn"; \nconfig.options.chkAutoSave = false; saveOptionCookie('chkAutoSave');\n\n//}}}\n////===\n\n////+++!![Core Hijacking]\n\n//{{{\nconfig.macros.saveChanges.label_orig_UploadPlugin = config.macros.saveChanges.label;\nconfig.macros.saveChanges.label = config.macros.upload.label.saveToDisk;\n\nconfig.macros.saveChanges.handler_orig_UploadPlugin = config.macros.saveChanges.handler;\n\nconfig.macros.saveChanges.handler = function(place)\n{\n if ((!readOnly) && (document.location.toString().substr(0,4) != "http"))\n createTiddlyButton(place,this.label,this.prompt,this.onClick,null,null,this.accessKey);\n};\n\n//}}}\n////===\n
Test list\n* one item\n* two items\n
This document is a ~TiddlyWiki from tiddlyspot.com. A ~TiddlyWiki is an electronic notebook that is great for managing todo lists, personal information, and all sorts of things.\n\n@@font-weight:bold;font-size:1.3em;color:#444; //What now?// @@ Before you can save any changes, you need to enter your password in the form below. Then configure privacy and other site settings at your [[control panel|http://rtfm.tiddlyspot.com/controlpanel]] (your control panel username is //rtfm//).\n<<tiddler tiddlyspotControls>>\n@@font-weight:bold;font-size:1.3em;color:#444; //Working online// @@ You can edit this ~TiddlyWiki right now, and save your changes using the "save to web" button in the column on the right.\n\n@@font-weight:bold;font-size:1.3em;color:#444; //Working offline// @@ A fully functioning copy of this ~TiddlyWiki can be saved onto your hard drive or USB stick. You can make changes and save them locally without being connected to the Internet. When you're ready to sync up again, just click "upload" and your ~TiddlyWiki will be saved back to tiddlyspot.com.\n\n@@font-weight:bold;font-size:1.3em;color:#444; //Help!// @@ Find out more about ~TiddlyWiki at [[TiddlyWiki.com|http://tiddlywiki.com]]. Also visit [[TiddlyWiki Guides|http://tiddlywikiguides.org]] for documentation on learning and using ~TiddlyWiki. New users are especially welcome on the [[TiddlyWiki mailing list|http://groups.google.com/group/TiddlyWiki]], which is an excellent place to ask questions and get help. If you have a tiddlyspot related problem email [[tiddlyspot support|mailto:support@tiddlyspot.com]].\n\n@@font-weight:bold;font-size:1.3em;color:#444; //Enjoy :)// @@ We hope you like using your tiddlyspot.com site. Please email [[feedback@tiddlyspot.com|mailto:feedback@tiddlyspot.com]] with any comments or suggestions.
The wrapper class is an object representation of the [[primitive]]s. So for primitive ''int'' we have ''Integer'' and ''double'' we use ''Double''.
The ''Writer'' class is abstract, and is used to write out characters. Also a close method and others. We will typically used the [[FileWriter]] class.
An ''abstract class'' is a class that is uninstantiable. It may have both may have both concrete and abstract methods. Abstract methods have only their signature without any code. Therefore derived (inherited ie child) classes must provide a definition, making the method [[polymorphic|Polymorphism]].\nTherefore, the parent method will have an abstract method like:\n<html><pre>\n...\n public abstract int calcualteMagicNumber();\n...\n</pre></html>So when we extend the parent class, the child class *must* implement the ''calcualteMagicNumber'' method. If not you get a compiler error.
Java uses both ''application and transport'' layers in [[Networking]]. The transport layer has both TCP and UDP.\n*TCP is used when reliable communication is required, that is information is guaranteed or errors are reported (HTTP, FTP). \n*UDP does not guarantee if data gets there, uses datagrams and is used by Ping or clock functions\nThe application layer has HTTP, ftp, telnet. (Java classes: URL, URLConnection, Socket, and ServerSocket).\nThe transport layer has TCP, UDP, . (Java classes: DatagramPacket, DatagramSocket, and MulticastSocket).\nTCP and UDP deliver data to ''Ports'', which are identified by a 16-bit number.
Array is an object that holds information. Primitives are stored as [[primitive]]s and objects are stored as object reference variable - which points to the real object. The ''type'' below can either be primitive or an object and the array_name is how we identify the array. These variables names are created in stack memory are are not yet instantiated. See also [[2D array]].\n<html><pre>\n type [] array_name; // Declare - This creates the array identifier\n array_name = new type [length]; // Construct - This creates the array object, the array itself.\n array_name[index] = value; // Initialize - This is to place values in the array. Index starts at zero.\n\n String [] colours = { "red", "yellow", "green" }; // This creates and populates an array.\n</pre></html>\nThis table shows what the default values are when we create an array object..\n|!Type|!Default Value|\n|int, byte, short|0|\n|float|0.0f|\n|double|0.0d|\n|char|\su0000|\n|boolean|false|\n|String|null|\n\n
The assert statement is used to test pre and post conditions. Assertions are not used for production. If it fails an AssertionError is thrown.\n<html><pre>\n assert <boolean-expression> ;\n assert <boolean-expression> ; <detail-expression>;\n // Examples of assert.\n assert ( x == 42);\n assert false : "That was so wrong.";\n</pre></html>
Casting allows us to use objects of one type to represent another. There is implicit and explicit casting.\n<html><pre>\n Object obj = new Bike(); // implicit casting, obj is both an object and a bike.\n Bike a = (Bike)obj; // explicit casting\n</pre></html>
The ''class'' is like a blueprint of a building. Every java class has only one direct ''superclass'', except [[Object]] which is at the top of the pile. A class that you make can only inherit one class, but can implement multiple [[interface]]s. \nA class is declared like:\n<html><pre>\n <class_modifier> class class-name \n [extends superclass-name]\n [implements interface-name, interface-name2, ...] \n [throws exception-name, ...] { ... }\n</pre></html>A class [[extends]] a class and it [[implements]] an [[interface]].\nHere is a basic main class:\n<html><pre>\n public class FirstClass\n public static void main(Sting[] args) {\n // Some code here...\n }\n</pre></html>
The ''conditional operator'' or ''?'' is also known as a ternary operator. It is used to pack simple coding into one statement. For example the following code:\n<html><pre>\nif (x) { a = b; }\n else { a = c; }\n</pre></html>Can be written as:<html><pre>\n a = x ? b : c;\n</pre></html>\n
The ''enum'' is a Java keyword used to declare an enumerated type. \n<html><pre>\n public enum TrafficLights { RED, YELLOW, GREEN }\n...\n public class TrafficGame (\n private TrafficLight light;\n \n public TrafficGame(TrafficLight light) {\n this.light = light;\n }\n }\n</pre></html>
The operator [[==]] tests for equality of the ''reference''.\nThe operator ''equals()'' tests the equality of the ''content''.\n<html><pre>\n String s1 = "hello";\n String s2 = "hello";\n String s3 = new String("hello");\n\n System.out.println( s1 == s2); // will be true\n System.out.println( s1 == s3); // will be false\n System.out.println( s1.equals(s3)); // will be true\n</pre></html>
An ''exception'' is an event that disrupts the normal flow of a program. When an error occurs, the method that it occurs in creates an exception object and hands it off the the runtime system. This system then tries to find something to handle this object, an ''exception handler''. It does this by going thru the call stack looking for some block of code to handle this, that will take responsibility. If it finds something, this code then ''catches the exception'' and all is well. If not then the program terminates. There are three kinds of exceptions:\n*[[Checked]] exceptions.\n*[[Error]].\n*[[runtime exceptions]].\nAn exception is caught by a either a\n*[[try-catch]] construct. \n*[[throws]] clause in the method declaration.
We use ''extends'' to implement inheritance. We can only extend one other superclass.\n<html><pre>\n <class_modifier> class class-name extends superclass-name\n\n public class Bike extends Vehicle { ... }\n</pre></html>\nThis class now a [[subclass]] to the superclass we extended from. We can access the superclass methods by using the [[super]] keyword.
Final on a class modifier means that you cannot subclass it. String class in java.lang is a ''Final'' class.\nFinal on a method means that you cannot override it when the class is subclassed.\nFinal on a static variable, it becomes a constant.\n<html><pre>\n private static final int MAGIC_NUMBER = 42; // Essentially a constant\n private final int greatNumber; // So this can be set some other time, but not changed thereafter.\n public final void someMethod () { ... }\n public final class String { ... }\n</pre></html>\n
Here is an example of a for-each:\n<HTML><PRE>\n List<String> colours = new ArrayList<String>();\n // Load up colours list.\n for (String colour: colours )\n System.out.println(colour);\n</PRE></HTML>
In java a class ''implements'' an [[interface]]. \n<html><pre>\n <class_modifier> class class-name [implements interface-name, interface-name2, ...] { ... }\n</pre></html>\nThe implementation of a class is an actual object. An ''implementation'' is the realization of something.
To import:\n<html><pre>\n import package_name.*;\n import package_name.class_name;\n</pre></html>\n
When a class is [[instantiated]] it is called an ''instance''. Therefore you can have many instances of a class. In each instance the variables are called ''instance variables''. Each method in an instance is an ''instance method''. \nThe opposite of this is a [[class variables|Static Variables]] and ''class method'', which is specified by the [[static]] keyword.
The ''instanceof'' keyword is used to determine if an object is an instance of some object. This is useful for casting ''upward'' to make sure we are casting properly - no [[runtime exceptions]].\n<html><pre>\nif (bike instanceOf vehicle) \n Vehicle myBike = (Vehicle)bike ;\n}\n\n</pre></html>
An ''interface'' is a description of typically related methods that an implementing class must have. This allows non-hierarchical classes to have an inheritance relationship. It is just like a class but all of its methods must be abstract. This is the only way in Java to have multiple inheritance. An interface can be implemented any way that you like but its method signatures must be followed exactly.Here are a list of other characteristics:\n*Key uses of interfaces are: @@inheritance@@ and as an @@API@@.\n*Can be implemented by classes.\n*Can be extended by one or more other interfaces.\n*A class must implement all methods in the interface - if not it must be [[abstract]].\n*Methods must be ''public'', ''abstract'' or ''default''.\n*All variables must be ''public'', [[static]] and [[final]].\n*An interface name can be used anywhere a type can be used.\n*Can contain nested types.\n*an interface is a reference type @@more info@@ please.\n\nA typical interface is defined like:\n<html><pre>\n public interface SomethingCool extends OtherIface { // public = all have access\n int gears = 22; // All constant are implicitly public, static and final.\n void DoSomething (int i, String s);\n int UndoSomething (double d) ;\n}\n</pre></html>
The ''interrupt()'' method will halt a thread. This can be called on itself. \n<html><pre>\n t.interrupt();\n</pre></html>\n The ''interrupted()'' method can be used to determine if an interrupt has been called. It is up to the programmer to determine what to do when detected.<html><pre>\nif (Thread.interrupted()) {\n throw new InterruptedException();\n}\n</pre></html>\n Many threading operation operations (like ''sleep()'') require a [[try-catch]] construct.<html><pre>\n try { \n Thread.sleep(4000);\n } catch (InterruptedException e) {\n //We've been interrupted: no more messages.\n return;\n }\n</pre></html>\n
This class is always loaded, it contains: [[String]], Math, System and Integer, amoung others. Others have to be[[import]]ed.
Stack memory is short term memory - short lived variables, ie local vars.\nHeap Memory is long term memory - long term variables, ie instance variables.
A ''method'' is a block of code that can be called many times to perform some systematic task. Its format is:\n<html><pre>\n [modifier] return_type method_name ( [arguments] } { ... code ... } \n //\n int addNumbers (int one, int two) { return one+two; }\n</pre></html>\nSee [[modifiers]].
Here are ''Access Modifiers''\n|!Name|!Description|\n|private|Open only to the same class.|\n|<default>|Open only to same [[package]].|\n|protected|Open only to same package & [[subclass]].|\n|public|Open for everyone.|\nThere can be more than one modifier.\n|!Name|!Description|\n|void|This means that the [[method]] returns nothing.|\n|[[final]]|Final is well, final!|\n|static|There is only ever one.|\n
Java has great support for ''multithreading'''. Multithreading is where you have two or more tasks running at the same time. In java there are four thread states:\n*''New'' - A [[Thread]] has been declared, but no resources are allocated, the ''start()'' method has not been called.\n*''Running'' & [[Runnable]] - A thread has to be ''runnable'', then scheduled for execution, and when executing it is in a ''running'' state. \n*''Blocked'' - Two different blocked states.\n**If the thread tries to get the ''lock'' for code that is [[synchronized]] and is blocked then the thread is placed in a special ''blocked'' state waiting for a lock. Once it has the lock it is then placed in a ''runnable'' state.\n**A thread cannot access an unavailable resource (ie a file) or we hit a [[sleep()|Thread]] method, the thread is then ''blocked''.\n*''Dead'' - Aka Terminated - execution is stopped and cannot be resumed. \nA problem with multithreading is that there can be errors introduced, many can be solved with the [[synchronized]] keyword for locking code.\nSee also [[Concurrency]] for more info.\n
Java organizes code by packages. The package [[java.lang]] is automatically loaded. It is declared as:\n<html><pre>\npackage ca.rtfm.widget;\n</pre></html>
The defulat ''parameterized type'' name conventions used in the Java apis are:\n* E - Element (used extensively by the Java Collections Framework)\n* K - Key\n* N - Number\n* T - Type\n* V - Value\n* S,U,V etc. - 2nd, 3rd, 4th types \n
There are 8 primitive [[variables]] in Java.\n|!Type|!Min|!Max|!Default|!size (bits)|!Example|!Example|\n|boolean|false|true|false|1|boolean biteMe = true;|\n|byte|-126|127|0|8|byte b = 10;|\n|short|-32768|32767|0|16|short s = 9;|\n|int|-2147483648|2147483647|0|32|int i = 1; |int j = 0x1a;|\n|long|-2^^63^^ |-2^^63^^ - 1|0|64|long x = 123L |long z = 0xfff;|\n|float|-big-|-big-|0.0|32|float f = 1.2f;|float f2 = 1.23F;|\n|double|-big-|-big-|0.0|64|double d = 3.14;|double dd = 6.02E23;|\n|char|\su0000|\suffff|\su0000|16|char c = 'w'; |char c1 = '\su4567';|\n\nLocal vars do not get a default value. You must specify a value for a local variable.
The ''println'' is an [[overloaded|Overloading]] method that will convert its parameter to a string. The ''ln'' ending gives us a new line. Printing an object will actually call its ''toSting'' method. Make it look nice, could also try using ''printf''.
A ''process'' can be considered a single program running. It has resources like memory and is self contained. Most Java programs run in a single process. A multiprocess application is advanced. Running multiple processes will chew up resources, a lightweight approach is to use [[threads|Thread]].
''runtime exceptions'' are exceptions that the application typically cannot recover from. They are either from the ''~RuntimeException'' class or a subclass. You typically don't catch them via [[try-catch]] because they are often logic or programming errors.
The keyword ''static'' is used in java to make a variable a ''class variable'' and a method a ''class method''. Class variables are [[variables]] where all instances of the class have access to the same variable in memory. This is the opposite of instance variables where each instance has its own variable in memory. A static method means that there is only one of them associated with the object, no matter how many instances there are. Static methods can only access static variables.\n<html><pre>\n // Static variable\n private static int counter = 0;\n\n // Static method\n public static boolean doesItHurt() { ... );\n</pre></html>\nThere are also [[static initializers|Static Initializers]].\n\n
A ''subclass'' is a class that is derived from another class. aka derived or child class. The ''superclass'' would be the parent or original class.\nA ''subclass'' can override a parent method - but has to have exact same signature. The [[super]] keyword allows you to access methods in the parent class. A subclass all public and protected methods and fields of the parent class. You can hide fields from the superclass by declaring them in the subclass, this is not a good idea - because depending on where the field is accessed from - you'll get different answers! This also applies to [[class methods]].
Substring...and a few other things...\n<html><pre>\n String alpha = "abcdefghijkl";\n alpha.substring(0,2); // would be "ab"\n alpha.substring(2); // would be "cdefghijkl"\n\n alpha.indexOf("ef"); // would be 4\n alpha.indexOf("xyz"); // would be -1\n</pre></html>
The [[super]] keyword allows you to access methods and variables in the parent or superclass.
The ''synchronized'' keyword is used in a [[multithreading]] environment which means that the system will lock the code and treat it as a block that will not allow other threads to interrupt it. This requires processing overhead, so only use when there is a possibility of code corruption. You can synchronized an entire method or a portion of code.\n<html><pre>\n public synchronized void something() { ... }\n // ...or...\n synchronized(this) { ..... }\n</pre></html>\nBe careful of ''deadlock'', where two threads lock a resource and wait for the other to release it.
''Local variables'' - are stored in the threads own stack and are therefore thread safe.\n''Local references to objects'' - the reference is thread safe but the object is ''not''. Objects are stored on a shared heap. If the object is only used internally, it is safe.\n''Object members'' - are not thread safe. They are stored, along with the Object on a shared heap.\n\nTo avoid race conditions, you have to use the [[synchronized]] keyword.\n
The ''throws'' clause is used to throw [[checked|Checked]] exceptions. The syntax can be seen in the [[class]] declaration.\n<html><pre>\n \n</pre></html>
| tiddlyspot password:|<<option pasUploadPassword>>|\n| site management:|<<upload http://rtfm.tiddlyspot.com/store.cgi index.html . . rtfm>>//(requires tiddlyspot password)//<<br>>[[control panel|http://rtfm.tiddlyspot.com/controlpanel]], [[download (go offline)|http://rtfm.tiddlyspot.com/download]]|\n| links:|[[tiddlyspot.com|http://tiddlyspot.com/]], [[FAQs|http://faq.tiddlyspot.com/]], [[announcements|http://announce.tiddlyspot.com/]], [[blog|http://tiddlyspot.com/blog/]], email [[support|mailto:support@tiddlyspot.com]] & [[feedback|mailto:feedback@tiddlyspot.com]], [[donate|http://tiddlyspot.com/?page=donate]]|
The ''try-catch-finally'' block allows us to try code that may throw an exception and not crash the program. When an error is encountered, Java creates an [[Exception]] object. We have access to this object. Note that the ''finally'' is not required.\n<html><pre>\n try {\n x = y * z;\n } catch (SomeException ex) {\n // Some code you want executed.\n } finally (\n // This code always executes, no matter what.\n }\n</pre></html>
A ''utility class'' is a class with all static members and is therefore not instantiated.
This allows the last method parameter to be an array. Format:\n\n\n public static <T> void something(String title, T... arr) {...\n \nYou can explicitly declare what <T> is by:\n\n List<Integer> ints = <Integer>something();
Local variables are used to hold information. There are also [[Static Variables]] and [[Instance Variables]].\n<html><pre>\n [modifiers] type variable_name [ = value] ;\n</pre></html>\nVariables can be given literals, for example:\n|!Decimal|!Octal|!Hexidecimal|!long|!float|!double|!Scientific|\n|10|013|0xA|10.0L|3.1415986f|1212d|1.23e22|\n
The ''vector'' class extends AbstractList and implements the List interface. It is a dynamic array.\n<html><pre>\n Vector v = new Vector(3, 2); // size, inc\n v.addElement(new Integer(1)); // Same as "add" below.\n\n Vector<CustomRecord> vc=new Vector<CustomRecord>();\n vc.add(new CustomRecord(11,"biteme"));\n</pre></html>\nSee [[Enumeration]] to print these out.