Java Lobby Announcements

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

The Future of Java EE May Be Bright After All

Thu, 2016-08-18 07:31

I don’t think anybody with the slightest interest in server-side Java™, and Java EE in particular, have missed the frustrations (and anger) in the community for the hiatus regarding the specification work of Java EE 8. The activity for most of the Java EE 8 targeted JSRs have more or less stagnated for almost a year, with only a few exceptions.

This has resulted in initiatives such as the Java EE Guardians and the Microprofile.io. Both emerging from a community eager to move Java EE forward to continue being the preferred platform for enterprise Java™.

Categories: Java

Using Apache Sling adaptTo API

Wed, 2016-08-17 15:31

Apache Sling provides a way to adpat Sling related classes to our domain classes. The Resource and ResourceResolver interface provides the adaptTo method, which adapts the objects to other classes.

Examples of the usage of this API would be when we want to get the JCR Node instance from the current Resource object. The API documentation can be found here.

Categories: Java

How to Debug Chained WebDriver 'findElement' Methods in Java

Wed, 2016-08-17 13:31

Have you ever had an argument about fluent code? Discussions about “train wrecks” and “impossible to debug?”

WebDriver has the ability to chain findElement calls, and create such “train wrecks.” How do you debug it if you use it? (There is a summary video at the bottom of this post.)

Categories: Java

How Java 8 Binds Generic Types to Method References

Wed, 2016-08-17 12:31

So most of the time you are probably aware of method references that reference instances of static methods directly, and they are useful but not necessarily that interesting.

Integer example = 1; // We can bind the instance variables, in this case just the return type is bound but there couple be method parameters also Supplier<String> s = example::toString; // We can bind to static method, here the generic parameter are the method parameter and return type Supplier<Long> f = System::currentTimeMillis; Function<Integer,Integer> f = example::compareTo;
 A less common formulation is to pass in instance methods and find the first generic parameter of of the function to be the type; this allows you to easily pass in a range of actions to operate on a common type:

Function<Integer,String> f = Integer::toString
For example, you can create an equals method that works on a subset of properties using functions mapped to instance methods as in the above example:

public static <T> boolean equals(T one, T two, Function<? super T, ?>... accessors) { if (one == two) { return true; } else if (one==null || two==null) { return false; } return Stream.of(accessors).allMatch(accessor -> Objects.equals(accessor.apply(one),accessor.apply(two))); } if (equals(one, two, Thing::getName, Thing:getOtherProperty)) ...;
Finally you can also bind the exception thrown from the method to one of the generic parameters. (Here I am using ThrowingException and ThrowingSupplier my home brew interfaces that are like there namesakes but have a generic parameter E for the exception thrown) This allows you to make you "closure" transparent to exceptions. This is more useful in a lot of cases when compared to the Stream throw nothing and "throws Exception" extremes.
ThrowingException<String,Integer,NumberFormatException> te = Integer::parseInt;
You can write funky closure methods that will throw different exceptions based on the passed-in method reference--no more catch (Exception).

public static <T, E extends Exception> T withCC(Class<?> contextClass, ThrowingSupplier<T,E> action) throws E { Thread t = Thread.current(); ClassLoader cl = t.getContextClassLoader(); try { t.setContextClassLoader(contextClass.getClassLoader()); return action.get(); } finally { s.setContextClassLoader(cl); } } // Throws IOException, complier knows that this method call throws IOException withCC(Example.class, () -> { ... ... new FileOutpuStream(file); ... ... }); // Throws another exception, complier knows that this method call throws RMIExeption withCC(Example.class, () -> { ... throw new RMIException(); });
Once you understand the last two, method references start to become far more interesting.

Categories: Java

Is Mastering the Art of 'Embracing the Change in Software Design' Too Difficult?

Wed, 2016-08-17 10:31

We as software developers often find ourselves in situations where making a small change in the code becomes a nightmare for us. Though we acknowledge the fact that "Change is inevitable", we haven't been able to master the art of changing the Code and or the design with ease. 

Why? Have we neglected the design principles, or have we rejected the thought of evolving the design, or have we ignored the refactoring hints which we might have seen during development?

Categories: Java

Java Can Have Coroutines!

Wed, 2016-08-17 08:31

Java can have coroutines like Lua has. Impossible? Not so! It can be done in JavaX (a Java dialect that compiles into Java source code).

For now, turning a function into a coroutine requires a bit of (straight-forward) source code transformation — but of course those transformations could later be automated too.

Categories: Java

SLAP Your Methods and Don't Make Me Think!

Tue, 2016-08-16 15:31

In my recent post about creating a blogging platform I posted a piece of code like this:

public MarkdownPost(Resource resource) { try { this.parsedResource = parse(resource); this.metadata = extractMetadata(parsedResource); this.url = "/" + resource.getFilename().replace(EXTENSION, ""); } catch (IOException e) { throw new RuntimeException(e); } }

Never mind the smart constructor (which hasn't caused any problems so far!), there's an important rule that's been violated: the Single Level of Abstraction Principle.

Categories: Java

Spring Boot Secured By Let's Encrypt

Tue, 2016-08-16 13:31

In this article, we want to know how we can (1) generate a valid certificate for free; (2) configure a Spring Boot app with it; and lastly (3) how to renew it when it expires.

In my previous blog post, we became familiar with configuration of an Spring Boot Application with a self-signed certificate. Self-signed certificates are good for specific purposes such as test and development. But, if one needs to ship his application to production, certificates should be signed by known and legitimate Certificate Authorities (CA).

Categories: Java

Groovify CUBA Platform — An Overview of Groovy

Tue, 2016-08-16 10:31

Developing an application in CUBA Platform is mostly about productivity. It has other advantages, but productivity is probably one of the most important reasons. To ramp up productivity on all stages of CUBA app development, we can invite Groovy to the party.

In this first of two blog posts i will give you an overview about Groovy, so you get a understanding that this might be valuable for you. Why? Because in my opinion the productivity advantage of CUBA falls apart when turn from generating the UI or creating the domain model to the part of programming where you actually want to implement business logic. In this case you are back at the POJO model either in your controller logic or in the services that are just Spring beans.

Categories: Java

Java Concurrency ReentrantLock

Tue, 2016-08-16 08:31

In this article, we will discuss Java ReentrantLock. ReentrantLock is somewhat similar to synchronize block, but provides much more flexibility. I encourage all my readers to use ReentrantLock as it is extrinsic in nature and developers have much more control over it, unlike synchronize.

Benefits of Using ReentrantLock Over Synchronize.

Categories: Java

The Most Popular Java Tools for Every Phase of Development

Mon, 2016-08-15 15:31

Just because a tool is the most popular doesn’t mean it’s the “best.” What’s best is always context-dependent in programming. However, popularity is an undeniably important metric when choosing between a handful of similar tools. It’s not the popularity itself that adds to a tool’s value; it’s the greater supply of resources and support from the larger community of a given tool.

Popular tools are easier to learn because so many people can help you use them. And popular open-source tools tend to be less buggy because more eyes are on the code and more people are testing it in a greater number of scenarios.

Categories: Java

New Book — Microservices for Java Developers By Christian Posta

Mon, 2016-08-15 13:31

One of our Camel riders, Christian Posta, recently had his first book published.

Microservices for Java Developers

Categories: Java

Reduce Boilerplate Java Using try-with-resources

Mon, 2016-08-15 10:31

Java 8 has been out for a while, and Java 7 has been out even longer. But even so, many people still unfortunately are not taking advantage of some of the new features, many of which make reading and writing Java code much more pleasant. For example, Java 7 introduced some relatively simple things like strings in switch statements, underscores in numeric literals (e.g. 1_000_000 is easier to read and see the magnitude than just 1000000), and the try-with-resources statement. Java 8 went a lot further and introduced lambda expressions, the streams API, a new date/time API based on the Joda Time library, Optional, and more.

In this blog and in a few subsequent posts, I will take a simple snippet of code from a real project, and show what the code looked like originally and what it looked like after refactoring it to be more readable and maintainable. To start, this blog will actually tackle the try-with-resources statement introduced in Java 7. Many people even in 2016 still seem not to be aware of this statement, which not only makes the code less verbose, but also eliminates an entire class of errors resulting from failure to close I/O or other resources.

Categories: Java

Scala vs Kotlin: Operator Overloading

Mon, 2016-08-15 08:31

Last week, I started my comparison of Scala and Kotlin with the Pimp my library pattern. In the second part of this serie, I’d like to address operator overloading.

Overview

Before we dive into the nitty-gritty details, let’s try first to tell what it’s all about.

Categories: Java

The Missing Link of Software Engineering

Mon, 2016-08-15 07:31

One of the major challenges of Software Engineering is the numerous information gaps between different activities around it (requirements, design, algorithm, user interface, testing, bug tracking, documentation, etc). Can we easily check if all requirements are covered by a design? Can we identify if all design points are covered by an implementation or by user interface controls, or all requirement items by testing and documentation? Sometimes restrictions are found during coding and testing, so they should be considered as a part of requirements. Or imagine coverage of all options to generate all possible use-cases for test coverage. Wouldn't it be great if we could control all this and use it with Continuous Integration?

Why can't we fill these gaps today? Well, actually we do but only in our minds. What are the obstacles for doing this at least in semi-automatic mode? The most probable cause is our belief that meaning cannot be extracted from ambiguous natural language and partially it is enchantment by natural language itself. Concerning the first point, we do agree this is a difficult task but why can't we facilitate it by having some interim forms between natural language and formal data (and metadata)? The second point could be more tough but try to accept it: natural language forms are not ideal (though convenient) representation of meaning, it is just one of many others.

Categories: Java

Pages