Java Specialists' Java Training Europehome of the java specialists' newsletter

Newsletters related to Language

Issue Subject Date
238 java.util.Optional - Short Tutorial By Example
Java 8 introduced the java.util.Optional class, based on the famous Guava class by the same name. It was said that we should hardly ever call get(). In this newsletter we offer a short tutorial that demonstrates coding examples of alternatives to get().
225 Hiding Interface Methods
Whenever a class implements an interface, all the implemented methods have to be public. In this newsletter we look at a trick that we can use to make them private.
223 ManagedBlocker
Blocking methods should not be called from within parallel streams in Java 8, otherwise the shared threads in the common ForkJoinPool will become inactive. In this newsletter we look at a technique to maintain a certain liveliness in the pool, even when some threads are blocked.
222 Identity Crisis
The JavaDocs for method Object.hashCode() seems to suggest that the value is somehow related to memory location. However, in this newsletter we discover that there are several different algorithms and that Java 8 has new defaults to give better threading result if we call hashCode a lot.
213 Livelocks from wait/notify
When a thread is interrupted, we need to be careful to not create a livelock in our code by re-interrupting without returning from the method.
212 Creating Sets from Maps
Maps and Sets in Java have some similarities. In this newsletter we show a nice little trick for converting a map class into a set.
210 Calling Methods from a Constructor
In this newsletter we investigate what can go wrong when we call methods from constructors, showing examples from the JDK, Glassfish, Spring Framework and some other well known frameworks..
208 Throwing Exceptions from Fields
How can you set a field at point of declaration if its constructor throws a checked exception?
207 Final Parameters and Local Variables
The trend of marking parameters and local variables as "final" does not really enhance your code, nor does it make it more secure.
203 GOTO in Java
It is possible to use the break statement to jump out to the end of a labelled scope, resulting in some strange looking code, almost like the GOTO statement in C.
199 Hacking Java Surreptitiously
Surreptitious: stealthy, furtive, well hidden, covert. In this newsletter we will show two Java puzzles written by Wouter Coekaerts that require a surreptitious solution. You cannot do anything to upset the security manager.
198 Pushing the Limits in Java's Random
What is the largest double that could in theory be produced by Math.random()? In this newsletter, we look at ways to calculate this based on the 48-bit random generator available in standard Java. We also prove why in a single-threaded program, (int)(Random.nextDouble() + 1) can never be rounded up to 2.
197 What is the Meaning of Life?
In this newsletter we try to calculate the meaning of life, with surprising results.
190b Automatically Unlocking with Java 7 - Follow-up
In this newsletter we discuss why we unfortunately will not be able to use the try-with-resource mechanism to automatically unlock in Java 7.
190 Automatically Unlocking with Java 7
In this newsletter we explore my favourite new Java 7 feature "try-with-resource" and see how we can use this mechanism to automatically unlock Java 5 locks.
186 Iterator Quiz
Most of the northern hemisphere is on holiday, so here is a quick quiz for those poor souls left behind manning the email desk. How can we prevent a ConcurrentModificationException in the iterator?
178b WalkingCollection Generics
Generics can be used to further improve the WalkingCollection, shown in our previous newsletter.
177 Logging Part 3 of 3
After almost nine years of silence, we come back to bring the logging series to an end, looking at best practices and what performance measurements to log.
168 The Delegator
In this newsletter we show the reflection plumbing needed for writing a socket monitor that sniffs all the bytes being sent or received over all the Java sockets. The Delegator is used to invoke corresponding methods through some elegant guesswork.
167 Annotation Processing Tool
In this newsletter we answer the question: "How do we force all subclasses to contain a public no-args constructor?" The Annotation Processing Tool allows us to check conditions like this at compile time, rather than only at runtime.
161 Of Hacking Enums and Modifying "final static" Fields
The developers of the Java language tried their best to stop us from constructing our own enum instances. However, for testing purposes, it can be useful to temporarily add new enum instances to the system. In this newsletter we show how we can do this using the classes in sun.reflect. In addition, we use a similar technique to modify static final fields, which we need to do if we want the switch statements to still work with our new enums.
141 Hacking Enums
Enums are implemented as constant flyweights. You cannot construct them. You cannot clone them. You cannot make copies with serialization. But here is a way we can make new ones in Java 5.
127 Casting like a Tiger
Java 5 adds a new way of casting that does not show compiler warnings or errors. Yet another way to shoot yourself in the foot?
126 Proxy equals()
When we make proxies that wrap objects, we have to remember to write an appropriate equals() method. Instead of comparing on object level, we need to either compare on interface level or use a workaround to achieve the comparisons on the object level, described in this newsletter.
123 Strategy Pattern with Generics
The Strategy Pattern is elegant in its simplicity. With this pattern, we should try to convert intrinsic state to extrinsic, to allow sharing of strategy objects. It gets tricky when each strategy object needs a different set of information in order to do its work. In this newsletter, we look at how we can use Java 5 Generics to pass the correct subtype of the context into each strategy object.
121 How Deep is Your Hierarchy?
Someone asked me yesterday what the maximum inheritance depth is in Java. I guessed a value of 65535, but for practical purposes, not more than 5. When I asked performance guru Kirk Pepperdine to estimate, he shot back with 63. In this newsletter, we look at the limitations in the JVM and examine some existing classes.
120 Exceptions From Constructors
What do you do when an object cannot be properly constructed? In this newsletter, we look at a few options that are used and discuss what would be best. Based on the experiences of writing the Sun Certified Programmer for Java 5 exam.
117 Reflectively Calling Inner Class Methods
Sometimes frameworks use reflection to call methods. Depending how they find the correct method to call, we may end up with IllegalAccessExceptions. The naive approach of clazz.getMethod(name) is not correct when we send instances of non-public classes.
114 Compile-time String Constant Quiz
When we change libraries, we need to do a full recompile of our code, in case any constants were inlined by the compiler. Find out which constants are inlined in this latest newsletter.
113 Enum Inversion Problem
A problem that I encountered when I first started using enums was how to serialize them to some persistent store. My initial approach was to write the ordinal to the database. In this newsletter, I explore some ideas of a more robust approach. It will also show you some applications of Java generics.
110 Break to Labeled Statement 2005-06-30
109 Strategy Pattern of HashCode Equality 2005-05-18
108 Object Adapter based on Dynamic Proxy 2005-05-10
107 Making Enumerations Iterable 2005-04-19
103 New for/in loop gymnastics 2005-02-07
102 Mangling Integers 2005-01-31
097 Mapping Objects to XML Files using Java 5 Annotations 2004-10-17
096 Java 5 - "final" is not final anymore 2004-10-07
095b Follow-up: Self-reloading XML Property Files 2004-10-01
095 Self-reloading XML Property Files 2004-09-30
094 Java Field Initialisation 2004-09-20
087 sun.reflect.Reflection 2004-04-09
084 Ego Tripping with Webservices 2004-02-05
083 End of Year Puzzle 2003-12-26
083b End of Year Puzzle Follow-up 2003-12-26
080 Many Public Classes in One File 2003-10-13
079 Generic toString() 2003-10-08
076 Asserting Locks 2003-08-05
073 LinkedHashMap is Actually Quite Useful 2003-06-22
072 Java and Dilbert 2003-06-15
071 Overloading considered Harmful 2003-06-01
067 BASIC Java 2003-03-31
063 Revisiting Stack Trace Decoding 2003-01-28
062b Follow-up and Happy New Year! 2002-12-31
062 The link to the outer class 2002-12-27
056 Shutting down threads cleanly
Starting threads is easy. Shutting them down again in an orderly fashion is not. In this newsletter we explore how to use interrupts to indicate to a thread that it should cooperatively shut down.
055 Once upon an Oak ... 2002-08-26
050 Commenting out your code? 2002-06-10
047 Lack of Streaming leads to Screaming 2002-05-24
043 Arrgh, someone wants to kill me! 2002-03-11
040 Visiting your Collection's Elements 2002-01-31
036 Using Unicode Variable Names 2001-11-23
034 Generic Types with Dynamic Decorators 2001-10-24
032 Exceptional Constructors - Resurrecting the dead 2001-10-11
031 Hash, hash, away it goes!
When I first started using Java in 1997, I needed very large hash tables for matching records as quickly as possible. We ran into trouble when some of the keys were mutable and ended up disappearing from the table, and then reappearing again later.
028 Multicasting in Java 2001-08-14
026 Package Versioning 2001-07-25
025 Final Newsletter 2001-07-12
022 Classloaders Revisited: "Hotdeploy" 2001-06-07
021 Non-virtual Methods in Java 2001-05-31
020 Serializing Objects Into Database 2001-05-24
018 Class names don't identify a class 2001-05-03
017b Follow-up 2001-04-28
017a Switching on Object Handles 2001-04-26
014 Insane Strings 2001-03-21
011 Hooking into the shutdown call 2001-02-28
009 Depth-first Polymorphism
Usually in Java, polymorphism is done depth-first. This is the reason why in Java 5, classes implementing Comparable cannot be further specialized to another Comparable type (compareTo takes an Object). In this newsletter we look at how we can change this to breadth-first polymorphism.
008 boolean comparisons
Java was based on ideas taken from C/C++, but the designers of the language tightened up the language significantly. In C/C++, a zero (0) means false and non-zero (e.g. 1) means true. In this newsletter, we examine how we should be comparing booleans.
006 Implementation code inside interfaces
Did you know that it is possible to define inner classes inside interfaces? This little trick allows us to create method objects inside an interface.
005 Dynamic Proxies - Short Tutorial
Dynamic proxies can help us reduce the amount of code we have to write. In this newsletter, our guest author, Dr Christoph Jung, gives us a short tutorial on how the dynamic proxies work.
004 Logging part 2
We look at some tricks on how we can track where things are happening in our code, which can then be used for producing more detailed logging.
003 Logging part 1
In this newsletter we look at how we can write a TeeOutputStream that works similarly to the unix "tee" utility and pipes the output to two different OutputStreams. We can then reassign System.out to be written to a file and to the old System.out.
002 Anonymous Inner Classes
Anonymous inner classes allow us to call super class methods inside its initializer block. We can use this to add values to a collection at point of creation, for example: new Vector(3) {{ add("Heinz"); add("John"); add("Anton"); }});

Extreme Java - Concurrency and Performance for Java 8
Extreme Java - Advanced Topics for Java 8
Design Patterns
In-House Courses

© 2010-2017 Heinz Kabutz - All Rights Reserved Sitemap
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. is not connected to Oracle, Inc. and is not sponsored by Oracle, Inc.