Articles

Java for a lot of time has been accused and mocked for its verbosity. Even the most passionate Java developers have to admit that it felt ridiculous to declare a bean class with two attributes. If you follow the right recommendations, you end up adding not only getters and setters, but also the implementations of toString hashcode and equals methods. The final result is a chunk of boilerplate that invites you to start learning another language. 

Java

 

import java.util.Objects; public class Car { private String brand; private String model; private int year; public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } @Override public String toString() { return "Car{" + "brand='" + brand + ''' + ", model='" + model + ''' + ", year=" + year + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Car car = (Car) o; return year == car.year && Objects.equals(brand, car.brand) && Objects.equals(model, car.model); } @Override public int hashCode() { return Objects.hash(brand, model, year); }
}

Source de l’article sur DZONE

Java

 

class Base<T> { T obj; Base(T obj) { this.obj = obj; } T getob() { return obj; } } class Sub extends Base<String> { Sub(String str) { super(str); } String getob() { return obj; } }

How many methods of the sub-class in the above code snippet will have after compilation, and why? Let’s make it a little bit simpler: How many methods the sub-class will have, excluding the methods inherited from java.lang.Object?

Source de l’article sur DZONE

In the video below, we take a closer look at MySQL DB Installation: Using MySQL Workbench to connect to MySQL DB and how to install the Mysql 8 Server. Let’s get started!

Source de l’article sur DZONE

In the video below, we take a closer look at JDBC PreparedStatement with example and Statement vs PreparedStatement. Let’s get started!

Source de l’article sur DZONE

As I’m becoming a senior developer in terms of age, I’ve transitioned from one language to another. One of my main interests has always been clean, easy-to-understand UIs (User Interface). That journey started for me with Director (to create multimedia CD-ROMs), Flash website animation, and Flex Rich Internet Applications (= « Flash on steroids »). When I started developing with Java over 10 years ago, we had some projects with the early versions of Vaadin and JavaFX. As I went on with serverside applications, I only continued with JavaFX for some personal and side projects and loved the way you can create a UI both with XML (FXML actually) and code, exactly the same approach I loved with Flex. Since then, my love for Java and JavaFX only grew and it’s still my major programming environment.

But JavaFX has one missing piece: running it in the browser… Yes, JPRO can do this, but it needs a license and a dedicated server. And yes, there are some projects ongoing to bring JavaFX fully to the browser, but they are ongoing and not mature yet… Let’s look at another approach: Vaadin Flow and run it on a Raspberry Pi to control a LED and show the state of a button.

Source de l’article sur DZONE

Since Java 5, the core Java APIs have been enhanced with more features for handling coordination between threads in concurrent programming. In this post, we discuss a class in the java.util.concurrent package that aids in this purpose: the CountDownLatch.

Introduction

The CountDownLatch class enables us to coordinate threads by introducing awareness of the number of threads that are carrying out related tasks and keeping track of the number of threads that have completed their task. 

Source de l’article sur DZONE

BellSoft issued a new version of Liberica Native Image Kit (NIK), 22.0.0.2, so in this short article, I will provide a tutorial on how to use it with the Quarkus framework.

Liberica NIK is based on the open-source project GraalVM (Community Edition) and is compatible with many platforms, including lightweight musl-based Alpine Linux. Liberica NIK in essence is a utility that converts JVM-based applications into native executables (AOT compilation).

Source de l’article sur DZONE

In this video tutorial below, we take a closer look at Messaging Design Pattern(MDP) in Java. This tutorial includes an introduction and implementation of a proxy, adapter, and web service. Let’s get started!

Source de l’article sur DZONE

When we build a microservice architecture and the number of services keeps growing, we face the problem of debugging and tracing requests through our entire system. What happened when a user got a 500 error on his request? What service incorrectly processed his request? All these questions can be solved by the Distributed Tracing System. Let’s take Spring Cloud Sleuth as an example.

How Spring Cloud Sleuth Works

To trace a request through a distributed system, the concepts TraceID and SpanID are introduced. TraceID is generated when a request enters our system and remains unchanged throughout its path. SpanID changes as the request passes from one service to another. If necessary, it is possible to generate new spans within one service to distinguish business processes.

Source de l’article sur DZONE

In the video below, we take a closer look at the State Design Pattern in Java. This tutorial includes an introduction, real-time examples, class/sequence diagram, and implementation. Let’s get started!

Source de l’article sur DZONE