<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Java 15 - Inero Software - Software Consulting</title>
	<atom:link href="https://inero-software.com/tag/java-15-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://inero-software.com/tag/java-15-en/</link>
	<description>We unleash innovations using cutting-edge technologies, modern design and AI</description>
	<lastBuildDate>Thu, 21 Apr 2022 12:53:22 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://inero-software.com/wp-content/uploads/2018/11/inero-logo-favicon.png</url>
	<title>Java 15 - Inero Software - Software Consulting</title>
	<link>https://inero-software.com/tag/java-15-en/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">153509928</site>	<item>
		<title>Java 17: New features overview</title>
		<link>https://inero-software.com/java-17-overview/</link>
		
		<dc:creator><![CDATA[Andrzej Chybicki]]></dc:creator>
		<pubDate>Thu, 21 Apr 2022 12:53:22 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Company]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[java 11]]></category>
		<category><![CDATA[java 14]]></category>
		<category><![CDATA[java 15]]></category>
		<category><![CDATA[java 16]]></category>
		<category><![CDATA[java 17]]></category>
		<category><![CDATA[pattern matching]]></category>
		<category><![CDATA[records]]></category>
		<category><![CDATA[sealed modifier]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[switch]]></category>
		<guid isPermaLink="false">https://inero-software.com/?p=4918</guid>

					<description><![CDATA[<p>Java 17 was released in September 2021. This is the latest release of LTS (Long Term Support). This means that this version will receive updates until 2029. An earlier version of LTS (Java 11) was released in September 2018, and between these two there were new releases every six months, but not covered by extended support.</p>
<p>Artykuł <a href="https://inero-software.com/java-17-overview/">Java 17: New features overview</a> pochodzi z serwisu <a href="https://inero-software.com">Inero Software - Software Consulting</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>&nbsp;</p>
<div class="row">
<p><div class="col-sm-1"></div></p>
<p><div class="col-sm-10">
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<h2><span style="color: #800080;">Java 17</span></h2>
<p>&nbsp;</p>
<p><span data-contrast="auto"><span class="TextRun SCXW189727610 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW189727610 BCX0"><span class="TextRun SCXW21457896 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW21457896 BCX0"><img decoding="async" data-attachment-id="2768" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-08/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Glyph v8" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08.png" tabindex="0" role="button" class="alignleft wp-image-2768 " src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08-80x80.png" alt="" width="53" height="53" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08-50x50.png 50w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-08.png 208w" sizes="(max-width: 53px) 100vw, 53px" /></span></span></span></span></span>Java 17 was released in September 2021. This is the latest release of <strong>LTS (Long Term Support)</strong>. This means that this version will receive updated until 2029. An earlier version of LTS (Java 11) was released in September 2018, and between these two there were new releases every six months, but not covered by extended support.</p>
<p>Java was developed slowly to version 8. This appears to be due to a conservative and defensive strategy for introducing changes to the language. At a similar time to Java, the C# language was created, which was characterized by introducing additions on a regular basis to keep the language attractive and effective for programmers. Currently, the Java language is quite often extended with new functionalities but with the usual caution. We’ll cover the latest improvements between versions 11-17 in this article.</p>
<p>&nbsp;</p>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Switch modification</span></h2>
<p>&nbsp;</p>
<p>Switch in previous versions of Java looked like this:</p>
<p><img fetchpriority="high" decoding="async" data-attachment-id="4890" data-permalink="https://inero-software.com/?attachment_id=4890" data-orig-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update.png" data-orig-size="781,563" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Java 17 Switch przed update" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update-300x216.png" data-large-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update.png" tabindex="0" role="button" class="aligncenter wp-image-4890 size-full" src="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update.png" alt="switch przed aktualizacją" width="781" height="563" srcset="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update.png 781w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update-300x216.png 300w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update-768x554.png 768w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-przed-update-416x300.png 416w" sizes="(max-width: 781px) 100vw, 781px" /></p>
<p style="text-align: center;"><em>Source: Learn Java 17 with IntelliJ IDEA, https://www.youtube.com/watch?v=FP0V98S4l9w&amp;ab_channel=Java</em></p>
<p>This function is used to consider different variants of a value. Depending on the value we want to convey the appropriate information to the user. Of course, we don’t have to use Switch for this task but the Switch syntax makes the code much more readable.</p>
<p>As you can see in the image above, there is a <strong>break</strong> command after each sequence. If we don’t locate this command in a specific case the executed code will go to the next sequence. Such a mechanism allowed to handle several cases with the same code. This style is also derived from the C language, where it referred to the assembly programming method (a low-level language specific to a given family of processors). Over the years, the style of programming has changed significantly and this use of the <strong>break</strong> command, or the lack of it, is less and less used. If someone forgets to add the <strong>break</strong> commands, the code may not work as intended. Therefore, an arrow notation was invented that implies <strong>break</strong> in arrows. This makes the Switch itself more readable to the user. This is important because there is less chance of making a mistake by accident. Below you can see how this record looks like.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="4891" data-permalink="https://inero-software.com/?attachment_id=4891" data-orig-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa.png" data-orig-size="818,575" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Java 17 Switch wersja strzałkowa" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa-300x211.png" data-large-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa.png" tabindex="0" role="button" class="aligncenter wp-image-4891 size-full" src="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa.png" alt="switch w wersji strzałkowej" width="818" height="575" srcset="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa.png 818w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa-300x211.png 300w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa-768x540.png 768w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-wersja-strzalkowa-427x300.png 427w" sizes="(max-width: 818px) 100vw, 818px" /></p>
<p>It is also possible to implement a return value, depending on the specific variant. This is advantageous because we can get a result that will be analysed further by the program. These features make the expression Switch much more convenient to use. So <a href="https://inero-software.com/inero-software-team-work/">developers</a> can write cleaner code that is easier to understand.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="4892" data-permalink="https://inero-software.com/?attachment_id=4892" data-orig-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci.png" data-orig-size="1609,372" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Java 17 Switch zwrócenie wartości" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-300x69.png" data-large-file="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-1030x238.png" tabindex="0" role="button" class="aligncenter wp-image-4892 size-full" src="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci.png" alt="" width="1609" height="372" srcset="https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci.png 1609w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-300x69.png 300w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-1030x238.png 1030w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-768x178.png 768w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-1536x355.png 1536w, https://inero-software.com/wp-content/uploads/2022/03/Java-17-Switch-zwrocenie-wartosci-1298x300.png 1298w" sizes="(max-width: 1609px) 100vw, 1609px" /></p>
<h2></h2>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">NullPointerExceptions</span></h2>
<p>&nbsp;</p>
<p>When programming in a language like Java, there is often a problem with no reference to an object. In earlier versions of the language, the system provided relatively accurate error information but this was not always sufficient to quickly identify the location where the error was causing the error. So far we have been able to find out that it exist at a specific line in the given file. This was problematic because there could be complicated code in one line, which made locating the mistake cumbersome. Before Java 14 the error information was as follows:</p>
<p><span style="color: #ff0000;">Exception in thread „main” java.lang.NullPointerEsception</span></p>
<p><span style="color: #ff0000;">pl.inero.ExamplesTest.NotMeaningFullNullPointerTest(ExamplesTest.java:155)</span></p>
<p>Java 14 introduces a facility that makes messages convey more precise information to programmers. This way, programmers can locate the error faster and go straight to repairing the code. An example of information about the lack of reference to the object in, after the implementation of this improvement, looks like this:</p>
<p><span style="color: #ff0000;">Cannot invoke „String.toUpperCase()” because „testOne.company” is null</span></p>
<p>&nbsp;</p>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Improvement to String constant in Java 17</span></h2>
<p>&nbsp;</p>
<p>Java 15 introduces so-called <strong>Text Blocks</strong>. Thanks to them, entering multi-line fixed string is much more convenient. Before Java 15 you had to enter multi-line constant strings on one line and save newlines as /n. The only way to write a multi-line constant in the code on many lines (for readability) was to divide it into smaller fragments connected by the + operator.</p>
<p>In java 15 start a block of text with three quotation marks <span style="color: #008000;">“ “ “</span> and a new line. All subsequent lines up to the next sequence of three quotation marks <span style="color: #008000;">“ “ “</span> will be the contents of the constant. It is not necessary to add newlines with /n. In addition, the indents will be left-aligned as much as possible.</p>
<p>Multi-line String constant before Java 15:</p>
<pre>String beforeTextBlock = <span style="color: #339966;">"SELECT some_id, COUNT(*)</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"FROM (</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"         select da.some_date dd, d.id some_id</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"         from some_aud da</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"     ) as subq</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"GROUP BY some_id</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span> + 
        <span style="color: #339966;">"</span><span style="color: #3366ff;">\t\t</span><span style="color: #339966;">Double</span> <span style="color: #3366ff;">\"</span><span style="color: #339966;">Double</span> <span style="color: #3366ff;">\"</span><span style="color: #339966;">quotes</span><span style="color: #3366ff;">\"\"</span> <span style="color: #339966;">test</span><span style="color: #3366ff;">\n</span><span style="color: #339966;">"</span>;</pre>
<p>Equivalent multi-line constant String after the introduction of Java 15:</p>
<pre>String withTextBlock = <span style="color: #339966;">"""</span> 
        <span style="color: #339966;">SELECT some_id, COUNT(*)</span> 
<span style="color: #339966;">        FROM (</span> 
<span style="color: #339966;">                 select da.some_date dd, d.id some_id</span> 
<span style="color: #339966;">                 from some_aud da</span> 
<span style="color: #339966;">             ) as subq</span> 
<span style="color: #339966;">        GROUP BY some_id</span> 
        <span style="color: #3366ff;">\t\t</span><span style="color: #339966;">Double „Double „quotes”” test</span> 
<span style="color: #339966;">        """</span>;</pre>
<h2></h2>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Pattern Matching</span></h2>
<p>&nbsp;</p>
<p>Java 16 introduced <strong>pattern matching</strong> extension for instanceof operator. Before introducing this functionality, after successfully verifying the class of an object, in order to use its properties, you had to manually cast the object to the verified type. It looked like this:</p>
<pre><span style="color: #3366ff;">if</span>(someObject <span style="color: #3366ff;">instanceof</span> String) { 
    String someString = (String) someObject; 
    <em><span style="color: #808080;">//Operacje na zmiennej someString</span> 
</em>}</pre>
<p>However, thanks to <strong>pattern matching</strong> for instanceof we are able to express the program logic more clearly. Below you can see what the code looks like:</p>
<pre><span style="color: #3366ff;">if</span>(someObject <span style="color: #3366ff;">instanceof</span> String someString) { 
    <em><span style="color: #808080;">//Operacje na zmiennej someString</span> 
</em>}</pre>
<p>Thanks to this update, we can check if an object is an instance of a given class and define a new variable that we assign to the Spring type with one notation:</p>
<p><em>someObject <span style="color: #3366ff;">instanceof</span> <span style="color: #ff0000;">String</span> someString</em></p>
<p>This provision:</p>
<ol>
<li>Checks if someObject is an instance of the <span style="color: #ff0000;">String</span> class,</li>
<li>cast someObject to the <span style="color: #ff0000;">String</span> type,</li>
<li>and assigns a <span style="color: #ff0000;">String</span> object to the variable someString.</li>
</ol>
<p>&nbsp;</p>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Records</span></h2>
<p>&nbsp;</p>
<p>Records have been introduced in Java 16. They allow easier creation of classes for data models. Records automatically implement equals(), hashCode(), toString() and field accessors.</p>
<p>Thanks to this, instead of describing the class with data like this:</p>
<pre><span style="color: #3366ff;">public final class</span> NoRecordClass { 
    <span style="color: #3366ff;">private final</span> String <span style="color: #e000e0;">title</span>; 
    <span style="color: #3366ff;">private final</span> String <span style="color: #e000e0;">author</span>; 

    <span style="color: #3366ff;">public</span> <span style="color: #008080;">NoRecordClass</span>(String title, String author, String isbn) { 
        <span style="color: #3366ff;">this</span>.<span style="color: #e000e0;">title</span> = title; 
        <span style="color: #3366ff;">this</span>.<span style="color: #e000e0;">author</span> = author; 
    } 

    <span style="color: #3366ff;">public</span> String <span style="color: #008080;">getTitle</span>() { 
        <span style="color: #3366ff;">return</span> <span style="color: #e000e0;">title</span>; 
    } 

    <span style="color: #3366ff;">public</span> String <span style="color: #008080;">getAuthor</span>() { 
        <span style="color: #3366ff;">return</span> <span style="color: #e000e0;">author</span>; 
    } 

    <span style="color: #c7a20e;">@Override</span> 
    <span style="color: #3366ff;">public boolean</span> equals(Object o) { 
        <span style="color: #3366ff;">if</span> (<span style="color: #3366ff;">this</span> == o) <span style="color: #3366ff;">return true</span>; 
        <span style="color: #3366ff;">if</span> (o == <span style="color: #3366ff;">null</span> || getClass() != o.getClass()) <span style="color: #3366ff;">return false</span>; 
        NoRecordClass book = (NoRecordClass) o; 
        <span style="color: #3366ff;">return</span> Objects.<em>equals</em>(<span style="color: #e000e0;">title</span>, book.<span style="color: #e000e0;">title</span>) 
                &amp;&amp; Objects.<em>equals</em>(<span style="color: #e000e0;">author</span>, book.<span style="color: #e000e0;">author</span>); 
    } 

    <span style="color: #c7a20e;">@Override</span> 
   <span style="color: #3366ff;"> public int</span> <span style="color: #008080;">hashCode</span>() { 
       <span style="color: #3366ff;"> return</span> Objects.<em>hash</em>(<span style="color: #e000e0;">title</span>, <span style="color: #e000e0;">author</span>); 
    } 
}</pre>
<p>We can use such a short notation:</p>
<pre><span style="color: #3366ff;">public record</span> RecordExample(String title, String author) { 
}</pre>
<p>Note that for a Java 16 record the accessors differ from those shown in the previous sample – to get the value corresponding to the title field in NoRecordClass use the getTitle() method. However, for the RecordExample class use the title() method, that was generated at compile time. As you can see, the difference is that the accessors generated for the record do not have the prefix get. For this reason, the records do not follow the Java Beans encoding convention. According to the <a href="https://openjdk.java.net/jeps/395">JEP 395</a> document, the records are primarily to play the role of the so-called named tuple rather than the easier creation of immutable Java Beans. The difference is rather subtle but it can make it incompatible with some older libraries.</p>
<p>&nbsp;</p>
<p><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></p>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Sealed modifier in Java 17</span></h2>
<p>&nbsp;</p>
<p>The last functionality we describe is especially useful for library creators. It is used to control what classes/interfaces can inherit or implement a given class/interface. Thanks to this, no unauthorized person can connect his class to our library. Below you will find what such a record looks like:</p>
<pre><span style="color: #3366ff;">public sealed interface</span> SealedInterface 
        <span style="color: #3366ff;">permits</span> ImplementationNo1, 
                ImplementationNo2, 
                ImplementationNo3 { 
    <span style="color: #3366ff;">int</span> <span style="color: #008080;">getNumber</span>(); 
    String <span style="color: #008080;">getText</span>(); 
    List&lt;String&gt; <span style="color: #008080;">getStrings</span>(); 
}</pre>
<p>&nbsp;</p>
<h2><img decoding="async" data-attachment-id="2770" data-permalink="https://inero-software.com/data-the-playground-of-machine-learning/inero-glify-10-2/" data-orig-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-orig-size="208,208" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Inero Software" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" data-large-file="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" tabindex="0" role="button" class=" wp-image-2770 aligncenter" src="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png" alt="" width="75" height="75" srcset="https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10.png 208w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-80x80.png 80w, https://inero-software.com/wp-content/uploads/2019/05/inero-glify-10-50x50.png 50w" sizes="(max-width: 75px) 100vw, 75px" /></h2>
<p>&nbsp;</p>
<h2><span style="color: #800080;">Summary</span></h2>
<p>&nbsp;</p>
<p><strong>Java 17</strong> doesn’t actually provide any spectacular modifications. In fact, it stabilizes the changes that occurred during version 12-16. However, we can point out a few fixes that will definitely improve the work of programmers. This is primarily about: <strong>records, switch, pattern matching, sealed modifier or text blocks</strong>. Java 17 is definitely a big step forward, mainly because it is an LTS version, Thanks to this, developers will be able to count on ongoing support for the functionalities mentioned in this article.</p>
<p><a href="https://inero-software.com/contact-us/"><strong><span style="color: #800080;">Inero Software</span></strong></a> provides knowledge and expertise on how to successfully use cutting edge technologies and data to shape corporate digital products of the future.</p>
<p><span data-contrast="auto">In the <a href="https://inero-software.com/category/blog/company/"><strong><span style="color: #800080;">blog post</span></strong></a> section you will find other articles about IT systems and more!</span></p>
<p><strong>Consulted by: Tomasz Bieliński.</strong></p>
<p></p></div><br />
</p></div>
<p>Artykuł <a href="https://inero-software.com/java-17-overview/">Java 17: New features overview</a> pochodzi z serwisu <a href="https://inero-software.com">Inero Software - Software Consulting</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4918</post-id>	</item>
	</channel>
</rss>
