java-11-what-is-new

Java 11 – What’s new?

Java 11 have many things we should know. That’s very helpful, when know what’s exactly change. When your production using Java 11, you can choose what we can do to compile Java source, excute string utility functions.

In this post, I will share to you a little thing I know about what’s new in Java Eleven.

1. The new make us easy to work.

Before we begin, if you don’t know what’s new in old Java 8 version. You can read post Java Stream in Java8 (by Kieblog).

1.1 Java 11 String method

1.1 isBlank()

Of course, the method work with String always make me happy. Three years ago, when work in Japanese company (Aureole It Inc), the coding conversion when working with string is “always check it’s not null or empty“.

Before Java 11 add a new method isBlank, we can check a String variable is null or empty by use package provide by Tomcat.

Currently, isBlank() function will help us to check string is empty or blank. Easy to do it.

import java.utils.*;

public class Main {
  public static void main(String[] args) throws Exception {
    
    System.out.println(" ".isBlank()); // true
    System.out.println("".isBlank()); // true
  }
}

1.1.2 lines()

A lines function provide by new Java 11 will return a string array which is a collection of allsubstrings split by lines.

import java.util.stream.Collectors;

public class KieBlog {
    public static void main(String[] args) throws Exception {
        
        String str = "KieBlog\KieBlog\KieBlog"; 
        System.out.println(str);
    }
}

// Output
KieBlog
KieBlog
KieBlog

1.1.3 strip()

Today, when use Java 11, it’s very easy to trim both Leading and Trailing Java String. But the questions is, if already have trim() method. What’s new in strip()?

public class Main {
    public static void main(String[] args) throws Exception {
        String str = " JD "; 
        System.out.print("Start");
        System.out.print(str.strip());
        System.out.println("End");
        
        System.out.print("Start");
        System.out.print(str.stripLeading());
        System.out.println("End");
        
        System.out.print("Start");
        System.out.print(str.stripTrailing());
        System.out.println("End");
    }
}

1.1.4 repeat()

With repeat, when you want to duplicate a String, just call this function with parameter is number time want to repeat. Let see example below.

public class Main {
    public static void main(String[] args) throws Exception {
        String str = "KKK".repeat(3);
        System.out.println(str); 
        //prints KKKKKKKKK - repeat three times.
    }
}

1.2 Run Java File with single command.

Yes, this is true. The new thing change is we don’t need to compile the java source file with javac tool. We can run it directly with the Java command (new thing suprise in Java 11).

When we call with java command, it will implicitly compiles.

1.3 About the license.

Know about the license in Java 11 is very important thing you should know.

In the past, there is easy way to download and use Oracle’s JDK. But the agreement just changed. Currently, we have two different JDK builds

  • Oracle’s JDK (commerical): you can use this in development and test (it’s free). But if you use it in production, you will have pay for it.
  • Oracle’s JDK (open source):

As you know, there is always have difference between Pay and Not Pay version. When you use commerical version. Oracle with support and updates. But if you use open source, Oracle won’t be providing update for past version.

Now, Oracle will no longer be updating their OpenJDK builds for 10 or 9. Futhermore, please remember that Java is Still Free.

2. Why it’s important

Know everything about what’s new in Java 11 will help you so much!

If you’re software engineer, and the customer want to use Java 11 in their production, you can give them a advice. Explain that if they want to use Java 11 with comerical version, they need to pay.

Honesty, in my old comany, when Oracle update license and pricing to Oracle Database, many company choose covert their project to using MySQL or PostgreSQL. In the future, I think that not many new project will use Java 11 (special is Startup project)

Thank you so much for reading, and becarefully when use Java 11 in production

Suprise!

3. Reference



Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *