├── .idea ├── .gitignore ├── .name ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── Java-17-OCP-And-Java-21.iml ├── README.md ├── Readms └── README.pt_br.md └── src ├── Others ├── alghoritms │ ├── BinarySearch.java │ └── VectorTesting.java ├── designPatterns │ ├── Product.java │ └── ProductBuilder.java └── interceptor │ ├── Example.java │ ├── IExampleInterceptor.java │ ├── Interceptor.java │ └── RunMainInterceptorTest.java ├── Zoo.java ├── java17 ├── Chapter_10_Streams │ └── Readme.md ├── Chapter_11_Exceptions_and_Localization │ └── Readme.md ├── Chapter_12_Modules │ └── Readme.md ├── Chapter_13_Concurrency │ └── Readme.md ├── Chapter_14_I_O │ └── Readme.md ├── Chapter_15_JDBC │ ├── MyFirstDataBaseConnection.java │ └── Readme.md ├── Chapter_1_Building_Blocks │ ├── Animal.java │ ├── Creating_Wrapper_Classes.java │ ├── Data_Types_Primitives.java │ ├── Declaring_Variables.java │ ├── Defining_Text_Blocks.java │ ├── Garbage_Collection.java │ └── Readme.md ├── Chapter_2_Operators │ ├── Operator_Precedence.java │ └── Readme.md ├── Chapter_3_Making_decisions │ └── Readme.md ├── Chapter_4_Core_APISs │ ├── ArraysExamples.java │ ├── MathApiAndDateAndTimes.java │ ├── Readme.md │ ├── StringBuilderExample.java │ └── Strings.java ├── Chapter_5_Methods │ ├── Methods.java │ ├── Methods_examples.java │ ├── Passing_Data_among_methods.java │ └── Readme.md ├── Chapter_6_Class_Design │ ├── Animal.java │ ├── Constructor.java │ ├── Creating_Classes.java │ ├── Crocodile.java │ ├── Lion.java │ ├── Readme.md │ └── Reptile.java ├── Chapter_7_Beyond_Classes │ └── Readme.md ├── Chapter_8_Lambdas_and_Funcionals_Interfaces │ ├── LambdasAndOthers.java │ └── Readme.md └── Chapter_9_Collections_and_Generics │ └── Readme.md └── java21 └── virtualThreads ├── VirtualThreads.java └── descrição.md /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Java-17-Certification-OCP.iml -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Java-17-OCP-And-Java-21.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-17-Certification-OCP | exam 1Z0-829 2 | Repository to study OCP Java 17. You can contribute and to make a fork this project. 3 | 4 | Access page Oracle. 5 | https://education.oracle.com/pt_BR/cat%C3%A1logo-de-produtos-ouexam-pexam_1z0-829/pexam_1Z0-829 6 | 7 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 |
12 | 13 | 14 | 15 |
16 | 17 | Willyan Faria 18 | 19 |
20 |
21 | 22 | 23 |
28 | 29 | Shqip 30 | Uzbek language 31 | Azərbaycan dili 32 | বাংলা 33 | Bulgarian 34 | Português 35 | Català 36 | 中文 (Simplified) 37 | Czech 38 | Deutsch 39 | Dansk 40 | العربية 41 | Española 42 | Française 43 | Galego 44 | Ελληνικά 45 | ქართული 46 | Magyar 47 | Bahasa Indonesia 48 | עִברִית 49 | हिंदी/ગુજરાતી/मराठी/മലയാളം/ಕನ್ನಡ/తెలుగు/छत्तीसगढ़ी/বাংলা/தமிழ் 50 | தமிழ் 51 | فارسی 52 | Italiano 53 | 日本語 54 | සිංහල 55 | Kiswahili (Kenya) 56 | 한국어 한국어 57 | Lietuvių kalba 58 | Limba Română Limba Română 59 | မြန်မာ 60 | Македонски 61 | Español de México 62 | Bahasa Melayu / بهاس ملايو‎ / Malay 63 | Dutch 64 | Norsk 65 | नेपाली 66 | Wikang Filipino 67 | English (Pirate) 68 | اردو 69 | Polski 70 | Português (Portugal) 71 | Русский язык 72 | عربى 73 | Svenska 74 | Slovenčina 75 | Slovenščina 76 | ภาษาไทย 77 | Türkçe 78 | 中文(Traditional) 79 | Українська 80 | Tiếng Việt 81 | Zulu (South Africa) 82 | Afrikaans (South Africa) 83 | Igbo (Nigeria) 84 | Yoruba (Nigeria) 85 | Latvia 86 | Suomeksi 87 | Беларуская мова 88 | Српски 89 | Қазақша 90 | Bosanski 91 | -------------------------------------------------------------------------------- /Readms/README.pt_br.md: -------------------------------------------------------------------------------- 1 | # Java 17 Certificação 2 | Programa para estudo da prova OCP java da Oracle. Segue capitulos para estudos adicionados periodicamente, conforme 3 | os estudos. 4 | 5 | Você pode contribuir caso queira fazer a prova. Favorite e faça um fork para estudar e contribuir! Juntos somos mais fortes. 6 | Bons estudos. 7 | 8 | Access page Oracle. 9 | https://education.oracle.com/pt_BR/cat%C3%A1logo-de-produtos-ouexam-pexam_1z0-829/pexam_1Z0-829 10 | 11 |
12 | 13 | 14 | 15 | 28 | 29 | 30 | 31 |
16 | 17 | 18 | 19 |
20 | 21 | Willyan Faria 22 | 23 |
24 |
25 | 26 | 27 |
-------------------------------------------------------------------------------- /src/Others/alghoritms/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package Others.alghoritms; 2 | 3 | import java.util.Arrays; 4 | 5 | public class BinarySearch { 6 | 7 | public static void main(String[] args) { 8 | int[] ints = {1, 2, 4, 5, 7, 9, 11}; 9 | 10 | System.out.println(binarySeach(ints, 9)); 11 | 12 | // OR 13 | 14 | /** YOU CAN RESOLVE WITH METHODS ARRAYS BINARYSEARCH**/ 15 | System.out.println(Arrays.binarySearch(ints, 9)); 16 | } 17 | 18 | 19 | public static int binarySeach(int[] numbers, int numberToFind) { 20 | 21 | int low = 0; 22 | int high = numbers.length - 1; 23 | 24 | while (low <= high) { 25 | int middlePosition = (low + high) / 2; 26 | int middleNumber = numbers[middlePosition]; 27 | 28 | if (numberToFind == middleNumber) { 29 | return middlePosition; 30 | } 31 | 32 | if (numberToFind < middleNumber) { 33 | high = middlePosition - 1; 34 | } else { 35 | low = middlePosition + 1; 36 | 37 | } 38 | 39 | } 40 | 41 | return -1; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/Others/alghoritms/VectorTesting.java: -------------------------------------------------------------------------------- 1 | package Others.alghoritms; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Vector; 6 | 7 | public class VectorTesting { 8 | 9 | 10 | public static void main(String[] args) throws InterruptedException { 11 | 12 | int size = 1_000_000; 13 | 14 | List arrayList = new ArrayList<>(); 15 | 16 | long start = System.currentTimeMillis(); 17 | 18 | for(int i=0; i < size; i++){ 19 | arrayList.add(i); 20 | } 21 | 22 | long end = System.currentTimeMillis(); 23 | 24 | System.out.println("added " + size + " elements to ArrayList: " + ( end - start) +" ms"); 25 | 26 | 27 | List vectorList = new Vector<>(); 28 | 29 | start = System.currentTimeMillis(); 30 | 31 | for(int i=0; i < size; i++){ 32 | vectorList.add(i); 33 | } 34 | 35 | end = System.currentTimeMillis(); 36 | System.out.println("added " + size + " elements to vectorList: " + ( end - start) +" ms"); 37 | 38 | /** You can to correct this problem with ... = Collections.synchronizedList(new ArrayList<>(); **/ //threadsafe 39 | List multiThreadList = new ArrayList<>(); 40 | start = System.currentTimeMillis(); 41 | 42 | Thread t1 = new Thread(()-> { 43 | for(int i=0; i < size; i++){ 44 | multiThreadList.add(i); 45 | } 46 | }); 47 | 48 | Thread t2 = new Thread(()-> { 49 | for(int i=0; i < size; i++){ 50 | multiThreadList.add(i); 51 | } 52 | }); 53 | 54 | t1.start(); 55 | t2.start(); 56 | t1.join(); 57 | t2.join(); 58 | 59 | end = System.currentTimeMillis(); 60 | System.out.println("added elements to multiThreadList way to ArraytList: " + ( end - start) +" ms"); 61 | System.out.println("size is " + multiThreadList.size()); 62 | 63 | 64 | List multiThreadVector = new Vector<>(); 65 | start = System.currentTimeMillis(); 66 | 67 | t1 = new Thread(()-> { 68 | for(int i=0; i < size; i++){ 69 | multiThreadVector.add(i); 70 | } 71 | }); 72 | 73 | t2 = new Thread(()-> { 74 | for(int i=0; i < size; i++){ 75 | multiThreadVector.add(i); 76 | } 77 | }); 78 | 79 | t1.start(); 80 | t2.start(); 81 | t1.join(); 82 | t2.join(); 83 | 84 | end = System.currentTimeMillis(); 85 | System.out.println("added elements to multiThreadList way to ArrayVector: " + ( end - start) +" ms"); 86 | 87 | System.out.println("size is " + multiThreadVector.size()); 88 | 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/Others/designPatterns/Product.java: -------------------------------------------------------------------------------- 1 | package Others.designPatterns; 2 | 3 | class Product { 4 | private String name; 5 | private String description; 6 | private double price; 7 | 8 | public Product(String name, String description, double price) { 9 | this.name = name; 10 | this.description = description; 11 | this.price = price; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public double getPrice() { 19 | return price; 20 | } 21 | 22 | public String getDescription() { 23 | return description; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Others/designPatterns/ProductBuilder.java: -------------------------------------------------------------------------------- 1 | package Others.designPatterns; 2 | 3 | public class ProductBuilder { 4 | 5 | private String name; 6 | private String description; 7 | private double price; 8 | 9 | 10 | public ProductBuilder withName(String name){ 11 | this.name = name; 12 | return this; 13 | } 14 | 15 | public ProductBuilder withDescription(String description){ 16 | this.description = description; 17 | return this; 18 | } 19 | 20 | public ProductBuilder withPrice(double price){ 21 | this.price = price; 22 | return this; 23 | } 24 | 25 | public Product builder(){ 26 | return new Product(name, description, price); 27 | } 28 | 29 | public static void main(String[] args) { 30 | Product product = new ProductBuilder() 31 | .withName("ball") 32 | .withDescription("ofFootball") 33 | .withPrice(2000) 34 | .builder(); 35 | 36 | 37 | System.out.println("Product name: " + product.getName()); 38 | System.out.println("Product description: " + product.getDescription()); 39 | System.out.println("Product price: " + product.getPrice()); 40 | 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/Others/interceptor/Example.java: -------------------------------------------------------------------------------- 1 | package Others.interceptor; 2 | 3 | public class Example implements IExampleInterceptor{ 4 | 5 | @Override 6 | public void doAnyThings() { 7 | System.out.println(" doing any things "); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Others/interceptor/IExampleInterceptor.java: -------------------------------------------------------------------------------- 1 | package Others.interceptor; 2 | 3 | public interface IExampleInterceptor { 4 | 5 | void doAnyThings(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/Others/interceptor/Interceptor.java: -------------------------------------------------------------------------------- 1 | package Others.interceptor; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | 6 | // interceptor to register call the method before the method doing a any thing 7 | public class Interceptor implements InvocationHandler { 8 | 9 | private Object object; 10 | 11 | public Interceptor(Object object) { 12 | this.object = object; 13 | } 14 | 15 | @Override 16 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 17 | System.out.println("method " + method.getName() + "() is being called"); 18 | 19 | return method.invoke(object, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Others/interceptor/RunMainInterceptorTest.java: -------------------------------------------------------------------------------- 1 | package Others.interceptor; 2 | 3 | import java.lang.reflect.Proxy; 4 | 5 | public class RunMainInterceptorTest { 6 | 7 | public static void main(String[] args) { 8 | 9 | Example example = new Example(); 10 | 11 | Interceptor interceptor = new Interceptor(example); 12 | 13 | IExampleInterceptor exampleProxy = (IExampleInterceptor) Proxy.newProxyInstance( 14 | IExampleInterceptor.class.getClassLoader(), 15 | new Class[]{IExampleInterceptor.class}, interceptor 16 | 17 | ); 18 | 19 | exampleProxy.doAnyThings(); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Zoo.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; // import tells us where to find Random // Can use java.util.*; to import all the classes in path. 2 | //You can create your own package and put in external libraries to call imports. 3 | 4 | /** 5 | * The main methos lets the JVM call our code. 6 | * the variable name args is common because it hints that this list contains values taht wewe read in (arguments) in JVM 7 | * [] are brackets and represent an array. 8 | * public and static are required for main(), methods there are some optional modifiers allowed. 9 | */ 10 | public class Zoo { 11 | public static void main(String[] args) { 12 | System.out.println("Hello world!"); 13 | 14 | Random r = new Random(); 15 | System.out.println(r.nextInt(10)); // a number 0 - 9 16 | } 17 | } -------------------------------------------------------------------------------- /src/java17/Chapter_10_Streams/Readme.md: -------------------------------------------------------------------------------- 1 | explains stream pipelines in detail.It also covers the Optional class. 2 | If you want to become skilled at creating streams, red this chapter more than once. -------------------------------------------------------------------------------- /src/java17/Chapter_11_Exceptions_and_Localization/Readme.md: -------------------------------------------------------------------------------- 1 | Demonstrates the different types of exception classes and how to apply them to build more 2 | resilient programs.It concludes with localization and formatting, which allow your program 3 | to gracefully support multiple countries or languages. -------------------------------------------------------------------------------- /src/java17/Chapter_12_Modules/Readme.md: -------------------------------------------------------------------------------- 1 | Details the benefits of the new moules feature.It show how to compile and run module programs 2 | from the command line. Additionally, it describes services and how to migrate an application to a 3 | modular infrastructure. -------------------------------------------------------------------------------- /src/java17/Chapter_13_Concurrency/Readme.md: -------------------------------------------------------------------------------- 1 | Introduces the concept of threds life cycle and thread-safety.It teaches you how to build 2 | multithreded programs using the concurrency API and parallel streams. -------------------------------------------------------------------------------- /src/java17/Chapter_14_I_O/Readme.md: -------------------------------------------------------------------------------- 1 | Introduces you to managing files and directories using the I/O and NIO.2 APIS. 2 | It coves a number of I/O stream clases, teaches your how to serialize data, 3 | and shows how to interact with a user. Additionally, it include techniques for using 4 | strams to traverse and seach the file system. -------------------------------------------------------------------------------- /src/java17/Chapter_15_JDBC/MyFirstDataBaseConnection.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_15_JDBC; 2 | 3 | 4 | //all database are in the package java.sql 5 | 6 | import java.sql.*; 7 | 8 | /** 9 | * 10 | * You need know 5 key interfaces of jdbc 11 | * 12 | * 1 Driver: Establishes a connection to the database 13 | * 2 Connection: Sends commands to a database 14 | * 3 PreparedStatement : Execute a SQL query 15 | * 4 callableStatment: Executes commands stored in the database 16 | * 5 ResultSet: Reads the result of query 17 | * 18 | * -------------------------------------------------------------------------- 19 | * EXECUTING A PREPARESTATMENT - methods down 20 | * 21 | * SQL runnab;e by the execute methods DELETE INSERT SELECT UPDATE 22 | * 23 | * ps.execute() = processing data yes yes yes yes 24 | * ps.executeQuery() = reading Data no no yes no 25 | * ps.executeUpdating() = modyfing Data yes yes no yes 26 | * 27 | * Returns types of execute methods Return type | What is returned for SELECT |... DELETE / INSERT / UPDATE 28 | * ps.execute() boolean true false 29 | * ps.executeQuery() ResultSet Rows and columns returned n/a 30 | * ps.executeUpdating() int n/a Number of rows added/changed/removed 31 | * -------------------------------------------------------------------------- 32 | */ 33 | public class MyFirstDataBaseConnection { 34 | 35 | 36 | public static void main(String[] args) { 37 | 38 | String url = "jdbc:hsqldb:filezoo"; 39 | 40 | try(Connection conn = DriverManager.getConnection(url)) { 41 | PreparedStatement ps = conn.prepareStatement( 42 | "SElECT name FROM exhibits"); 43 | 44 | ResultSet rs = ps.executeQuery(); 45 | 46 | while(rs.next()) 47 | System.out.println(rs.getString(1)); 48 | 49 | 50 | } catch (SQLException e) { 51 | throw new RuntimeException(e); 52 | } 53 | 54 | 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/java17/Chapter_15_JDBC/Readme.md: -------------------------------------------------------------------------------- 1 | provides the basics of working with databases in Java, including working with stored procedures and transactions. -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Animal.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | 4 | /* 5 | ORDER FOR DECLARING A CLASS 6 | - package -> package abc; 7 | - imports -> import.util.*; 8 | - top-level(Class) type declaration -> public class C 9 | -field declaration -> int value; 10 | -methods declarations -> void method(); 11 | 12 | */ 13 | 14 | /** Java class have two primary elements -> methods and fields = members. 15 | * @author Willyan Faria 16 | * javadoc 17 | */ 18 | 19 | // comments 20 | 21 | /* 22 | other comments/ 23 | */ 24 | public class Animal { 25 | 26 | String name; 27 | 28 | public String getName() { //we define a method, this is operation can called other classes. 29 | return name; 30 | } 31 | 32 | public void setName(String name) { //Other method, but void and is called a parameter where you pass a string parameter to be returned. 33 | this.name = name; 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Creating_Wrapper_Classes.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | 4 | /** 5 | * Each pritive type has a wrapper class, which is an object type that corresponds to the primitive. 6 | * 7 | */ 8 | 9 | public class Creating_Wrapper_Classes { 10 | 11 | 12 | //list all the wra[[er classes along with how to create them/ 13 | 14 | //primitive_type Wrapper-Class Wr..-inherits-Number Example-of-creating 15 | /************************************************************************************************ 16 | * boolean Boolean NO Boolean.valueOf(true) * 17 | * byte Byte YES Byte.valueOf((byte) 1) * 18 | * short Short YES Short.valueOf((short) 1) * 19 | * int Integer YES Integer.valueOf(1) * 20 | * long Long YES Long.valueOf(1) * 21 | * float Float YES Float.valueOf((float) 1.0) * 22 | * double Double YES Double.valueOf(1.0) * 23 | * char Character NO Character.valueOf('c') * 24 | ***********************************************************************************************/ 25 | 26 | //there is also calueOf() variant that converts a String into the wrapper class. For example. 27 | 28 | int primitive = Integer.parseInt("123"); //Converts a String to an int primitive 29 | Integer wrapper = Integer.valueOf("123");// Converts a String to an Integer wrapper class. 30 | 31 | /* Some wrapper classes contain additional helper methods for working with numbers. 32 | 33 | max (int num1, int num2), which returns the largest of the two numbers. 34 | min (int num1, int num2), which returns the smallest of the two numbers. 35 | sum (int num1, int num2), which adds the two numbers. 36 | 37 | */ 38 | 39 | 40 | /* any examples 41 | 42 | Also note that primitive types cannot be used in Collections, only objects. 43 | Therefore, the solution is to use Wrappers. 44 | 45 | "Non-primitive" types allocate space on the heap and put pressure on the garbage collector. 46 | 47 | Primitives allocate on the stack and management is simple and fast. They even waste a lot of memory because of 48 | the natural overhead that objects have. Again this has changed a bit in some cases. 49 | 50 | Primitive types will not have NullPointerException issues. 51 | 52 | In the specific case of Java, the syntax of primitive types is more convenient than non-primitive types. 53 | Primitive types don't need to use equals(), for example, but that may be changing, at least in part. 54 | 55 | */ 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Data_Types_Primitives.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | 4 | /** 5 | * @author Willyan faria 6 | * 7 | * types primitive is just a single value in memory. is not an objet in java. 8 | */ 9 | 10 | 11 | public class Data_Types_Primitives { 12 | 13 | // Types primitive begin with lowercase. 14 | // Reference types begin with Uppercase. 15 | 16 | 17 | boolean x; //true or false 18 | 19 | //decimal 20 | byte a; //8 bit 123 21 | short b; //16 bit 123 22 | int c;// 32 bit 123 23 | long d; // 64 bit 123L 24 | 25 | // 26 | float f;// 32 bit 123.45f 27 | double g;// 64 bit 123.456 28 | char h;// 16 bit 29 | 30 | String i;// is a object and not type primitive. 31 | // long max = 321654897; // does not compile 32 | // long max = 321654987L; // now java it is a long 33 | // int million = 1000000; 34 | //int million = 1_000_000; // You can use underscore to make them easier to read; 35 | 36 | /** 37 | * Primitives do not have methods declared on them. 38 | * */ 39 | 40 | //int value = null; DOES NOT COMPILE 41 | // You can use Integer to wrapper class, instead of int. 42 | 43 | // String name = null; 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Declaring_Variables.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | /** 4 | * A variable is name for a piece of memory that stores data. * 5 | */ 6 | 7 | public class Declaring_Variables { 8 | 9 | 10 | String zooName = "The Best Zoo"; 11 | int ola, oi, teste = 3; // multiple variable 12 | final int y = 10; //final is equivalent to declaring constants in the other languages. 13 | 14 | //ps: if variable is declared but never used, so it is not required to be initialized. 15 | 16 | 17 | //Reserved words 18 | /****************************************************************************************** 19 | * abstract assert boolean break byte * 20 | * case catch char class const* * 21 | * continue default do double else * 22 | * for goto* if implements float * 23 | * enum extends final finally while * 24 | * instanceof int interface long import * 25 | * new package private protected native * 26 | * return short static strictfp public * 27 | * switch synchronized this throw super * 28 | * transient try void volatile throws * 29 | *****************************************************************************************/ 30 | 31 | // Java use uppercase snake case to CONSTANTS(final) and ENUM values. EXAMPLE_JAVA_HERE 32 | 33 | 34 | // var tricky = "hello" // DOES NOT COMPILE ... type inference 35 | public void whatTypeAmI(){ 36 | var name = "hello"; // type local variable 37 | var size = 7; 38 | 39 | //var = compiler to determine the type for you 40 | 41 | //var n = null //DOES NOT COMPILE 42 | 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Defining_Text_Blocks.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | public class Defining_Text_Blocks { 4 | 5 | // String block = """ doe """; DOES NOT COMPILE 6 | 7 | /** 8 | * The text block requite a line break after tje opening """; 9 | */ 10 | 11 | static String block = """ 12 | doe 13 | deer"""; 14 | 15 | //use "\" tells java not to add a new line before deer. 16 | 17 | public static void main(String[] args) { 18 | System.out.println(block); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Garbage_Collection.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_1_Building_Blocks; 2 | 3 | public class Garbage_Collection { 4 | 5 | /* 6 | Garbage collection refers to the process of automatically freeing memory on the HEAP by deleting 7 | objects that are no longer reachable in your program. 8 | 9 | Java provides a garbage collector to automatically look for objects that aren't needed anymore. 10 | 11 | */ 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/java17/Chapter_1_Building_Blocks/Readme.md: -------------------------------------------------------------------------------- 1 | Describes the basics of java, such as how to run a program. 2 | It covers variables such as primitives, object data types, and scoping variables. 3 | It also discusses garbage collection. 4 | ----------------------------------------------------------------------- 5 | ## Understanding the class structure. 6 | 7 | - In java programs, classes are basic building blocks. 8 | - To use most classes, you have to create objects. 9 | - An object is often referred to as an instance. 10 | - Reference is a variable that points to an objects. 11 | -------------------------------------------------------------------------------- /src/java17/Chapter_2_Operators/Operator_Precedence.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_2_Operators; 2 | 3 | public class Operator_Precedence { 4 | 5 | //java supports threee flavors of operators: unary, binary and ternary. 6 | 7 | public static void main(String[] args) { 8 | int cookies = 4; 9 | double reward = 3 + 2 * --cookies; 10 | System.out.println( "Zoo animal receives: " +reward+ " reward points"); 11 | 12 | // the multiplication operator (*) has a higher precedente. 13 | // the assignment operator (=) has the lowest order of precedente. 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/java17/Chapter_2_Operators/Readme.md: -------------------------------------------------------------------------------- 1 | explains operations with variables. it also talks about casting and the precedence of operators. -------------------------------------------------------------------------------- /src/java17/Chapter_3_Making_decisions/Readme.md: -------------------------------------------------------------------------------- 1 | covers core logical constructs such as decision statements, pattern matching, and loops. -------------------------------------------------------------------------------- /src/java17/Chapter_4_Core_APISs/ArraysExamples.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_4_Core_APISs; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ArraysExamples { 6 | 7 | 8 | public static void main(String[] args) { 9 | 10 | 11 | String[] strings = {"10", "9", "100"}; 12 | 13 | Arrays.sort(strings); //This case, string sort in alphabetic order. 14 | 15 | for(String s : strings){ 16 | System.out.println(s + " "); 17 | } 18 | 19 | System.out.println("--------------"); 20 | System.out.println(strings.length); 21 | System.out.println(strings[2]); 22 | 23 | System.out.println("--------------"); 24 | 25 | System.out.println(Arrays.equals(new String[] {"a"}, new String[] {"A"} )); 26 | //compare 2 arrays to determine are equals. 27 | 28 | System.out.println(Arrays.compare(new String[] {"a"}, new String[] {"A"} )); 29 | //compare 2 arrays to determine which is "smaller" 30 | 31 | System.out.println(Arrays.mismatch(new String[] {"A"}, new String[] {"A"} )); 32 | //if arrays are equals, mismatch return -1 33 | 34 | 35 | /*********************************************************************************** 36 | * Methods When arrays contain same data When arrays are different * 37 | *********************************************************************************** 38 | * equals true false * 39 | * compare 0 positive or negative * 40 | * mismatch -1 Zero or positive index * 41 | *********************************************************************************** 42 | */ 43 | 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/java17/Chapter_4_Core_APISs/MathApiAndDateAndTimes.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_4_Core_APISs; 2 | 3 | import java.time.Instant; 4 | import java.time.LocalDateTime; 5 | import java.time.ZoneId; 6 | 7 | public class MathApiAndDateAndTimes { 8 | 9 | //any example of Math Apis 10 | int first = Math.max(3, 7); // 7 11 | int second = Math.min(7, -9); // -9 12 | 13 | long low = Math.round(123.34); // 123 14 | long high = Math.round( 123.50);// 124 15 | int fromFloat = Math.round(123.45f); //123 16 | 17 | double squared = Math.pow(5,2); // 25.0 exponents 18 | double num = Math.random();// randon number 19 | 20 | //---------------------------------------------------------------------------- 21 | 22 | // Localdate, LocalDateTime and ZonedDateTime 23 | //Exist many ways... any example... 24 | 25 | //(.of), (.plus), (.minus), (duration), (period),(toInstante), (truncatedTo)... and other "need access documentation" 26 | 27 | public static void main(String[] args) { 28 | 29 | var zone = ZoneId.of("America/Sao_Paulo"); 30 | var now = Instant.now(); // class represent a specific moment in time in the GMT time zone. 31 | var dateTime = LocalDateTime.now(); 32 | System.out.println(now); 33 | System.out.println(dateTime); 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /src/java17/Chapter_4_Core_APISs/Readme.md: -------------------------------------------------------------------------------- 1 | Works with strings, StringBuilder, arrays, and, dates. -------------------------------------------------------------------------------- /src/java17/Chapter_4_Core_APISs/StringBuilderExample.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_4_Core_APISs; 2 | 3 | 4 | /** 5 | * StringBuilder class creates or manipulat a String without storing interim String values. 6 | * Is not immutable. 7 | * You can inserting Data, Deleting Contents, Replacing Portions, Reversing and others. 8 | * the append() method is by far the most frequently used method in stringBuilder 9 | * 10 | * Stores characters specified by its capacity, if it is exceeded, it is increased to accommodate the additional characters; 11 | * You don't need to allocate new objects when you perform a concatenation; 12 | * They are not synchronized; 13 | * They are not thread safe; 14 | */ 15 | 16 | public class StringBuilderExample { 17 | 18 | public static void main(String[] args) { 19 | 20 | /** EXEMPLE 21 | * WITHOUT STRINGBUILDER... 22 | */ 23 | 24 | String alpha = ""; 25 | 26 | for (char current = 'a'; current <= 'z'; current++) { 27 | alpha += current; 28 | System.out.println(alpha); 29 | } 30 | 31 | System.out.println("----------------------------------------------"); 32 | 33 | 34 | /** EXEMPLE 35 | * WITH STRINGBUILDER... 36 | */ 37 | 38 | StringBuilder alphaa = new StringBuilder(); 39 | 40 | for(char current = 'a'; current <= 'z'; current++){ 41 | alphaa.append(current); 42 | System.out.println(alphaa); 43 | } 44 | System.out.println("----------------------------------------------"); 45 | 46 | 47 | /** EASY EXEMPLE 48 | * WITH STRINGBUILDER... 49 | */ 50 | 51 | StringBuilder a = new StringBuilder("abc"); 52 | 53 | StringBuilder b = a.append("de"); 54 | 55 | b = b.append("f").append("g"); 56 | 57 | System.out.println("a=" + a); 58 | System.out.println("b=" + b); 59 | 60 | 61 | 62 | 63 | 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/java17/Chapter_4_Core_APISs/Strings.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_4_Core_APISs; 2 | 3 | /** 4 | * 5 | * Any example methods in Strings 6 | * 7 | */ 8 | 9 | public class Strings { 10 | 11 | 12 | public static void main(String[] args) { 13 | 14 | String example = "Hello world"; 15 | 16 | 17 | System.out.println(example.length()); //return numbers of characteres in the string. 18 | System.out.println(example.charAt(5));// return characteres is a specific position. 19 | System.out.println(example.indent('e')); //add same numbers of blank spaces 20 | System.out.println(example.substring(3)); // find and return parts of the string. 21 | System.out.println(example.substring(example.indexOf('w'))); //find and return index/ 22 | System.out.println(example.toUpperCase());// or lowercase // convert strings. 23 | 24 | //boolen 25 | System.out.println(example.equals("Hello world")); // checks objets contain same order 26 | System.out.println(example.equalsIgnoreCase("hello world")); // ignore uppercase or lowercase 27 | System.out.println(example.startsWith("a")); //is contained and start letter ? 28 | System.out.println(example.isBlank()); // is blank ? 29 | System.out.println(example.isEmpty()); // is empty? 30 | 31 | //others 32 | System.out.println(example.replace('H', 'R')); //replace values 33 | System.out.println(example.trim()); // remove space 34 | System.out.println(example.strip()); // remove space and support unicode 35 | 36 | //example 37 | String exampleTwo = "Hello world atomic ".trim().toLowerCase().replace('H', 'a'); 38 | System.out.println(exampleTwo); 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/java17/Chapter_5_Methods/Methods.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_5_Methods; 2 | 3 | 4 | 5 | public class Methods { 6 | 7 | //tow of the parts - the method name and parameter list - are called the method signature. 8 | //acess modifiers -> private, public, protected and package access. 9 | 10 | 11 | /** optional specifiers 12 | 13 | static -> shared class object 14 | abstract -> used in an abstract class 15 | final -> not be overridden in a subclass 16 | default -> used i na interface to provide a default implementation 17 | syncronized -> used with multithread code 18 | native -> used when interacting with code written in another language, such c++ 19 | strictfp -> used for making floating-point calculations portable 20 | 21 | **/ 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/java17/Chapter_5_Methods/Methods_examples.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_5_Methods; 2 | 3 | 4 | 5 | public class Methods_examples { 6 | 7 | int hunger = 4; 8 | 9 | 10 | 11 | /* return type other than void are required to have a return. This return statement 12 | must include the primitive or object to be returned.*/ 13 | 14 | 15 | int getHeight1() { 16 | int temp = 9; 17 | return temp; 18 | } 19 | 20 | void nap() { 21 | } 22 | 23 | //parameter List and method signature 24 | public void visitZoo(String name, int waitTime) { 25 | 26 | } 27 | 28 | public void oneExeption() throws IllegalArgumentException { 29 | } 30 | 31 | 32 | //declaring local and instance variable 33 | public int feedZooAnimals() { 34 | int snack = 10; 35 | 36 | if (snack > 4) { 37 | long dinnerTime = snack++; 38 | hunger--; 39 | } 40 | return snack; 41 | } 42 | 43 | public void zooAnimalCheckup(boolean isWeekend) { 44 | final int rest; 45 | 46 | if (isWeekend) rest = 5; 47 | else rest = 20; 48 | System.out.println(rest); 49 | 50 | } 51 | 52 | public static void main(String[] args) { 53 | Methods_examples teste = new Methods_examples(); 54 | teste.zooAnimalCheckup(false); 55 | System.out.println(teste); 56 | run(11, 77); 57 | walkdog(1); 58 | walkdog(1, 2); 59 | walkdog(1, 2, 3); 60 | walkdog(1, new int[]{4, 5}); 61 | 62 | int resultado1 = soma(1, 2, 3); 63 | System.out.println(resultado1); 64 | 65 | printMensagem("olá", "mundo"); 66 | } 67 | 68 | //The compiler does not apply a default value to final variables. must receive a value... 69 | 70 | /** 71 | * Varargs 72 | * A method can have at most one varargs parameter 73 | * if a method contains a varargs parameter, it must be the last parameter in the list. 74 | */ 75 | 76 | 77 | public void walk1(int... steps) { 78 | } 79 | 80 | public void walk2(int start, int... steps) { 81 | } 82 | //public void walk3(int...steps, int start){} // DOES NOT COMPILE 83 | //public void walk4(int...start, int... steps){} // DOES NOT COMPILE 84 | 85 | 86 | //exemplo 87 | public static void walk11(int... steps) { 88 | int[] step2 = steps; //not necessary, but shows steps is of type int[]. 89 | System.out.println(step2.length); 90 | } 91 | 92 | //acessing elements of a Varargs 93 | public static void run(int... steps) { 94 | System.out.println(steps[1]); 95 | } 96 | 97 | //using Varargs with other methods parametes 98 | public static void walkdog(int start, int... steps) { 99 | System.out.println(steps.length); 100 | } 101 | 102 | public static int soma(int... numeros) { 103 | 104 | int resultado = 0; 105 | 106 | for (int numero : numeros) { 107 | resultado += numero; 108 | } 109 | return resultado; 110 | } 111 | 112 | public static void printMensagem(String... mensagens) { 113 | 114 | for (String mensag : mensagens) { 115 | System.out.println(mensag); 116 | } 117 | 118 | } 119 | 120 | //Static initializersPassing 121 | private static final int NUM_SECONDS_PER_MINUTE; 122 | 123 | private static final int NUM_MINUTES_PER_HOUR; 124 | 125 | static { 126 | 127 | NUM_SECONDS_PER_MINUTE = 60; 128 | NUM_MINUTES_PER_HOUR = 60; 129 | 130 | } 131 | 132 | //methods final cannot be overridden. 133 | //methods private cannot be overridden. 134 | } 135 | 136 | -------------------------------------------------------------------------------- /src/java17/Chapter_5_Methods/Passing_Data_among_methods.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_5_Methods; 2 | 3 | public class Passing_Data_among_methods { 4 | 5 | /** 6 | * Java is a "##### pass-by-value ######" language. This means that a copy of variable is made and the method receives tha copy. * 7 | * Assignments made in the method do not affect the caller. * 8 | */ 9 | 10 | public static void main(String[] args) { 11 | //primitive 12 | int num = 4; 13 | newNumber(num); 14 | System.out.println(num); 15 | //the variable on line 12 never changes because no assignments are made to it 16 | 17 | //objects 18 | String name = "webby"; 19 | speak(name); 20 | System.out.println(name); 21 | //the correct is webby. The variable assignment is only ti the method parameter and doesn't affect the caller. 22 | 23 | 24 | //In this case, falar() calls a method on the parameter.the variable s is a copy of the variable nome. 25 | //both point to the same StringBuilder, which means that changes made to the StringBuilder are available to both references. 26 | var nome = new StringBuilder("willyan"); 27 | falar(nome); 28 | System.out.println(nome); 29 | 30 | } 31 | 32 | public static void falar(StringBuilder s) { 33 | s.append("Henrique"); 34 | } 35 | 36 | public static void speak(String name ){ 37 | name = "Faria"; 38 | } 39 | 40 | public static void newNumber(int num) { 41 | num = 8; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/java17/Chapter_5_Methods/Readme.md: -------------------------------------------------------------------------------- 1 | explains how to design and write methods. It also introduces access modifiers, 2 | which are used throughout the book. -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Animal.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Animal { 4 | 5 | private int age; 6 | protected String name; 7 | 8 | public int getAge(){ 9 | return age; 10 | } 11 | 12 | public void setAge(int newAge){ 13 | age = newAge; 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Constructor.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Constructor extends Animal { 4 | int age; 5 | String teste; 6 | 7 | //a Class can have multiple constructors, as long as each constructor has a unique constructor signature 8 | /* we need declaring multiple constructors with different signatures */ /** Constructor overloading */ 9 | 10 | public Constructor(int age){ 11 | this.age = age; 12 | } 13 | public Constructor(String teste ){ 14 | this.teste = teste; 15 | } 16 | 17 | 18 | // the default constructor has an empty parameter list and an empty body. 19 | 20 | // super is used to reference members of the parent class 21 | // super() calls a parent constructor 22 | 23 | // Construtor are used when creating a new object. This process is called instantiation because it creates 24 | // a new instance od the class. A constructor is called when we write new followed by the name pf the class 25 | // we want to instantiate. 26 | 27 | 28 | public static void main(String[] args) { 29 | Constructor constructor = new Constructor(15); 30 | Constructor constructor1 = new Constructor("faria"); 31 | System.out.println(constructor); 32 | System.out.println(constructor1); 33 | } 34 | 35 | 36 | } -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Creating_Classes.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Creating_Classes { 4 | 5 | //understanding inheritance 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Crocodile.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Crocodile extends Reptile{ 4 | protected int speed = 20; 5 | 6 | public int getSpeed(){ 7 | return speed; 8 | } 9 | 10 | public static void main(String[] args) { 11 | var croc = new Crocodile(); 12 | System.out.println(croc.getSpeed()); 13 | System.out.println(croc.getSpeed2()); 14 | } 15 | 16 | // Calling the super Reference 17 | public int getSpeed2(){ 18 | return super.speed; 19 | } 20 | 21 | 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Lion.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Lion extends Animal { 4 | 5 | protected void setProperties(int age, String n){ 6 | setAge(age); 7 | name = n; 8 | } 9 | 10 | public void roar(){ 11 | System.out.println( name + ", age" + getAge() + ", says: Roar!"); 12 | } 13 | 14 | public static void main(String[] args) { 15 | var lion = new Lion(); 16 | lion.setProperties(3 , "kion"); 17 | lion.roar(); 18 | } 19 | 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Readme.md: -------------------------------------------------------------------------------- 1 | covers class structure, constructors, inheritance, and initialization. 2 | It also teaches you how to create abstract classes and overload methods. -------------------------------------------------------------------------------- /src/java17/Chapter_6_Class_Design/Reptile.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_6_Class_Design; 2 | 3 | public class Reptile { 4 | protected int speed = 10; 5 | } 6 | -------------------------------------------------------------------------------- /src/java17/Chapter_7_Beyond_Classes/Readme.md: -------------------------------------------------------------------------------- 1 | introduces many top-levels types (other than class), including interfaces, enums, sealed classes, records, and nested classes. 2 | It also covers polymorphism. -------------------------------------------------------------------------------- /src/java17/Chapter_8_Lambdas_and_Funcionals_Interfaces/LambdasAndOthers.java: -------------------------------------------------------------------------------- 1 | package java17.Chapter_8_Lambdas_and_Funcionals_Interfaces; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.concurrent.atomic.AtomicReference; 6 | import java.util.stream.Collectors; 7 | 8 | public class LambdasAndOthers { 9 | private String testObj; 10 | public String getTestObj() { 11 | return testObj; 12 | } 13 | public void setTestObj(String testObj) { 14 | this.testObj = testObj; 15 | } 16 | 17 | public static void main(String[] args) { 18 | LambdasAndOthers lambdasAndOthers = new LambdasAndOthers(); 19 | lambdasAndOthers.setTestObj("hello"); 20 | 21 | AtomicReference testThisObjAtomic = new AtomicReference<>(lambdasAndOthers.getTestObj()); 22 | 23 | List objFront = List.of("obj1", "obj1", "obj1", "obj4", "obj5"); 24 | List objTratadoListStream = new ArrayList<>(objFront); 25 | List objTratadoList = new ArrayList<>(); 26 | 27 | objFront.forEach(obj -> { 28 | if (!objTratadoList.contains(obj)) { 29 | objTratadoList.add(obj); 30 | } 31 | }); 32 | 33 | if (!objTratadoList.isEmpty()) { 34 | // objTratadoList.forEach(obj -> { 35 | testThisObjAtomic.set(lambdasAndOthers.getTestObj() + " - " + String.join(" - ", objTratadoList)); 36 | // }); 37 | } 38 | 39 | //normal 40 | System.out.println(testThisObjAtomic); 41 | //with stream 42 | objTratadoListStream.stream().distinct().forEach(System.out::println); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/java17/Chapter_8_Lambdas_and_Funcionals_Interfaces/Readme.md: -------------------------------------------------------------------------------- 1 | show how to you use lambdas, method references, and built-in functional interfaces. -------------------------------------------------------------------------------- /src/java17/Chapter_9_Collections_and_Generics/Readme.md: -------------------------------------------------------------------------------- 1 | demonstrates methods references, generics with wilcards, and Collections. 2 | The Colleciotns portion covers many common interfaces, classes, and methods that are useful for exam and 3 | in everyday software developer. -------------------------------------------------------------------------------- /src/java21/virtualThreads/VirtualThreads.java: -------------------------------------------------------------------------------- 1 | package java21.virtualThreads; 2 | 3 | import java.time.Duration; 4 | import java.util.concurrent.Executors; 5 | import java.util.stream.IntStream; 6 | 7 | public class VirtualThreads { 8 | 9 | //... 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/java21/virtualThreads/descrição.md: -------------------------------------------------------------------------------- 1 | 2 | # pt-br 3 | Hoje, cada instância de java.lang.Threadno JDK há um thread de plataforma . Um thread de plataforma executa código Java em um thread de sistema operacional subjacente e captura o thread de sistema operacional durante todo o tempo de vida do código. O número de threads de plataforma é limitado ao número de threads do sistema operacional. 4 | 5 | Um thread virtual é uma instância de java.lang.Threadque executa código Java em um thread de sistema operacional subjacente, mas não captura o thread de sistema operacional durante todo o tempo de vida do código. Isso significa que muitos threads virtuais podem executar seu código Java no mesmo thread do sistema operacional, compartilhando-o efetivamente. Embora um thread de plataforma monopolize um thread precioso do sistema operacional, um thread virtual não o faz. O número de threads virtuais pode ser muito maior que o número de threads do sistema operacional. 6 | 7 | Threads virtuais são uma implementação leve de threads fornecida pelo JDK em vez do sistema operacional. Eles são uma forma de threads em modo de usuário , que tiveram sucesso em outras linguagens multithread (por exemplo, goroutines em Go e processos em Erlang). Os threads de modo de usuário eram até mesmo apresentados como os chamados "threads verdes" nas primeiras versões do Java, quando os threads do sistema operacional ainda não estavam maduros e difundidos. No entanto, todos os threads verdes do Java compartilhavam um thread de sistema operacional (agendamento M:1) e acabaram sendo superados por threads de plataforma, implementados como wrappers para threads de sistema operacional (agendamento 1:1). Threads virtuais empregam agendamento M:N, onde um grande número (M) de threads virtuais é programado para ser executado em um número menor (N) de threads do sistema operacional. --------------------------------------------------------------------------------