22 Aug 2019

feedDZone Java Zone

How Do Annotations Work in Java?

Annotations have been a very important part of Java, and it's been there from the time of J2SE 5.0. All of us have seen annotations like @Override and @Deprecated in our application code at some place or another. In this article, I will discuss what exactly annotations are, why they were introduced, how they work, how to write custom annotations (with example code), what could be valid scenarios for annotations, and lastly annotations and ADF. It's going to be a long post, so grab some coffee and get ready to dive into the world of annotations.

What Are Annotations?

One word to explain annotation is metadata. Metadata is data about data. So annotations are metadata for code. For example, look at the following piece of code.

22 Aug 2019 2:15pm GMT

An Introduction to JUnit

Testing is an essential part of creating software and one that is often looked at as a second class citizen in the realm of application code. Despite this mischaracterization, test code often plays just as much - or an even larger - role in successfully releasing software that contains as few bugs as possible.

In this tutorial, we will walk through each of the steps required to develop simple but well-thought-out tests, starting with the theory and concepts behind creating tests. With this theory in hand, we will create a test fixture in JUnit 4 to exercise an example application and add test cases to this fixture as necessary. We will also learn how to mock external dependencies and use the setup mechanism provided by JUnit to abstract the initialization logic for our test cases. Along the way, we will cover the given-when-then approach to testing and the standard naming conventions used in many large-scale projects.

22 Aug 2019 1:47pm GMT

How to Schedule a Task Using the Cron Expression in Spring Boot [Video]

In the video below, we take a closer look at how to schedule a task using the Cron expression in Spring Boot. Let's get started!

22 Aug 2019 12:12pm GMT

This Week in Spring: Securing Spring Cloud, Performance, Releases, and More

Hi, Spring fans! I'm in delightful Denver and Boulder, Colorado, talking to customers and working with my buddies Matt Raible and James Ward on our Spring One Platform 2019 talk. It's going to be amazing!

I'm oh-so-excited to be working on today's roundup, as usual, because there's a ton of good stuff to cover, so let's get to it!

22 Aug 2019 12:12pm GMT

Java Garbage Collection Types and Settings in Jelastic PaaS

Performance and price are two big considerations in application hosting that always matter. And, often, we question ourselves on how to decrease the spends, without affecting the performance of your apps at the same time. In this article, we'd like to address automatic memory management for Java applications hosted with Jelastic using garbage collection.

Let's clarify what garbage collection is, what it does for Java applications, and how it works within Jelastic PaaS.

22 Aug 2019 12:12pm GMT

21 Aug 2019

feedDZone Java Zone

When to Use Abstract Class and Interface

Abstract Class

An abstract class is a class that is declared abstract - it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract class may have static fields and static methods. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.

An abstract method is a method that is declared without an implementation (without braces and followed by a semicolon), like this:

21 Aug 2019 4:10pm GMT

How to Deep Clone an Object Using Java in Memory Serialization

In my previous articles, I explained the difference between deep and shallow cloning and how copy-constructors and defensive copy methods are better than default Java cloning.

Java object cloning using copy constructors and defensive copy methods certainly have some advantages but we have to explicitly write some code to achieve deep cloning in all these approaches. And still, there are chances that we might miss something and do not get a deeply cloned object.

21 Aug 2019 1:35pm GMT

Intro to Unit Testing in Java With JUnit5 Library

Hello, DZone! In this post, I would like to focus on unit testing in Java with the JUnit5 library. JUnit 5 introduced new features and approaches to testing - compared to the older JUnit 4 version - that are worth checking out. First, we will look at an overview of what unit testing is and why it is so important to test. Later, we will look at how to install JUnit 5 in your projects, what is a basic test structure, how to use the Assertions API, and finally, how to combine multiple tests in a test suite. Let's get started.

What Is Unit Testing?

Unit testing is a level of software testing where we test individual software's components in isolation. For example, we have UserService. It may have various connected dependencies, like UserDAO to connect to a datasource, or EmailProvider to send confirmation emails. But for unit testing, we isolate theUserService and may even mock connected dependencies (in regards to how to conduct mocking, we will dive deeper in the next section).

21 Aug 2019 1:35pm GMT

How to Change the Default Context Path Using Application.Properties [Video]

In the video below, we take a closer look at Spring Boot and how to change the default context path using application.properties? Let's get started!

21 Aug 2019 1:35pm GMT

20 Aug 2019

feedDZone Java Zone

Java Cloning: Copy Constructors vs. Cloning

In my previous article, Shallow and Deep Java Cloning, I discussed Java cloning in detail and answered questions about how we can use cloning to copy objects in Java, the two different types of cloning (Shallow and Deep), and how we can implement both of them. If you haven't read it, please go ahead.

In order to implement cloning, we need to configure our classes and to follow the following steps:

20 Aug 2019 8:34pm GMT

How to Define Constants in Java

There seems to be a lot of confusion around the topic of constants in Java. Some people make use of integers or Strings to define constants, while others make use of enums.

I've also come across constants defined in their own interface - where classes that make use of the constants have to implement the interface. This strategy is often referred to as the interface constant design pattern.

20 Aug 2019 4:04pm GMT

How to Schedule a Task at a Fixed Delay in Spring Boot [Video]

In the video below, we take a closer look at Spring Boot, specifically how to schedule a task at a fixed delay. Let's get started.

20 Aug 2019 1:04pm GMT

java.lang.Record: Draft Specification

Work on proposed Java Records continues to proceed. Brian Goetz started three new threads on the OpenJDK amber-spec-experts mailing list yesterday, and two of them are focused on Java Records. One of these two Record-oriented threads discusses whether Java records should support varargs. The other thread provides the initial draft specification for the proposed class java.lang.Record and that is the subject of this post.

The first sentence of the proposed class-level Javadoc for java.lang.Record currently says of this class, "This is the common base class of all Java language record classes." This initial specification also shows java.lang.Record being designated as a public abstract class.

20 Aug 2019 1:03pm GMT

When to Use JSR 305 for Nullability in Java

JSR 305 became a de-facto standard despite its many problems. I advise to use it for nullability until something better is adopted by Kotlin and major IDEs.


When it comes to nullability annotations in Java, there is no official standard. In this post, I describe:

20 Aug 2019 1:03pm GMT

19 Aug 2019

feedDZone Java Zone

Mutation Testing: Covering Your Code With the Right Test Cases (Part 2)

In part one, we achieved 100 percent coverage. In this installment, we mutate our code and check how good our tests are.

There are several mutation testing frameworks. In this case, we will use PITEST.

19 Aug 2019 7:22pm GMT

Mutation Testing: Covering Your Code With the Right Test Cases (Part 1)

Mutation Testing Basics

The concept of mutation testing is to modify code in a small way and verify that tests detect that modification. Undetected modification gives a hint to what test is likely missing.

Mutation Procedure Next Steps:

  1. Modify code in small way (creating mutant)
  2. Execute existing test suites (killing mutant)
  3. Verify that at least one existent test failed (mutant killed)
  4. If all test succeded (mutant survived), there is likely a missing test case

But why do we have to consider testing the result of the modified code? Let's take a look at an example:

19 Aug 2019 7:21pm GMT

10 Nov 2011


OSDir.com - Java: Red Hat's top secret Java Killer/Successor: The Ceylon Project

From the Ceylon dept.:

Gavin King of Red Hat/Hibernate/Seam fame recently unveiled the top secret project that he has been working on over the past two years, a new language and SDK designed to replace Java in the enterprise. The project came out of hiding without much fanfare or publicity at QCon Beijing in a keynote titled "The Ceylon Project - the next generation of Java language?".

10 Nov 2011 6:01am GMT

OSDir.com - Java: Oracle Introduces New Java Specification Requests to Evolve Java Community Process

From the Yet Another dept.:

To further its commitment to the Java Community Process (JCP), Oracle has submitted the first of two Java Specification Requests (JSRs) to update and revitalize the JCP.

10 Nov 2011 6:01am GMT

OSDir.com - Java: No copied Java code or weapons of mass destruction found in Android

From the Fact Checking dept.:

ZDNET: Sometimes the sheer wrongness of what is posted on the web leaves us speechless. Especially when it's picked up and repeated as gospel by otherwise reputable sites like Engadget. "Google copied Oracle's Java code, pasted in a new license, and shipped it," they reported this morning.

Sorry, but that just isn't true.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Java SE 7 Released

From the Grande dept.:

Oracle today announced the availability of Java Platform, Standard Edition 7 (Java SE 7), the first release of the Java platform under Oracle stewardship.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Java SE 7 Passes JCP

From the Jitters dept.:

The next edition of Java has been approved by a Java Community Process executive committee, but not without some acrimony.

10 Nov 2011 6:01am GMT

OSDir.com - Java: JDK 7 RC1 Released

From the JDK dept.:

After an initial round of testing we've declared build 147 to be the first Release Candidate of JDK 7.

There are only thirteen changes in this build. Over half of them are administrivial updates that don't affect the actual code; the remainder are true showstoppers, including several hard VM crashes and a JIT correctness bug identified by an Eclipse unit test.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Google Files Sizzling Answer to Oracle's Amended Java Complaint

From the Counter dept.:

Google has filed its answer to Oracle's amended complaint and its memorandum opposing Oracle's Motion to Dismiss. And we find out why Google didn't just roll over and pay Oracle for a license. Oracle asked in its motion to dismiss that the counterclaims alleging that Oracle's patents are invalid be dismissed. So Google explains more thoroughly why it believes they are in fact invalid. First, Google asserts:

Each of the Patents-in-Suit is invalid under 35 U.S.C. ยง 101 because one or more claims are directed to abstract ideas or other non-statutory subject matter.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Apache loses Java showdown vote to Oracle

From the Dis Harmony dept.:

The Apache Software Foundation - one of tech's most influential open-source groups - is closer to quitting Java's governing body after losing a stand-off vote against Oracle on Java.

The Reg has learned that with 75 per cent of qualifying Java Community Process (JCP) members having voted on whether to ratify Oracle's proposed roadmap for Java 7 and 8, Oracle's plan has been accepted.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Apache Software Foundation Resigns from Java Community Process

From the So Long dept.:

The Apache Software Foundation has resigned its seat on the Java SE/EE Executive Committee. Apache has served on the EC for the past 10 years, winning the JCP "Member of the Year" award 4 times, and recently was ratified for another term with support from 95% of the voting community. Further, the project communities of the ASF, home to Apache Tomcat, Ant, Xerces, Geronimo, Velocity and nearly a 100 mainstay java components have implemented countless JSRs and serve on and contribute to many of the JCPs technical expert groups.

We'd like to provide some explanation to the community as to why we're taking this significant step.

The recent Java SE 7 vote was the last chance for the JCP EC to demonstrate that the EC has any intent to defend the JCP as an open specification process, and demonstrate that the letter and spirit of the law matter. To sum up the issues at stake in the vote, we believe that while continuing to fail to uphold their responsibilities under the JSPA, Oracle provided the EC with a Java SE 7 specification request and license that are self-contradictory, severely restrict distribution of independent implementations of the spec, and most importantly, prohibit the distribution of independent open source implementations of the spec. Oracle has refused to answer any reasonable and responsible questions from the EC regarding these problems.

10 Nov 2011 6:01am GMT

OSDir.com - Java: Apache Discontinues Independent Java Implementation 'Harmony'

From the DisHarmony dept.:

After the resignation of Apache from the Java SE/EE Executive Committee, the time has now come for Harmony to be added to the Apache Attic. Harmony was 'the project to produce an open source cleanroom implementation of Java.' An open vote was taken within the Project Management Committee, which resulted in a 20-2 majority to discontinue development.

10 Nov 2011 6:01am GMT

Javable: YourKit Java Profiler 7.0 released

The major update to YourKit Java Profiler has been released. Version 7.0 includes

10 Nov 2011 6:01am GMT

Javable: Sun phases out mobile Java

Sun will gradually phase out mobile Java (Java Micro Edition) and move respective services to Standard Edition. "We're trying to converge

10 Nov 2011 6:01am GMT

Javable: Google Android SDK is available

The development kit and API for Google mobile platform, Android, has been released.

10 Nov 2011 6:01am GMT

Javable: Consumer JRE Early Access

Sun has started an early access program to Java SE 6 Update N (formerly known as the "Consumer

10 Nov 2011 6:01am GMT

Javable: NetBeans 6.0 released

New version of pure Java IDE has been released, with support for many new

10 Nov 2011 6:01am GMT

Javable: Happy New Year!

We wish a Happy New Year to all our readers and contributers. Hope to see you all in 2008.

10 Nov 2011 6:01am GMT