Posts

Showing posts from May, 2024

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 XXIII): transient

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. Before getting on how to use transient , you must understand why you need to use it. And for that, you must understand the concept of serialization in Java. Serialization is simply the mechanism provided by the language to turn an instance of an object into a byte stream, so that it can be sent over the wire. Remember, objects encapsulate data. So serialization is basically creating a byte array to transmit the object's data. But

Java Keywords (Part XXII): volatile

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. In the last article, we learned about the use of synchronized keyword, and we scratched the surface a little bit about concurrency. The keyword volatile is also relevant in concurrency. To learn more about why this keyword is applicable to concurrency, please read about Atomic Access . You could also read the Threads and Locks section of the Java Specification . As we learned before, the Java programming language allows threads to a

Java Keywords (Part XXI): synchronized

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. Before diving into the use of the synchronized keyword, we must understand concurrency. I will do my best to summarize the concept of concurrency first and then provide use cases for using synchronization. What is concurrency? The dictionary definition of the word concurrent is "occurring, arising, or operating at the same time." In computing, this means that a certain operation, or group of operations, must be executed at th