Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on
Updated: 10 hours 5 min ago

Everything You Need to Know About the Brave Web Browser

12 hours 4 min ago

The new Brave web browser is trying to do something radically different with your boring old browser. Brave burst onto the scene at the start of 2016, positioning itself as the latest battleground in the war between ad producers and ad blockers. Brave is built on the promise of faster load times and better privacy protection by blocking web trackers and targeted ads. If Brave users agree to replace those ads with anonymous ads from the Brave network, the user will be paid in bitcoin. Being paid to surf has been the dream of many web aficionados and Brave promises to make it real.

The Philosophy Behind Brave

Brave is the brainchild of Brendan Eich, one of the co-founders of Mozilla and the creator of the JavaScript language when he worked at Netscape. Eich announced the arrival of Brave by saying, “We are building a new browser and a connected private cloud service with anonymous ads,” Eich said. “I contend that the threat we face is ancient and, at bottom, human. Some call it advertising, others privacy. I view it as the Principal-Agent conflict of interest woven into the fabric of the web.”

Categories: Java

Akka Notes: Finite State Machines Part 2

Thu, 2016-05-26 15:16

In the first part of notes on Akka FSM, we saw the basics of Akka FSM and the outline of the Coffee vending machine that we planned to build - the structure of the Actor and a list of messages we pass to the Actor. In this second and final part, we will go ahead and implement each of these States.


As a quick recap, let's look at the structure of the FSM and the messages that can be sent to it.

Categories: Java

To Scala or Not to Scala? That Is the Question

Thu, 2016-05-26 14:31

Every so often I’ll crawl out of my Java cave and run into a seasoned dev who has embraced Scala. And I have noticed that not one of them seems to want to go back to Java programming. 

Having moved to Java 8 and embraced Optional and streams, I can see the appeal of thinking functionally. Whenever I see a nested for loop iterating over a collection or a bunch of null checks on a class hierarchy, I shudder little. Not only because the code is so ugly, but because for the longest time I didn’t know any better myself.

Categories: Java

Gradle Goodness: Enable Compiler Annotation Processing For IntelliJ IDEA

Thu, 2016-05-26 12:31

Suppose we have a project where we use Lombok annotations. To use it we must change the compiler configuration for our project and enable annotation processing. We can find this in the Preferences or Settings window under Build, Execution, Deployment | Compiler | Annotation Processors. Here we have a checkbox Enable annotation processing that we must check to use the annotations from IntelliJ IDEA. We can automate this setting with some configuration in our Gradle build file.

In the next example build file we alter the generated IntelliJ IDEA project file using the withXml hook. We can access the generated XML as a groovy.util.Node and change the XML.

Categories: Java

Polymorphism in Java

Thu, 2016-05-26 11:16

Polymorphism is one of the pillars of OOP in Java.

An object showing different behaviors at different stages of its life cycle is known as polymorphism. There are two types of polymorphism:

Categories: Java

Setting Up Distributed Infinispan Cache with Hibernate and Spring

Thu, 2016-05-26 09:01

You obviously need cache. There are options to do that with EhCache, Hazelcast, Infinispan, memcached, Redis, AWS’s ElastiCache and some others. However, EhCache supports only replicated and not distributed cache, and Hazelcast does not yet work with the latest version of Hibernate. Infinispan and Hazelcast support consistent hashing, so the entries live only on specific instance(s), rather than having a full copy of all the cache on the heap of each instance. ElastiCache is AWS-specific, so Infinispan seems the most balanced option with the Spring / Hibernate setup.

So, let’s first setup the Hibernate 2nd-level cache. The official documentation for Infinispan is not the top Google result—it is usually either very old documentation, or just 2 versions old documentation. You’d better open the latest one from the homepage.

Categories: Java

IntelliJ IDEA 2016.2 EAP 162.426.1 Is Out

Thu, 2016-05-26 07:01

A fresh EAP build for IntelliJ IDEA 2016.2 is out and, being a good EAP build that it is, has something new for you to try:

  • A new inspection that warns you when you instantiate new objects inside equals, hashCode, compareTo or methods. This helps to avoid significant performance problems when, for example, objects of classes with such constructs are added to Set or Map, where these methods will be frequently invoked.

Categories: Java

Java Quiz: Exception Handling in Java

Thu, 2016-05-26 04:01
Last Week's Answer: Using Inheritance and Static Methodsint x = 2; static int s = 3; MyClass mc = new MyClass(); x=2, s=3; super(3) this(); x+=4; x=2+4 =6; x += x + 20; // ignore this value because it is a parameter x -= 7 = 6-7= -1 s += x = 3 -1 = 2 mc.method(); x+= 7; x = -1+7=6; super.method(); x += 35 = 6+35 = 41; // ignore this value, see next step. new MyClass(); // returns a new object, the value of x reset to 2. x=2, s=2; // the last value of “s” is 2 because it is static. super(3) this(); x+=4; x=2+4 =6; x += x + 20; //ignore this x because it is a parameter. x -= 7 = 6-7=-1 s += x = 2 -1 = 1

The result is that the code writes "1" to the standard output

This Week's Quiz: Exception Handling in Java

This quiz is aimed at advanced Java programmers.

Categories: Java

Java Code Challenge: Bus Gossip

Wed, 2016-05-25 17:52

Java Code Challenge is a new weekly segment taking the best challenge from Reddit's dailyprogrammer. Things are a little different here as we're focused on Java. A working solution is not enough; we're looking for the cleanest Java code with tests. 3rd party libraries are welcome but if you can do it without it will be easier for others to comprehend.

If you can fit your solution in the comments then go for it, but preferably put your answer in GitHub and link in the comments. Next week we'll be sharing the best solutions and sharing the best code practices we see!

Categories: Java

Processing JSON With Jackson

Wed, 2016-05-25 15:16

It's not uncommon for computers to need to communicate with each other. In the early days this was done with simple string messages. Which was problematic. There was no standard language. XML evolved to address this. XML provides a very structured way of sharing data between systems. XML is so structured, many find it too restrictive. JSON is a popular alternative to XML. JSON offers a lighter and more forgiving syntax than XML.

JSON is a text-based data interchange format that is lightweight, language-independent, and easy for humans to read and write. In the current enterprise, JSON is used for enterprise messaging, communicating with RESTful web services, and AJAX-based communications. JSON is also extensively used by NoSQL database such as, MongoDB, Oracle NoSQL Database, and Oracle Berkeley DB to store records as JSON documents. Traditional relational databases, such as PostgreSQL is also constantly gaining more JSON capabilities. Oracle Database also supports JSON data natively with features, such as transactions, indexing, declarative querying, and views.

Categories: Java

Testing Multithreaded Code in Java

Wed, 2016-05-25 14:31

Testing multithreaded code is a tough challenge. The first advice that you get when trying to test concurrency is to isolate your concurrent concerns in the code as much as possible. This a general design advice but in this case it's even more important. Make sure to first properly unit test the logic that is wrapped by the concurrent construct. Otherwise you might spend a long time trying to figure out a concurrency problem that turns out to be flawed business logic in the end.

Once you have got that covered, you can think about your strategy to test concurrent systems. GOOS covers how you can do it. Here you can find the code that I'm going to explain:

Categories: Java

Singleton Pattern: The Good, the Bad, and the Ugly

Wed, 2016-05-25 12:31

OK, let’s have a look at our first pattern.

The singleton pattern is one of the most well-known design patterns and is used extensively by frameworks such as Spring, pool managers, and loggers.

Categories: Java

Immutable Pointers—A Pattern for Modular Design

Wed, 2016-05-25 11:16

Modular design has a lot of benefits, including:

  • making it easier to predict the impacts from a change
  • helping developers work in parallel

But, it is much much much harder than people think.  For a start, the abstractions have to be at the right level.  Too high and they can become meaningless and too low and they cease to be abstractions, as they will end up having way too many dependencies ( efferent and afferent).

Categories: Java

Generating a J2EE Stack Using AndroMDA

Wed, 2016-05-25 09:01

AndroMDA is a framework for code generation based on UML modeling.

In this article I use AndroMDA to build a complete stack of (JPA, Spring, CXF Apache web service) as a basic traditional J2EE application.

Categories: Java

Export to Word DotCMS Plugin

Tue, 2016-05-24 15:16

Export to Word Plugin for dotCMS allow users to export online content into Word Processing document using Aspose.Words for Java. It dynamically exports the content of the Web page to a Word Processing document and then automatically downloads the file to the disk location selected by the user in just a couple of seconds. The generated Word processing document can then be opened using any Word Processing Application such as Microsoft Word, Apache OpenOffice, etc.

Supported Platforms

In order to deploy Export to Word OSGI/Dynamic Plugin you need to have the following requirements met:

Categories: Java

Constructor Function - Java

Tue, 2016-05-24 14:31

A Constructor Function implementation in Java.

Implementation: Java

The Constructor Function is not a pattern commonly used in Java, since most of the time the desire when holding state is to hold it as accessible member variables of an object, which Java supports directly via fields. Additionally, thanks to Java’s “C-family” heritage, it directly supports encapsulatory access control (meaning we can annotate the field with “private” to prevent access to the field from outside the class). However, in some cases, this standard mode of access control is not enough, and/or we want to provide a slightly different means of construction for clients. This is when a Constructor Function can be of use, usually modeled as a static method (or methods) on the class itself.

Categories: Java

Constructor Function: Scala

Tue, 2016-05-24 12:31

Given that Scala is a functional language (object/functional, really), building a Constructor Function in Scala is actually pretty straightforward.

Object Method Constructor

Scala allows us to create per-class methods on the class object, providing a convenient place on which to store methods designed to construct instances of the class. Scala traits are used to define the Interface, so as to better take advantage of the statically-typed nature of the compiler and provide compilation guarantees. In addition, because Scala supports nested classes (meaning, in this particular case, classes whose definition appears entirely inside a function definition), we can “hide” the implementation in much the same way that Java uses inner-class implementations, though we still do need to provide a name to the type.

Categories: Java

Akka Notes: Finite State Machines Part 1

Tue, 2016-05-24 11:16

I recently had the opportunity to play with Akka FSM at work for some really interesting use-case. The API (in fact, the DSL) is pretty awesome and the entire experience was amazing. Here's my attempt to log my notes on building a Finite State Machine using Akka FSM. As an example, we'll walk through the steps of building a (limited) Coffee vending machine.

Why not become and unbecome?

We know that the plain vanilla Akka Actors can switch its behavior by using become/unbecome. Then, why do we need Akka FSM? Can't a plain Actor just switch between the States and behave differently? Yes, it could. But while Akka's become and unbecome is most often enough to switch the behavior of Actors with a couple of states involved, building a State Machine with more than a few states quickly makes the code hard to reason with (and even harder to debug).

Categories: Java

The Top 100 Java Libraries in 2016 After Analyzing 47,251 Dependencies

Tue, 2016-05-24 09:01

Who’s on top and who’s left behind? We analyzed 47,251 dependencies on GitHub and pulled out the top 100 Java libraries

Our favorite pastime for long weekends is to go through GitHub and search for popular Java libraries. We decided to share the fun and the information with you.

Categories: Java

Java Code Challenge: Nodes Solution

Mon, 2016-05-23 17:32

I’ve been really pleased with the responses to the node challenge. Great work everybody!

This is a relatively simple challenge but one that demonstrates why programming is more of an art than a science. Every single response was different in design and style. There is no one “correct” answer, which is one of the wonderful things about programming.

Categories: Java