Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on DZone.com
Updated: 7 hours 50 min ago

Notes on Reactive Programming Part II

Thu, 2016-06-16 08:01

The basic building block of Reactive is a sequence of events, and two protagonists, a publisher and a subscriber to those events. It’s also OK to call a sequence a "stream" because that’s what it is. If we need to, we will use the word "stream" with a small "s", but Java 8 has a java.util.Stream which is different, so try not to get confused. We will try to concentrate the narrative on the publisher and subscriber anyway (that’s what Reactive Streams does).

Reactor is the library we are going to use in samples, so we’ll stick to the notation there, and call the publisher a Flux (it implements the interface Publisher from Reactive Streams). The RxJava library is very similar and has a lot of parallel features, so in that case we would be talking about an Observable instead, but the code would be very similar. (Reactor 2.0 called it a Stream which is confusing if we need to talk about Java 8 Streams as well, so we’ll only use the new code in Reactor 2.5.)

Categories: Java

Java Annotated Monthly: June 2016

Thu, 2016-06-16 07:01

Java: past, present and future – we’re still counting down to the release of Java 9, there are ever more resources for getting a handle on what Java 8 can offer us, and the Oracle vs Google court case is over (for now). The language is not the only thing that continues to evolve, well-used libraries like JUnit and Log4J are making the most of modern Java. But with all this change, we need to keep an eye on performance and correctness.

Java 9

Early Access build 121 is now available for JDK 9 and JDK 9 with Jigsaw.  Check the documentation for using the early access builds. There’s also a matrix of open source projects that have been tested against JDK 9. And don’t forget, if you do run into any unexpected behaviour, you can ask for help.

Categories: Java

Java Quiz: Switch Statements and Static Variables

Thu, 2016-06-16 06:18
Last Week's Answer

TreeMaps work with unique keys, which are the names of the students in this example.

When you enter the same name several times, the old one will be overwritten.

Categories: Java

Code Mistakes: Python's for Loop

Wed, 2016-06-15 10:01

I'm learning Python right now after years of using Java. It has actually helped a lot that I have been doing some work with Lisp and functional programming, as I think that has helped me bridge the gap between Python and Java. Still, there are some Java practices that I cling onto that cause me some trouble in a new language. Python's for loop was one of those trouble-makers for me recently.

I actually really like the way Python handles for loops, but years of Java conditioning had me a bit mixed up. I've gotten so used to defining an iterator, creating the end condition based on the iterator, and then defining how to iterate. For many applications in Python, there's no need to have all that detail. But it was the simplicity of the for loop that ended up causing me problems.

Categories: Java

Lambda Expressions in Java 8

Wed, 2016-06-15 09:01

Let's start with lambda expressions. What are they? And how do they work?

I Googled lots of posts and YouTube videos before now to understand lambda expressions, but I found it difficult to understand because I haven't used any functional language before. So I decided to write a blog post to help people like me.

Categories: Java

The Name Should Express the Intention

Wed, 2016-06-15 08:01

Here I will start with a code sample. Take a look at this:

if (code.isComplexOrUnreadable()) { refactor(code); }

Can you tell me what is wrong with this code? No?

Categories: Java

Scala Notes - Futures - 3 (Combinators and Async)

Wed, 2016-06-15 07:01

In the previous parts of this post, we discussed Futures and Promises. In this last part, we'll compose Futures using its powerful combinators.

Composing Futures

In the first post, we saw how to extract a value from Future using onComplete, foreach and in test cases using Await.result. Extracting a value from a single Future is good but many times we spawn more than one asynchronous operation and wait on multiple Futures to arrive at the final result. Even better, sometimes the result of one Future is fed into another or a chain of Futures.

Categories: Java

We Just Made Hazelcast 3.7 30% Faster

Wed, 2016-06-15 06:01

3.7 EA just got released. And I am happy to say our Performance Team led by Peter Veentjer found another amazing optimization. The main change this time was to remove notifyAll and synchronized blocks in the networking layer and replace them with LockSupport.park/unpark. The code change was done on the Member to Member code and the Client to Member code. So the change lifts performance for most operations by 30% across both topologies.

Hazelcast 3.6, based on the extensive benchmarks we do and publish, was already the fastest In-Memory Data Grid and Distributed Cache, including Redis. With this change we will open up a larger air gap between us and the rest. Look for our benchmarks against each to get updated over the next few months.

Categories: Java

Functional Programming: The Good and the Bad

Tue, 2016-06-14 10:01

Functional programming is becoming more popular today. We have more and more languages that support functional programming styles, and people are learning how to use them. It's no longer as esoteric as it once was—Ruby, Java, and JavaScript all use functional programming concepts today.

These languages have functional features, but are not functional languages. In my experience, functional languages like Erlang or ML have other features that lend a certain safety to programming that mainstream languages don't. One of these is the use of recursion and argument pattern matching to control program looping. You can use these kinds of constructs for flow control as well. Another is taking constant assignment seriously. I say constant assignment here because in these languages once you've bound a value to a variable, that variable is permanently bound to that value until it falls out of scope. The downside to these kinds of features is the difficulty in learning how to develop software using them. For those of us who have grown up using imperative languages, it's a hard transition.

Categories: Java

Folding the Universe Part I: Functional Java

Tue, 2016-06-14 09:01

Folding the Universe is actually the title of a book by Peter Engel, which is subtitled "Origami From Angelfish to Zen", suggesting that anything in the universe may be modeled out of folded paper. The analogy with computer programming is interesting since, in functional programming, nearly every problem can be solved with folds.

Computer programming is primarily about abstraction. Instead of doing the same basic tasks again and again, we once write programs to performs these tasks, and we can then build larger programs by composing these basic tasks. Probably one difference between functional and imperative programmers is the way they handle task abstractions. Most often, imperative programmers start thinking about abstracting subtasks when they realize that they are repeatedly writing the same code. But the depth of abstraction is often kept quite minimal. The main reason is that higher-level abstractions are generally provided by the language. Arithmetic operations on integers, for example, is provided by nearly all programming languages, so there is no need to write specific code to abstract them (although it is possible, and an interesting challenge!).

Categories: Java

Everyone Should Learn to Code?

Tue, 2016-06-14 08:01

Politicians, programmers, and celebrities have said it. Are they right?

It irritates me. It annoys me. It outrages me. People with very little understanding of schools try to dictate what we do. This is a good example. ‘Everyone’ doesn’t mean eighty-four-year-olds in dementia clinics. It doesn’t mean successful sole-traders. It means children. It means students. It means schools finding time in their curriculums.

Categories: Java

My Journey to Face the Lambda Expressions in Java

Tue, 2016-06-14 07:01

It’s not a great surprise that even when I am using many different programming techniques, programming languages, and libraries, I barely know five percent of them in a deep way. The fact is, it’s not a major problem, the real problem is that I only know the bare minimum about half of Java's core libraries and am only using them as APIs—Lambda expressions fall into this category. On top of which, whenever there is a talk about Lambda expressions, I get the feeling that everyone knows more about them than me. This is something I intend to change.

Lambda expressions are great in my eyes, but recently I discovered my inability to apply or write them without the help of an intelligent IDE (Intellij IDEA in my case). They have become only syntactic sugar for me (for more than two years, huh), and I wasn’t diligent enough to find out how they actually might work. So I have begun to study them and here in this post I have collected some of my reflections. I’ll not include any of code examples as you can find plenty of them following the links throughout the article.

Categories: Java

Spring Framework 4.3 Goes GA

Mon, 2016-06-13 10:01

Dear Spring community,

I’m pleased to announce that Spring Framework 4.3 GA (a.k.a. 4.3.0.RELEASE) is now available from repo.spring.io as well as Maven Central!

Categories: Java

Carving the Java EE Monolith Into Microservices

Mon, 2016-06-13 09:01

Following my introduction blog about why microservices should be event-driven, I’d like to take another few steps and blog about it while I prep for a bunch of talks I’ve got coming up (See you at jBCNconf and Red Hat Summit in San Francisco). Follow me on twitter @christianposta for updates on this project. In this article, we discuss the first parts of carving up a monolith.

The monolith I’m exploring in depth for these articles will be from the Ticket Monster tutorial which for a long time has been the canonical example of how to build an awesome application with Java EE and Red Hat technologies. We are using Ticket Monster because it’s a well-written app that straddles the “non-trivial” and “too-complex for an example” line pretty well. It is perfect for illustrative purposes and we can point to it concretely and discuss the pros and cons of certain approaches with true example code. Please take a closer look at the domain and current architecture in light of the further discussions.

Categories: Java

Geek Reading: Encapsulation, Search Strategy, and a Look Into the Brain of (Almost) Deep Blue

Mon, 2016-06-13 08:01

Leading our day is a post from Kent Beck about mastering programming. It is more of an outline than a full post, but it still has a ton of excellent information. At Ayende @ Rahien we have a great series of posts regarding the “guts n’ glory” of database internals. Today’s installment talks about the problems with some file formats when you want to search for data. If you have any interest in this area, I highly recommend that you pay attention to that series. Meteor Engineering gives us an interesting post about MongoDB not returning all matching documents for a query. This is really not an issue that is specific to MongoDB, it is highly possible that non-ACID databases or even odd clustering situations can yield the same results.

As always, enjoy today’s items, and please participate in the discussions on these sites.

Categories: Java

An Introduction to Inform and Natural Language Programming

Mon, 2016-06-13 07:01

If you're reading this, there's a pretty good chance that you have written a program/script/class/method/whatever involving the Fibonacci sequence. It's a great way to logic through a new language (after you've Hello Worlded, right?), and often it's a good intro into recursion. So this code likely won't be too unfamiliar to you:

public class fib { public static void main(String[] args) { Scanner scan = new Scanner (System.in); System.out.println("Enter a number: "); int num = scan.nextInt(); System.out.println(calculate(num)); } private static int calculate(int n){ if (n <= 1) return 1; else return calculate(n - 1) + calculate(n - 2); } }

We all know that Java is fairly verbose. So yeah, this isn't the shortest program ever (especially with the included boilerplate). But it's recursive and takes an input and does what we need it to do.

Categories: Java

Add Editor Support to Your Groovy Builder with a DSLD

Sun, 2016-06-12 07:01

In a previous article, A Basic Builder with Groovy, I showed how to make a DSL with a Groovy Builder. The next thing you probably want to have is editor support. Groovy offers support for DSL's with a DSL Definition, which makes Groovy DSL's in Eclipse feel like they're really part of the language.

A DSLD consists of a single file and must be on the class path. I like to store it in a package called 'dsld'. A full overview of the DSLD syntax and semantics can be found at: DSL Descriptors for Groovy and Eclipse.

Categories: Java

Pages