DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. API Updates in Java SE 11 (18.9)

API Updates in Java SE 11 (18.9)

Java 11 will soon be upon us in a few months. Let's take a look at some of the upcoming changes and features that you can expect.

Mohamed Sanaulla user avatar by
Mohamed Sanaulla
CORE ·
Jun. 07, 18 · News
Like (8)
Save
Tweet
Share
9.36K Views

Join the DZone community and get the full member experience.

Join For Free

Java SE 11, which is also named 18.9 (based on the new naming scheme that uses the year and month of release), is slated to be in GA during the last week of September. The new approach for releasing the new JDK version frequently is allowing the language creators to introduce new features, API updates more quickly to the developer community.

Often, API updates go unnoticed and are buried under some major changes. So I thought of enumerating some of the API changes that would be in Java 11 that were not present in Java 10.

I am using the jdk-11-ea+16 build downloaded from here.

Character.toString(int)

This method returns the string representation for the given Unicode code point as shown below:

jshell> Character.toString(100)
$10 ==> "d"
jshell> Character.toString(66)
$7 ==> "B"


CharacterSequence.compare(java.lang.CharSequence, java.lang.CharSequence)

This compares two character sequences lexicographically and returns negative, zero, or positive if the first character sequence is lexicographically less than or equal to or greater than the second, respectively.

Lexicographically means in dictionary order or in alphabetical order.

jshell> CharSequence.compare("girl", "boy")
$12 ==> 5

jshell> CharSequence.compare("girl", "girl")
$13 ==> 0

jshell> CharSequence.compare("hello", "world")
$14 ==> -15


New APIs in java.lang.String

repeat(int)

jshell> "**".repeat(5)
$15 ==> "**********"

jshell> "**".repeat(-7)
|  Exception java.lang.IllegalArgumentException: count is negative: -7
|        at String.repeat (String.java:3147)
|        at (#16:1)

jshell> "**".repeat(0)
$17 ==> ""

jshell> "**".repeat(1)
$18 ==> "**"


isBlank()

jshell> String msg = "hello"
msg ==> "hello"

jshell> msg.isBlank()
$22 ==> false

jshell> String msg = ""
msg ==> ""

jshell> msg.isBlank()
$24 ==> true

jshell> String msg = " "
msg ==> " "

jshell> msg.isBlank()
$26 ==> true


strip(), stripTrailing(), stripLeading()

jshell> " hello world ".strip()
$29 ==> "hello world"

jshell> "hello world    ".strip()
$30 ==> "hello world"

jshell> "hello world    ".stripTrailing()
$31 ==> "hello world"

jshell> "        hello world    ".stripLeading()
$32 ==> "hello world    "

jshell> "    ".strip()
$33 ==> ""


lines()

jshell> String content =  "this is a multiline content\nMostly obtained from some file\rwhich we will break into lines\r\nusing the new api"
content ==> "this is a multiline content\nMostly obtained fro ... ines\r\nusing the new api"

jshell> content.lines()
$36 ==> java.util.stream.ReferencePipeline$Head@5ec0a365

jshell> content.lines().forEach(System.out::println)
this is a multiline content
Mostly obtained from some file
which we will break into lines
using the new api


java.nio.file.Path.of()

Prior to this release, there were no factory methods in java.nio.file.Path, while there was one method in java.nio.file.Paths. This release introduces a factory method in java.nio.file.Path, of which there are two variants:

  1. Takes String location to the resource

  2. Takes URI location to the resource

Both of them are shown below:

jshell> Path uriPath = Path.of(new URI("file:///C:/Program%20Files/Java/jdk-11/release"))
uriPath ==> C:\Program Files\Java\jdk-11\release

jshell> Files.readAllLines(uriPath).forEach(System.out::println)

jshell> Path filePath = Path.of("..", "release")
filePath ==> ..\release

jshell> Files.readAllLines(filePath).forEach(System.out::println)


Pattern.asMatchPredicate()

This API returns a java.util.function.Predicate, which can be used to test if a given string matches the pattern compiled using the java.util.regex.Pattern

jshell> Pattern somePattern =  Pattern.compile("\\w+@\\w+[.]com")
somePattern ==> \w+@\w+[.]com

jshell> Predicate<String> somePredicate = somePattern.asMatchPredicate()
somePredicate ==> java.util.regex.Pattern$$Lambda$26/0x00000008000d0840@34c4973

jshell> somePredicate.test("sana@gmail.net")
$55 ==> false

jshell> somePredicate.test("sana@gmail.com")
$56 ==> true

jshell> somePredicate.test("sana#@gmail.com")
$57 ==> false


The Java EE-related APIs, namely Corba, JAXB, JAX WS (Web Services) are being removed. The HTTP Client library, which was in the incubator until Java 10, is being moved out of incubation into its own module — java.net.http. I will soon write some posts on the new HTTP Client.

API Java (programming language)

Published at DZone with permission of Mohamed Sanaulla, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Core Machine Learning Metrics
  • The Real Democratization of AI, and Why It Has to Be Closely Monitored
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It
  • Apache Kafka Introduction, Installation, and Implementation Using .NET Core 6

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: