vimwiki/tech/Java.wiki

56 lines
2.1 KiB
Plaintext

= Java =
Java is a strongly typed, garbage collected language that runs in the JVM. It
can run on almost anything.
== Data structures ==
| C++ DS | Java DS | Notes |
| Vector | ArrayList | Threadsafe |
| Vector | Vector | Not threadsafe; deprecated |
| Deque | Deque | |
| Stack | Stack | Stack implementation using a vector |
| List | ArrayList | Both linked lists; Singly linked |
| List | LinkedList | Doubly linked list |
| Map | TreeMap | Red-black tree |
| Set | TreeSet | Red-black tree |
| unordered_set | Hashset | Hashtable |
| unordered_map | Hashmap | Non blocking but race conditions can occour |
| unordered_map | Hashtable | Threadsafe but blocking; deprecated |
| N/A | LinkedHashMap | LRUCache; Hash table that knows order of elements inserted/accessed |
| N/A | LinkedHashSet | LRUCache; Hash set that knows order of elements inserted/accessed |
== Classes ==
=== Constructor ===
{{{
public class MyClass{
public MyClass(){
//constructor code here
}
}
}}}
=== Deconstructor/Finalize ===
finalize provides security and is called by the garbage collector. We can call
it directly to clean up the object. All exceptions thrown by it are ignored by
the garbage collector.
{{{
public class MyClass{
public MyClass(){
//constructor code here
}
protected void finalize(){
//clean up code here
}
}
}}}