Thursday, August 31, 2023

Quiz yourself: Try-with-resources and PreparedStatement database access

The best uses—and some limitations—of try-with-resourcesImagine that your system runs against a JDBC driver and a target database that fully and correctly implement the JDBC specifications, and your system has code that handles database resources properly by using the following try-with-resource statement:String url = … //var sql =...

Monday, August 28, 2023

Going inside Java 21’s rich, upcoming goodness

Final features, continuing previews, and brand-new treats—with video linksAre you ready for all the new technology in Java 21? This article will take you on a tour of many of the changes, small and large, covering final JEPs, a progressing preview, and something entirely new for the platform.Final...

Friday, August 25, 2023

Quiz yourself: The overloaded submit(…) methods in Java’s ExecutorService

Know when to use Runnable and Callable in multithreaded code.Given the following code fragment00:  ExecutorService es = ...01:  // es.submit(() -> {;} );02:  // es.submit(() -> null );03:  // es.submit(() -> { throw new NullPointerException(); });04:  // es.submit(() -> { throw new IOException(); });05:  // es.submit(() ->  new...

Wednesday, August 16, 2023

Quiz yourself: Using anonymous classes in Java

How are anonymous classes related to the Liskov substitution principle?Imagine that you are doing an audit of a third-party desktop Java application that interacts with users’ input and has the following code:var c = new Control();c.registerHandler(  new Handler<Event>() {    @Override    void handle(Event e) {     ...

Monday, August 14, 2023

Inside the JVM: Arrays and how they differ from other objects

Arrays are unique objects inside the JVM, and understanding their structure makes for better coding.The simplest way of classifying Java data items is to divide them into primitives and objects. Primitives, as most Java developers know, comprise booleans, bytes, chars, the integer variants (short, int, and long), and...

Friday, August 11, 2023

Quiz yourself: Abstract classes and the difference between Java’s super() and this()

See what happens when you instantiate and initialize a Java object.Given the following two classes01:  abstract class SupA {02:    SupA() { this(null); }03:    SupA(SubA s) {this.init();}04:    abstract void init();05:  }06:  class SubA extends SupA {07:    void init() {System.out.print("SubA");}08:  }Which statement is correct if you...

Friday, August 4, 2023

Curly Braces #11: Writing SOLID Java code

Following the five principles of SOLID object-oriented design will make you a better Java developer.In this article, I am going to talk about writing SOLID Java code. No, I’m not talking about the excellent, classic book by Steve Maguire, Writing Solid Code, now out in its 20th anniversary...

Pages (26)1234567 »