SEARCH BY

All

  • All
  • Java8
  • Spring

What is preview feature in java

Post a Comment

What is Preview Feature?

For every six months new feature is adding into Java, to make new feature permanent into Java lib, community feedback is considering to understand real time use of added new feature. So to avoid disturbances of existing production code new features are releasing as a preview feature of the version. We cannot execute/test the preview feature of java directly, we must enable preview feature to use new feature(preview feature). New feature added will be trying into real world applications and then feedback will be considered from developer community to continue the feature or to update the feature in the next coming versions.
Every preview feature will be described as JEP ( JDK Enhancement Proposal ). JEP-359 is for Records in Java14

How to enable/use preview features

Enabling preview feature with compiler 

for example if our program is using Java14 Records feature then we need to enable preview feature while compiling with javac
javac --enable-preview --release 14 Account.java
In the above snippet you can notice that we have used the command --enable-preview and --release by providing java version that is 14 in our example.

Enabling preview feature with java command to run program

Here we need to enable preview feature while runing java program too.
java --enable-preview RunBank
In the above code RunBank is a class which start program execution and using Account class so we must enable preview feature and current system must be installed with Java14 supporting JDK.

using with maven based application

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>13</source>
                <target>13</target>
                <compilerArgs>
                    --enable-preview
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
We need to add --enable-preview as compilerArgs in pom.xml file to enable preview feature in maven based applications

References

https://docs.oracle.com/en/java/javase/14/language/preview-language-and-vm-features.html
jaya
I love software designing, coding, writing and teaching...

Share this article

Related Posts

Post a Comment

Place your code in <em> </em> tags to send in comments | Do not add hyper links in commnet

Close

Subscribe our newsletter for the latest articles directly into your email inbox