Fundamental practice for building up strong base and preparation for advanced java.
- Constructor
- Inheritance
- Reference, object, instance, class
- This, super, static
- Overriding and overloading, covariant return type
- Static vs instance method (which to use)
- Static vs instance variable (static: shared between instance)
- Extends Object class
- Composition vs inheritance
- Encapsulation: protect fields
- Polymorphism: unique functionality in inherited class
- Array, bubble sorting (while flag + for loop), common error (index out of bounds)、
- Reference type and value type
- ArrayList (advantage: automatic re-sizing)
- ArrayList (crud operations), scanner.nextLine() and scanner.nextInt()
- ArrayList, how to copy arraylist: 1) addAll 2) initialization with previous one (new arraylist<>(previousList)), turn arraylist into the array: toArray(T a) method
- Factory method to create a new object
- ClassA.method() call Class_a.method and enhance it according to scenario in ClassA. class_ a is a variable of classA (contact and mobilePhone)
- Deal with duplicate in arrayList: indexOf() method's return value
- Arraylist store object (not primitive type data); primitive vs reference (stored in stack or heap); autoboxing and unboxing
- LinkedList: save more work when add/delete one element from list, arrayList has to move many elements to the next position when saving, arrayList has to move many elements to the previous position when deleting.
- Iterator & listIterator, insert and remove of linkedList.
- ListIterator's infinite loop when using iterator.previous() and followed by iterator.next() because the implementation of its cursor.
- Operation on listIterator needs to be followed by next() or previous(). (such as remove() is called, needs to follow either next() or previous(), otherwise if you use remove() again, error will be thrown.)
- Interface: abstraction, used to group related methods with empty body (which will be implemented in classes)
- Use extends or interface.
- Use interface as method parameter. Such as Collections.sort(List list)
- Declare the interface object, and get access to concrete class's method. (scenario: when plan to use variable/methods defined in the interface, which makes code generic).
- Inner class: when it will be only useful in the outer class, such as keySet in HashMap, it can be static when no need to access members for outer class. (initialize: GearBox.Gear myGear = myGearBox.new Gear()).
- Local class and anonymous class.
- Abstract class. Difference between abstract class and interface.
- Implement abstract class.
- Generics in java. Use T in class (Except primitive type).
- Use to restrict the type of T in generics.
- Naming convention.
- Package creates namespace, so that class and interface name conflicts are avoided; different restriction on class access.
- Use exact package name when importing instead of using asterisk.
- Generate jar and add external jar in Intellij.
- Scope: enclosing block check for nearest declared variable; visibility in Java for inner class's variable.
- Access modifier.
- Static variable and static method. Static method is not allowed to access non-static variable.
- Final variable and final class. XOR operator.
- Final method can't be override by sub class, static block will be executed before constructor.
- Collection. Collections.binarySearch() improve the efficiency compared to brute force search.
- Collection.copy() common exception, the difference among copy list methods.
- Comparator method and Comparable class。
- Map, difference between Map and Collection. remove and replace methods for different parameters.
- Map iteration. Split method.
- Immutable class. Search in intellij with regular expression. The use of private, final in variable and class, how to refer a mutable object. Avoid setter method. A Strategy for Defining Immutable Objects.
- Set, addAll method in Set, compressed pointer in Java 7 (Virtual Machine Performance Enhancements)
- HashSet, override equals method in intellij. hashCode method and equals methods
- When to mark equal and hashcode methods as final in a class: consider behavior of subclass; otherwise in the overridden methods, prevent class and its subclass to be equal.
- Set bulk operations: addAll(), retainAll(), removeAll(), containAll().
- Sorted collection. Collections.unmodifiableMap() method. LinkedHashMap, TreeMap.
- Exception: LBYL: look before you leak (test on null ...). EAFP: easy to ask for forgiveness than permission (with try catch, which has less code and elegant).
- Catching specific exception instead of general exception. Stack trace's printing way. Stack trace and call stack.
- Catching and throwing exceptions. Multiple catch exceptions. Difference between single pipe and double pipe.
- IO: sequential data and random access data. Checked exception and unchecked exception. Close file in a final block.
- Try with resource: code without writing close in finally block; enable throwing exception when closing file writer stream.
- FileReader and closeable. BufferedReader. Difference between BufferedReader, FileReader, InputStreamReader.
- DataOutputStream, BufferedOutputStream, FileOutputStream. Bitshift operator.
- ObjectInputStream, ObjectOutputStream.
- Random access file, seek method.
- Java NIO. Reading and writing in NIO (Files.write, Files.readAllLine...), NIO vs. IO.
- Writing binary file with NIO.
- Reading file with NIO: absolute/relative read.
- Chained put methods. Writing sequentially by using channel.position method + flip method.
- Pipes with threads. How to copy file in NIO channel.
- Working with file system(copy, delete, move file ...): java.nio.file; Path interface; delimiter in windows: backslash; escape the backslash of path when it's in a string that has double quotes.
- Check the existence of a file: Files.exists(); copy a file: Files.copy(); move/rename a file: Files.move(); delete a file: Files.deleteIfExists()
- Create a file: Files.createFile; create directory: Files.createDirectories(); file size, last modified time... by using Files.readAttributes().
- Bitwise or used in catching multiple exception. DirectoryStream for reading directory content. Avoid hard-code separator in the path. Create temp file. Filestore (such as C: in windows).
- Walk through directory tree: SimpleFileVisitor, Files.walkFileTree().
- When to use IO: file contents. When to use NIO: file system such as copy file.
- Thread and process; our code runs on main thread or other explicitly created thread. Thread stack and heap.
- Thread color. Such as ANSI_GREEN, ANSI_PURPLE...
- Runnable interface. run() and start(); sleep() method;
- There are the interrupt() and join() from one thread to another.
- Multiple threads: can't predict which will run first.
- Stack (data is not shared in thread) and heap (data is shared in thread). Thread interfering happens when multiple threads are writing to the same resource.
- Synchronization. Intrinsic lock, how local variable influence the synchronized code block (don't use local variable for synchronized()) ,avoid using String or boxed primitives such as Integer, Boolean for synchronization.
- Producer and consumer, deadlock, wait(), notify(), notifyAll() methods. Thread-safe collections
- Java util concurrent package.
- Lock interface, Reentrant lock, lock() and unlock() in the loop. Try Finally in the lock and unlock methods.
- Executor Service, execute() and shutdown() methods. It suits application with large number of threads.
- ArrayBlockingQueue.
- Avoid deadlock: try to obtain the lock in the same order.
- Thread starvation, setPriority() method is a suggestion to operating system.
- Fair Lock: in Reentrant lock it guarantees FIFO. Live lock. Slipped condition.
- Atomic action, volatile, AtomicInteger, compareAndSet().
- Lambda expression: argument list, arrow token, body.
- Variable outside of anonymous class is final to prevent sync error by the different instance updating that variable.
- effectively final for variable in lambda expression, forEach() method.
- Enhanced for loop; predicate test() as condition, write the predicate using lambda expression or anonymous class.
- IntPredicate, chain multiple predicates by using and() method. Supplier.
- Use Function to avoid using interface and implement it. Chaining Functions by using andThen() method. BiFunction.
- Stream, method reference, map() method in the stream, terminal operation and intermediate operation, peek() method used for debug.
- flatMap() method, lazily evaluated.
- Carrot boundary matcher, dollar sign $ means characters in the end, [^ ej] means match any character except e and j. [a-fA-F3-8] match a to f, A to F and 3 to 8. It works the same as (?i)[a-f3-8],\d and \D, \s, \t, \S, \w, \W, \b. regexpal used as online regular expression tool.
- Quantifier, Matcher and Pattern, Group pattern, greedy quantifier such as *, lazy quantifier such as *?
- Debugger. Step over button, step into button, Force step into button, step out button, drop frame button, run to cursor button.
- Watch panel. Field watch point.
- Smart step into in intellij to check specific method when there are multiple methods called in one line. Associate source with its third party library.
- Junit test. Assert methods. assertArrayEqals() method. AssertThat() method, which is often used, beforeClass && afterClass; Before && After annotations.
- Parameterized test for multiple test cases.
- Java network. java.net package(low level and high level API), intranet, Ipv4 and Ipv 6, TCP/IP, Socket.
- Client and server app by using socket. Server handles multiple clients by threads.
- Using timeout to block client gets blocked.
- TCP: handshaking, used when need response from server, UDP is used when speed is essential and no need for reliable connection, no requirement for getting response from the server. Need to choose by use case.
- Difference between URL and URL, what to use in java network programming.
- Absolute URI and relative URI (when a URI doesn't specify the scheme), use URL when access resources, use base URI + relative URI in big project.
- Use URL to get resource by InputStreamReader.
- HTTPUrlConnection, flickr api consists of callable methods and some API endpoints.
- Popular alternatives to HttpUrlConnections: Jetty and Apache HTTPClient. (They're more suggested nowadays)
- Java 9, module: container of packages. Normal module and open module.
- Module declarations
- Google java style guide
- Java operator precedence