Skip to main content

Java Keywords (Part XXIV): native

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 the last chapter of the Java Keyword series. This is probably the keyword I have used the least. In my 20 year career as a software developer, I have used this keyword once, and that was to make some addition to legacy code. The keyword native is a method modifier . Basically, it is a keyword that can only be applied to methods. According to the Java Language Specification (JLS), A method that is native is implemented i...

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 the class, interface, or method. Since this is no longer the case with x86 architecture, Java 17 inherently does all floating point calculations in accordance with IEEE-754. In summary, different computer architectures were designed to handle floating point calculations for precision (strict) or for efficiency or speed (non strict). Becuase these differences in philosophies, porting Java across multiple platforms meant that floating point calculations were not guaranteed to yield the same results unless strictfp was used. Since modern computer architectures don't need x87 chips for these calculations, non-strict calculations are no longer needed.


public strictfp class MyCalculator {
    // Your code here
}

public class SomeClass {
    public strictfp double calculateSomething(double x, double y) {
        // DO some calculation
    }
}
Before Java 1.2, all floating point calculations were strict. This means that The IEEE 754 standard applied for both floating-point calculations and storage of floating-point values in various formats, including single (32-bit, used in Java's float) or double (64-bit, used in Java's double) precision. After Java 1.2, this keyword was created to allow the Operating System to manage underflows or overflows in a more flexible manner. This was allowed simply because strict floating point calculations were expensive for x87 architecture.

Next up, Part XXI: synchronized

Comments

Popular posts from this blog

Implementing Interfaces with Java Records

If you have not read my article on Java records and do not know about this topic, please read my blog titled " Customizing Java Records " first and then come back to this one. Now that you know how to customize Java records, implementing an interface using Java records should be very easy to understand. If you don't know about interfaces in Java, you can read more on my article about interfaces. The recipe for implementing an interface is simply an expansion of what you learned in my previous blog on how to customize a Java record. Following our Rectangle example, let's create an interface with the same two methods we used before. public interface Shape { double area(); double perimeter(); } Now, let's further customize the previous example by doing two things: Add implements Shape at the end of the record declaration (after the record constructor), and Add @Override to the existing methods to ensure these methods com...

Customizing Java Records

If you have not read my article on Java records and do not know about this topic, please read my blog titled " Java Keywords Addendum: The Java Record " first and then come back to this one. What is a customization of a record? A customization of a record is simply the addition of code inside the body of the class. Before proceeding further, let's recap important aspects of a Java Record: Java records are immutable Because of item 1 above, you cannot add new fields unless defined in the record constructor Java records already override: Object#equals(Object) and Object#hashCode() , and then override Object#toString() You could redefine overridden methods as part of your customization if you would like. For example, if you want a fancier implementation of the Object#toString() method, you could do so. Let's look at our first customization example. Using the example from my previous blog, public record Student(...

Object-Oriented Programming Basics: What is in a Class?

EDITORIAL NOTE : This article was published briefly back in 2016 and quickly set back to draft because I wasn't happy with its contents. It is a shame that it was taking me three years to revisit this topic and work on a new and improved version. At least, I'm hoping it will be to the liking you the reader. Keep in mind that the opening paragraph will still read as if I just wrote it for my (former) students at Texas Wesleyan. I started working on lecture on the topic of Object-Oriented (OO) Programming by gathering some material, old and new, when I realized this might be good and simple post for my second attempt at blogging. To be completely honest, in the 8 hours I spent collecting information and preparing material for this week's lecture, I realized I still made some of the mistakes I am about to blog about. I am actually hoping I can write a series of postings regarding Object-Oriented Programming (OOP). But to do so, I must start from the very beginning. ...