├── Java17 ├── out │ └── production │ │ └── Java17 │ │ ├── Main.class │ │ └── himash │ │ ├── util │ │ ├── Book.class │ │ └── Car.class │ │ ├── sealClasses │ │ ├── Laptop.class │ │ └── Market.class │ │ └── switchPattern │ │ └── Illustration_01.class ├── src │ ├── Main.java │ └── himash │ │ ├── sealClasses │ │ ├── Market.java │ │ ├── Bottle.java │ │ └── Laptop.java │ │ ├── util │ │ ├── Car.java │ │ └── Book.java │ │ └── switchPattern │ │ └── Illustration_01.java └── Java17.iml └── README.md /Java17/out/production/Java17/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/Main.class -------------------------------------------------------------------------------- /Java17/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world!"); 4 | } 5 | } -------------------------------------------------------------------------------- /Java17/out/production/Java17/himash/util/Book.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/himash/util/Book.class -------------------------------------------------------------------------------- /Java17/out/production/Java17/himash/util/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/himash/util/Car.class -------------------------------------------------------------------------------- /Java17/out/production/Java17/himash/sealClasses/Laptop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/himash/sealClasses/Laptop.class -------------------------------------------------------------------------------- /Java17/out/production/Java17/himash/sealClasses/Market.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/himash/sealClasses/Market.class -------------------------------------------------------------------------------- /Java17/out/production/Java17/himash/switchPattern/Illustration_01.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himash79/Java-17-features/HEAD/Java17/out/production/Java17/himash/switchPattern/Illustration_01.class -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-17-features 2 | 3 | Includes Java 17 related features. 4 | 5 | ## Requirements 6 | 7 | 01) Java 17 8 | 9 | ## Project setup 10 | 11 | 01) Clone the project 12 | 13 | https://github.com/himash79/Java-17-features.git 14 | 15 | 02) Figure out the features about Switch, Sealed classes 16 | -------------------------------------------------------------------------------- /Java17/src/himash/sealClasses/Market.java: -------------------------------------------------------------------------------- 1 | package himash.sealClasses; 2 | 3 | public sealed class Market permits Laptop { 4 | 5 | public static void main(String[] args) { 6 | 7 | Laptop l = new Laptop(1,"Dell","XPS Pro",100.00,false); 8 | System.out.println(l); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Java17/Java17.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Java17/src/himash/util/Car.java: -------------------------------------------------------------------------------- 1 | package himash.util; 2 | 3 | public class Car { 4 | 5 | private int id; 6 | private String manufacture; 7 | private String model; 8 | private double cost; 9 | private boolean status; 10 | 11 | public Car(int id, String manufacture, String model, double cost, boolean status) { 12 | this.id = id; 13 | this.manufacture = manufacture; 14 | this.model = model; 15 | this.cost = cost; 16 | this.status = status; 17 | } 18 | 19 | public Car() { 20 | } 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getManufacture() { 31 | return manufacture; 32 | } 33 | 34 | public void setManufacture(String manufacture) { 35 | this.manufacture = manufacture; 36 | } 37 | 38 | public String getModel() { 39 | return model; 40 | } 41 | 42 | public void setModel(String model) { 43 | this.model = model; 44 | } 45 | 46 | public double getCost() { 47 | return cost; 48 | } 49 | 50 | public void setCost(double cost) { 51 | this.cost = cost; 52 | } 53 | 54 | public boolean isStatus() { 55 | return status; 56 | } 57 | 58 | public void setStatus(boolean status) { 59 | this.status = status; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Java17/src/himash/sealClasses/Bottle.java: -------------------------------------------------------------------------------- 1 | package himash.sealClasses; 2 | 3 | public class Bottle { 4 | 5 | private int id; 6 | private String manufacture; 7 | private double cost; 8 | private boolean status; 9 | 10 | public Bottle(int id, String manufacture, double cost, boolean status) { 11 | this.id = id; 12 | this.manufacture = manufacture; 13 | this.cost = cost; 14 | this.status = status; 15 | } 16 | 17 | public Bottle() { 18 | } 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getManufacture() { 29 | return manufacture; 30 | } 31 | 32 | public void setManufacture(String manufacture) { 33 | this.manufacture = manufacture; 34 | } 35 | 36 | public double getCost() { 37 | return cost; 38 | } 39 | 40 | public void setCost(double cost) { 41 | this.cost = cost; 42 | } 43 | 44 | public boolean isStatus() { 45 | return status; 46 | } 47 | 48 | public void setStatus(boolean status) { 49 | this.status = status; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Bottle{" + 55 | "id=" + id + 56 | ", manufacture='" + manufacture + '\'' + 57 | ", cost=" + cost + 58 | ", status=" + status + 59 | '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Java17/src/himash/util/Book.java: -------------------------------------------------------------------------------- 1 | package himash.util; 2 | 3 | public class Book { 4 | 5 | private int id; 6 | private String category; 7 | private String name; 8 | private String author; 9 | private double cost; 10 | private boolean status; 11 | 12 | public Book(int id, String category, String name, String author, double cost, boolean status) { 13 | this.id = id; 14 | this.category = category; 15 | this.name = name; 16 | this.author = author; 17 | this.cost = cost; 18 | this.status = status; 19 | } 20 | 21 | public Book() { 22 | } 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public void setId(int id) { 29 | this.id = id; 30 | } 31 | 32 | public String getCategory() { 33 | return category; 34 | } 35 | 36 | public void setCategory(String category) { 37 | this.category = category; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | 48 | public String getAuthor() { 49 | return author; 50 | } 51 | 52 | public void setAuthor(String author) { 53 | this.author = author; 54 | } 55 | 56 | public double getCost() { 57 | return cost; 58 | } 59 | 60 | public void setCost(double cost) { 61 | this.cost = cost; 62 | } 63 | 64 | public boolean isStatus() { 65 | return status; 66 | } 67 | 68 | public void setStatus(boolean status) { 69 | this.status = status; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Java17/src/himash/sealClasses/Laptop.java: -------------------------------------------------------------------------------- 1 | package himash.sealClasses; 2 | 3 | import himash.sealClasses.Market; 4 | 5 | public final class Laptop extends Market { 6 | 7 | private int id; 8 | private String brand; 9 | private String model; 10 | private double cost; 11 | private boolean status; 12 | 13 | public Laptop(int id, String brand, String model, double cost, boolean status) { 14 | this.id = id; 15 | this.brand = brand; 16 | this.model = model; 17 | this.cost = cost; 18 | this.status = status; 19 | } 20 | 21 | public Laptop() { 22 | } 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public void setId(int id) { 29 | this.id = id; 30 | } 31 | 32 | public String getBrand() { 33 | return brand; 34 | } 35 | 36 | public void setBrand(String brand) { 37 | this.brand = brand; 38 | } 39 | 40 | public String getModel() { 41 | return model; 42 | } 43 | 44 | public void setModel(String model) { 45 | this.model = model; 46 | } 47 | 48 | public double getCost() { 49 | return cost; 50 | } 51 | 52 | public void setCost(double cost) { 53 | this.cost = cost; 54 | } 55 | 56 | public boolean isStatus() { 57 | return status; 58 | } 59 | 60 | public void setStatus(boolean status) { 61 | this.status = status; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Laptop{" + 67 | "id=" + id + 68 | ", brand='" + brand + '\'' + 69 | ", model='" + model + '\'' + 70 | ", cost=" + cost + 71 | ", status=" + status + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Java17/src/himash/switchPattern/Illustration_01.java: -------------------------------------------------------------------------------- 1 | package himash.switchPattern; 2 | 3 | import himash.util.Book; 4 | import himash.util.Car; 5 | 6 | public class Illustration_01 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Car c = new Car(1, "Toyota", "axio",500.00, true); 11 | Book b = new Book(1, "Adventure", "Sherlock homes","George", 200.00, false); 12 | System.out.println(evaluate(b)); 13 | System.out.println("======================================================================"); 14 | System.out.println(evaluate_2(b)); 15 | System.out.println("======================================================================"); 16 | System.out.println(newMultiSwitch(1)); 17 | System.out.println("======================================================================"); 18 | System.out.println(newSwitch(1)); 19 | } 20 | 21 | private static String evaluate(Object obj) { 22 | return switch(obj) { 23 | case Car c -> "Manufacture is : %s\nmodel is : %s\nprice is : %s\nproduct is : %s".formatted( 24 | c.getManufacture(),c.getModel(),c.getCost(),c.isStatus() ? "Available" : "N/A"); 25 | case Book b -> "Category is : %s\nName is : %s\nAuthor is : %s\nCost is : %s\nProduct is : %s".formatted( 26 | b.getCategory(),b.getName(),b.getAuthor(),b.getCost(),b.isStatus() ? "Available" : "N/A"); 27 | default -> "Details error found"; 28 | }; 29 | } 30 | 31 | private static String evaluate_2(Object obj) { 32 | return switch(obj) { 33 | case Car c && (c.isStatus()) -> "Vehicle item available"; 34 | case Car c && (!c.isStatus()) -> "Vehicle item not available"; 35 | case Book b && (b.isStatus())-> "Book item available"; 36 | case Book b && (!b.isStatus())-> "Book item not available"; 37 | default -> "Details error found"; 38 | }; 39 | } 40 | 41 | public static String newSwitch(int number) { 42 | return switch (number) { 43 | case 1 -> "one"; 44 | case 2 -> "two"; 45 | case 3 -> "three"; 46 | default -> "other"; 47 | }; 48 | } 49 | 50 | public static String newMultiSwitch(int day) { 51 | return switch (day) { 52 | case 1, 2, 3, 4, 5 -> "workday"; 53 | case 6, 7 -> "weekend"; 54 | default -> "invalid"; 55 | }; 56 | } 57 | 58 | } 59 | --------------------------------------------------------------------------------