Java Seminar (2009/2010)

NPRG013 - Information for students, Winter semester 2009/2010

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 St, SU2

Some proposals for your Java projects are located here: JavaProjectIdeas?

For more information see:


Lab 1: 2009-10-07

  • Getting acquainted with UNIX environment ;) (home, stdin/stdout, mc, env vars, man java, man javac)
  • CLASSPATH vs -cp
  • Hello world example
  • Binary view of the .class files (first 4 bytes contain CAFEBABE)
  • advanced hello world (calling a method from a class from a different package)
  • malicious examples from the lecture - comparing values vs objects, priority of operators, label and comment, overflow

Lab 2: 2009-10-14

  • Getting acquainted with the Eclipse IDE (download at - Eclipse IDE for Java Developers (92 MB))
    • 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.
  • funny example : i=-i && i != 0
  • funny example : for cycle and float
  • practicing inheritance
    • IPrinter interface
    • GenericPrinter implements IPrinter
    • TimestampPrinter extends GenericPrinter
    • PrefixPrinter extends GenericPrinter
    • Logger + Logger with a queue
    • MyCollection interface
    • Implementacia of MyCollection using an array, that resizes on demand

Lab 3: 2009-10-21

  • Several "tests" to begin with
    • calling a method with different signatures (null also matches long[], rather than Object)
    • behaviour of try-finally when on normal method return and on System.exit()
    • \u000A character sequence in source code
    • EXAMINATION: static methods in Java are NOT virtual
  • 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

Lab 4: 2009-10-28 (holiday)

  • agin the Iterator, now with generic types e.g. Iterable<String>
  • reading from a file - 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

Practice at home, the whole description is here:

Lab 5: 2009-11-04

  • Recap: generic types and iteration Iterable<T> and Iterator<T>
  • Recap: file access using FileReader, BufferedReader

Tasks (catching up Ex4 + Ex5):

  • 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 6: 2009-11-11

Lab 7: 2009-11-18

  • synchronisation in multithreaded environment
  • Producers vs Consumers on a single round buffer

Lab 8: 2009-11-25

  • finished the RoundBuffer implementation
  • comparator/comparable

Lab 9: 2009-12-02

  • basic principles of TCP/UDP communication in Java and also 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: 2009-12-09

Lab 11: 2009-12-16

  • Simple GUI with SWING
    • listeners
    • basic widgets
    • overview of layout managers

Lab 12: 2010-01-13

  • 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 ...)