Posts

Showing posts from 2022

Java Keywords Addendum: The Java Record

Since originally my Java series was based on Java 8, it did not include a new keyword introduced later on. For that reason, I decided to post an addition to the Java Keyword series to include the Java record keyword. Introduced in Java 14, the purpose of this keyword is to eliminate all the boilerplate code when creating a Java POJO. For example, public class Student { private String name; private int id; public Student(String name, int id) { this.name = name; this.id = id; } public String getName() { return name; } public int getId() { return id; } public void setName(String name) { this.name = name; } public void setId(int id) { this.id = id; } } can be replaced simply with a record that looks like this: public record Student(String name, int id){ } And not only it replaces the boilerplate code I showed you, it also automatically overrides Object#equals(Object) , Object#hashCode() , and Object#toStr

Java Keywords (Part XX): The strictfp Keyword

Java keyword list abstract continue for new switch assert default goto * package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const * float native super while Keyword marked with an asterisk (*) are keywords that, although valid, are not used by programmers. This is going to be an easy one. As of Java 17, this keyword is obsolete. Prior to Java 17, this keyword was used to establish a strict floating-point (strict fp) policy. This meant that, when in use, this keyword guaranteed that floating point calculations would yield the same result across all hardware. When not in use, the Operating System had some leeway in refining precision of floating-point calculations. The keyword would be applied at

Java Keywords (Part XIX): The assert Keyword

Java keyword list abstract continue for new switch assert default goto * package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const * float native super while Keyword marked with an asterisk (*) are keywords that, although valid, are not used by programmers. The assert keyword enables you to test an assumption about a part of your program. If the assertion is proven to be true, execution of your program will continue. If it's proven to be false, an AssertionError will be thrown. Assertions confirm your assumptions about the behavior of your program, thus increasing confidence that the program is free of errors. This keyword has been part of the Java language since Java 1.4.2 and yet, very l