Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Uncovering Project Amber

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Uncovering Project Amber

Evolution has always been in the Java DNA, and according to Darwin, “It is neither the strongest nor the most intelligent that survives. It is the one that is most adaptable to change”.

Project Amber is transforming Java’s basic language constructs and introducing features to enhance productivity and coding experience. Join this session to stay ahead of the curve as Java adapts to the changing technology landscape and becomes more relevant than ever. The audience will take away why, how, and where to use these language modifications that will transform your everyday coding experience. You’ll see for yourself if it is worthwhile adopting all these new features.

Avatar for Mala Gupta

Mala Gupta

August 30, 2019
Tweet

Other Decks in Programming

Transcript

  1. It is neither the strongest nor the most intelligent that

    survives. It is the one that is most adaptable to change. -Darwin
  2. In today’s session: Delivered: Type inference with ‘var’(Java 10) Local-Variable

    Syntax for Lambda Parameters (Java 11) Switch Expressions (Java 12) Coming soon: Old: Raw String Literals, Now: Text Blocks (Java 13) (Updated) Switch Expressions (Java 13) Yet to be released: Pattern Matching (https://openjdk.java.net/jeps/305) Old: Data classes, Now: Records and Sealed Types (https://openjdk.java.net/jeps/8222777) Enhanced enums (http://openjdk.java.net/jeps/301) Concise Method Bodies (https://openjdk.java.net/jeps/8209434)
  3. Text Blocks String html = "<HTML>" + "\n\t" + "<BODY>"

    + "\n\t\t" + "<H1>Meaning of life</H1>" + "\n\t" + "</BODY>" + "\n" + "</HTML>";
  4. Text Blocks Try the following – with and without text

    blocks: (\w)(\s+))[\.] {"plastic": { "id": "98751", "singleuse": { "item": [ {"value": "Water Bottle", "replaceWith": "Steel Bottle()"}, {"value": "Straw", "replaceWith": "Ban Straws"}, {"value": "Spoon", "replaceWith": "Steel Spoon"} ] } }}
  5. Object obj = new Ocean(); if (obj instanceof Ocean) {

    System.out.println(((Ocean)obj).getBottles()); }
  6. Object obj = new Ocean(); if (obj instanceof Ocean) {

    Object ocean = (Ocean)obj; System.out.println(ocean.getBottles()); }
  7. Object obj = new Ocean(); if (obj instanceOf Ocean o)

    { // LINE 1 System.out.println(o.getBottles()); } else { // can’t use o defined at line1 here }
  8. Enhanced enums (Currently on hold) enum Size { SMALL(36, 19),

    MEDIUM(32, 20) { int number = 10; int getSize() { return length + width; } }, LARGE(34, 22); int length; int width; Size(int length, int width) { this.length = length; this.width = width; } int getLength() { return length; } }
  9. Enhanced enums (Currently on hold) enum Size <T extends Measurement>

    { // enum with type parameter SMALL(new Small()), MEDIUM(new Medium()), LARGE(new Large()); private T mObj; Size(T obj) { mObj = obj; } T getMeasurement() { return mObj; } }
  10. Enhanced enums (Currently on hold) class Measurement {} class Small

    extends Measurement { String text = "Small"; } class Medium extends Measurement {} class Large extends Measurement { public int getLength() { return 40; } }
  11. Enhanced enums (Currently on hold) Let’s say you want to

    code something like the following: FormData data = new FormData(); data.add(Data.NAME, "Pavni"); data.add(Data.AGE, 22); data.add(Data.ADDRESS, "California");
  12. Enhanced enums (Currently on hold) public enum Data<T> { NAME<String>,

    // constants of generic AGE<Integer>, // enum Data ADDRESS<Address>; }
  13. Enhanced enums (Currently on hold) public class FormData { public

    <T> void add(Data<T> type, T value) { //..code } }
  14. Enhanced enums (Currently on hold) FormData data = new FormData();

    data.add(Data.NAME, "Pavni"); data.add(Data.AGE, 22); data.add(Data.ADDRESS, "California");