Support for Ubuntu Unity Desktop after 16.04 LTS

Can still use the Unity Desktop after Ubuntu 16.04 Xenial Xerus? Is it still supported?

I like the Unity desktop way of things. Been using it many years now. Read about and tried the new Ubuntu that with Gnome Shell, but I don’t like it much at all. It look clunky with many of missing things from it.

Come April 2021 Ubuntu 16.04 will EOL. Starting to find alternatives, but if Unity is still out there, I’d pick it over the others.

ANSWER

In one word, Yes.

Still can run on both LTS versions of 18.04 and 20.04. Go ahead and install it with:

sudo apt install ubuntu-unity-desktop

Choose Lightdm display manager when asked during install. Best to restart your computer afterwards. Then enjoy.

Consider that many people have said some weird looks of Unity when installed on said LTS versions appear. I forget, but I think its the window decorations and such. This is supposedly caused by the newer Gnome versions, and unpatched by Ubuntu. Unlike before.

You may also like to try out an alternative in the Ubuntu Unity Desktop spinoff. Can be found at this website – https://ubuntuunity.org/

It is not official Ubuntu flavor, but being maintained by some other 3rd party group. The experience is different from just installing 20.04 and then install Unity DE afterwards. Try it out if it suits you.

How to convert For loop using Stream in Java

Creating a Map of Applicant object, where I filter out on the applicant’s age. I only need the first name and last name of the applicant. Using the application ID as the key. The ID is generated integer and unique. Also, testing for null, don’t want that in there. I am using a traditional for loop where I am most comfortable at. But I want to use the Java 8 Stream instead. How is it done?

My code for this is below:

        Applicant a1 = new Applicant();
        a1.setId(1001);
        a1.setFirstName("Joseph");
        a1.setLastName("Dey");
        a1.setAge(25);

        Applicant a2 = new Applicant();
        a2.setId(2001);
        a2.setFirstName("Maxine");
        a2.setLastName("Summers");
        a2.setAge(21);

        Applicant a3 = new Applicant();
        a3.setId(3001);
        a3.setFirstName("Jimmy");
        a3.setLastName("Cox");
        a3.setAge(17);

        Applicant a4 = null;

        List<Applicant> list = new ArrayList<>();
        list.add(a1);
        list.add(a2);
        list.add(a3);
        list.add(a4);

        Map<Integer, String> map = new HashMap<>();
        for (Applicant a : list) {
            if (a != null && a.getAge() > 18) {
                map.put(a.getId(), a.getFirstName() + " " + a.getLastName());
            }
        }

ANSWER

By Statement Lambda in Collectors.toMap – right-hand side is a block. This can become longer to write but sometimes when you have to do more transformations, then it can’t be avoided.

1       Map<Integer, String> map = list.stream()
2                .filter(applicant -> applicant != null)
3                .filter(applicant -> applicant.getAge() >= 18)
4                .collect(Collectors.toMap(applicant -> applicant.getId(), applicant -> {
5                    return applicant.getFirstName() + " " + applicant.getLastName();
6                }));

By Expression Lambda in Collectors.toMap – right-hand side is an expression.

1       Map<Integer, String> map = list.stream()
2                .filter(applicant -> applicant != null)
3                .filter(applicant -> applicant.getAge() >= 18)
4                .collect(Collectors.toMap(applicant -> applicant.getId(), applicant -> applicant.getFirstName() + " " + applicant.getLastName()));

In both cases above, line #2 the Lambda can be replaced with method reference too. It will look like:

.filter(Objects::nonNull)

And on line #4, the same can be done for the Lamba replacing it with a method reference. It will look like:

.collect(Collectors.toMap(Applicant::getId,  // rest of code ommitted

Avro – Unions

As a boolean:

{
	"fieldOne": "hello world",
	"fieldTwo": true,
	"foobar": {
		"boolean": false
	}
}

If value is null:

{
	"fieldOne": "hello world",
	"fieldTwo": true,
	"foobar": null
}

The above is what a field will look like as output where in Avro that field is defined as one of the Complex Types – Unions. Example below, it declares a schema which may be one of null or boolean.

{
  "type": [
    "null", 
    "boolean"
  ]
}

Convert a Map to POJO in Java

How do I convert a Map object to my other plain old Java object (POJO) without going into loops and having to write a class using Java reflection, or some other?

ANSWER

Well, yes, reflection is one but you didn’t want to do that yourself. For some good reason, I bet. It’s a good exercise if you have all the time in the world. But when faced with deadlines and having to write Unit tests for a whole class you wrote, there must be an easier way.

There is more than one way, but what I normally use is the Jackson ObjectMapper. Yes, the same one from the com.fasterxml.jackson library.

Anyway, with ObjectMapper it is pretty straightforward to do so. If I have a Person class like this:

    public class Person {
        private String firstName;
        private String lastName;
    }

My Map object will look like this:

        Map<String, Object> map = new HashMap<>();
        map.put("firstName", "Johnny");
        map.put("lastName", "Foo");

Then with ObjectMapper one can simply do this:

        ObjectMapper mapper = new ObjectMapper();
        Person person = mapper.convertValue(map, Person.class);

Alternatively, the keys in the Map may not align with the fields in the Person class. Well, I usually encounter this when working with JSON objects with lots of crazy looking field names. Something like this – NZT_Mor_First_Name__c – which I clearly don’t want my class field name to be like.

Well, we can use @JsonProperty annotation which is part of Jackson by the way and assign that our class field. The Person class will now look like:

    public class Person {

        @JsonProperty("NZT_Mor_First_Name__c")
        private String firstName;

        @JsonProperty("NZT_Mor_Last_Name__c")
        private String lastName;
    }

Again the Map will hold these values:

        Map<String, Object> map = new HashMap<>();
        map.put("NZT_Mor_First_Name__c", "Jose");
        map.put("NZT_Mor_Last_Name__c", "Yamut");

Now it will map out those weird looking key names to its corresponding class fields.

One thing to note is you might need to set ObjectMapper features such as ignoring unknown properties and make it case insensitive. Allow it a bit more room to wiggle, wiggle.

        ObjectMapper mapper = new ObjectMapper()
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES);

Should I quote Strings in YAML?

Should I or should I not? Is it required? Will it work even without quotes – single or double?

ANSWER

I’ve asked myself these questions several times. Often I end up double-quoting long strings, but not for one word ones or shorter strings. Which makes it rather inconsistent. Especially if that string contains characters like a forward slash, a colon or semi-colon. Like when you have a URL as a value. I suppose it’s out of habit.

Thing is, it is not required. Strings can be quoted or not. There is no difference. It will still work with or without it. Even with spaces in that string. YAML allows it. Below are 2 examples:

phrase: 'The quick brown fox jumps over the lazy dog.'
poem: "Hey, diddle, diddle. The cat and the fiddle. The cow jumped over the moon."

The key part of the key-value pair can also be quoted too. The YAML won’t error out. Again, it’s allowed. So this is valid:

'foo':
  "bar": foobar

Single quote or double quotes don’t matter. It can be mixed. Above examples are both acceptable.

However, not quoting is not true in all cases. There are certain instances when it is required such as when there is a colon in the key. In this case, the key needs to be quoted.

'key:': value

What about quotes in the value itself?

CORRECT - phrase1: 'The quick ''brown'' fox jumped over the lazy dog.'
WRONG- phrase2: "The quick ""brown"" fox jumped over the lazy dog."
CORRECT - phrase3: "The quick \"brown\" fox jumped over the lazy dog."
WRONG - phrase4: "The quick '"brown"' fox jumped over the lazy dog."
CORRECT - phrase6: The quick 'brown' fox jumped over the lazy dog.
CORRECT - phrase7: The quick "brown" fox jumped over the lazy dog.

Finally, what does YAML mean?

It is short for – YAML Ain’t Markup Language.

What’s my Windows version

You’ll probably get asked this once or twice. Especially when your Windows computer is not working right, and you are running all over the Internet trying to look for answers. Perhaps would-be good Samaritans might ask this off you as well.

And you reply, “Windows 10”. But rightfully so.

After all, isn’t that the Windows that is installed on your machine right now. Well, yes. Then again, no. No not in the sense that you are wrong. But sometimes the answer to the question of what Windows version is installed on your PC might be something else. Sometimes support may ask you this, and likely they will tell you how to give them the answer they are looking for. If you don’t already know this, then this can save time and misunderstanding. Below are the steps on how to get that information.

What version is my Windows?

  • Go to the Start Menu. Click it. Press the Windows key
  • Type “Run”. The shortcut key is Windows key + R.
  • Type “winver” in the field labeled with Open. You may also type winver in the search box on your taskbar if you have that one.
  • Click OK or press enter
  • Small dialog Windows will pop out title – About Windows.

The information will be found on this pop up window. On the first few lines you should see something like:

Microsoft Windows
Version 2004 (OS Build 19041.630)

Note: Don’t include quotes when typing in those words in the steps.