Java News and Code, Episode 14

Welcome

Welcome to Java News and Code, where I tell you about interesting goings-on in the world of IT in general, and Java in particular.

And there’s always code.

On This Episode:

  • Oracle wants to open source Java EE
  • Android Oreo is here
  • Code: A custom Maven archetype for JUnit 5

TLDR;

TODO: VIDEO HERE

Oracle wants to open source Java EE

On August 17th, Oracle Software Evangelist David Delabassee said Oracle wants to open up Java EE.

The announcement on the Oracle Blog says that as the summer ends, releases wrap up, and JavaOne 2017 approaches, this is an “…opportunity to rethink how Java EE is developed in order to make it more agile and responsive to changing industry and technology demands.”

As InfoQ points out, Oracle has been criticized regarding how it’s steered Java EE in the past, which has led to efforts such as the Java EE Guardians, a group “…committed to moving the Java EE platform forward through active community participation and advocacy.”

Java EE Guardians’ members include James Gosling, the Father of Java, and Cameron McKenzie, editor-in-chief of the Server side. It’s not clear what qualifies someone to be a Java EE Guardian, but qualifications span the spectrum from Father of Java, to Java Blogger, to this Java EE Guardian, whose qualifications include Student.

Reaction outside Oracle seems to be positive, with IBM’s Ian Robinson weighing in on the WASDev blog saying, “…we are delighted that Java EE is moving with the times to an open foundation for its ongoing development following the completion of Java EE 8 this year.”

So who will take over Java EE?

Responses to an unofficial Twitter poll by Java EE Guardian Reza  Rahman asking that question seem overwhelmingly in favor of handing stewardship of the platform over to Apache.

So what does this mean for Java EE? It depends on whom you ask, but given the popularity and prevalence of the platform, I’m sure it will stay in good hands.

Be sure to check out the show notes page, where you can find more information on this story, and everything I talk about in this episode.

Android Oreo is here

We’ve been following Android O for some time now here at Java News and Code, and at long last, Android O, named Oreo, has been released!

For users, Android Oreo has a bunch of new features, some of which are immediately obvious like picture in picture, and per-app notification options.

Other changes like background limits, are designed to improve device responsiveness and extend battery life.

For developers, things get more complicated. The optimizations and improvements come at a cost, which will be paid on the development side. And rightly so.

What does that mean for developers like me, who have apps in the Play Store?

For now, probably not much. Oreo is not even showing up on the Android Dashboard as of today, but of course, it’s only a matter of time.

Android Marshmallow has the single greatest share of installations, and it was released in October of 2015, coming on two years. So we have time.

But as developers we need to be ready. Fortunately, there is information available already to help us get ahead of this, like this video on the Android Developers YouTube channel.

This release is huge, there’s no denying it. And in my opinion totally worth it. Check out this article at Gizmodo, that lays out 11 cool new features in Oreo.

Be sure to check out the show notes page, where you can find more information on this story, and everything I talk about in this episode.

Code: A custom Maven archetype for JUnit 5

On August 24th, JUnit 5, Release Candidate 3 was released.

This release, which signals the impending General Availability (GA) Release, includes the usual spate of bug fixes, breaking changes, and new features.

The GA release is scheduled for September 6th, according to the milestones page.

A Maven archetype is a special type of Maven project that is used to generate other Maven projects. If you’ve ever used the New Project wizard in Eclipse to create a Maven project, chances are you’ve used the maven-quick-start archetype. Guess what? That’s a Maven archetype!

For this episode’s code talk through, I want to show you how to create a Maven archetype that you can use to create new projects that will come with JUnit 5 dependencies and boilerplate code.

The source code for the archetype is available in GitHub. And in this episode I want to do a quick walk through of the code for a Maven archetype, how it’s structured, and how to use it to generate a new project.

Let’s get started.

First, clone the code from GitHub. Open a Terminal window, navigate to the directory where you want the code to land and execute the git clone command:

git clone https://github.com/makotogo/JUnitJupiterArchetype

Next, import the code into Eclipse.

With the code in Eclipse, let’s take a quick tour. Expand all of the nodes in the source tree. Open the src/main/resources/META-INF/maven/archetype-metadata.xml file, which tells the archetype generator what source files, test  source files, resources and so forth you want to be included in new projects generated from the archetype.

A Maven archetype project is itself a Maven project, so there are two POM files to deal with:

The one that controls the archetype project itself, located in the project root:

  4.0.0
  com.makotojava.learn
  junit-jupiter-archetype
  0.9.1
  Archetype - jupiterArchetype
  http://maven.apache.org
  jar

And the POM file that will be included in any projects created from the archetype, src/main/resources/archetype-resources/pom.xml.

The archetype project also includes boilerplate code like this:

package $package;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.log4j.Logger;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

/**
 * Unit test for simple App.
 */
@RunWith(JUnitPlatform.class)
public class AppTest {
  
  private static final Logger log = Logger.getLogger(AppTest.class);

  private App classUnderTest;

  @BeforeEach
  void setUp() {
    classUnderTest = new App();
  }

  @Test
  @DisplayName("assertAll on a bunch of Strings should succeed.")
  public void doIt() {
    log.info("Testing doIt()...");
    assertAll(
        () -> assertEquals("String", classUnderTest.doIt("String")),
        () -> assertEquals("StringToo", classUnderTest.doIt("StringToo")),
        () -> assertEquals("String2", classUnderTest.doIt("String2")),
        () -> assertEquals("StringAlso", classUnderTest.doIt("StringAlso")));
  }

}

To use the archetype to create new projects, you first have to build the archetype project itself. Like I said, it’s a Maven project, so to build it go to Run As > Maven Project and specify the install and archetype:crawl goals to install it in your local Maven repository, and update your local archetype catalog, respectively.

Next, make sure the archetype is included in your local Maven archetype catalog, which is located in the repository root in a file called archetype-catalog.xml. And there it is.

Screen Shot 2017-08-28 at 12.07.50 PM

Now, I can use that to create projects in Eclipse. First, make sure Eclipse recognizes the local maven catalog. Under Preferences > Maven > Archectypes, click on Add Local Catalog. Browse or enter the path to your local archetype-catalog.xml file, give it a description you’ll recognize later, click Ok. Then Click Apply and close.

To create a new project based on the new archetype, go to File > New Project > Maven Project. Click Next. Click Next again. Select the archetype in the list, and complete the wizard.

Screenshot 2017-08-28 12.14.44

When the wizard completes, you now have a new project based on your custom archetype!

How cool is that?

For a detailed walkthrough of this, check out this video.

Fini

Well, that’s it for today’s episode. Be sure to check out the show notes page, where you can find more information on this story, and everything I talk about in this episode.

Thanks for watching Java News and Code (and reading this post).

I’ll see you next time.

–jsp

Advertisement

Java News and Code, Episode 13

Welcome

Welcome to Java News and Code, where I tell you about interesting goings-on in the world of IT in general, and Java in particular.

And there’s always code.

On This Episode:

  • Java Still on top in the Tiobe Index (but falling)
  • Android O Final Preview
  • Code Talkthrough: Android and the Cloud

TLDR;

Java Still on Top (but Falling)

Screen Shot 2017-08-14 at 10.26.31 AM

According to the Tiobe index for August 2017, Java is at #1 and still has a commanding lead over all other languages. But its percentage score has fallen to about 13%, down from just over 19% a year ago.

And Java is not alone: the top 5 are all in decline from a year ago, with C at 6 1/2%, C++ at 5.6%, C# at 4.2%, and Python at 3.7%.

Scroll down on the page to see just how far ahead of the pack Java is:

Screenshot 2017-08-14 15.10.52

From the graph you can see Java had a similar drop back in 2004 from which it rebounded strongly, so maybe this is a temporary trend. Who can say?

If you want to see how the index is put together, you can visit this page.

The Tiobe index is put together during the first week of each month.

Make sure and check out the show notes page, where you can find this story, along with all the links in this episode of Java News and Code.

So be sure to check that out.

Android O Final Preview is Out

On July 24th, Android O Developer Preview 4 was made available.

The announcement on the Android Developer’s Blog, comes one month after the announcement of Developer Preview 3, which I told you about in episode 8 of Java News and Code.

Preview 3 contained some very nice features like simplified settings, battery life optimizations, and per app notifications.

Preview 4 is the final preview before the official O release later this summer:

Screenshot 2017-08-14 15.25.35

Preview 4 is a Release Candidate build of the Android O platform, and while it doesn’t have any new features, it contains the final system behaviors, bug fixes, and the final API (level 26).

Coming soon is also a new release of the Android Testing Support Library. The blog post says to stay tuned for more details coming soon.

And if you want to use Developer Preview 4, it’s recommended that you download Android Studio 3 Canary 1 as well, available in the Canary channel.

The show notes page has links to the blog post, download page, and lots more.

So be sure to check that out.

Code Talkthrough: Android and the Cloud

Finally, in today’s code talk through, I’d like to show you a recipe for building a RESTful web service application, deploying it to the Bluemix cloud as a Cloud Foundry application, and building an Android app to communicate with it.

The code I’ll show you is available in GitHub, and is from a recipe I wrote for IBM developerWorks called Android and the Cloud.

To follow along with the video, you will need a Bluemix account, JDK 8, Eclipse, WebSphere Liberty, and Android studio installed on your computer.

You will need three projects from GitHub also:

In today’s show, I’m just going to show you the high level steps.  The recipe walks you through it step-by-step if you’re interested in reproducing this yourself, which I hope you are.

Let’s get started.

First, clone the code from GitHub for the two web services projects.

git clone https://github.com/makotogo/oDoTCore
git clone https://github.com/makotogo/OdotWrapper

Now import the code into Eclipse.

With the code in Eclipse, build the oDoTCore JAR file using Maven, specifying the install goal so the JAR file gets installed to your local Maven repository.

Next, build the OdotWrapper WAR file using Maven, specifying the package goal.

Locate the WAR file in the target directory, and copy it to the WebSphere Liberty droppins directory.

Start WebSphere Liberty in Eclipse.

To verify the WebService is working, go to a browser and access this URL

http://localhost:9080/OdotWrapper/ItemRestService/Ping

When you see the JSON message, you know you have everything built and packaged correctly.

Now I’ll bundle the WebSphere Liberty server, including the WAR file, and deploy it to Bluemix.

For this part I need my Bluemix credentials, and the route I want to deploy it to.

I’m going over this fast, I know, but this is just an overview. The recipe has all the details.

Once I’ve deployed the application to Bluemix, I can test it and make sure it’s running. Open a browser, and hit this URL:

https://androidcloudrecipe.mybluemix.net/OdotWrapper/ItemRestService/Ping

Again, when I see the JSON message “Hello from the server side!” I know it’s up and running.

Now to build the code for the Android app, run the app in the Android Emulator, and access the Web Service running in Bluemix.

Don’t worry, we’re almost there!

First, pull the code from GitHub:

git clone https://github.com/makotogo/AndroidCloudRecipe

Now import the code into Android Studio, and run the code in the Android Emulator. Choose the virtual device you setup when you installed and smoke tested Android Studio. It takes a minute or two for the device to start.

When the device starts, it will load the application. If you don’t see the application, click the Run button again in Android Studio.

Verify that the URL is correct (if not, change the code and run it again), and click the Info floating action button to invoke the Ping method. If you get back a Toast message that looks like this, then you’re good to go:

AndroidCloudRecipe-Figure-5

Under the hood, the Android app receives the JSON message we saw earlier in the browser, and is rendering it as a Toast message.

Now click on the Refresh From Server button, and the list should fill with data:

AndroidCloudRecipe-Figure-6

And that’s how you connect an Android app to an application running in the Cloud!

The developerWorks recipe has the steps broken down in much more detail, so be sure to check that out.

That’s all for this episode of Java News and Code.

Make sure to visit the show notes page, click the subscribe button, and you’ll be notified each time a new episode comes out!

–jsp

Android Hello, World Video Tutorial

Check out my latest video Tutorial on YouTube!

In this video I show you how to:

  • Create an Android Studio project
  • Create an Android Virtual Device (AVD)
  • Run the Hello World program
  • Add custom behavior to the program
  • Add a string resource to strings.xml

Below is the main source code for the project.

MainActivity.java:

package com.makotogo.mobile.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   // Add button
   Button helloButton = (Button)findViewById(R.id.helloButton);

   helloButton.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
       TextView textView = (TextView)findViewById(R.id.textView);
       textView.setText(R.string.seriouslyHelloWorld);
     }
   });
 }
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context="com.makotogo.mobile.helloworld.MainActivity">

 <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/helloWorld"
   android:id="@+id/textView"
   android:layout_alignParentTop="true"
   android:layout_alignRight="@+id/helloButton"
   android:layout_alignEnd="@+id/helloButton"/>

 <Button
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Click Me!"
   android:id="@+id/helloButton"
   android:layout_marginTop="76dp"
   android:layout_below="@+id/textView"
   android:layout_centerHorizontal="true"/>

</RelativeLayout>

strings.xml:

<resources>
  <string name="app_name">HelloWorld</string>
  <string name="helloWorld">Hello, World!</string>
  <string name="seriouslyHelloWorld">Seriously, HELLO, WORLD!!</string>
</resources>

I hope you enjoy the video!

–jsp