- Using Threads in Java
An introduction to "raw" threads in Java, looking at the Thread and Runnable
classes and issues such as thread interruption
and thread safety. Plus more advanced
threading information such as:
- Synchronization and concurrency in Java
Going "beyond the thread", with various aspects of synchronization in Java:
- Basic synchronization constructs: synchronized,
wait/notify and various more recent
Java 5 concurrency utilities.
- The Why are synchronization and concurrency difficult? section covers aspects of computer architecture, illustrating why synchronization is both necessary and a tricky problem.
- In Synchronization and concurrency before Java 5, we look at some of the "fundamental building blocks" of synchronization, such as synchronized blocks and the wait/notify construct.
- Thread-local variables in Java are an occasional alternative to shared, synchronized variables.
- Problems with the standard Java synchronization model examines why these fundamental buildings blocks were extended in Java 5.
- How synchronization works under the covers gives some information on how the JVM implements synchronization, and thus how improvements are possible in the Java 5 synchronization classes.
- final and Volatile variables in Java: what they are, when to use volatile fields, and their new significance under Java 5.
- the dreaded (and still misunderstood) double-checked locking antipattern, and how to fix it!
The following go in to some more detail on the Java 5 synchronization libraries:
- The Atomic classes in Java 5 provide a more lightweight way of atomically accessing various types of variables.
- Explicit locks in Java 5 explains a more flexible locking mechanism that in some cases may be a benefit over the standard synchronized block.
- The wait/notify mechanism (and Java 5 alternatives) looks in detail at the standard wait/notify, which pre-Java 5 was the main means for threads to communicate with one another, and at constructions in Java 5, such as queues and Semaphores, which now make it less necessary. In particular, the Java BlockingQueue implementations are useful for implementing the typical producer-consumer pattern.
- A page on ConcurrentHashMap Performance compares the concurrency of the latter class with the pre-Java 5 method of synchronizing around an ordinary HashMap.
- Introduction and discussion of exceptions, Java's means of managing errors and
unexpected conditions. Topics include a general introduction to exceptions, exception-handling syntax including the try/catch block
and a look at the exception hierarchy. More advanced topics include
uncaught exception handlers
and exception recasting.
- Java Servlets
- Servlets are an excellent low-resource way of serving dynamic web pages, and are increasingly
supported by cheap hosting packages. In our introduction, we look at how
to write a Servlet, then look at more advanced techniques such as using sessions
and cookies and reading request headers.
- What is the Java equivalent of...?
- New section on how to immitate in Java certain features of other languages such as C++, starting with the Java equivalent of const plus the Java
equivalents of C/C++ memory management operators
such as new, delete and malloc().
- Doing math in Java
This section gives an overview of using floating point
primitives in Java. The section includes a look at the
performance of java.util.Math methods.
We also look at the BigDecimal and
BigInteger classes, which allow calculations on numbers of arbitrary numbers of digits,
some information on the performance
of multiplication using both a naive method and implementations of Karatsuba's algorithm.
- Java Collections
This tutorial looks at using collections in Java
firstly from a practical point of view,
focussing on the basic list (including
how to sort data in a list), set and map. Advanced topics then include guidelines to writing a hashCode() method and a look at how the String hash function works,
and a look at the performance of the Java
Finally, we look at some advanced hashing techniques to
reduce memory usage in certain cases.
- Java & random numbers
- Are you generating and using random numbers correctly in your Java programs?
Are you aware of the security and testing issues of not using them correctly?
Find out more with this Java random number tutorial.
- Java memory usage
- Articles on how to calculate or query the use of Java objects, including the
Classmexer agent which provides calls to make it easier to
query the memory usage of Java objects from the JVM itself via the
Java Instrumentation framework.
- How to fix...
- Find out what to do with those awkward OutOfMemoryErrors,
StackOverflowErrors and StreamCorruptedExceptions.
- Java Swing
- How to use Swing, Java's rich and extensible user interface library.
Currently available tutorial pages include a Swing components gallery, giving an overview of the most common
- Java cryptography
- An overview of the main encryption and authentication facilities offered
by Java, with a discussion of caveats you need to be aware of to
use them securely.
- Databases with Java
How to access a database from Java. Topics covered include
connecting to a database with Java
and the mapping between SQL and Java data types.
- Profiling in Java 5
This section looks at various aspects of profiling, focussing on how it actually works, and how with Java 5 you can write some flexible profiling code of your own, and even leave profiling running permanently on your live server.
- Regular Expressions in Java
Tutorial on using regular expressions from scratch, including basic expressions with the String.matches() method, moving on
to topics such as the Pattern and Matcher classes, used to give more control over expression matching, and capturing groups and the
performance of string tokenisation using regular expressions. Plus examples of using regexular expressions for IP location and HTML scraping.
- Java I/O
This section gives a basic tutorial on I/O in Java, concentrating corrently on the standard I/O libraries.
- Bits and bytes in Java
A look at how computers store and manipulate numbers, with particular reference
to Java, including a look at binary numbers in
general, and how they apply to computer number representation.
- Data compression in Java
A look at how to use the standard compression library, including some advanced
tips for improving compression ratio in Java. We cover reading from standard
ZIP and GZIP
Then in the how to use Deflater section, we give a 5-minute practical summary of 'raw' data compression with default options. Then we show
how to configure Deflater to trade off
compression ratio for CPU usage, and how in some cases we can transform our data to use the
FILTERED and HUFFMAN_ONLY modes, which
can give a 10-20% improvement on compression ratio with text.