JDK

Breaking static dependencies using Java 8 lambdas

Static dependencies are usually bad , because that dependencies are based on the class level and class objects can not be replaced at runtime in contrast to object instances. That’s why static dependencies are usually a pain if it comes to tests. When you want to write a unit test you usually want to mock the dependent objects, but you can’t do that if the dependent object is a class. Timing is for example hard to test, because it is based on the static call to System.currentTimeMillis(); and the result of currentTimeMillis changes all the time. Of course it does, because it’s the nature of time but that makes it also hard… Read More »Breaking static dependencies using Java 8 lambdas

Global java vm arguments

When you start a Java virtual machine you can specify various vm arguments. Some alter the memory management, some the garbage collection and some are system properties. But you can also specify global vm arguments that are picked up by every virtual machine that starts within an environment context. These global options are specified using the _JAVA_OPTIONS environment variable. _JAVA_OPTIONS=-Xmx1024m When you start a JVM while the _JAVA_OPTIONS environment variable is set you will see something like Picked up _JAVA_OPTIONS: -Xm1024m on the command line. The JVM tells you that it has found global java options and picked it up. Useful _JAVA_OPTIONS use cases Certificate management In a lot of… Read More »Global java vm arguments

Clean Code with underscores in literals

As of java 1.7 the java language specification allows integer literals to contain underscores in order to make them more readable. If it is applied in a good way it can enormously increase the readability of your code. In java 1.6 one had to define integer literals like this: int iterations = 10000000; long bytes = 0b11010010011010011001010010010010; With java 1.7 such integer literals can be written more readably by using the underscore as a  thousands separators. int iterations = 10_000_000; or when using binary literals one can use the underscores to group bytes long bytes = 0b11010010_01101001_10010100_10010010;   Further information can be found at http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1 Recommended Reading  

The MVC pattern implemented with java swing

MVC Pattern Basics The MVC pattern describes a way to organize the components of a graphical user interface. Therefore it must cover all aspects of a user’s interaction with an application. If we take an analytic look at a graphical user interface we will understand why the MVC pattern is composed of the 3 elements model, view and controller. Model A model is an abstraction of something that you want to present the user in a view. Therefore there are two stereotypes of models: UI-model A ui model is an abstraction of a ui component’s state. Therefore it has properties like: focus, enablement, selection and so on. A good example… Read More »The MVC pattern implemented with java swing

The difference between pojos and java beans

Java Beans and Pojos are often used and misunderstood terms. Some think that a pojo is a java bean and vice versa. In fact it is not. There are differences that matter. The pojo If you want to know what a term really means you have to find the source context in which the term has been created. So for the term pojo it was originally created by Martin Fowler, Rebecca Parsons and Josh MacKenzie at a time when J2EE had it’s hype. At that time J2EE developer were more busy with technology instead of concentrating on the business value. The problem arised because J2EE requires a lot of techology code in your… Read More »The difference between pojos and java beans