Home » Java » Core Java

Core Java

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 »

The Final Word on “final”

In Java, overuse of final feels like SHOUTING. It’s outdated and inappropriate much of the time. Java and JavaScript This is mainly about the final keyword in Java, but my opinion on its counterpart const in JavaScript has changed slightly. That I can think that const is a good thing and final is a bad thing needs some unpacking. I ...

Read More »

JVM with no garbage collection

JVM community keeps on adding new GC and recently new one was added and it is called  Epsilon and is very special one. Epsilon only allocates memory but will not reclaim any memory. It might look like what is use of GC that does not perform any garbage collection. This type of Garbage Collector has special use and we will look ...

Read More »

Need driven software development using Mocks

Excellent  paper on mocking framework by jmock author. This paper was written in 2004 that is 18 years ago but has many tips of building maintainable software system. In this post i will highlight key ideas from this paper but suggest you to read the paper to get big ideas behind mocking and programming practice.  Mock objects are extension of ...

Read More »

Adapter Design Pattern In Java

The Adapter design pattern is a structural design pattern that helps us to connect to the legacy or third-party code that exposes a similar functionality through a different interface. A real-world analogy for an adapter is the one we use to connect our USB cable to an ethernet port. While designing an object-oriented application, we might feel the need for an adapter when say our ...

Read More »

Java: ChronicleMap Part 3, Fast Microservices

Standard Java Maps needs to be initialized upon startup. Learn how to leverage ChronicleMaps that is initializable from a file and reduce microservice startup times significantly and how to share Maps between JVMs. The built-in Map implementations, such as HashMap and ConcurrentHashMap are fast but they must be initialized with mappings before they can be used for looking up values. ...

Read More »

Java: ChronicleMap Part 2, Super RAM Maps

The standard Java Maps, such as the ubiquitous HashMap, are ultimately limited by the available RAM. Read this article and learn how you can create Java Maps with virtually unlimited sizes even exceeding the target machine’s RAM size. The built-in Map implementations, such as HashMap and ConcurrentHashMap work fine as long as they are relatively small. In all cases, they ...

Read More »