Feed aggregator

What Can Men Do?

Javalobby Syndicated Feed - Wed, 09-Nov-16 23:31

So, I wrote a long email to the London Java Community in answer to an excellent question: “What can men do to support Women in Technology?”

It’s a bit of a brain dump, by no means comprehensive, and is in answer to a specific question in a specific context, but I’ve been asked to make the information public so it can be useful in a broader context. So here it is.

Categories: Java

This Week in Spring: Squashing Bugs, Saying Hi to the CLI, and jOOQ

Javalobby Syndicated Feed - Wed, 09-Nov-16 22:31

Welcome to another installment of This Week in Spring! This week I’m in London, England for µCon, Antwerp, Belgium for Devoxx, and Malmö, Sweden for Oredev. If you’re around, ping me and say hi.

Categories: Java

Parallelizing Hystrix Calls

Javalobby Syndicated Feed - Wed, 09-Nov-16 03:31

This is more common sense than anything else. If you make calls to multiple remote systems and aggregate the results in some way, represented as a marble diagram here ...

... and you protect each of the remote calls using the awesome Hystrix libraries, then the best way to aggregate the results is using native rx-java operators.

Categories: Java

Auto-Generating Spring Security: Default JDBC Realms

Javalobby Syndicated Feed - Wed, 09-Nov-16 02:01

The previous tutorial showed how we can auto-generate of spring security using a memory realm. This tutorial expands on this to cover Default JDBC Realms using the source code from the parkrunPB application

Security Requirements

The site has the following links and security requirements:

Categories: Java

Gradle Goodness: Custom Plugin Repositories With Plugins DSL

Javalobby Syndicated Feed - Wed, 09-Nov-16 01:01

To apply a plugin in our Gradle build script, we can use the plugins DSL. The plugins DSL is very concise and allows Gradle to be more efficient and more in control when loading the plugin. Normally the plugin we define is fetched from the Gradle plugin portal. If we have our own repository, for example on the intranet of our company, we have to define that extra repository with a pluginRepositories configuration block in the settings.gradle file of our project.

In the following sample, we have a plugin mrhaki.gradle.version-file that is stored in the company intranet repository with the URL http://intranet/artifactory/libs-release/.

Categories: Java

Java Annotated Monthly: Oracle Appeals, Updates on Java 9, and a Kotlin Cheatsheet

Javalobby Syndicated Feed - Tue, 08-Nov-16 23:31

The froth of JavaOne has died down (already!) and it’s almost back to business as usual. Although here at JetBrains we’re working hard on our latest product releases, and gearing up to see some of you at Devoxx this week. This month’s annotated monthly looks outward to more than just things that impact Java and the JVM, and pulls together content that affects all developers, like design, architecture and security.


In news that will surprise no-one, Oracle is appealing again. Meh.

Categories: Java

Solving Small Problems (Part 1)

Javalobby Syndicated Feed - Mon, 07-Nov-16 03:01

Although I tried to make this post comprehensible by itself, you might want to read previous parts before this one.

One of the keys to being a good programmer is working in an organized way. You pick a small, easy problem, solve it and move to the next small, easy one. One after another, step by step, something greater emerges. Our brains have limited capacity and processing speed. We can't do everything at once, we can't solve multiple complicated problems at the same time. Knowing this we can conciously limit our current "context" to something simple enough to chew at once.

Categories: Java

Breadth-First Search With Java 8 Stream API

Javalobby Syndicated Feed - Mon, 07-Nov-16 02:01

I recently had the problem of walking through some data and collect elements on the go. I thought it would be nice to use theStream API in Java 8. After a short search on “the Internet,” I found a solution in this blog post for tree structures and in this one for recursing through a file system (which is a tree structure again). So, story told? No way! I needed to walk through graph structures (i.e., there might be cycles in it). On the contrary, the solutions above will run forever, or more precisely, they will terminate relatively fast with a StackOverflowException.

A solution is e.g. a breadth-first search (BFS). In essence, a BFS explores the search space level by level. On the go, it stores the so-called open list. open contains the nodes (on the next level) not explored, yet. Already processed nodes won’t be put into open again. This enables searching through structures with cycles.

Categories: Java

New features in iOS 10 Notifications

codecentric Blog - Mon, 07-Nov-16 01:01

This text mostly focuses on the local notifications and what we can do in UIViewController in Notification Content Extension.

Notifications in iOS 10 got quite a lot of improvements. The first one is a higher contrast with the notification view on a Lock Screen, so it stands out more. The second one is a total customization of notification presentation.


As seen in the picture above, the notifications stand out more and are attention-grabbing.

We can put custom content in the notification: music, video, images, custom drawing and animations.

When a user is unlocking his device, the first thing a user will see when he taps on the Touch ID button are notifications that are waiting for him.
Since the lock screen unlocking procedure has also been changed, the notifications have a greater chance of getting attention from a user. To unlock a phone, the user needs to tap twice and it is during this process that notifications get a small window of opportunity for presentation.


When the phone is locked, tapping the Home button reveals Lock Screen with pending notifications for user.

Tapping on the notification on the lock screen will open associated app for that notification. Swiping the notification to the left reveals View and Clear buttons. The View button is available only if device does not support 3d Touch.

On devices with 3d Touch, the user can get preview of the content by force touching the notification, which is either on the Lock Screen or Springboard. For example, the user receives a notification about new message for him. User can Force Touch notification and open the message view. The user can then type reply directly on the lock screen, instead of opening the app.

When a notification appear on Springboard, user can swipe down on notification view and get content extension presented to him. That is possible if the app has Notification Content Extension implemented about that notification.

In addition, developers can add more than one extension to their app. They just need to create new target in Xcode project and assign a category identifier in extension’s Xcode target Info.plist file.

On the time of writing, no iPad devices has Force Touch feature. Some iPhone models in production do not have Force Touch feature. On these devices, user can reveal notification by swiping.


Developers can add actions to notifications. Actions are visible when user expand the notification.
We don’t need to have Notification Content Extension for this feature.

Developers can add actions to the notification when configuring the category object:

let cool = UNNotificationAction.init(identifier: "CoolAction", title: "Cool", options: [.foreground])
let approve = UNNotificationAction.init(identifier: "ApproveAction", title: "Approve", options: [.foreground])
let later = UNNotificationAction.init(identifier: "LaterAction", title: "Later", options: [.foreground])
let like = UNNotificationAction.init(identifier: "LikeAction", title: "Like", options: [.foreground])
let category = UNNotificationCategory.init(identifier: "CategoryId", actions: [cool, approve, later, like], intentIdentifiers: [], options: [])

Note that we need category identifier later, when configuring the notification content object.
Notification category needs to be created and registered with UNUserNotificationCenter early in the application lifecycle, preferably in app delegate.

Every notification can have several actions assigned to it. The actions will appear in an ordered fashion. If we put more notification actions that can fit in the screen real estate, user will not be able to use them.


Actions are the only way a developer can enable user to interact with the notification, because adding Gesture Recognizers or UIControl objects won’t work. UIViewController that is shown when notification is expanded does not process touch input. The default behaviour for tapping the notification view is launching the app.


Notification attachments are a new way of customising notifications. This is a convenient and easy way to add content to notifications without making an extension. With the help of UNNotificationAttachement class we can attach media files to the notification. By using the options dictionary argument we can also customise the thumbnail image.

We can add three types of attachments to notifications:

1. Image attachment:


2. Video attachment:


3. Music attachment:


When a user interacts with notification, media which is inside attachments are shown or playback controls are presented, depending on media type.
For example, if we send a birthday notification to user we can send image of contact whose birthday it is.

All attachments are created by creating UNNotificationAttachment object with path to media resource and attaching that object to notification content object.

let url: URL? = Bundle.main.url(forResource: "sound", withExtension: "mp4")
let attachment = try? UNNotificationAttachment.init(identifier: "AttachmentId", url: url!, options: [UNNotificationAttachmentOptionsTypeHintKey : "mp4"])


We cannot get text from the user by an UITextView or UITextField. Putting those objects in our UIViewController will just display them, but the user won’t be able to interact with them. The keyboard will not show on touch gesture, instead notification content extension view will process tap gesture as interacting via the notification view. Depending on whether notification occurred in our app or on Springboard, tapping will close the notification view and then show the app.

ViewController with moving CALayers

The Notification Content Extension contains full UIViewController for absolute customization. As mentioned, there is no way to process touches on that screen. But nothing stops developer from putting some pictures to move around and paint some UIView’s using Core Graphics.

Developers can use Core Animation frameworks in their notifications. In this extension, we have several CALayer objects moving around:


Drawing is also possible, here we have UIView with the overriden drawRect method:


As we can see, many things are possible with new notifications.


Ok, so we have powerful notifications. How are we going to write code for them and debug it?

The developer can debug the notification content extension code by putting breakpoints in his project. When trying to debug notifications, breakpoints in the notification target won’t work unless target is changed. In Xcode, target must be switched to point to the notification content extension target.


After that, when Run button is clicked, Xcode will ask to select an app:


Breakpoints that are set in the notification content extension will now be hit and debugging is possible.

Conclusion: we can use full UIViewController capabilities, along with autolayout, to produce beautiful and inviting notifications.

Grab the project here.

The post New features in iOS 10 Notifications appeared first on codecentric AG Blog.

Categories: Agile, Java, TDD & BDD

ClassNotFoundException vs. NoClassDefFoundError

Javalobby Syndicated Feed - Mon, 07-Nov-16 01:01

ClassNotFoundException and NoClassDefFoundError occur when a particular class is not found at runtime. However, they occur at different scenarios.

ClassNotFoundException is an exception that occurs when you try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath.

Categories: Java

Calculating the Memory Usage of Objects and Arrays

Javalobby Syndicated Feed - Sun, 06-Nov-16 23:31

This article represents a list of web pages which can help one understand the memory usage of Java objects and arrays — along with examples. Please feel free to comment/suggest any other cool pages. Also, sorry for the typos.

The in-memory size of the object depends on the architecture, mainly on whether the VM is 32 or 64-bit. The actual VM implementation also matters.
  • How to calculate memory usage of a Java object?: Very simplified explanation of how one could calculate a memory of any Java object. For example, lets say, you want to calculate the memory of a Java object which holds two int variables, one boolean variable, one Long object, and a reference to other objects. The memory would turn out to be following:
    • 8 bytes for the object header
    • 2 x 4 = 8 bytes for two int variables
    • 1 byte for a boolean variable
    • 8 bytes (object reference) + 8 bytes for long data type = 16 bytes for long object
    • 4 bytes for reference to some other object
    • The total size of the above mentioned object will be 8 + 8 + 1 + 16 + 4 = 37 bytes + 3 bytes (for padding) = 40 bytes.
  • How to calculate memory usage of a Java array?: The page presents examples on how to calculate size of a Java array object. For example, lets say a Java array consisting of 20 Integer objects. Following is the detail on the size:
    • 12 bytes for array header object (8 bytes for header and 4 bytes for storing length of the array)
    • 20 x 16 bytes = 320 bytes for integer objects.
  • The total size of the said Java array object = 12 + 320 bytes = 332 bytes + 4 bytes (padding) = 336 bytes.
  • Memory usage of both Java Objects and Array: This article presents more examples on memory usage of objects types such as String.

Categories: Java

Issues in Creating a Single JAR Bundle With All Dependency JARs Nested Within

Javalobby Syndicated Feed - Sun, 06-Nov-16 22:31

If you’re implementing any projects with Spring and Gradle (for build), as your project grows you may run into this issue. Or you’ve landed on this page by searching on Google for “Unable to locate Spring NamespaceHandler for XML schema namespace” (your actual XML that it’s error-ing out may vary).

Either way, you’re in luck! Most likely, you’re using the fatjar Gradle plugin to create a single JAR for executing as “java -jar one-big-bundle.jar”. The problem that happens is that if two or more dependent jar libraries contain the same file/artifact, then the last one wins the race in the fatjar bundle.

Categories: Java

Configuring WebSocket Server Endpoints

Javalobby Syndicated Feed - Sun, 06-Nov-16 03:01

Before we dive into the details, here is a quick snapshot of the related interfaces

ServerEndpointConfigA derivative of EndpointConfig interface which is specific for configuration related to server side WebSocket endpoints
ServerEndpointConfig.ConfiguratorAn interface whose custom implementation allows sharing of global (for all endpoints) available logic/state as well opportunity to intercept the WebSocket handshake process (via method override)
ServerEndpointConfig.BuilderUsed only for programmatic server endpoints to build a ServerEndpointConfig instance

From here on, we’ll explore the configuration strategies for annotated and programmatic server endpoints

Categories: Java

OSGi Services: Automated Discovery and Registration

Javalobby Syndicated Feed - Sat, 05-Nov-16 21:31

This article continues a series on declarative services in OSGi. We started with a basic OSGi bundle, then discussed architecting a multi-bundle application. Then we looked closer at declarative services and how to register them. All of this is fully demonstrated in an example application on GitHub.

With the last article, we left off with a service interface, and implementation, and a few ways to tell the service registry about it. However, we didn't cover the mechanics of registration for our last method (SCR using Java annotations) and we didn't cover service lookup. In this article, I'll be tackling the first of those two topics.

Categories: Java

A Look at Composition vs. Inheritance

Javalobby Syndicated Feed - Sat, 05-Nov-16 02:01
Designing object-oriented software is hard, and designing reusable object-oriented software is even harder.

This is the opening line of the classic manual on software design Design Patterns: Elements of Reusable Object-Oriented Software, published in 1994.

More than 20 years later, this statement still rings true. The first chapter of the book introduces a few high-level principles to accomplish this goal. One of them stands out:

Categories: Java

Spring Boot: Hazelcast for Session Replication

Javalobby Syndicated Feed - Fri, 04-Nov-16 21:31

In an earlier blog post, Caching Made Bootiful: The Hazelcast Way, Hazelcast’s Viktor Gamov demonstrated the ease of doing caching with Hazelcast in Spring.

In this post, we’ll continue the theme to show how trivial session clustering is to implement from a coding perspective but also how this can radically change the application architecture for the web tier.

Categories: Java

Internationalization (I18n): A Simple Definition

Javalobby Syndicated Feed - Fri, 04-Nov-16 02:31

Internationalization is an essential part of development, and it has to be incorporated into the framework you're using from the very start.

“Think Globally, Act Locally.”

Akio Morita, co-founder of Sony (1921-99) said these famous words. Local cultures are much more than just about language. Much like how different groups in the United States have their own in-jokes, dialects, idioms and customs, different countries have their own ideas about how things should be done and how things should be presented. That’s why software, websites, and apps need to be developed with internationalization (i18n) in mind.

Categories: Java

About Design Patterns

Javalobby Syndicated Feed - Fri, 04-Nov-16 01:01

Many times, I've seen messy, unmaintainable code, mainly due to the absence of design patterns. But even more often, I've seen design patterns being applied at places where no one will ever value them. Knowing not only when and how to apply design patterns, but also when and where to not use them, is crucial to avoid frustrations at work.

Example: The State Pattern

Say you have the OrderState enum and you do different things on different parts of your code, depending on the value of the enum:

Categories: Java

Spring-Aware Beans

Javalobby Syndicated Feed - Fri, 04-Nov-16 00:01

Speaker: Josh Long

Hi, Spring fans! In this tip, we’ll look at how to create components that are aware of the Spring container

Categories: Java

OSGi: Declarative Services and the Registry

Javalobby Syndicated Feed - Thu, 03-Nov-16 22:31

In two previous articles, I introduced building an OSGi bundle and the architecture of a multi-bundle OSGi solution. One of the key features of that multi-bundle solution in its associated GitHub repository is the use of OSGi declarative services.

OSGi declarative services are the OSGi way to handle the instantiation problem: the fact that we want to code to interfaces, but we need some way to instantiate classes and some way to provide some concrete instance of an interface in order for the parts of our modular application to work together.

Categories: Java

Thread Slivers eBook at Amazon

Syndicate content