Home » Java » Core Java (page 10)

Core Java

How to Customize Serialization In Java By Using Externalizable Interface

In a previous article Everything About Java Serialization Explained With Example, I explained how we can serialize/deserialize one object usingSerializable interface and also explain how we can customise the serialization process using writeObject and readObject methods. Disadvantages Of Java Serialization Process But these customizations are not sufficient because JVM has full control of the serialization process and those customization logics ...

Read More »

Java: An Optional Implementation of Optional

The class java.util.Optional is implemented as a single immutable concrete class that internally handles two cases; one with an element and one without. Wouldn’t it have been a better choice to let Optional be an interface and have two different implementations implement that interface instead? After all, that is what we generally are taught to do in an object-oriented language. ...

Read More »

Java: Benefit from Inline Class Properties Starting from Java 8

In some years, Java will hopefully have an “inline class” feature which solves many challenges with the current state of Java. Read this article and learn how to use Java 8 and upwards today, and still benefit from some of the advantages of the coming inline object arrays such as; no indirect pointers, eliminated object header overhead and improved data ...

Read More »

Why Declarative Coding Makes You a Better Programmer

Declarative solutions with functional composition provide superior code metrics over legacy imperative code in many cases. Read this article and understand how to become a better programmer using declarative code with functional composition. In this article, we will take a closer look at three problem examples and examine two different techniques (Imperative and Declarative) for solving each of these problems. ...

Read More »

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 ...

Read More »

Draft JEP to Remove Deprecated CMS Garbage Collector

In the 10 April 2017 post “Java Garbage Collectors: When Will G1GC Force CMS Out?,” I discussed JEP 291 (“Deprecate the Concurrent Mark Sweep (CMS) Garbage Collector”) and provided a summary of some of the feedback for and against deprecating (and ultimately removing) the Concurrent Mark Sweep (CMS) Garbage Collector (GC). Earlier this month, a draft JEP called “Remove the ...

Read More »

Checking What’s Thrown in Java Tests

Someone came up with the idea of using try and catch blocks in unit tests in Java: 1 2 3 4 5 6 7 8 @Test public void test() {    try {       callSomeCode();    } catch (Exception e) {       assertEquals("foo", e.getMessage());    } } The above is tempting, but doesn’t work. If the code under test didn’t throw, then no assertion would ...

Read More »

The Chameleon Function

In Doctor Who the character Kamelion was a robot which could take any form. The physical prop they used was allegedly very troublesome and only understood by its creator, who wasn’t around to help put it right. So to the Chamelion function … Consider this code: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ...

Read More »