OOP Concepts for Beginners: What Is Polymorphism
By Thorben Janssen
The word polymorphism is used in various contexts and describes situations in
which something occurs in several different forms. In computer science, it
describes the concept that objects of different types can be accessed through
the same interface. Each type can provide its own, independent implementation
of this interface. It is one of the core concepts of object-oriented
programming (OOP).
If you're wondering if an object is polymorphic, you can perform a simple
test. If the object successfully passes multiple is-a or instanceof tests,
it's polymorphic. As I've described in my post about inheritance, all Java
classes extend the class Object. Due to this, all objects in Java are
polymorphic because they pass at least two instanceof checks.
Different types of polymorphism
Java supports two types of... (more)
A Deep Dive into the Core Metrics of the Java Virtual Machine
By Eugen Paraschiv
Overview of JVM Metrics
In this article, we'll cover how you can monitor an application that runs on
the Java Virtual Machine by going over some of the critical metrics you need
to track. And, as a monitoring tool, we'll use Stackify Retrace, a full APM
solution.
The application we'll monitor to exemplify these metrics is a real-world Java
web application built using the Spring framework. Users can register, login,
connect their Reddit account and schedule their posts to Reddit.
How JVM Memory Works
There are two important types of JVM memory to watch: heap and non-heap
memory, each of these with its own purpose.
The heap memory is where the JVM stores runtime data represented by allocated
instances. This is where memory for new objects comes from, and is released
when the Garbage Colle... (more)
Java 9 Language Features
By Philipp Lengauer
Java 9 ships with some minor—yet awesome—new language features that make
developing easier and cleaner. In this post, we’ll take a look at three of
these new features.
Private interface methods
You probably remember interface methods, which were introduced in Java 8.
These are required so that Java itself, as well as framework vendors, can add
new methods to interfaces without breaking pre-existing implementations. As
these methods can become rather complex, Java now enables you to declare
interface methods as private. This allows for extracting common code from
interface methods while hiding the code from external use.
public interface DeepThought {
abstract int foo();
abstract int bar();
default int fooDecorated() {
return decorate(foo());
}
default int barDecorated() {
return decorate(bar());
}
private int decorate(int valu... (more)
A Practical Guide to Java Remote Debugging
By Eugen Paraschiv
Introduction to Debugging
Troubleshooting a problem on a remote server, especially in production, is
not an easy task. Sometimes it involves debugging the application code
directly on the server.
But the production servers are usually run in a strict environment, where not
all convenient developer tools are available.
In this article, you'll discover how to configure a running web server and
debug your application using standard facilities provided by the Java
platform.
Caveats
First off, if you try to connect to a remote running Java server which you
did not specifically configure for debugging, you'd most likely fail. This
means that the configuration steps should be taken in advance.
On the other hand, you wouldn't want to always keep the production server
running with debugging configuration enabled, a... (more)
An update to the Web Content Accessibility Guidelines (WCAG) is coming. Did I
lose you already? If you're not familiar with WCAG, it's a collection of
guidelines that developers, designers and accessibility experts use to help
ensure the apps and websites they create are accessible to people with
disabilities. The W3C has the latest guidelines published here.
As an active member of the Accessibility Guidelines Working Group at the W3C,
I'd like to share with you all what to expect in upcoming changes to these
guidelines, currently referred to as WCAG version 2.1. But, before we get
into the weeds about how 2.1 is different, let's review a history of WCAG as
it stands today:
Stay tuned for future posts and videos in this series where I dig in to
additional detail surrounding the WCAG 2.1 updates!
CloudExpo | DXWorldEXPO have announced the conference tracks for Cloud... (more)
Seven Common Mistakes You Should Avoid When Handling Java Exceptions
By Thorben Janssen
Handling an exception is one of the most common but not necessarily one of
the easiest tasks. It is still one of the frequently discussed topics in
experienced teams, and there are several best practices and common mistakes
you should be aware of.
Here are a few things you should avoid when handling exceptions in your
application.
Mistake 1: Specify a java.lang.Exception or java.lang.Throwable
As I explained in one of my previous posts, you either need to specify or
handle a checked exception. But checked exceptions are not the only ones you
can specify. You can use any subclass of java.lang.Throwable in a throws
clause. So, instead of specifying the two different exceptions that are
thrown by the following code snippet, you could just use the
java.lang.Exception in the throws cla... (more)
Java Web Services Tutorial: Improve App Communication and Flexibility
By Eugen Paraschiv
Web services have taken the development world by storm, especially in recent
years as they've become more and more widely adopted. There are naturally
many reasons for this, but first, let's understand what exactly a web service
is.
The World Wide Web Consortium (W3C) defines "web of services" as
"message-based design frequently found on the Web and in enterprise
software". Basically, a web service is a method of sending a message between
two devices through a network.
In practical terms, this translates to an application which outputs
communication in a standardized format for other client applications to
receive and act on.
Web services have been adopted so quickly because they bring several
important advantages:
Allow communication and interoperability between applications r... (more)
Solving the XML Problem with Jackson
By Eugen Paraschiv
Jackson is a popular library for handling JSON in Java applications, quickly
becoming the de-facto standard in the ecosystem. Starting with version 2, it
has also introduced a mature XML implementation alongside its established
JSON support.
Adding Jackson XML to the Project
Adding the Jackson XML module to the project only needs a single dependency -
the Jackson XML module itself:
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
2.9.0
And in Gradle:
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.0"
This will automatically pull in all of the other Jackson dependencies that
are needed:
Jackson Core Jackson Annotations Jackson Databind Jackson Module JAXB
Annotations Woodstox StAX Implementation
Not... (more)
Finally Getting the Most out of the Java Thread Pool
By Eugen Paraschiv
First, let's outline a frame of reference for multithreading and why we may
need to use a thread pool.
A thread is an execution context that can run a set of instructions within a
process - aka a running program. Multithreaded programming refers to using
threads to execute multiple tasks concurrently. Of course, this paradigm is
well supported on the JVM.
Although this brings several advantages, primarily regarding the performance
of a program, multithreaded programming can also have disadvantages - such as
increased complexity of the code, concurrency issues, unexpected results and
adding the overhead of thread creation.
In this article, we're going to take a closer look at how the latter issue
can be mitigated by using thread pools in Java.
Why Use a Thread Pool?
Creating and starting a thread ... (more)
How Memory Leaks Happen in a Java Application
By Eugen Paraschiv
Introduction to Memory Leaks In Java Apps
One of the core benefits of Java is the JVM, which is an out-of-the-box
memory management. Essentially, we can create objects and the Java Garbage
Collector will take care of allocating and freeing up memory for us.
Nevertheless, memory leaks can still occur in Java applications.
In this article, we're going to describe the most common memory leaks,
understand their causes, and look at a few techniques to detect/avoid them.
We're also going to use the Java YourKit profiler throughout the article, to
analyze the state of our memory at runtime.
1. What is a Memory Leak in Java?
The standard definition of a memory leak is a scenario that occurs when
objects are no longer being used by the application, but the Garbage
Collector is unable to remove them from working mem... (more)
What is Java DevOps? Benefits, Considerations, Tutorials and More
By Angela Stringfellow
DevOps sees the coming together of practices, philosophies, and tools that
allow you to create services and applications very quickly. This means that
you can improve on your apps and evolve them at a much faster rate than those
developers who are using traditional software development processes. We’ve
talked about DevOps, in general, a great deal, but today, we’re going to
dig a little deeper and take a look at Java DevOps specifically.
What Is DevOps?
DevOps is simply a portmanteau of software DEVelopment and IT OPerations. It
was first called agile operations and involves different disciplines in
building, operating and evolving applications and services.
Using a DevOps model, you are bringing together your development team and
your operations team, and their work is no longer i... (more)