Sorting with Comparable and Comparator in Java

See the original posting on JavaWorld

Programmers frequently need to sort elements from a database into a collection, array, or map. In Java, we can implement whatever sorting algorithm we want with any type. Using the Comparable interface and compareTo() method, we can sort using alphabetical order, String length, reverse alphabetical order, or numbers. The Comparator interface allows us to do the same but in a more flexible way.

Whatever we want to do, we just need to know how to implement the correct sort logic for the given interface and type.

Comparing Java objects with equals() and hashcode()

See the original posting on JavaWorld

In this Java Challenger you’ll learn how equals() and hashcode() combine to make object comparisons efficient and easy in your Java programs. Simply put, these methods work together to verify if two objects have the same values.  

Without equals() and hashcode() we would have to create very large “if” comparisons, comparing every field from an object. This would make code really confusing and hard to read. Together, these two methods help us create more flexible and cohesive code.

Polymorphism and inheritance in Java

See the original posting on JavaWorld

According to the legend Venkat Subramaniam, polymorphism is the most important concept in object-oriented programming. Polymorphism–or the ability of an object to execute specialized actions based on its type–is what makes Java code flexible. Design patterns like Command, Observer, Decorator, Strategy, and many others created by the Gang Of Four, all use some form of polymorphism. Mastering this concept greatly improves your ability to think through solutions to programming challenges.

To read this article in full, please click here

String comparisons in Java

See the original posting on JavaWorld

In Java, the String class encapsulates an array of char. Put simply, String is an array of characters used to compose words, sentences, or any other data you want.

Encapsulation is one of the most powerful concepts in object-oriented programming. Because of encapsulation, you don’t need to know how the String class works; you just need to know what methods to use on its interface.

When you look at the String class in Java, you can see how the array of char is encapsulated:

To read this article in full, please click here

Method overloading in the JVM

See the original posting on JavaWorld

Welcome to the new Java Challengers blog! This blog is dedicated to challenging concepts in Java programming. Master them and you will be well on your way to becoming a highly skilled Java programmer.

The techniques in this blog take some effort to master, but they’ll make a great difference in your daily experience as a Java developer. Avoiding bugs is easier when you know how to properly apply core Java programming techniques, and tracking bugs is much easier when you know exactly what is happening on your Java code.

Are you ready to start mastering core concepts in Java programming? Then let’s get started with our first Java Challenger!  

To read this article in full, please click here

Microsoft buys jClarity to boost Java on Azure

See the original posting on JavaWorld

With its acquisition of Java support services company jClarity, Microsoft is making a play to optimize Java workloads on its Azure cloud platform.

Microsoft calls jClarity the leading contributor to the AdoptOpenJDK project, which provides free, open source OpenJDK binaries. Microsoft has been a sponsor of AdoptOpenJDK, which has provided binaries for both Windows and Linux.

Ruby on Rails 6.0 adds rich text capabilities

See the original posting on JavaWorld

Ruby on Rails 6.0, the latest version of the veteran web application framework, has improvements for composing rich text content and JavaScript integration.

Version 6.0 of the 15-year-old framework includes the Action Text framework for rich text content and editing, using the Trix editor for formatting. Text edited by Trix is saved to its own rich text model associated with any Active Record model in the application. Also with Action Text, embedded images or other attachments are automatically stored using Active Storage.