Main

Java Seminar (2010/2011)

Annotation from SIS:
Basic syntax - primitive types, classes, interfaces, objects, inheritance, packages, operators. Differences between Java and C++. Exception handling: try, catch, throw. Arrays. Strings. Java memory management and garbage collection. Virtual machine and runtime environment. Development tools. Threads and synchronization. Overview of the packages in the standard Java distribution - accessing files, collection library, networking,...

14:00 Th, SU2

NPRG013 - Winter semester 2010/2011

For more information see: http://dsrg.mff.cuni.cz/~hnetynka/index.cgi/teaching/java

Information for Czech students

  • konzultácie po dohode e-mailom, Malá Strana, druhé poschodnie, dvere č. 204

Project Ideas

Tests

Lab 1: 2010-10-05

  • home vs home/BIG
  • Getting acquainted with UNIX (home, stdin/stdout, mc, env vars, man java, man javac)
  • Hello world example : public static void main(String[] args)
  • Binary view of the .class files (first 4 bytes contain CAFEBABE)
  • CLASSPATH vs -cp
    • Calling a method from a class from a different package:
      1. the package is located in the same subtree (no CLASSPATH needed)
      2. the package is somewhere else (CLASSPATH should be specified)
  • Tricky examples from the lecture:

Lab 2: 2010-10-12

  • Getting acquainted with the Eclipse IDE (download at http://www.eclipse.org/downloads/ - Eclipse IDE for Java Developers)
    • You can also use Netbeans, just do not forget to create symlinks from your home directory to home/BIG (you can use quota_free script)
    • You can use multiple workspaces at a time. All workspaces should be located in the BIG dir.
    • To see source code of the standard Java classes in Eclipse, you've got to find the src.zip file.
      • On Ubuntu: apt-get install openjdk-6-source, it should be located in /usr/lib/jvm/java-6-openjdk/src.zip
  • Separation of specification from implementation
    • Specification:
      • Printer interface
      • MyCollection interface
    • Implementation:
      • GenericPrinter implements IPrinter
      • TimestampPrinter extends GenericPrinter
      • PrefixPrinter extends GenericPrinter
      • Logger + Logger with a queue
      • FixedCollection
      • ResizeableCollection

Lab 3: 2010-10-19

  • Recap from the last lecture: iterfaces, exceptions, inner classes, shell args, exit codes
  • Iterable/Iterator (btw. could you describe the difference ? :-) )
    • Task 1: Implement an iterable collection that reallocated its buffer on demand
    • Task 2: Implement an iterable binary search tree
  • Few "tests":
    • calling a method with different signatures (null also matches long[], rather than Object)
    • behaviour of try-finally on normal method return and on System.exit()
    • \u000A character sequence in source code
    • IMPORTANT: static methods in Java are NOT virtual

Lab 4: 2010-10-26

  • again the Iterator/Iterable approach, now with generic types e.g. Iterable<String>
  • reading from files - reading chars (FileReader class), reading lines (BufferedReader class)
  • Three simple tasks:
    • Task 1: Implement MyString with an iterator over individual characters.
      • Here, you should practice strings handling. You can use private String buf; or private char[] buf; as a buffer
      • Implement the iterator at the very beginning.
    • Task 2: Implement a file reader that reads words from a file delimited by a set of characters e.g. whitespaces. Implement your class using the iterator.
      • Use FileReader in such a way that you always remember one character ahead.
      • Store regular characters into the buffer and ignore all sequences of delimiters.
      • The iterator should be implemented at the very end in order to prevent changes in the original implementation. This allows for better reusability of your code.
    • Task 3: Reuse the previous implementation and create a word-wrapper

Lab 4+: 2010-11-02

  • implement MyHashTable class
    • KEY: String
    • VALUE: Object
    • methods: get(key), set(key, value)
    • Iterable + Iterator over elements
  • Splitter class
    • takes an instance of Reader in the constructor (Note: only reset(), read() and close() methods are needed from the Reader class, in Java: Object->Reader->InputStreamReader->FileReader)
    • supports a set of delimiters (e.g. newline, tab, space ...) - setDelimiters(String) method
    • Iterable + Iterator over individual words
  • WordWrapAlignLeft, WordWrapJustify
    • setLineLength() method
    • iterator over lines
    • last line should not be justified
  • Counter
    • takes an instance of Reader in the constructor
    • number of characters
    • number of words
    • number of lines
    • method setMinWordLength()
    • occurrences of every word (word:count)

Lab 5: 2010-11-09

  • Finishing all assignments from previous lectures
  • heapsort, quicksort

Lab 6: 2010-11-16

  • I/O

Lab 7: 2010-11-23

  • concurrent systems in general
    • threads vs processes
    • shared memory
    • multicores, caches, ccNUMA ...
    • critical section - coarse-grained vs fine-grained locking
      • passive vs active waiting
    • race condition a:=0; runParallel(a++); print(a)
    • deadlock (simple approach to deadlock prevention using partial ordering of resources)
      • how to model a deadlock situation
      • verification
    • problems with lock-based approaches (fragile, poor scalability, non-composability)
    • non-blocking synchronization
  • synchronization in Java
    • two types of locks in Java
      • per class (synchronized keyword used in a method definition)
      • per instance (synchronized block of code)
  • Thread, Runnable
  • wait(), notify(), notifyAll()
  • volatile - new memory model in Java 1.5
    • volatile variables do not use cache, they go directly into main memory
    • when working with volatile variable, reordering of instructions will be avoided (prevents double-checked locking problem)
  • more synchrnoziation primitives in java.util.concurrent

Lab 8: 2010-11-30

  • finished the RoundBuffer implementation
  • comparator/comparable

Lab 9: 2010-12-07

  • basic principles of TCP/UDP communication in Java and in general
  • Task: write a multithreaded TCP server + TCP client that implement a remote Todo list
  • Simple TCP echoing server and client available here (TGZ).
    • Multithreaded TCP server
    • contains ANT build file and also works as an Eclipse project
    • ant - compiles the sources
    • ant client - runs the client
    • ant server - runs the server

Lab 10: 2010-12-14

Lab 11: 2010-12-21

Lab 11+: 2011-01-04

  • Finish previous assignment
  • Simple Web Downloader available here (TGZ)
    • URL.openStream allows for downloading content through HTTP protocol (and more)
    • SwingWorker can handle time-consuming operations in background
    • JScrollPane + JTextArea, JTextField
    • BorderLayout (NORTH, SOUTH, CENTER ...)

Lab 12: 2011-01-11

  • Free/Max memory + Garbage Collector