background preloader

Java

Facebook Twitter

Java Secret: Using an enum to build a State machine. Overview The enum in Java is more powerful than many other languages which can lead to surprising uses.

Java Secret: Using an enum to build a State machine

How to tame java GC pauses? Surviving 16GiB heap and greater. Memory is cheap and abundant on modern servers.

How to tame java GC pauses? Surviving 16GiB heap and greater.

Unfortunately there is a serious obstacle for using these memory resources to their full in Java programs. Garbage collector pauses are a serious treat for a JVM with a large heap size. There are very few good sources of information about practical tuning of Java GC and unfortunately they seem to be relevant for 512MiB - 2GiB heaps size. Recently I have spent a good amount of time investigating performance of various JVMs with 32GiB heap size. In this article I would like to provide practical guidelines for tuning HotSpot JVM for large heap sizes. You may also want to look at two articles explaining particular aspects of HotSpot collectors in more details “Understanding GC pauses in JVM, HotSpot's minor GC” and “Understanding GC pauses in JVM, HotSpot's CMS collector”.

Target application domain. Java Secret: More uses for varargs. Java Secret: Double Brace Initialization. Overview Java allow you to add initialisation blocks to a class definition.

Java Secret: Double Brace Initialization

This is particularly useful in combination with anonymous classes for creating mock collections. esp for unit tests. Initializer Blocks In a class you can add blocks of code which are called during class initialisation. This are not widely used because they tend to be confusing. Public class A { private int version; { String versionText = System.getProperty("A.version", "-1"); try { version = Integer.parseInt(System.getProperty("A.version", "-1")); } catch (NumberFormatException nfe) { System.err.println("Unable to parse A.version "+versionText); version = -1; } } } JavaFX 2.0 Charts. May 28, 2011 By Jasper Potts We did a complete rewrite of charts in JavaFX 2.0 to add cool features like: Dynamic Data SupportAnimationAuto RangingCSS Styling There is a sample application called “Chart Sampler” that ships with JavaFX 2.0 Beta that shows some of what can be done with the new charts.

JavaFX 2.0 Charts

Using JavaFX UI Controls:About This Tutorial. Task Notification with Google Talk via XMPP. NUI Chapter 8. Face Recognition. This chapter does not appear in the book.

NUI Chapter 8. Face Recognition

In the last chapter I developed software that could detect and track a face as it moved in front of a webcam. The next step, and the topic of this chapter, is to attach a name to the face, to recognize it using a technique called eigenfaces. The outcome is the GUI application shown at the top of this page. When the user presses the "Recognize Face" button (at the bottom of the window in the picture), the currently selected face is compared against a set of images that the recognizer code has been trained against.

The name associated with closest matching training image is reported in a textfield (and in yellow text in the image pane), along with a distance measure represented the 'closeness' of the match. The recognition process relies on a preceding training phase involving multiple facial images, with associated names. The PDF file for the draft chapter (752 KB). Navigation: How to use annotations for configuration. In the java world we have been using and getting used to annotations since Java 1.5.

How to use annotations for configuration

Although there were some critical voices at first, I think most of us have come around and are using annotations now quite extensively. In my experience annotations are mostly used on POJO domain classes to configure frameworks like Hibernate, Spring and Seam and many other frameworks to be able to handle the custom objects correctly. There are as many different approaches to this as there are implementations.

In this blog I try to identify a few of the better approaches and a few of the poorer ones. Java Tip: Find process id of running Java process.

Generic

Graphics in Java - Part 2. Graphics and Primitives Well, what exactly are primitives?

Graphics in Java - Part 2

How are they useful? Well, simply, primitives are shapes and colors that the Graphics class can render without using loaded images. Most of the time, primitives are Circles, Rectangles, and such things. The Basic Graphics Class The Graphics class includes many methods to allow for the drawing of both images and simple graphics. The important thing to note is the number of arguments that each method receives and how it works.

JVM Web Framework Matrix. Embed Ivy - How to use Ivy with Java. Remote debugging in Java. Buzz Word: Remote DebuggingConsider a scenario where you can't run the application in your development environment, e.g. say your application can run only on a server machine (because it is dependent on some third party interface that are not accessible in your development machine) and you have to resolve a problem (bug).

Remote debugging in Java

What you can do? The solution is Remote debugging. Remote debugging is debugging an application by connecting the remotely running application with your development environment ( i.e. you can say to connect with code in your IDE). How it works : Basic concept Remote debugging feature is provided by Java specification itself. Chapter 34. GPS Mapping and Geotagged Images. [ This chapter does not appear in the book. ] GPS chips are becoming standard in smart phones, but what about adding similar functionality to laptops, netbooks, and other mobile PCs?

Chapter 34. GPS Mapping and Geotagged Images

GPS receivers that connect to devices via a USB port aren't particularly expensive (US$30 for a decent one), and are surprisingly easy to utilize from Java. The first part of this chapter describes my experience using the Canmore GT-730F USB GPS receiver for obtaining latitude and longitude information to display on a map downloaded from OpenStreetMap. The image at the top of this page shows a map of the road outside my office building, created as I walked around with the GPS receiver plugged into my netbook. JMX - Life Savior or Backdoor. The Java Management Extensions (JMX) API is a standard for managing and monitoring applications and services.

JMX - Life Savior or Backdoor

Its usage in application build using Spring Framework is very simple and easy. I hope you'll agree with me after lecture of this post. We will use one of the possible solutions for JMX and Spring usage, based on Java 5 annotations. On the Spring configuration level we need only one new line: <beans xmlns:context=" xmlns:xsi=" xmlns=" xsi:schemalocation=" ... The rest of this magic is done at the Java source :). @ManagedResource(objectName = "Test:name=Cerberus") public class Cerberus extends HandlerInterceptorAdapter { private boolean opened = true; @ManagedOperation public void close() { this.opened = false; } @ManagedAttribute public boolean isOpened() { return opened; } @ManagedOperation public void open() { this.opened = true; } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (!

Spring

JWt, Java Web Toolkit - Introduction. Best Java Swing Look and Feel Themes. For Years, Java Swing has suffered from poor UI colors and designs. Since the support of Java to let people desing their own Themes, it has revamped those old boring UIs. When we talk about designing look and feel, we know it is about implementing different UI classes for different components. Today, we can use Synth look and feel, which allow us to customize the look and feel by writing an XML file.

The other way is to use UIManager to load the L&F class directly from classpath. For which the code goes like this: UIManager.setLookAndFeel("fully qualified name of look and feel"); The Look and Feel Libraries are broadly divided into two categories. SkinnableNon-Skinnable Skinnable look and feel can’t only change the LAF of wigets in your application, but, can also change the look and feel of window title bars and borders. Professional Themes. Embedding a Visual HTML Editor in the NetBeans RCP. Getting the NetBeans RCP/DJ Native Swing integration to work with the FCKEditor or the CKEditor (the same lib, just renamed) is quite easy. After taking the steps described in the link above, to add CKEditor/FCKEditor support, you just download the CKEditor ZIP file or the FCKEditor ZIP file from the ZIP file to the classpath. I simply added the zip-file to the "DJSwing-Windows64" module, via Properties->Libraries->Wrapped Jars->Add Jar. Btrace: BTrace. How to write Secure Java Code « My Blog – My Thoughts.

There are many young programmers who come up to me asking for guidelines on how to write secure Java code. MyBatis Home. Sending delayed JMS Messages. Rich Internet Applications (RIA) » Blog Archive » Beautiful Java Enums.

Java EE

5 things you didn't know about ... Everyday Java tools. Know the JVM Series – 1 – The Uncaught Exception Handler. The Java API, backed by the JVM provides tons of features and facilities to Java developers, which could be used to get things done easily for certain specific scenarios. However, these features are often overlooked by developers, mainly due to the lack of reading material and resources regarding these APIs.

The purpose of this article series is to introduce such features of the JVM and Java API to intermediate Java developers. Quick Review of Inner Classes in Java. Today I was again going through SCJP Sun Certified Programmer for Java 5 Study Guide by Keithy Sierra and Bert Bates as I needed some clarification.

Libraries

CodingThis.com. Java 6.0 introduces many Application Programming Interfaces and there are many enhancements in existing classes especially in collection APIs. Javac. Office desde Java. Making the JVM much faster.