Skip to content

LizChe/organism-java-improved-sequences-augmented

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Organism Java Improved Sequences Augmented

Java. Enhanced. Evolution never over.

Duke

This is the presentation about new additions in Java.
Versions included are: Java 9, Java 10 and Java 11 LTS. Java 12 and Java 13 are omitted.
Slides can be found in resources/presentation directory.

P.S. I DO NOT own any pictures of Duke.
Duke appeared on slides out of his own will.

Table of Contents

☕︎ Lost in Java Updates?

☕︎ Wha' do ye mean ain't fer free?

☕︎ Collecting Garbage efficiently

☕︎ public static void main(String[] args){} no more

☕︎ Snug as a bug in a rug mug

Lost in Java Updates?

This chapter is an introduction to the presentation.

Approximate speech:

Java 8 was a revolutionary release in 2014.
The features we take now for granted made Java easier to use, improved productivity and performance.
However, the IT world doesn't stand in place.
Java 8 happened 5 years ago and in 2020 Oracle will no longer update our beloved.
Does it end here or this story has a happy continuation?

Wha' do ye mean ain't fer free?

This chapter focuses on the main differences between Oracle JDK and Open JDK.

Approximate speech:

With Java 11, Oracle changes its' license from Binary Code License to General Public License v2 with the Classpath Exception. It means that using Oracle JDK that is being developed by Oracle is only allowed in development and test environments. Any other use would imply buying the license. However, there is another option - Open JDK that is being developed not only by Oracle, Open JDK, and Java Community but collaborated as well by IBM, Apple, Redhat, and other top-notch companies.

For more in-depth analysis, please, check the following links:

Collecting Garbage efficiently

In this chapter we will dive in main difference between Parallel Full GC and Garbage First GC.

Approximate speech:

In Java 8 the default GC is Parallel Full Garbage Collector with Java 9 things change in favor of so-called G1.
We all know the story of how JVM manages memory in Java 8. There is heap structure that looks as follow:

Young Generation Old Generation Permanent Generation
Eden & Survivor Space Tenured Permanent

Newly created objects live in the young generation, when the young generation is full, all survived objects are eventually moved to the old generation.

So, what's so special about G1? The heap structure of Garbage First GC looks as follow:

O O E E O
E O O S
E O S O
O E E O O
O S S O O
O O E O

Garbage First splits heap into many small regions. It still assigns the same roles (eden, survivor, old) but there is no limit on how many of each we have. After the marking phase, G1 knows which regions are almost empty and collects those first. The rest of alive objects are being copied to unassigned space and become survivors or old, depending on what they were before (eden or survivors). In case if the whole region was full of garbage, it becomes unassigned.

For more in-depth information, please, follow these links:

public static void main(String[] args){} no more

This chapter is about JShell that was introduced with Java 9.

Approximate speech:

JShell is a Read-Eval-Print Loop tool for exploring the Java language.

Commands to review:

  1. Start the tool:

jshell

  1. create method greetJShell(String name):
String greetJShell(String name) {
   ...> return name + " greets JShell!";
   ...> }
  1. call created method:
greetJShell("World") // no semicolon required!
  1. getting help:

/help

  1. listing created methods or variables:

/v /m

  1. saving workspace to a file:
/save -all <file>
  1. open file:
/open <file>
  1. Tab completion tool:
System.out.<Tab>
  1. exit the tool

/exit

Important things to mention:

  • Checked exceptions are being wrapped for us automatically;
  • Whenever we insert a value in parameters or returning a value in a method, JShell automatically places the result in a variable.

For a short JShell tutorial go here:

Snug as a bug in a rug mug

P.S. "Snug as a bug in a rug" idiom means to be warm, cozy and comfortable

This chapter has aims to get you comfortable with Java 9, 10, 11 features. All the code is provided in com/codecool/organismjava directory.

Approximate speech:

  • Compile and run a single file in one line with Java 11.

    • there is no need in javac command anymore
    • in order to try this feature out navigate to organismjava directory
    • type: java CompileMe.java
  • Java 11 brings out new features of String class, these features can be found in strings package

    • public String strip()
    • public String stripLeading()
    • public String stripTrailing()
    • public boolean isBlank()
    • public Stream<String> lines()
    • public String repeat(int count)
  • Additions to interfaces can be found in InterfaceFeatures.java class

    • private methods in interfaces are now possible with Java 9.
  • Features of immutable collections can be found in ImmutableCollectionFeatures.java class

    • creating an immutable collection became easier in Java 9.
  • Try with Resources improvement can be found in trywithresources package

    • with Java 9 it is possible to use resource reference in try with resources
  • New Optional features broke through with Java 9 and 11. Showcase methods can be found in OptionalFeatures.java class

    • public void ifPresentOrElse​(Consumer<? super T> action, Runnable emptyAction)
    • public Optional<T> or​(Supplier<? extends Optional<? extends T>> supplier)
    • public Stream<T> stream​()
    • public boolean isEmpty()
  • Stream API features of Java 9 can be found in StreamFeatures.java class

    • default Stream<T> takeWhile​(Predicate<? super T> predicate)
    • default Stream<T> dropWhile​(Predicate<? super T> predicate)
  • New Type var can be found in VarType.java class

    • Java 10 introduced a new type name available for our use
  • Here come Java 11 and new Files methods that can be found in FilesFeatures.java class

    • public static Path writeString​(Path path, CharSequence csq, OpenOption... options) throws IOException
    • public static String readString​(Path path) throws IOException

For more information about possible questions related to this section, check these links:

Releases

No releases published

Packages

No packages published

Languages