Functional Programming Principles Every Imperative Programmer Should Use

Java Lobby Announcements - Sat, 2018-01-20 08:01

Sometimes it seems like functional programmers are a totally different breed. Even by programmer standards, they seem more nerdy than the rest. They use weird terms such as "monad," "for-comprehension," and "lambda." They use languages that don't end every line with a semicolon. And, no matter how uneasy Java programmers are around C++ programmers, both groups can at least agree that Haskell is weird.

The truth is, functional programming has much to offer, even to developers accustomed to working in imperative languages. (Source:

Categories: Java

This Week in Spring: Kafka, Spring Cloud, and Testing

Java Lobby Announcements - Fri, 2018-01-19 16:59

Aloha! This week I’m in sunny Honolulu for the first annual LavaOne conference. If you’re not here, you should be! The show is amazing, enjoys 50% female to male audience attendance, the speakers are world-class (well, except yours truly, but don’t tell them that..), and the location is pretty hard to beat!

That said, nothing gives me more pleasure than saddling up to a table with a laptop, some green tea, sunglasses, and sunscreen and checking in on the community. This week’s been a heckuva week indeed! Lot’s of great stuff so let’s get to it!

Categories: Java

9 Things Java Programmers Should Learn in 2018

Java Lobby Announcements - Fri, 2018-01-19 10:01

First of all, I wish you a very happy new year, guys. It's that time of year when we start afresh, make plans, set goals, and make resolutions for the new year.

Being a Java developer and the author of a Java blog, I frequently receive requests from Java programmers from all over the world asking how they can improve themselves.

Categories: Java

Why You Should Take a Look at Kotlin's Standard Library

Java Lobby Announcements - Fri, 2018-01-19 07:01

As we add support for Java deployments at Octopus, more integration code is being written in Kotlin. As a longtime Java developer, I took the opportunity to learn some of the improvements that the Kotlin language designers added to their language over Java.

About the same time, I completed Dave Fancher's Functional Programming with C# course on Pluralsight. I enjoyed the course because it provides some clear and practical advice on how to approach function programming in C#. In it, Dave provides two extension methods, Map and Tee, which allow you to transform objects and pass them onto other mutating methods, along with examples on how and why you would use them.

Categories: Java

Java Quiz 9: Demonstrating Multilevel Inheritance

Java Lobby Announcements - Thu, 2018-01-18 16:02

Before we start with this week's quiz, here is the answer to Java Quiz 8: Upcasting and Downcasting Objects.

By upcasting objects, the overridden variable depends on the type of the object reference vc, but the overridden methods depend on the type of the object that was created. By downcasting objects, both variables and methods depend on the type of the object reference car.

Categories: Java

Docker and Java: Why My App Is OOMKilled

Java Lobby Announcements - Thu, 2018-01-18 10:01

Those who have already run a Java application inside Docker have probably come across the problem of the JVM incorrectly detecting the available memory when running inside of the container. The JVM sees the available memory of the machine instead of the memory available only to the Docker container. This can lead to cases where applications running inside the container is killed when tries to use more memory beyond the limits of the Docker container.

The JVM incorrectly detecting the available memory has to do with the fact that the Linux tools/libs created for returning system resource information (e.g. /proc/meminfo, /proc/vmstat) were created before cgroups even existed. These will return resource information of the host (physical or virtual machine).

Categories: Java

Play Zork, Learn OAuth

Java Lobby Announcements - Thu, 2018-01-18 00:57

In the early '80s, some of the best “video” games were text-based adventures. These games would print out descriptive text of your surroundings and you would interact with the game using simple, but natural language commands like: “go north” or “take sword”. Fast forward some 30 years and a specification for an authorization framework called OAuth 2.0 was published. This framework allows an application to receive a token from an external party (like Okta) that indicates a user is authorized to use the application. What do these two things have in common? Absolutely nothing. But, I thought it would be fun to mash them together to demonstrate how OAuth works by playing a text-based game.

Infocom was a popular producer of text-based games and they standardized a file format and interpreter for them called zMachine. There’s a great zMachine interpreter written in Java. I incorporated this into a Spring Boot/Spring Security application that interacts with Okta for OAuth so that you can play Zork — one of the most iconic of these games. The application is available on the Okta Developer GitHub account.

Categories: Java

Classification of Development Frameworks for Enterprise Apps

Java Lobby Announcements - Wed, 2018-01-17 23:01

If you Google "best Java framework", most probably, you will stumble on this article, which gives a great overview of the landscape in the Java Enterprise world. However, from my point of view, it lacks a very important thing — classification of the mentioned frameworks. Let's have a look at another angle at this ecosystem and go beyond the Java world.

Picking the best framework for developing an application (or another framework), means trying to find the best trade-off between the following criteria:

Categories: Java

Java 8: Oogway's Advice on Optional

Java Lobby Announcements - Wed, 2018-01-17 19:01

While Po was reading about Java 8 Optionals, a few questions popped into mind. Why was it added to Java? How does it save us from the almighty villain the null pointer exception?

So, he goes to Master Shifu, but the irony is that Shify was also unsure of how Optional will save the Java villagers from NPEs. But Oogway foretold their arrival, so they went to Oogway for advice on Optionals.

Categories: Java

Would You Use JSF for Your Next Project?

Java Lobby Announcements - Wed, 2018-01-17 13:01

There was an excellent StackOverflow blog post last week about the “Brutal Lifecycle of JavaScript Frameworks”. The article was about the speed at which JavaScript UI frameworks (Angular, Jquery, and React) come into and fall out of fashion. The key metric for this post is questions per month on the framework, which is a reasonable metric to demonstrate these trends. Downloads would have been interesting too.

It got me thinking: Where are we with JSF? And my starting point was to superimpose JSF on top of the JavaScript data.

Categories: Java

How to Add JARs to a JetBrains MPS Project

Java Lobby Announcements - Wed, 2018-01-17 10:01

JetBrains MPS is a wonderful tool to create DSLs. We love it and use it regularly in our consultancy work, and we have written about JetBrains MPS before.

Being a projectional editor, it allows you to easily create DSLs that can be used through a graphical interface or things like mathematical formulas, though all this power requires a bit of preparatory work.

Categories: Java

Using Google's Protocol Buffers With Java

Java Lobby Announcements - Wed, 2018-01-17 07:01

Effective Java, Third Edition was recently released, and I have been interested in identifying the updates to this classic Java development book, whose last edition only covered through Java 6. There are obviously completely new items in this edition that are closely related to Java 7, Java 8, and Java 9 such as Items 42 through 48 in Chapter 7 ("Lambdas and Streams"), Item 9 ("Prefer try-with-resources to try-finally"), and Item 55 ("Return optionals judiciously"). I was (very slightly) surprised to realize that the third edition of Effective Java had a new item not specifically driven by the new versions of Java, but that was instead was driven by developments in the software development world independent of the versions of Java. That item, Item 85 ("Prefer alternatives to Java Serialization") is what motivated me to write this introductory post on using Google's Protocol Buffers with Java.

In Item 85 of Effective Java, Third Edition, Josh Bloch emphasizes in bold text the following two assertions related to Java serialization:

Categories: Java

Rust for Java Devs: Creating Variables

Java Lobby Announcements - Tue, 2018-01-16 23:01

I’m going to do something different today and write about Rust instead of Java. This is something that I want to give a try, and if it all goes well, I will continue writing some posts about Rust in the future.

I will be writing about learning Rust from the perspective of a Java developer by making comparisons where appropriate to help you (and me) understand what is going on. These will most likely be shorter posts and, honestly, might not even contain that much information — but hopefully, someone finds these sort of posts helpful and makes it all worth it.

Categories: Java

Effective Java 3rd Edition: A Must-Read for Every Developer

Java Lobby Announcements - Tue, 2018-01-16 19:01

Joshua Bloch finally updated his popular book Effective Java for Java 7, 8, and 9. The previous edition was one of the most popular books among professional Java developers, and I couldn’t wait to finally read the updated 3rd edition.

I got this book two weeks ago, and it more than fulfilled my expectations. It is packed with best practices and detailed descriptions of the finer details of the Java language. Every developer should at least read the chapters about generics and lambdas.

Categories: Java

Closures in Scala [Video]

Java Lobby Announcements - Tue, 2018-01-16 13:01

Before we begin discussing closures in Scala, let us have a quick look at a function. The function literal bill below accepts only one input parameter: netBill. However, the function calculates the final bill by adding a service charge to netBill.

val bill = (netBill: Double) => netBill*(1 + serviceCharge/100)

Categories: Java

An Introduction to Hollow JARs

Java Lobby Announcements - Tue, 2018-01-16 10:01

I have written in the past about the difference between an application server and an UberJAR. The short version of that story is that an application server is an environment that hosts multiple Java EE applications side by side, while an UberJAR is a self-contained executable JAR file that launches and hosts a single application.

There is another style of JAR file that sits in-between these two styles called a Hollow JAR.

Categories: Java

Application Design the Java 9 Way

Java Lobby Announcements - Tue, 2018-01-16 07:01

Java 8 brought many great improvements to the language. Java 9 enhanced them further! A major paradigm shift now needs to occur. The tools that Java 8 and 9 provide for application design are immensely improved. Java 8 allows static methods on interfaces. Java 9 provides a level of organization above the package: the module. Putting these two techniques together results in better designs and stronger object-oriented guarantees.

Interfaces Rule!

It feels like interfaces passed out of favor in the Java world. There was a time when classes not implementing interfaces were considered suspicious and discussed in code review. Now, major IDEs provide class templates that automatically declare classes public and don't provide or expect an "implements" clause.

Categories: Java

JUnit4, JUnit5, and Spock: A Comparison

Java Lobby Announcements - Mon, 2018-01-15 23:01

Recently, I gave a talk in my local Java User Group about unit testing. Some of the content of the talk was about some popular libraries you can use in your Java project. I’ve reviewed JUnit4, JUnit5, and the Spock framework. Many of the attendees were quite surprised with the differences. In this post, I will summarize asserts, parametrized tests, and mocking.

I always like to demonstrate the concepts with examples and live coding, so I chose a simple algorithm: a Fibonacci number calculator. If you don’t know it, it’s just to generate numbers that are the sum of the two previous ones in the series: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377.

Categories: Java

Java Annotated Monthly: January 2018

Java Lobby Announcements - Mon, 2018-01-15 19:01

Hopefully, everyone has recovered from the holidays. November is probably one of the craziest months, a sharp contrast to late December and early January, which are some of the quietest ones, at least in my experience. People are wrapping up the year’s results, making plans for the year ahead, and of course, enjoying the holidays. If you had holidays like we did, this January digest might be helpful for updating you on what has happened in the community during the last month. If not, I hope you find the news and articles interesting anyway.

If you missed all the champagne and watched the blogs and social accounts closer than we did, please feel free to share the missing news in the comments. Since Trisha, your regular host, is still on maternity leave; I will do my best to fill in for her.

Categories: Java

Kotlin: Tail Recursion Optimization

Java Lobby Announcements - Mon, 2018-01-15 13:01

The Kotlin compiler optimizes tail recursive calls — with a few catches. Consider a ranking function to search for the index of an element in a sorted array, implemented the following way using tail recursion (and a test for it):

fun rank(k: Int, arr: Array<Int>): Int { tailrec fun rank(low: Int, high: Int): Int { if (low > high) { return -1 } val mid = (low + high) / 2 return when { (k < arr[mid]) -> rank(low, mid) (k > arr[mid]) -> rank(mid + 1, high) else -> mid } } return rank(0, arr.size - 1) } @Test fun rankTest() { val array = arrayOf(2, 4, 6, 9, 10, 11, 16, 17, 19, 20, 25) assertEquals(-1, rank(100, array)) assertEquals(0, rank(2, array)) assertEquals(2, rank(6, array)) assertEquals(5, rank(11, array)) assertEquals(10, rank(25, array)) }

Categories: Java


Subscribe to EGJUG aggregator - Java