├── LICENSE ├── Lesson1 ├── Classes-objects and methods │ ├── Choosing the correct type │ │ ├── Account.java │ │ └── Main.java │ ├── Classes objects and methods (video 1) │ │ ├── Dog.java │ │ └── Person.java │ ├── More about objects and methods │ │ ├── Account.java │ │ └── Main.java │ └── Screencast of class objects and methods │ │ ├── Human.java │ │ └── Main.java ├── Control Flow │ ├── Branching Statements │ │ └── Main.java │ ├── Conditionals and Short Circuit Evaluation │ │ └── Main.java │ ├── Control Flow (video 1) │ │ ├── branching-statement-break │ │ │ └── Main.java │ │ ├── branching-statement-continue │ │ │ └── Main.java │ │ ├── do-while │ │ │ └── Main.java │ │ ├── for-statement │ │ │ └── Main.java │ │ ├── if-then-statement │ │ │ └── Main.java │ │ ├── infinite-loop │ │ │ └── Main.java │ │ ├── switch-statement │ │ │ └── Main.java │ │ └── while-statement │ │ │ └── Main.java │ ├── Screencast if-then-statement and switch-case │ │ ├── if-then-statement │ │ │ └── Main.java │ │ └── switch-case-statement │ │ │ └── Main.java │ └── Screencast loops │ │ ├── for-loop │ │ └── Main.java │ │ └── while_do-while-loop │ │ └── Main.java └── Recap Lesson │ ├── Assign-the-result-of-the-method │ └── Main.java │ ├── Void-methods │ └── Main.java │ ├── if-then without braces │ └── Main.java │ └── switch-case without break │ └── Main.java ├── Lesson2 ├── Access Control │ └── Access Control Screencast │ │ ├── Main.java │ │ ├── atm │ │ └── ATM.java │ │ └── bank │ │ ├── BankAccount.java │ │ └── BankTeller.java ├── Inheritance │ └── Inheritance Screencast │ │ ├── Car.java │ │ ├── F1Car.java │ │ └── Main.java ├── Interface │ ├── Interface Screencast │ │ ├── Car.java │ │ ├── Main.java │ │ └── Vehicle.java │ └── Interface Using a real interface │ │ ├── Main.java │ │ └── PokerCard.java └── Polymorphism │ ├── More about using inheritance and polymorphism │ ├── Main.java │ └── animal │ │ ├── Animal.java │ │ ├── Bear.java │ │ └── PolarBear.java │ └── Screencast Interfaces, inheritance y polymorphism │ ├── BandMember.java │ ├── Guitarist.java │ ├── Human.java │ ├── Main.java │ ├── PlaySong.java │ └── Vocalist.java ├── Lesson3 ├── Activities │ ├── IO │ │ ├── recipes.json │ │ └── recipes.txt │ └── SOLID │ │ ├── dessert.txt │ │ ├── drinks.txt │ │ └── main_dish.txt ├── DataStructures │ ├── Practice of the theory of Array video 1 │ │ └── Static.java │ ├── Practice of the theory of Array video 4 │ │ └── Dynamic.java │ ├── Screencast Hashmap │ │ └── Main.java │ ├── Screencast-ArrayList │ │ └── Main.java │ ├── Screencast-Multidimensional Array │ │ └── Main.java │ └── Screencast-Simple array │ │ └── Main.java ├── IO │ └── Example of files and IO │ │ ├── BufferReaders.java │ │ ├── FileReaders.java │ │ ├── FileStreams.java │ │ ├── ScannerFile.java │ │ ├── SerializeObject.java │ │ ├── listofFigures.txt │ │ └── listofFigures_out.txt └── SOLID │ └── Example of SOLID principles │ ├── DependencyInversion.java │ ├── InterfaceSegregation.java │ ├── LiskovSubstitution.java │ ├── OpenClosed.java │ ├── SingleResponsibility.java │ └── Solid_principles.txt ├── Lesson4 ├── Exception Handling practice │ └── HandlingExceptions.java ├── FunctionalInterfaces │ └── FunctionalInterfaces.java ├── Lambda Demo │ ├── pom.xml │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── nabenik │ │ │ ├── Main.java │ │ │ └── MyFunctionalInterface.java │ └── target │ │ └── classes │ │ └── com │ │ └── nabenik │ │ ├── Main$1.class │ │ ├── Main.class │ │ └── MyFunctionalInterface.class ├── Multi Threading practice │ ├── CAAD001X_L4_MT.png │ ├── MultiThreading.java │ └── movies.txt ├── StreamsDemo │ └── StreamsDemo │ │ ├── pom.xml │ │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── nabenik │ │ │ └── Main.java │ │ └── target │ │ └── classes │ │ └── com │ │ └── nabenik │ │ ├── Main$1.class │ │ └── Main.class └── Threads demo │ ├── pom.xml │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── nabenik │ │ ├── Main.java │ │ ├── ThreadAltObject.java │ │ └── ThreadObject.java │ └── target │ └── classes │ └── com │ └── nabenik │ ├── Main.class │ ├── ThreadAltObject.class │ └── ThreadObject.class ├── Lesson5 ├── Introduction │ ├── EchoServer │ │ └── EchoServer.java │ ├── Echoclient │ │ └── EchoClient.java │ ├── URL Connetion Example │ │ └── URLPost.java │ └── Working with URLS │ │ ├── URLConnectionReader.java │ │ └── URLReader.java ├── Java 8 On Android │ └── Demo Java 8 on Android │ │ └── Creating my First App │ │ └── ClicksCounter │ │ ├── .gitignore │ │ ├── .idea │ │ ├── compiler.xml │ │ ├── copyright │ │ │ └── profiles_settings.xml │ │ ├── gradle.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── runConfigurations.xml │ │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── androidcourse │ │ │ │ └── yosef │ │ │ │ └── clickscounter │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── androidcourse │ │ │ │ │ └── yosef │ │ │ │ │ └── clickscounter │ │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── androidcourse │ │ │ └── yosef │ │ │ └── clickscounter │ │ │ └── ExampleUnitTest.java │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle ├── Meet Android Studio │ └── Creating my First App │ │ └── ClicksCounter │ │ ├── .gitignore │ │ ├── .idea │ │ ├── compiler.xml │ │ ├── copyright │ │ │ └── profiles_settings.xml │ │ ├── gradle.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── runConfigurations.xml │ │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── androidcourse │ │ │ │ └── yosef │ │ │ │ └── clickscounter │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── androidcourse │ │ │ │ │ └── yosef │ │ │ │ │ └── clickscounter │ │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── androidcourse │ │ │ └── yosef │ │ │ └── clickscounter │ │ │ └── ExampleUnitTest.java │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle ├── Serialization │ ├── DOM Parser Example │ │ ├── DOMParser.java │ │ └── Student.xml │ ├── Jason Processing Example │ │ ├── JSONParserDemo.java │ │ └── Student.json │ └── SAX Parse Code Example │ │ ├── SAXParserDemo2.java │ │ └── Student.xml ├── clickcounter.java └── clickcounterJ8.java └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Universidad Galileo - EDX 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Choosing the correct type/Account.java: -------------------------------------------------------------------------------- 1 | public class Account{ 2 | 3 | public static int nextAccount = 1; 4 | 5 | public String name; 6 | public int accountNumber; 7 | public short balance; 8 | 9 | public Account(String n){ 10 | name = new String(n); 11 | accountNumber = nextAccount; 12 | balance = 0; 13 | 14 | nextAccount++; 15 | } 16 | 17 | public Account(String n, short b){ 18 | name = new String(n); 19 | accountNumber = nextAccount; 20 | balance = b; 21 | 22 | nextAccount++; 23 | } 24 | 25 | public void deposit(short b){ 26 | balance = balance + b; 27 | } 28 | 29 | public String toString(){ 30 | return "\nname: " + name + "\naccount number: " + accountNumber + "\nbalance: " + balance; 31 | } 32 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Choosing the correct type/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | Account alice = new Account("Alice", (short)100); 4 | System.out.println(alice); 5 | 6 | alice.deposit((short)100); 7 | System.out.println(alice); 8 | 9 | alice.deposit((short)40000); 10 | System.out.println(alice); 11 | } 12 | } 13 | 14 | //Complement to 2 15 | //2's complement -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Classes objects and methods (video 1)/Dog.java: -------------------------------------------------------------------------------- 1 | public class Dog{ 2 | int size; 3 | String name; 4 | 5 | public Dog(int inputSize, String inputName){ 6 | size = inputSize; 7 | name = inputName; 8 | } 9 | 10 | public void bark(){ 11 | System.out.println("woof! woof!"); 12 | } 13 | 14 | public void bark2(){ 15 | String sound = "Woof"; 16 | System.out.println(sound); 17 | } 18 | 19 | 20 | public void printName(String name){ 21 | System.out.println(name); 22 | } 23 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Classes objects and methods (video 1)/Person.java: -------------------------------------------------------------------------------- 1 | public class Person{ 2 | 3 | public void printData(String firstName, String lastName, int age){ 4 | System.out.println("You have " + age + " years old"); 5 | System.out.println("Your name is: " + firstName + " " + lastName); 6 | } 7 | 8 | public String getName(String firstName, String lastName){ 9 | String completeName = "Your name is: " + firstName + " " + lastName; 10 | return completeName; 11 | } 12 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/More about objects and methods/Account.java: -------------------------------------------------------------------------------- 1 | public class Account{ 2 | 3 | public static int nextAccount = 1; 4 | 5 | public String name; 6 | public int accountNumber; 7 | public int balance; 8 | 9 | public Account(String n){ 10 | name = new String(n); 11 | accountNumber = nextAccount; 12 | balance = 0; 13 | 14 | nextAccount++; 15 | } 16 | 17 | public Account(String n, int b){ 18 | name = new String(n); 19 | accountNumber = nextAccount; 20 | balance = b; 21 | 22 | nextAccount++; 23 | } 24 | 25 | public void deposit(int b){ 26 | balance = balance + b; 27 | } 28 | 29 | public String toString(){ 30 | return "\nname: " + name + "\naccount number: " + accountNumber + "\nbalance: " + balance; 31 | } 32 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/More about objects and methods/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | Account alice = new Account("Alice", 100); 4 | Account bob = new Account("Bob"); 5 | 6 | System.out.println(alice); 7 | System.out.println(bob); 8 | 9 | System.out.println(alice.nextAccount); 10 | System.out.println(bob.nextAccount); 11 | System.out.println(Account.nextAccount); 12 | } 13 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Screencast of class objects and methods/Human.java: -------------------------------------------------------------------------------- 1 | import java.util.Date; 2 | 3 | public class Human{ 4 | char gender; // 'F' or 'M' 5 | String firstNames, lastName; 6 | Human partner; 7 | int identificationNumber; 8 | int yearBirth; 9 | int monthBirth; 10 | int dayBirth; 11 | 12 | public Human(String firstNames, String lastName, char gender){ 13 | this.firstNames = firstNames; 14 | this.lastName = lastName; 15 | this.gender = gender; 16 | } 17 | 18 | public void speak(String words){ 19 | System.out.println(words); 20 | } 21 | 22 | public void addPartner(Human humanCouple){ 23 | this.partner = humanCouple; 24 | humanCouple.partner = this; 25 | } 26 | 27 | public Human getPartner(){ 28 | return this.partner; 29 | } 30 | 31 | public void setId(int id){ 32 | identificationNumber = id; 33 | } 34 | 35 | public int getId(){ 36 | return identificationNumber; 37 | } 38 | 39 | public void setBirthDate(int yearBirth, int monthBirth, int dayBirth){ 40 | this.monthBirth = monthBirth; 41 | this.dayBirth = dayBirth; 42 | this.yearBirth = yearBirth; 43 | } 44 | 45 | public int getAge(){ 46 | Date today = new Date(); 47 | 48 | //the current year represented by this date, minus 1900 49 | int currentYear = today.getYear() + 1900; 50 | int age = currentYear - yearBirth; 51 | 52 | //0 is January, so add 1 53 | int currentMonth = today.getMonth() + 1; 54 | if(currentMonth < monthBirth){ 55 | age--; 56 | }else if(currentMonth == monthBirth){ 57 | //day of the Month 58 | int currentDay = today.getDate(); 59 | if(dayBirth > currentDay){ 60 | age--; 61 | } 62 | } 63 | return age; 64 | } 65 | 66 | public String getPartnerName(){ 67 | return this.partner.getFullName(); 68 | } 69 | 70 | public String getFullName(){ 71 | return this.firstNames + " " + this.lastName; 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /Lesson1/Classes-objects and methods/Screencast of class objects and methods/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Human connie = new Human("Connie", "Smith", 'F'); 9 | connie.setBirthDate(1987,1,22); //January 22th, 1987 10 | System.out.println(connie.getFullName() + " is "+ connie.getAge() + " years old"); 11 | 12 | Human john = new Human("John", "Brown", 'M'); 13 | john.setBirthDate(1986,12,8);//December 08th, 1986 14 | System.out.println(john.getFullName() + " is "+ john.getAge() + " years old"); 15 | connie.addPartner(john); 16 | System.out.println(connie.getFullName() + "'s partner is " + connie.getPartnerName()); 17 | System.out.println(john.getFullName() + "'s partner is " + john.getPartnerName()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Branching Statements/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | System.out.println("Starting the countdown!"); 4 | 5 | for (int i = 7; i >= 0; i--) { 6 | 7 | System.out.println(i); 8 | 9 | //continue; 10 | break; 11 | 12 | /* 13 | if(i < 4){ 14 | //continue; 15 | break; 16 | }*/ 17 | 18 | System.out.println("beep"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Lesson1/Control Flow/Conditionals and Short Circuit Evaluation/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | System.out.println("Let's check the first table..."); 4 | boolean food = hotFood(); 5 | boolean table = tableServed(); 6 | /*hotFood() && tableServed()*/ /*tableServed() && hotFood()*/ /*tableServed() || hotFood()*/ /*hotFood() || tableServed()*/ 7 | if(table && food ){ 8 | System.out.println("Time to eat"); 9 | }else{ 10 | System.out.println("Let's wait"); 11 | } 12 | } 13 | 14 | public static boolean hotFood(){ 15 | System.out.println("Evaluating hotFood!"); 16 | return true; 17 | } 18 | 19 | public static boolean tableServed(){ 20 | System.out.println("Evaluating tableServered!"); 21 | return false; 22 | } 23 | } -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/branching-statement-break/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | int number = 1; 9 | loopNumber(number); 10 | } 11 | 12 | public static void loopNumber(int newNumber){ 13 | while(newNumber >= 0){ 14 | if(newNumber < 10){ 15 | newNumber++; 16 | continue; 17 | } 18 | System.out.println(newNumber); 19 | System.out.println("Done"); 20 | break; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/branching-statement-continue/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | int number = 1; 9 | String value = loopNumber(number); 10 | System.out.println(value); 11 | } 12 | 13 | public static String loopNumber(int newNumber){ 14 | while(newNumber >= 0){ 15 | if(newNumber < 10){ 16 | newNumber++; 17 | continue; 18 | } 19 | System.out.println(newNumber); 20 | return "Done"; 21 | } 22 | return newNumber + " is negative"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/do-while/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("While loop: Starting..."); 9 | int number = 2; 10 | while(number < 2){ 11 | System.out.println(number); 12 | number = number + 1; 13 | } 14 | System.out.println("While loop: Done."); 15 | System.out.println("Do While loop: Starting..."); 16 | int number2 = 2; 17 | do{ 18 | System.out.println(number2); 19 | number2 = number2 + 1; 20 | }while(number2 < 2); 21 | System.out.println("Do while loop: Done."); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/for-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | for(int count = 0; count < 10; count++){ 9 | System.out.println(count); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/if-then-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java Program 3 | */ 4 | public class Main{ 5 | public static void main(String[] args) { 6 | int grade =85; 7 | if(grade > 70){ 8 | System.out.println("Congratulations!"); 9 | }else{ 10 | System.out.println("You should work harder"); 11 | } 12 | 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/infinite-loop/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("While loop: Starting..."); 9 | int number = 1; 10 | while(number > 0){ 11 | System.out.println(number); 12 | number = number + 1; 13 | } 14 | System.out.println("While loop: Done."); 15 | System.out.println("Do While loop: Starting..."); 16 | int number2 = 1; 17 | do{ 18 | System.out.println(number2); 19 | number2 = number2 + 1; 20 | }while(number2 > 0); 21 | System.out.println("Do while loop: Done."); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/switch-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | public class Main { 5 | public static void main(String[] args) { 6 | int choice = 3; 7 | 8 | switch (choice) { 9 | case 1: 10 | System.out.println("Creating..."); 11 | break; 12 | case 2: 13 | System.out.println("Reading..."); 14 | break; 15 | case 3: 16 | System.out.println("Updating..."); 17 | break; 18 | case 4: 19 | System.out.println("Deleting..."); 20 | break; 21 | default: 22 | System.out.println("Invalid input"); 23 | break; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Lesson1/Control Flow/Control Flow (video 1)/while-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args){ 8 | 9 | int number = 1; 10 | 11 | while(number <= 5){ 12 | System.out.println(number); 13 | number = number + 1; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Lesson1/Control Flow/Screencast if-then-statement and switch-case/if-then-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | String weather = "rainy"; 9 | //String weather = "sunny"; 10 | //String weather = "windy"; 11 | //String weather = "snowy"; 12 | if(weather.equals("rainy")){ 13 | System.out.println("Don't forget to bring your umbrella"); 14 | }else if(weather.equals("sunny")){ 15 | System.out.println("Don't forget your sunglasses"); 16 | }else if(weather.equals("windy")){ 17 | System.out.println("Don't forget to bring your coat"); 18 | }else{ 19 | System.out.println("Enjoy the snow!"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Screencast if-then-statement and switch-case/switch-case-statement/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | int birthMonth = 4; 9 | 10 | switch(birthMonth){ 11 | case 1: 12 | System.out.println("You where born in January"); 13 | break; 14 | case 2: 15 | System.out.println("You where born in February"); 16 | break; 17 | case 3: 18 | System.out.println("You where born in March"); 19 | break; 20 | case 4: 21 | System.out.println("You where born in April"); 22 | break; 23 | case 5: 24 | System.out.println("You where born in May"); 25 | break; 26 | case 6: 27 | System.out.println("You where born in June"); 28 | break; 29 | case 7: 30 | System.out.println("You where born in July"); 31 | break; 32 | case 8: 33 | System.out.println("You where born in Agust"); 34 | break; 35 | case 9: 36 | System.out.println("You where born in September"); 37 | break; 38 | case 10: 39 | System.out.println("You where born in October"); 40 | break; 41 | case 11: 42 | System.out.println("You where born in November"); 43 | break; 44 | case 12: 45 | System.out.println("You where born in December"); 46 | break; 47 | default: 48 | System.out.println("Invalid Month"); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Lesson1/Control Flow/Screencast loops/for-loop/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | //basic example 4 | System.out.println("Basic example"); 5 | for (int sequence = 0; sequence <= 10; sequence++ /* sequence = sequence + 2*/) { 6 | System.out.println(sequence); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Lesson1/Control Flow/Screencast loops/while_do-while-loop/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | //while example 9 | int sequenceWhile = 9; 10 | while(sequenceWhile < 10){ 11 | System.out.println("while: " + sequenceWhile); 12 | sequenceWhile++; 13 | } 14 | //do-while example 15 | int sequenceDoWhile = 10; 16 | do{ 17 | System.out.println("do-while: " + sequenceDoWhile); 18 | sequenceDoWhile++; 19 | }while(sequenceDoWhile < 10); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lesson1/Recap Lesson/Assign-the-result-of-the-method/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | 3 | public static boolean isEven(int number){ 4 | int result = number % 2; 5 | if(result>0){ 6 | return false; 7 | } 8 | return true; 9 | } 10 | 11 | public static void main(String[] args) { 12 | int number = 127; 13 | boolean isEven = isEven(number); 14 | if(isEven){ 15 | System.out.println(number + " is an even number"); 16 | }else if(!isEven){ 17 | System.out.println(number + " is an odd number"); 18 | 19 | } 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /Lesson1/Recap Lesson/Void-methods/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | 3 | public static void printString(String valueToPrint){ 4 | System.out.println("<<-"+valueToPrint+"->>"); 5 | } 6 | 7 | public static void main(String[] args) { 8 | //printString("this is the string that i want to print."); 9 | printString("Hello world"); 10 | } 11 | } -------------------------------------------------------------------------------- /Lesson1/Recap Lesson/if-then without braces/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | int number = 10; 4 | if (number > 10){ 5 | System.out.println("The number is greater than 10"); 6 | System.out.println("You should enter a number smaller or equal than 10"); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Lesson1/Recap Lesson/switch-case without break/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | int number = 8; 4 | switch (number) { 5 | case 1: case 2 : case 3: case 4: case 5:{ 6 | System.out.println("The number is between 1 and 5."); 7 | break; 8 | } 9 | case 6: case 7 : case 8: case 9: case 10:{ 10 | System.out.println("The number is between 6 and 10."); 11 | break; 12 | } 13 | default:{ 14 | System.out.println("The number is greater than 10"); 15 | break; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Lesson2/Access Control/Access Control Screencast/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | * 4 | */ 5 | import bank.BankAccount; 6 | import bank.BankTeller; 7 | import atm.ATM; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | BankAccount a = new BankAccount(1234,100.00); 12 | BankTeller john = new BankTeller(); 13 | john.deposit(a,100.00); 14 | ATM xyz = new ATM(222); 15 | xyz.withdraw(a,50.00); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lesson2/Access Control/Access Control Screencast/atm/ATM.java: -------------------------------------------------------------------------------- 1 | package atm; 2 | 3 | import bank.BankAccount; 4 | 5 | public class ATM { 6 | private int id; 7 | 8 | public ATM(int id) { 9 | this.id = id; 10 | } 11 | 12 | public void withdraw(BankAccount account, double amount) { 13 | boolean result = account.withdraw(amount); 14 | if (result) { 15 | System.out.println("Successful withdraw on ATM of $" + amount); 16 | } else { 17 | System.out.println("Error!"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Lesson2/Access Control/Access Control Screencast/bank/BankAccount.java: -------------------------------------------------------------------------------- 1 | package bank; 2 | 3 | public class BankAccount { 4 | public int number; 5 | private double balance; 6 | 7 | public BankAccount(int number, double balance) { 8 | this.number = number; 9 | this.balance = balance; 10 | } 11 | 12 | protected boolean deposit(double amount) { 13 | if (amount > 0) { 14 | balance = balance + amount; 15 | return true; 16 | } 17 | return false; 18 | } 19 | 20 | public boolean withdraw(double amount) { 21 | if (amount > 0 && balance >= amount) { 22 | balance = balance - amount; 23 | return true; 24 | } 25 | return false; 26 | } 27 | } -------------------------------------------------------------------------------- /Lesson2/Access Control/Access Control Screencast/bank/BankTeller.java: -------------------------------------------------------------------------------- 1 | package bank; 2 | 3 | public class BankTeller { 4 | 5 | public void deposit(BankAccount account, double amount) { 6 | boolean result = account.deposit(amount); 7 | if (result) { 8 | System.out.println("Successful deposit of $" + amount); 9 | } else { 10 | System.out.println("Error!"); 11 | } 12 | } 13 | 14 | public void withdraw(BankAccount account, double amount) { 15 | boolean result = account.withdraw(amount); 16 | if (result) { 17 | System.out.println("Successful withdraw of $" + amount); 18 | } else { 19 | System.out.println("Error!"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson2/Inheritance/Inheritance Screencast/Car.java: -------------------------------------------------------------------------------- 1 | public class Car { 2 | public int topSpeed; 3 | 4 | public Car(int topSpeed) { 5 | this.topSpeed = topSpeed; 6 | } 7 | 8 | public int getTopSpeed() { 9 | return topSpeed; 10 | } 11 | 12 | public void printDescription() { 13 | System.out.println("Car"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson2/Inheritance/Inheritance Screencast/F1Car.java: -------------------------------------------------------------------------------- 1 | public class F1Car extends Car { 2 | 3 | public F1Car(int topSpeed) { 4 | super(topSpeed); 5 | } 6 | 7 | public void printDescription() { 8 | System.out.println("F1 Car"); 9 | } 10 | } -------------------------------------------------------------------------------- /Lesson2/Inheritance/Inheritance Screencast/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | * 4 | */ 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | 10 | Car ferrari = new F1Car(320); 11 | Car coupe = new Car(220); 12 | 13 | ferrari.printDescription(); 14 | coupe.printDescription(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson2/Interface/Interface Screencast/Car.java: -------------------------------------------------------------------------------- 1 | public class Car implements Vehicle { 2 | public String transportType = "terrestrial"; 3 | public int wheels; 4 | 5 | public Car(int wheels) { 6 | this.wheels = wheels; 7 | } 8 | public String getTransportType() { 9 | return this.transportType; 10 | } 11 | public boolean hasWheels() { 12 | return wheels>0; 13 | } 14 | public int getNumberOfWheels() { 15 | return wheels; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lesson2/Interface/Interface Screencast/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | * 4 | */ 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | Car taxi = new Car(4); 9 | System.out.println("Taxi has wheels? " + taxi.hasWheels() + " Number of wheels: " + taxi.getNumberOfWheels()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lesson2/Interface/Interface Screencast/Vehicle.java: -------------------------------------------------------------------------------- 1 | public interface Vehicle { 2 | public String getTransportType(); 3 | public boolean hasWheels(); 4 | } 5 | -------------------------------------------------------------------------------- /Lesson2/Interface/Interface Using a real interface/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main class of the Java program. 3 | */ 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | PokerCard eightOfSpades = new PokerCard(4, 8); 10 | PokerCard tenOfHearts = new PokerCard(3, 10); 11 | 12 | System.out.println(eightOfSpades.compareTo(tenOfHearts)); 13 | 14 | System.out.println(tenOfHearts.compareTo(eightOfSpades)); 15 | 16 | System.out.println(eightOfSpades.compareTo(eightOfSpades)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lesson2/Interface/Interface Using a real interface/PokerCard.java: -------------------------------------------------------------------------------- 1 | public class PokerCard implements Comparable { 2 | 3 | int suit; // 4 - spades, 3 - hearts, 2 - clubs, 1 - diamonds 4 | int number; // from 2 to 14, being 11 the Jack, 12 the Queen, 13 the King and 14 the Ace 5 | 6 | public PokerCard (int s, int n) { 7 | suit = s; 8 | number = n; 9 | } 10 | 11 | public int compareTo (PokerCard pc) { 12 | 13 | if (this.number < pc.number) { 14 | return -1; 15 | } else if (this.number > pc.number) { 16 | return 1; 17 | } else { 18 | 19 | if (this.suit < pc.suit) { 20 | return -1; 21 | } else if (this.suit > pc.suit) { 22 | return 1; 23 | } else { 24 | return 0; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/More about using inheritance and polymorphism/Main.java: -------------------------------------------------------------------------------- 1 | import animal.Animal; 2 | import animal.Bear; 3 | import animal.PolarBear; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Animal animal = new Animal(); 9 | Animal bear = new PolarBear(); 10 | 11 | animal.eat(); 12 | bear.eat(); 13 | 14 | // System.out.println(animal.hasEaten); 15 | // System.out.println(bear.color); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lesson2/Polymorphism/More about using inheritance and polymorphism/animal/Animal.java: -------------------------------------------------------------------------------- 1 | package animal; 2 | 3 | public class Animal { 4 | protected boolean hasEaten; 5 | 6 | public Animal () { 7 | hasEaten = false; 8 | } 9 | 10 | public void eat () { 11 | System.out.println("The animal is eating..."); 12 | hasEaten = true; 13 | } 14 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/More about using inheritance and polymorphism/animal/Bear.java: -------------------------------------------------------------------------------- 1 | package animal; 2 | 3 | public class Bear extends Animal { 4 | public String color; 5 | 6 | public Bear (String c) { 7 | super(); 8 | color = c; 9 | } 10 | 11 | public void eat () { 12 | super.eat(); 13 | System.out.println("The bear went fishing before eating."); 14 | } 15 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/More about using inheritance and polymorphism/animal/PolarBear.java: -------------------------------------------------------------------------------- 1 | package animal; 2 | 3 | public class PolarBear extends Bear { 4 | 5 | public PolarBear () { 6 | super("white"); 7 | 8 | } 9 | 10 | public void eat () { 11 | super.eat(); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/BandMember.java: -------------------------------------------------------------------------------- 1 | public class BandMember extends Human implements Vocalist, Guitarist{ 2 | public BandMember(String name){ 3 | super(name); 4 | } 5 | 6 | public void printName(){ 7 | System.out.println("Band Member: " + name); 8 | } 9 | 10 | public void sing(){ 11 | System.out.println("la la la"); 12 | } 13 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/Guitarist.java: -------------------------------------------------------------------------------- 1 | public interface Guitarist extends PlaySong{ 2 | public default void playFavoriteSong(){ 3 | System.out.println("Playing my favorite song"); 4 | PlaySong("My first song"); 5 | } 6 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/Human.java: -------------------------------------------------------------------------------- 1 | public class Human{ 2 | protected String name; 3 | 4 | public Human(String name){ 5 | this.name = name; 6 | } 7 | 8 | public void printName(){ 9 | System.out.println(name); 10 | } 11 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | Human john = new Human("john"); 4 | Human louis = new BandMember("louis"); 5 | BandMember jack = new BandMember("jack"); 6 | 7 | john.printName(); 8 | louis.printName(); 9 | jack.printName(); 10 | 11 | jack.sing(); 12 | jack.playFavoriteSong(); 13 | } 14 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/PlaySong.java: -------------------------------------------------------------------------------- 1 | public interface PlaySong{ 2 | public default void PlaySong(String songName){ 3 | System.out.println("Playing " + songName); 4 | } 5 | } -------------------------------------------------------------------------------- /Lesson2/Polymorphism/Screencast Interfaces, inheritance y polymorphism/Vocalist.java: -------------------------------------------------------------------------------- 1 | public interface Vocalist{ 2 | public void sing(); 3 | } -------------------------------------------------------------------------------- /Lesson3/Activities/IO/recipes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Crock Pot Roast", 4 | "ingredients": [ 5 | "1 beef roast, Meat", 6 | "1 package brown gravy mix, Baking", 7 | "1 package dried Italian salad dressing mix, Condiments", 8 | "1 package dry ranch dressing mix, Condiments", 9 | "1/2 cup water, Drinks" 10 | ], 11 | "steps": [ 12 | "Place beef roast in crock pot.", 13 | "Mix the dried mixes together in a bowl and sprinkle over the roast.", 14 | "Pour the water around the roast.", 15 | "Cook on low for 7-9 hours." 16 | ] 17 | }, 18 | { 19 | "name": "Roasted Asparagus", 20 | "ingredients": [ 21 | "1 lb asparagus, Produce", 22 | "1 1/2 tbsp olive oil, Condiments", 23 | "1/2 tsp kosher salt, Baking" 24 | ], 25 | "steps": [ 26 | "Preheat oven to 425°F.", 27 | "Cut off the woody bottom part of the asparagus spears and discard.", 28 | "With a vegetable peeler, peel off the skin on the bottom 2-3 inches of the spears (this keeps the asparagus from being all.\",string.\", and if you eat asparagus you know what I mean by that).", 29 | "Place asparagus on foil-lined baking sheet and drizzle with olive oil.", 30 | "Sprinkle with salt.", 31 | "With your hands, roll the asparagus around until they are evenly coated with oil and salt.", 32 | "Roast for 10-15 minutes, depending on the thickness of your stalks and how tender you like them.", 33 | "They should be tender when pierced with the tip of a knife.", 34 | "The tips of the spears will get very brown but watch them to prevent burning.", 35 | "They are great plain, but sometimes I serve them with a light vinaigrette if we need something acidic to balance out our meal." 36 | ] 37 | }, 38 | { 39 | "name": "Curried Lentils and Rice", 40 | "ingredients": [ 41 | "1 quart beef broth, Misc", 42 | "1 cup dried green lentils, Misc", 43 | "1/2 cup basmati rice, Misc", 44 | "1 tsp curry powder, Condiments", 45 | "1 tsp salt, Condiments" 46 | ], 47 | "steps": [ 48 | "Bring broth to a low boil.", 49 | "Add curry powder and salt.", 50 | "Cook lentils for 20 minutes.", 51 | "Add rice and simmer for 20 minutes." 52 | ] 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /Lesson3/Activities/IO/recipes.txt: -------------------------------------------------------------------------------- 1 | Crock Pot Roast 2 | ingredients: 3 | 1 beef roast, Meat 4 | 1 package brown gravy mix, Baking 5 | 1 package dried Italian salad dressing mix, Condiments 6 | 1 package dry ranch dressing mix, Condiments 7 | 1/2 cup water, Drinks 8 | steps: 9 | Place beef roast in crock pot 10 | Mix the dried mixes together in a bowl and sprinkle over the roast. 11 | Pour the water around the roast. 12 | Cook on low for 7-9 hours. 13 | 14 | Roasted asparagus 15 | ingredients: 16 | 1 lb asparagus, Produce 17 | 1 1/2 tbsp olive oil, Condiments 18 | 1/2 tsp kosher salt, Baking 19 | steps: 20 | Preheat oven to 425°F. 21 | Cut off the woody bottom part of the asparagus spears and discard. 22 | With a vegetable peeler, peel off the skin on the bottom 2-3 inches of the spears. 23 | Place asparagus on foil-lined baking sheet and drizzle with olive oil. 24 | Sprinkle with salt. 25 | With your hands, roll the asparagus around until they are evenly coated with oil and salt. 26 | Roast for 10-15 minutes, depending on the thickness of your stalks and how tender you like them. 27 | They should be tender when pierced with the tip of a knife. 28 | The tips of the spears will get very brown but watch them to prevent burning. 29 | They are great plain, but sometimes I serve them with a light vinaigrette if we need something acidic to balance out our meal. 30 | 31 | 32 | Curried Lentils and Rice 33 | ingredients: 34 | 1 quart beef broth, Misc 35 | 1 cup dried green lentils, Misc 36 | 1/2 cup basmati rice, Misc 37 | 1 tsp curry powder, Condiments 38 | 1 tsp salt, Condiments 39 | steps: 40 | Bring broth to a low boil. 41 | Add curry powder and salt. 42 | Cook lentils for 20 minutes. 43 | Add rice and simmer for 20 minutes. -------------------------------------------------------------------------------- /Lesson3/Activities/SOLID/dessert.txt: -------------------------------------------------------------------------------- 1 | Jelly 2 | Strawberry 3 | $2 4 | 5 | Flan 6 | Caramel Sauce 7 | $3 8 | 9 | Fruit Cocktail 10 | Pineapple, watermelon, ... 11 | $10 12 | 13 | Cheese Cake 14 | Blackberry Jelly 15 | $5 -------------------------------------------------------------------------------- /Lesson3/Activities/SOLID/drinks.txt: -------------------------------------------------------------------------------- 1 | Lemonade 2 | $3 3 | 4 | Soda 5 | $2 6 | 7 | Coffee 8 | $1 9 | 10 | Orange Juice 11 | $4 -------------------------------------------------------------------------------- /Lesson3/Activities/SOLID/main_dish.txt: -------------------------------------------------------------------------------- 1 | Hamburguer 2 | Bread, Meat, Cheese 3 | French Fries, ketchup 4 | $8.00 5 | 6 | Pizza 7 | Cheese, Pepperoni, Tomato Sauce 8 | Extra ingredients 9 | $18.00 10 | 11 | Chicken 12 | Grilled 13 | Potato Mash, salad 14 | $15.00 15 | 16 | BBQ Ribs 17 | Pork with BBQ Sauce 18 | Onion Rings 19 | $23.00 20 | 21 | Tacos 22 | Pork, Avocado Sauce 23 | Pineapple, Parsley, onion 24 | $3.00 25 | 26 | Lasagna 27 | Pasta, Tomato Sauce, Cheese 28 | Bread with garlic butter 29 | $25 30 | 31 | Fish 32 | Tilapia, Salmon 33 | Tartar sauce, Lemon 34 | $30.00 -------------------------------------------------------------------------------- /Lesson3/DataStructures/Practice of the theory of Array video 1/Static.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | public class Static { 3 | 4 | public static void main(String[] args) throws Exception { 5 | int intArray[] = new int[3]; 6 | System.out.println("Array of primitive int:"); 7 | System.out.println(Arrays.toString(intArray)); 8 | 9 | 10 | Integer integerArray[] = new Integer[3]; 11 | System.out.println("\n\nArray of Integer Object:"); 12 | System.out.println(Arrays.toString(integerArray)); 13 | 14 | integerArray[0] = new Integer(5); 15 | System.out.println(Arrays.toString(integerArray)); 16 | 17 | 18 | 19 | Foo fooArray[] = {new Foo(1), new Foo(2), new Foo(3)}; 20 | System.out.println("\n\nArray of Foo Object:"); 21 | System.out.println(Arrays.toString(fooArray)); 22 | 23 | fooArray[1] = null; 24 | System.out.println(Arrays.toString(fooArray)); 25 | } 26 | } 27 | 28 | class Foo { 29 | private int id; 30 | 31 | public Foo(int id) { 32 | this.id = id; 33 | } 34 | 35 | //Execute, then Uncomment and execute again 36 | /*public String toString(){ 37 | return "I'm Foo Object #" + this.id; 38 | }*/ 39 | } -------------------------------------------------------------------------------- /Lesson3/DataStructures/Practice of the theory of Array video 4/Dynamic.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | public class Dynamic { 5 | 6 | public static void main(String[] args) throws Exception { 7 | 8 | System.out.println("----Dynamic Structures----\n"); 9 | 10 | //ArrayList 11 | System.out.println("Empty ArrayList:"); 12 | ArrayList dynamiclist = new ArrayList(); 13 | System.out.println(dynamiclist); 14 | 15 | System.out.println("\nAdd an element to the ArrayList:"); 16 | dynamiclist.add("I'm Dynamic"); 17 | System.out.println(dynamiclist); 18 | System.out.println("My size: " + dynamiclist.size()); 19 | 20 | System.out.println("\nAdd a second element to the ArrayList:"); 21 | dynamiclist.add("I'm Growing"); 22 | System.out.println(dynamiclist); 23 | System.out.println("My size: " + dynamiclist.size()); 24 | 25 | 26 | //String Pool 27 | System.out.println("\n\nCreating String I'm Growing and another one"); 28 | String grow = "I'm Growing", other = "other"; 29 | System.out.println("== compare the direction (pointer) of a Object"); 30 | System.out.println( grow == dynamiclist.get(1) ); 31 | System.out.println( other == dynamiclist.get(1) ); 32 | System.out.println("The two strings has the same value so,\nthe String Pool of JVM assign the same direction to both strings\n\n\n\n"); 33 | 34 | 35 | 36 | 37 | 38 | 39 | //HashMap 40 | System.out.println("Empty HashMap:"); 41 | HashMap map = new HashMap(); 42 | System.out.println(map); 43 | map.put(10,"I'm Dynamic"); 44 | System.out.println(map); 45 | map.put(25,"I'm Growing"); 46 | System.out.println(map); 47 | 48 | //String Pool 49 | System.out.println("\n\nSee doesn't matter on what Structure the String are stored"); 50 | System.out.print("String I'm Growing: "); 51 | System.out.println( dynamiclist.get(0) == map.get(10) ); 52 | System.out.print("String I'm Dynamic: "); 53 | System.out.println( dynamiclist.get(1) == map.get(25) ); 54 | System.out.println("they all are just a referece to the String Pool"); 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /Lesson3/DataStructures/Screencast Hashmap/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | 5 | public class Main{ 6 | public static void main(String[] args) { 7 | /* 8 | 9 | HashMap months = new HashMap(); 10 | months.put(1, "January"); 11 | months.put(2, "Februray"); 12 | months.put(3, "March"); 13 | months.put(4, "April"); 14 | months.put(5, "May"); 15 | months.put(6, "June"); 16 | months.put(7, "July"); 17 | months.put(8, "Agust"); 18 | months.put(9, "September"); 19 | months.put(10, "October"); 20 | months.put(11, "November"); 21 | months.put(12, "December"); 22 | 23 | System.out.println(months.get(1)); 24 | System.out.println(months.get(12)); 25 | System.out.println(months.get(13)); // This will give you a null value 26 | 27 | */ 28 | HashMap countries = new HashMap (); 29 | 30 | countries.put("GTM", "Guatemala"); 31 | countries.put("USA", "United States of America"); 32 | countries.put("CHN", "China"); 33 | countries.put("ESP", "Spain"); 34 | 35 | countries.forEach((code,name)-> System.out.println("code: " + code + " name: "+ name)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Lesson3/DataStructures/Screencast-ArrayList/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Main{ 5 | public static void main(String[] args) { 6 | 7 | ArrayList list = new ArrayList(); 8 | 9 | list.add("Bananas"); 10 | 11 | Scanner scan = new Scanner(System.in); 12 | System.out.println("Input EXIT when you have finished"); 13 | String item = ""; 14 | do{ 15 | item = scan.next(); 16 | if(!list.contains(item) && !item.equals("EXIT")){ 17 | list.add(item); 18 | } 19 | 20 | }while(!item.equals("EXIT")); 21 | 22 | System.out.println(list); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson3/DataStructures/Screencast-Multidimensional Array/Main.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args) { 3 | String [][] pets = new String[2][3]; 4 | 5 | pets[0][0] = "French poodle"; 6 | pets[0][1] = "Boxer"; 7 | pets[0][2] = "Chihuahua"; 8 | 9 | pets[1][0] = "British shorthair"; 10 | pets[1][1] = "Himalayan"; 11 | pets[1][2] = "Siberian"; 12 | 13 | for (int type = 0; type " + input.next() + "\n"); 17 | } 18 | } finally { 19 | if (input != null){ 20 | input.close(); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Lesson3/IO/Example of files and IO/SerializeObject.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.io.FileInputStream; 3 | import java.io.FileOutputStream; 4 | import java.io.ObjectInputStream; 5 | import java.io.ObjectOutputStream; 6 | 7 | //Save Object in a file 8 | public class SerializeObject { 9 | public static void main(String[] args) throws Exception { 10 | ObjectOutputStream output = null; 11 | 12 | UserProfile localprofile = new UserProfile( 13 | "Jaime", "jaimito@gmail.com", "Green", "Some other data" 14 | ); 15 | 16 | //Serializable 17 | try { 18 | output = new ObjectOutputStream( new FileOutputStream( "userProfile.txt" ) ); 19 | output.writeObject(localprofile); 20 | } finally { 21 | if (output != null){ 22 | output.close(); 23 | } 24 | } 25 | 26 | //Deserialize 27 | UserProfile restoredprofile; 28 | ObjectInputStream input = null; 29 | try { 30 | input = new ObjectInputStream( new FileInputStream( "userProfile.txt" ) ); 31 | restoredprofile = (UserProfile) input.readObject(); 32 | 33 | System.out.println(restoredprofile); 34 | } finally { 35 | if (input != null){ 36 | input.close(); 37 | } 38 | } 39 | } 40 | } 41 | 42 | class UserProfile implements java.io.Serializable { 43 | private String name, email, themecolor; 44 | public transient String something; 45 | 46 | public UserProfile(String name, String email, String themecolor, String something){ 47 | this.name = name; 48 | this.email = email; 49 | this.themecolor = themecolor; 50 | this.something = something; 51 | } 52 | 53 | public String toString(){ 54 | return "User: " + name + 55 | "\nEmail: " + email + 56 | "\nTheme Color: " + themecolor + 57 | "\nSomething (transient): " + something; 58 | } 59 | } -------------------------------------------------------------------------------- /Lesson3/IO/Example of files and IO/listofFigures.txt: -------------------------------------------------------------------------------- 1 | Circle Triangle Square -------------------------------------------------------------------------------- /Lesson3/IO/Example of files and IO/listofFigures_out.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson3/IO/Example of files and IO/listofFigures_out.txt -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/DependencyInversion.java: -------------------------------------------------------------------------------- 1 | public class DependencyInversion { 2 | public static void main(String[] args) throws Exception { 3 | //Graphic UserInterface 4 | UserInterface.getUserInput( new Graphic() ); 5 | UserInterface.sendtoUserOutput( new Graphic() ); 6 | 7 | System.out.println(); 8 | 9 | //Commmand Line or Terminal UserInterface 10 | UserInterface.getUserInput( new CommandLine() ); 11 | UserInterface.sendtoUserOutput( new CommandLine() ); 12 | } 13 | } 14 | 15 | final class UserInterface { 16 | private UserInterface(){;} 17 | public static void getUserInput(Input in){ 18 | in.getInput(); 19 | }; 20 | public static void sendtoUserOutput(Output out){ 21 | out.sendOutput(); 22 | } 23 | } 24 | 25 | interface Input { 26 | public void getInput(); 27 | } 28 | 29 | interface Output { 30 | public void sendOutput(); 31 | } 32 | 33 | class Graphic implements Input, Output { 34 | public Graphic(){;} 35 | public void getInput() { 36 | System.out.println("Get Mouse Clicks and Movement"); 37 | } 38 | public void sendOutput() { 39 | System.out.println("Show data Graphically"); 40 | } 41 | } 42 | 43 | class CommandLine implements Input, Output { 44 | public CommandLine(){;} 45 | public void getInput() { 46 | System.out.println("Get Commands"); 47 | } 48 | public void sendOutput() { 49 | System.out.println("Print data to terminal"); 50 | } 51 | } -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/InterfaceSegregation.java: -------------------------------------------------------------------------------- 1 | public class InterfaceSegregation { 2 | public static void main(String[] args) throws Exception { 3 | MaquilaFactory maquilaX = new MaquilaFactory(); 4 | SodaFactory sodaX = new SodaFactory(); 5 | CarFactory carX = new CarFactory(); 6 | } 7 | } 8 | 9 | class MaquilaFactory implements ProductionDepartment, DeliveryDepartment{ 10 | public MaquilaFactory(){;} 11 | public void manufacture(){;}; 12 | public void transformRawMaterial(){;}; 13 | public void logistics(){;}; 14 | public void distribution(){;}; 15 | } 16 | 17 | class SodaFactory implements ProductionDepartment, AdministrativeDepartment, InvestigationDepartment{ 18 | public SodaFactory(){;} 19 | public void manufacture(){;}; 20 | public void transformRawMaterial(){;}; 21 | public void administration(){;}; 22 | public void accountancy(){;}; 23 | public void createNewProduct(){;}; 24 | public void costReduction(){;}; 25 | } 26 | 27 | class CarFactory implements ProductionDepartment, InvestigationDepartment{ 28 | public CarFactory(){;} 29 | public void manufacture(){;}; 30 | public void transformRawMaterial(){;}; 31 | public void createNewProduct(){;}; 32 | public void costReduction(){;}; 33 | } 34 | 35 | //Bad Implementation 36 | interface Factory { 37 | public void administration(); 38 | public void manufacture(); 39 | public void accountancy(); 40 | public void transformRawMaterial(); 41 | public void createNewProduct(); 42 | public void costReduction(); 43 | public void logistics(); 44 | public void distribution(); 45 | } 46 | 47 | //Better Implementation applying Interface Segregation 48 | //Segregate Factory interface on Department interfaces 49 | interface AdministrativeDepartment { 50 | public void administration(); 51 | public void accountancy(); 52 | } 53 | 54 | interface ProductionDepartment { 55 | public void manufacture(); 56 | public void transformRawMaterial(); 57 | } 58 | 59 | interface InvestigationDepartment { 60 | public void createNewProduct(); 61 | public void costReduction(); 62 | } 63 | 64 | interface DeliveryDepartment { 65 | public void logistics(); 66 | public void distribution(); 67 | } -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/LiskovSubstitution.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class LiskovSubstitution { 4 | public static void main(String[] args) throws Exception { 5 | PetShopInfoCenter.addProduct( 6 | new Dog(180, 100, 15, "If you Adopt Supplies are Free") 7 | ); 8 | PetShopInfoCenter.addProduct( 9 | new Fish(15, 15) 10 | ); 11 | 12 | System.out.println(PetShopInfoCenter.generateCatalogue()); 13 | } 14 | } 15 | 16 | final class PetShopInfoCenter { 17 | private static ArrayList productCatalogue = new ArrayList(); 18 | 19 | public PetShopInfoCenter() { 20 | ; 21 | } 22 | 23 | public static void addProduct(Animal pet) { 24 | productCatalogue.add(pet); 25 | } 26 | 27 | public static String generateCatalogue(){ 28 | String catalogue = ""; 29 | 30 | for (Animal pet: productCatalogue) { 31 | catalogue += pet.getName() + ":\n\t" + 32 | pet.getCompletePrice() + 33 | "\n\t" + pet.getExtraSupplies() + 34 | "\n\t" + pet.getBuyOptions() + "\n\n"; 35 | } 36 | 37 | return catalogue; 38 | } 39 | } 40 | 41 | //Father Class 42 | abstract class Animal { 43 | private String name; 44 | private int baseprice, suppliesprice; 45 | 46 | public Animal(String name, int baseprice, int suppliesprice) { 47 | this.name = name; 48 | this.baseprice = baseprice; 49 | this.suppliesprice = suppliesprice; 50 | } 51 | 52 | public String getName() { 53 | return this.name; 54 | } 55 | public String getCompletePrice() { 56 | return "Animal Price: $" + this.baseprice + ".00 + Supplies Price: $" + this.suppliesprice + 57 | ".00\n\tTotal Price: $" + (this.baseprice + this.suppliesprice) + ".00"; 58 | } 59 | 60 | public abstract String getExtraSupplies(); 61 | public abstract String getBuyOptions(); 62 | } 63 | 64 | //Child Class 65 | class Dog extends Animal { 66 | private String otherrelateddata; 67 | private int obligatorySuppliesprice, optionalSuppliesprice; 68 | public Dog(int baseprice, int obligatory, int optional, String otherrelateddata) { 69 | super("Dog", baseprice, obligatory + optional); 70 | this.otherrelateddata = otherrelateddata; 71 | this.obligatorySuppliesprice = obligatory; 72 | this.optionalSuppliesprice = optional; 73 | } 74 | 75 | public String getExtraSupplies(){ 76 | return "\tObligatory: Vaccines, Food 50kg\t($"+ 77 | this.obligatorySuppliesprice+ 78 | ".00)\n\t\tOptional: dog collar & harness\t($"+ 79 | this.optionalSuppliesprice+".00)"; 80 | }; 81 | 82 | public String getBuyOptions(){ 83 | return "Breeds: Golden Retriever, Schnauzer, Husky\n\t" + this.otherrelateddata; 84 | }; 85 | } 86 | 87 | //Child Class 88 | class Fish extends Animal { 89 | public Fish(int baseprice, int suppliesprice) { 90 | super("Fish", baseprice, suppliesprice); 91 | } 92 | 93 | public String getExtraSupplies(){ 94 | return "\tFishbowl, Food, Fungicide Drops"; 95 | }; 96 | 97 | public String getBuyOptions(){ 98 | return "Breeds: Beta, Koi, Angel\n\t"; 99 | }; 100 | } -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/OpenClosed.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class OpenClosed { 4 | private static ArrayList universityprocedures = new ArrayList(); 5 | private static int idcounter = 17000; 6 | 7 | public static void main(String[] args) throws Exception { 8 | //Incriptions 9 | newincription(new FirstYearStudent("Personal Identity Document Data")); 10 | newincription(new ReEntryStudent("14101010")); 11 | newincription(new TransferedStudent("Previous Study on X University")); 12 | 13 | System.out.println("\nProcedures:"); 14 | 15 | for (PaperWork procedure: universityprocedures) { 16 | System.out.println(procedure); 17 | } 18 | } 19 | // interface instance 20 | public static void newincription(Inscription inscription){ 21 | universityprocedures.add( inscription.procedure(idcounter) ); 22 | idcounter++; 23 | } 24 | } 25 | 26 | class PaperWork { 27 | private int ID; 28 | private boolean automated; 29 | private String state, typeofprocedure, information; 30 | 31 | public PaperWork(int id, boolean automated, String state, String typeofprocedure, String information) { 32 | this.ID = id; 33 | this.automated = automated; 34 | this.state = state; //"InProcess" "Aproved" "Rejected" 35 | this.typeofprocedure = typeofprocedure; //"Inscription" "AssignCourses" "UnassignCourse" ... 36 | this.information = information; //Some data to Store 37 | } 38 | 39 | public String toString(){ 40 | return this.ID + " " + this.state + " " + typeofprocedure + " " + 41 | ( (automated) ? "Automated" : "Manual" ) + 42 | "\n\t" + this.information; 43 | } 44 | } 45 | 46 | interface Inscription { 47 | public PaperWork procedure(int ID); 48 | } 49 | 50 | class FirstYearStudent implements Inscription { 51 | private String personalidentitydocument; 52 | public FirstYearStudent(String personalidentitydocument){ 53 | this.personalidentitydocument = personalidentitydocument; 54 | } 55 | public PaperWork procedure(int ID) { 56 | System.out.println("Inscription of New Student"); 57 | return new PaperWork(ID, false, "InProcess", "Inscription", personalidentitydocument); 58 | } 59 | } 60 | 61 | class ReEntryStudent implements Inscription { 62 | private String studentId; 63 | public ReEntryStudent(String studentId){ 64 | this.studentId = studentId; 65 | } 66 | public PaperWork procedure(int ID) { 67 | System.out.println("Inscription of Re-Entry Student"); 68 | return new PaperWork(ID, true, "InProcess", "Inscription", studentId); 69 | } 70 | } 71 | 72 | class TransferedStudent implements Inscription { 73 | private String previousStudies; 74 | public TransferedStudent(String previousStudies){ 75 | this.previousStudies = previousStudies; 76 | } 77 | public PaperWork procedure(int ID) { 78 | System.out.println("Inscription of Transfered Student"); 79 | return new PaperWork(ID, false, "InProcess", "Inscription", previousStudies); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/SingleResponsibility.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | public class SingleResponsibility { 5 | 6 | public static void main(String[] args) throws Exception { 7 | HashMap companyWorkers = new HashMap(); 8 | 9 | //Adding two workers 10 | companyWorkers.put(170015, 11 | new Worker(170015, 5000, 20, "John Johnz", "Project Developer") 12 | ); 13 | companyWorkers.put(170016, 14 | new Worker(170016, 5100, 20, "Rubi Ramos", "Project Manager") 15 | ); 16 | 17 | //Initialize overtime hour payment for the two types of Job Titles 18 | SalaryCalculator.initOvertimeHourPayment(); 19 | 20 | //Calculate Salary without extra hours 21 | HashMap companyWorkersSalaries = SalaryCalculator.calculateWorkersSalary(companyWorkers); 22 | 23 | //Print to Console 24 | System.out.println("Salaries without extra hours:"); 25 | System.out.println( companyWorkers.get(170015) + ",\n\tSalary: " + companyWorkersSalaries.get(170015) + " money unit" ); 26 | System.out.println( companyWorkers.get(170016) + ",\n\tSalary: " + companyWorkersSalaries.get(170016) + " money unit" ); 27 | 28 | //Adding Extra Hours 29 | companyWorkers.replace(170015, 30 | companyWorkers.get(170015).addExtraHour(10) ); 31 | companyWorkers.replace(170016, 32 | companyWorkers.get(170016).addExtraHour(5) ); 33 | 34 | //Calculate Salary without extra hours 35 | companyWorkersSalaries = SalaryCalculator.calculateWorkersSalary(companyWorkers); 36 | 37 | //Print to Console 38 | System.out.println("\n\nSalaries with extra hours:"); 39 | System.out.println( companyWorkers.get(170015) + ",\n\tSalary: " + companyWorkersSalaries.get(170015) + " money unit" ); 40 | System.out.println( companyWorkers.get(170016) + ",\n\tSalary: " + companyWorkersSalaries.get(170016) + " money unit" ); 41 | } 42 | } 43 | 44 | //This class is just responsible of managing worker data 45 | class Worker { 46 | private int basesalary, workhours, extrahourspermonth, ID; 47 | private String fullname, jobtitle; 48 | 49 | public Worker(int id, int basesalary, int workhours, String fullname, String jobtitle) { 50 | this.ID = id; 51 | this.basesalary = basesalary; 52 | this.workhours = workhours; 53 | this.fullname = fullname; 54 | this.jobtitle = jobtitle; 55 | } 56 | 57 | public Worker addExtraHour(int hoursperday){ 58 | this.extrahourspermonth += hoursperday; 59 | return this; 60 | } 61 | 62 | public void resetExtraHour(){ 63 | this.extrahourspermonth = 0; 64 | } 65 | 66 | public int getBaseSalary(){ 67 | return this.basesalary; 68 | } 69 | public int getWorkHours(){ 70 | return this.workhours; 71 | } 72 | public int getExtraHours(){ 73 | return this.extrahourspermonth; 74 | } 75 | public String getFullName(){ 76 | return this.fullname; 77 | } 78 | public String getJobTitle(){ 79 | return this.jobtitle; 80 | } 81 | 82 | public String toString(){ 83 | return this.fullname + " " + this.jobtitle; 84 | } 85 | } 86 | 87 | //This class is just responsible of calculate the salaries 88 | final class SalaryCalculator { 89 | private static HashMap extrahours = new HashMap(); 90 | 91 | private SalaryCalculator() { 92 | ; 93 | } 94 | public static void initOvertimeHourPayment() { 95 | extrahours.put("Project Developer", 40); 96 | extrahours.put("Project Manager", 25); 97 | } 98 | 99 | public static HashMap calculateWorkersSalary(HashMap companyWorkers) { 100 | HashMap companyWorkersSalaries = new HashMap(); 101 | 102 | for(Map.Entry workers : companyWorkers.entrySet()) { 103 | Integer id = workers.getKey(); 104 | Worker worker = workers.getValue(); 105 | int salary = worker.getBaseSalary() + 106 | worker.getExtraHours() * extrahours.get( worker.getJobTitle() ); 107 | 108 | companyWorkersSalaries.put(id, salary); 109 | } 110 | 111 | return companyWorkersSalaries; 112 | } 113 | } -------------------------------------------------------------------------------- /Lesson3/SOLID/Example of SOLID principles/Solid_principles.txt: -------------------------------------------------------------------------------- 1 | Single Responsibility 2 | Only one job to do 3 | Open Closed 4 | Open for extension but closed for modifications 5 | Liskov's Substitution 6 | Objects can be subtitutted by their subclasses 7 | Interface Segregation 8 | Don't Depend on things you won't need 9 | Dependency Inversion 10 | High-level modules should not depend upon low-level modules 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lesson4/Exception Handling practice/HandlingExceptions.java: -------------------------------------------------------------------------------- 1 | 2 | public class HandlingExceptions { 3 | 4 | public static void main(String [] args) throws Exception{ 5 | //Limit $2000.00 6 | CreditCard card = new CreditCard(62656565,2000.0); 7 | System.out.println("Credit Card State:"); 8 | System.out.println(card.getCreditState()); 9 | 10 | 11 | try { 12 | System.out.println("\n\tBuying $1500.00"); 13 | card.buy(1500.00); 14 | 15 | System.out.println("\nCredit Card State:"); 16 | System.out.println(card.getCreditState()); 17 | 18 | System.out.println("\n\tBuying $800.00\n"); 19 | card.buy(800.00); 20 | }catch(ExceededCreditCardLimitException e) { 21 | System.out.println("Invalid Buy, Limit Exceeded by " + e.getExceededAmount()); 22 | e.printStackTrace(); //Print Stack Trace 23 | } 24 | } 25 | } 26 | 27 | class CreditCard { 28 | private double creditavailable, limit; 29 | private int number; 30 | 31 | public CreditCard(int number, double limit) { 32 | this.number = number; 33 | this.creditavailable = limit; 34 | this.limit = limit; 35 | } 36 | 37 | public void paidCreditCard(double amount) { 38 | creditavailable += amount; 39 | } 40 | 41 | public void buy(double amount) throws ExceededCreditCardLimitException { 42 | if(amount <= creditavailable) { 43 | this.creditavailable -= amount; 44 | }else { 45 | double exceeded = amount - creditavailable; 46 | throw new ExceededCreditCardLimitException(exceeded); 47 | } 48 | } 49 | 50 | public String getCreditState(){ 51 | return "Credit Available: $" + this.creditavailable + " Credit Limit: $" + this.limit; 52 | } 53 | 54 | public double getCreditAvailable() { 55 | return this.creditavailable; 56 | } 57 | 58 | public double getLimit() { 59 | return this.limit; 60 | } 61 | 62 | public int getNumber() { 63 | return this.number; 64 | } 65 | } 66 | 67 | class ExceededCreditCardLimitException extends Exception { 68 | private double exceededamount; 69 | 70 | public ExceededCreditCardLimitException(double exceededamount) { 71 | this.exceededamount = exceededamount; 72 | } 73 | 74 | public double getExceededAmount() { 75 | return exceededamount; 76 | } 77 | } -------------------------------------------------------------------------------- /Lesson4/FunctionalInterfaces/FunctionalInterfaces.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.Arrays; 3 | import java.util.LinkedList; 4 | import java.util.function.Predicate; 5 | import java.util.stream.Collectors; 6 | import java.text.DecimalFormat; 7 | 8 | public class FunctionalInterfaces { 9 | 10 | public static void main(String[] args) throws Exception { 11 | //Create a new Grocery Store List 12 | //Arrays.asList: Returns a fixed-size list backed by the specified array 13 | //To be dynamic use LinkedList 14 | List groceryStore = new LinkedList( 15 | Arrays.asList( 16 | new Product(0,"Tomato","Fruit",1.75f), 17 | new Product(1,"Avocado","Fruit",5f), 18 | new Product(2,"Lemon","Fruit",0.5f), 19 | new Product(3,"Onion","Vegetable",1.50f), 20 | new Product(4,"Carrot","Vegetable",1.25f), 21 | new Product(5,"Broccoli","Vegetable",2f), 22 | new Product(6,"Shrimp","Seafood",10.99f), 23 | new Product(7,"Chicken","Meat",7.35f), 24 | new Product(8,"Roast Beef","Meat",8.35f) 25 | ) 26 | ); 27 | 28 | //Print each of the products 29 | System.out.println("Original List:"); 30 | groceryStore.forEach( 31 | product -> System.out.println(product) 32 | ); 33 | 34 | 35 | 36 | //Predicate filter of meat categorie 37 | Predicate meatRemover = 38 | (Product product) -> "Meat".equals(product.categorie); 39 | 40 | //Remove meat categories 41 | groceryStore.removeIf(meatRemover); 42 | //Print each of the products 43 | System.out.println("\n\nWithout Meat List:"); 44 | groceryStore.forEach(product -> System.out.println(product)); 45 | 46 | 47 | 48 | //Predicate filter of expensive product 49 | Predicate expensiveRemover = 50 | (Product product) -> product.price > 5f; 51 | 52 | //Remove expensive product 53 | groceryStore.removeIf(expensiveRemover); 54 | //Print each of the products 55 | System.out.println("\n\nWithout Expensive & Meat List:"); 56 | groceryStore.forEach(product -> System.out.println(product)); 57 | 58 | 59 | 60 | //Just Filter First Fruit without eliminating the other products 61 | System.out.println("\n\nFilter First Fruit:"); 62 | System.out.println( 63 | groceryStore.stream().filter( 64 | (Product product) -> product.categorie.equals("Fruit") 65 | ).findFirst() 66 | ); 67 | 68 | //Filter Fruit new List 69 | System.out.println("\n\nFilter All Fruit:"); 70 | System.out.println( 71 | groceryStore.stream().filter( 72 | (Product product) -> product.categorie.equals("Fruit") 73 | ).collect( Collectors.toList() ) 74 | ); 75 | 76 | //Print each of the products 77 | System.out.println("\nDon't eliminate the other products just filter:"); 78 | groceryStore.forEach(product -> System.out.println(product)); 79 | } 80 | } 81 | 82 | class Product { 83 | public int id; 84 | public String name, categorie; 85 | public float price; 86 | 87 | public Product(int id, String name, String categorie, float price) { 88 | this.id = id; 89 | this.name = name; 90 | this.categorie = categorie; 91 | this.price = price; 92 | } 93 | 94 | public String toString(){ 95 | return ( this.name + (new DecimalFormat(" $0.00")).format(this.price) ); 96 | } 97 | } -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nabenik 5 | DemoFunctional 6 | 1.0-SNAPSHOT 7 | jar 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/src/main/java/com/nabenik/Main.java: -------------------------------------------------------------------------------- 1 | package com.nabenik; 2 | 3 | /** 4 | * 5 | * @author tuxtor 6 | */ 7 | public class Main { 8 | 9 | /** 10 | * Java old days demonstration 11 | */ 12 | public void doItInTheOldWay(){ 13 | MyFunctionalInterface objImplementation = new MyFunctionalInterface() { 14 | @Override 15 | public void doSomethingFunctional(String txt) { 16 | System.out.println(txt); 17 | } 18 | }; 19 | objImplementation.doSomethingFunctional("Hello in the old way"); 20 | } 21 | 22 | public void doItWithLambdas(){ 23 | MyFunctionalInterface objImplementationOne = (String x) -> System.out.println(x); 24 | objImplementationOne.doSomethingFunctional("Hello from lambda fashion"); 25 | 26 | MyFunctionalInterface objImplementationTwo = x -> System.out.println(x); 27 | objImplementationTwo.doSomethingFunctional("Hello from short syntax"); 28 | 29 | MyFunctionalInterface objImplementationThree = x -> { 30 | objImplementationTwo.doSomethingFunctional("Hello from complex syntax"); 31 | System.out.println(x); 32 | System.out.println("Bye from complex syntax"); 33 | }; 34 | objImplementationThree.doSomethingFunctional("Regular code in complex syntax"); 35 | doSomethingHighOrder(objImplementationThree); 36 | } 37 | 38 | public void doSomethingHighOrder(MyFunctionalInterface behaviour){ 39 | behaviour.doSomethingFunctional("in high order way"); 40 | } 41 | 42 | public static void main(String[] args){ 43 | Main mainInstance = new Main(); 44 | //Calling the old implementation 45 | //mainInstance.doItInTheOldWay(); 46 | mainInstance.doItWithLambdas(); 47 | 48 | MyFunctionalInterface aBehaviour = System.out::println; 49 | mainInstance.doSomethingHighOrder(aBehaviour); 50 | 51 | MyFunctionalInterface bBehaviour = x -> { 52 | x = "Doing something ".concat(x); 53 | System.out.println(x); 54 | System.out.println("Making java great again"); 55 | }; 56 | mainInstance.doSomethingHighOrder(bBehaviour); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/src/main/java/com/nabenik/MyFunctionalInterface.java: -------------------------------------------------------------------------------- 1 | package com.nabenik; 2 | 3 | /** 4 | * 5 | * @author tuxtor 6 | */ 7 | public interface MyFunctionalInterface { 8 | abstract void doSomethingFunctional(String txt); 9 | } 10 | -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/target/classes/com/nabenik/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Lambda Demo/target/classes/com/nabenik/Main$1.class -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/target/classes/com/nabenik/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Lambda Demo/target/classes/com/nabenik/Main.class -------------------------------------------------------------------------------- /Lesson4/Lambda Demo/target/classes/com/nabenik/MyFunctionalInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Lambda Demo/target/classes/com/nabenik/MyFunctionalInterface.class -------------------------------------------------------------------------------- /Lesson4/Multi Threading practice/CAAD001X_L4_MT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Multi Threading practice/CAAD001X_L4_MT.png -------------------------------------------------------------------------------- /Lesson4/Multi Threading practice/MultiThreading.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Random; 3 | import java.lang.InterruptedException; 4 | import java.util.Scanner; 5 | 6 | public class MultiThreading { 7 | 8 | public static void main(String[] args) throws Exception { 9 | Scanner inputReader = new Scanner(System.in); 10 | String userinput; 11 | 12 | Chef chef = new Chef(); 13 | Entry comingcustomers = new Entry(); 14 | Attender attender1 = new Attender(0); 15 | Attender attender2 = new Attender(1); 16 | 17 | chef.start(); 18 | comingcustomers.start(); 19 | attender1.start(); 20 | attender2.start(); 21 | 22 | //Stop with any key, except just Enter 23 | while(true){ 24 | userinput = inputReader.next(); 25 | chef.end(); 26 | comingcustomers.end(); 27 | attender1.end(); 28 | attender2.end(); 29 | System.exit(0); 30 | } 31 | } 32 | } 33 | 34 | final class FoodStock { 35 | private static int burger, sandwich, salad; 36 | 37 | private FoodStock() { 38 | ; 39 | } 40 | public static synchronized boolean cooksellburger(String action) { 41 | if(action.equals("cook")) { 42 | burger++; 43 | return true; 44 | } else if (action.equals("sell")) { 45 | if(burger > 0){ 46 | burger--; 47 | return true; 48 | } 49 | } 50 | return false; 51 | } 52 | public static synchronized boolean cooksellsandwich(String action) { 53 | if(action.equals("cook")) { 54 | sandwich++; 55 | return true; 56 | } else if (action.equals("sell")) { 57 | if(sandwich > 0){ 58 | sandwich--; 59 | return true; 60 | } 61 | } 62 | return false; 63 | } 64 | public static synchronized boolean cooksellsalad(String action) { 65 | if(action.equals("cook")) { 66 | salad++; 67 | return true; 68 | } else if (action.equals("sell")) { 69 | if(salad > 0){ 70 | salad--; 71 | return true; 72 | } 73 | } 74 | return false; 75 | } 76 | 77 | public String toString(){ 78 | return "\tFood Stock burger: " + burger + " sandwich: " + sandwich + " salad: " + salad; 79 | } 80 | } 81 | 82 | final class CustomerQueues { 83 | private static LinkedList customerQueue1 = new LinkedList(); 84 | private static LinkedList customerQueue2 = new LinkedList(); 85 | 86 | private CustomerQueues() { 87 | ; 88 | } 89 | 90 | public static void enterCustomer(int queue, Customer customer) { 91 | if(queue == 0) 92 | customerQueue1.addLast(customer); 93 | else 94 | customerQueue2.addLast(customer); 95 | } 96 | 97 | public static Customer attendCustomer(int queue) { 98 | if(queue == 0){ 99 | if(customerQueue1.size() > 0) 100 | return customerQueue1.removeFirst(); 101 | return null; 102 | } 103 | if(customerQueue2.size() > 0) 104 | return customerQueue2.removeFirst(); 105 | return null; 106 | } 107 | 108 | public String toString(){ 109 | return "\tQueue 1: " + customerQueue1 + 110 | "\n\tQueue 2: " + customerQueue2; 111 | } 112 | } 113 | 114 | class Customer { 115 | public int id, timetodecide; 116 | public String desiredfood; 117 | 118 | public Customer(int id, int timetodecide, String desiredfood){ 119 | this.id = id; 120 | this.timetodecide = timetodecide; 121 | this.desiredfood = desiredfood; 122 | } 123 | 124 | public String toString(){ 125 | return "Customer #" + this.id; 126 | } 127 | } 128 | 129 | class Chef extends Thread { 130 | Random randomgenerator = new Random(); 131 | private boolean threadalive = true; 132 | 133 | public Chef() { 134 | ; 135 | } 136 | 137 | public void run() { 138 | int timetocook = 0, wichfood = 0; 139 | while(this.threadalive){ 140 | timetocook = 2000 + 1000*randomgenerator.nextInt(3); 141 | 142 | try { 143 | this.sleep(timetocook); 144 | 145 | wichfood = randomgenerator.nextInt(3); 146 | System.out.print("Chef on " + (timetocook/1000) + " seconds Cook a "); 147 | switch(wichfood){ 148 | case 0: 149 | FoodStock.cooksellburger("cook"); 150 | System.out.println("burger"); 151 | break; 152 | case 1: 153 | FoodStock.cooksellsandwich("cook"); 154 | System.out.println("sandwich"); 155 | break; 156 | case 2: 157 | FoodStock.cooksellsalad("cook"); 158 | System.out.println("salad"); 159 | break; 160 | } 161 | } catch(InterruptedException e){ 162 | System.out.println("Chef Interrupted"); 163 | } 164 | } 165 | } 166 | 167 | public void end(){ 168 | this.threadalive = false; 169 | } 170 | } 171 | 172 | class Entry extends Thread { 173 | Random randomgenerator = new Random(); 174 | private static int IDs; 175 | private boolean threadalive = true; 176 | 177 | public Entry() { 178 | ; 179 | } 180 | 181 | public void run() { 182 | int timecustomerenter = 0; 183 | 184 | while(this.threadalive){ 185 | timecustomerenter = 1000 + 1000*randomgenerator.nextInt(3); 186 | 187 | try { 188 | this.sleep(timecustomerenter); 189 | this.entry(timecustomerenter); 190 | } catch(InterruptedException e){ 191 | System.out.println("Entry Interrupted"); 192 | } 193 | } 194 | } 195 | 196 | public void entry(int timecustomerenter){ 197 | int wichqueue = randomgenerator.nextInt(2);; 198 | int wichfood = randomgenerator.nextInt(3); 199 | int timetodecide = 1000 + 1000*randomgenerator.nextInt(3); 200 | String foodname = ""; 201 | 202 | switch(wichfood){ 203 | case 0: 204 | foodname = "burger"; 205 | break; 206 | case 1: 207 | foodname = "sandwich"; 208 | break; 209 | case 2: 210 | foodname = "salad"; 211 | break; 212 | } 213 | 214 | 215 | CustomerQueues.enterCustomer(wichqueue, 216 | new Customer(IDs++, timetodecide, foodname) 217 | ); 218 | 219 | System.out.println("Customer #" + IDs + " enters " + (timecustomerenter/1000) + "seconds later to queue " + (wichqueue + 1)); 220 | } 221 | 222 | public void end(){ 223 | this.threadalive = false; 224 | } 225 | } 226 | 227 | class Attender extends Thread { 228 | private int wichqueue; 229 | private boolean threadalive = true; 230 | public Attender(int wichqueue) { 231 | this.wichqueue = wichqueue; 232 | } 233 | 234 | public void run() { 235 | int timetodecide = 0; 236 | Customer customer; 237 | 238 | while(this.threadalive){ 239 | customer = CustomerQueues.attendCustomer(this.wichqueue); 240 | 241 | if(customer != null){ 242 | try { 243 | this.sleep(customer.timetodecide); 244 | this.attend(customer); 245 | } catch(InterruptedException e){ 246 | System.out.println("Attender Interrupted"); 247 | } 248 | } else { 249 | try { 250 | this.sleep(500); 251 | } catch(InterruptedException e){ 252 | System.out.println("Attender Interrupted"); 253 | } 254 | } 255 | } 256 | } 257 | public void attend(Customer customer){ 258 | boolean sold = true; 259 | int wait = 0; 260 | while(sold){ 261 | switch(customer.desiredfood){ 262 | case "burger": 263 | if(FoodStock.cooksellburger("sell")) 264 | sold = false; 265 | break; 266 | case "sandwich": 267 | if(FoodStock.cooksellsandwich("sell")) 268 | sold = false; 269 | break; 270 | case "salad": 271 | if(FoodStock.cooksellsalad("sell")) 272 | sold = false; 273 | break; 274 | } 275 | if(sold){ 276 | try { 277 | this.sleep(1000); 278 | wait++; 279 | } catch(InterruptedException e){ 280 | System.out.println("Attender Interrupted wait food"); 281 | } 282 | } 283 | } 284 | System.out.println("Customer #" + (customer.id + 1) + " buy a " + customer.desiredfood + " and in " + (customer.timetodecide / 1000) + "seconds and wait for food " + wait + "seconds"); 285 | } 286 | 287 | public void end(){ 288 | this.threadalive = false; 289 | } 290 | } 291 | 292 | -------------------------------------------------------------------------------- /Lesson4/Multi Threading practice/movies.txt: -------------------------------------------------------------------------------- 1 | Star Trek Beyond 2 | Moana 3 | Arrival 4 | Star Wars: Rogue one 5 | Split 6 | Fantastic Beasts and where to find them 7 | Logan 8 | Justice League 9 | Alien: Covenant 10 | Thor: Ragnarok 11 | The Mummy 12 | Kingsman: The Golden Circle 13 | Wonder Woman 14 | Star Wars: Episode VIII - The Last Jedi 15 | Guardians of the Galaxy: Vol 2 -------------------------------------------------------------------------------- /Lesson4/StreamsDemo/StreamsDemo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nabenik 5 | StreamsDemo 6 | 1.0-SNAPSHOT 7 | jar 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | -------------------------------------------------------------------------------- /Lesson4/StreamsDemo/StreamsDemo/src/main/java/com/nabenik/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.nabenik; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.Comparator; 11 | import java.util.List; 12 | import java.util.Random; 13 | import java.util.stream.Collector; 14 | import java.util.stream.Collectors; 15 | 16 | /** 17 | * 18 | * @author tuxtor 19 | */ 20 | public class Main { 21 | 22 | public List generateRandomList(){ 23 | List numbersList = new ArrayList<>(); 24 | Random rGenerator = new Random(); 25 | for (int i = 0; i < 20; i++) { 26 | numbersList.add(rGenerator.nextInt(255)); 27 | } 28 | return numbersList; 29 | } 30 | 31 | public void oldSort(){ 32 | List unsortedList = generateRandomList(); 33 | System.out.println("Old way"); 34 | System.out.println(unsortedList); 35 | Collections.sort(unsortedList, new Comparator() { 36 | @Override 37 | public int compare(Integer o1, Integer o2) { 38 | return o1.compareTo(o2); 39 | } 40 | }); 41 | System.out.println(unsortedList); 42 | } 43 | 44 | public void lambdaSort(){ 45 | List theList = generateRandomList(); 46 | System.out.println("Lambda way"); 47 | System.out.println(theList); 48 | theList.sort((x,y) -> x.compareTo(y)); 49 | System.out.println(theList); 50 | } 51 | 52 | public void oldFilter(){ 53 | List unfilteredList = generateRandomList(); 54 | System.out.println("Old way"); 55 | List filteredList = new ArrayList<>(); 56 | for (Integer number : unfilteredList) { 57 | if(number > 50){ 58 | filteredList.add(number); 59 | } 60 | } 61 | System.out.println(filteredList); 62 | } 63 | 64 | public void lambdaFilter(){ 65 | System.out.println("Lambda way"); 66 | List unfilteredList = generateRandomList(); 67 | List filteredList = unfilteredList.stream() 68 | .filter(x -> x > 50) 69 | .collect(Collectors.toList()); 70 | System.out.println(filteredList); 71 | } 72 | 73 | public static void main(String[] args){ 74 | //Sorting demo 75 | Main mainInstance = new Main(); 76 | mainInstance.oldSort(); 77 | mainInstance.lambdaSort(); 78 | //Filtering demo 79 | mainInstance.oldFilter(); 80 | mainInstance.lambdaFilter(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Lesson4/StreamsDemo/StreamsDemo/target/classes/com/nabenik/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/StreamsDemo/StreamsDemo/target/classes/com/nabenik/Main$1.class -------------------------------------------------------------------------------- /Lesson4/StreamsDemo/StreamsDemo/target/classes/com/nabenik/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/StreamsDemo/StreamsDemo/target/classes/com/nabenik/Main.class -------------------------------------------------------------------------------- /Lesson4/Threads demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nabenik 5 | DemoThread 6 | 1.0-SNAPSHOT 7 | jar 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | -------------------------------------------------------------------------------- /Lesson4/Threads demo/src/main/java/com/nabenik/Main.java: -------------------------------------------------------------------------------- 1 | package com.nabenik; 2 | 3 | /** 4 | * 5 | * @author tuxtor 6 | */ 7 | public class Main { 8 | 9 | 10 | public static void main(String[] args) throws InterruptedException{ 11 | Thread thread1 = new ThreadObject(); 12 | Thread thread2 = new Thread(new ThreadAltObject()); 13 | 14 | //thread1.start(); 15 | thread2.start(); 16 | 17 | //Thread.sleep(500); 18 | //thread1.interrupt(); 19 | //thread2.interrupt(); 20 | thread2.join(); 21 | System.out.println("Main thread will continue"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Lesson4/Threads demo/src/main/java/com/nabenik/ThreadAltObject.java: -------------------------------------------------------------------------------- 1 | package com.nabenik; 2 | 3 | /** 4 | * 5 | * @author tuxtor 6 | */ 7 | public class ThreadAltObject implements Runnable { 8 | 9 | /**@Override 10 | public void run(){ 11 | System.out.println("Hello from thread 2"); 12 | for (int i = 0; i < 20; i++) { 13 | try { 14 | Thread.sleep(1500); 15 | } catch (InterruptedException e) { 16 | System.out.println("Thread has been interrupted"); 17 | Thread.currentThread().interrupt(); 18 | } 19 | System.out.println("Count from thread 2 - " + i); 20 | } 21 | }**/ 22 | 23 | @Override 24 | public void run(){ 25 | System.out.println("Hello from thread 2"); 26 | for (int i = 0; i < Integer.MAX_VALUE; i++) { 27 | if(i%10_000_000 == 0){ 28 | System.out.println("Count from thread 2 - " + i); 29 | 30 | if(Thread.interrupted()){ 31 | System.out.println("Thread 2 has been interrupted"); 32 | break; 33 | } 34 | } 35 | } 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Lesson4/Threads demo/src/main/java/com/nabenik/ThreadObject.java: -------------------------------------------------------------------------------- 1 | package com.nabenik; 2 | 3 | /** 4 | * 5 | * @author tuxtor 6 | */ 7 | public class ThreadObject extends Thread { 8 | 9 | @Override 10 | public void run(){ 11 | System.out.println("Hello from thread 1"); 12 | for (int i = 0; i < 20; i++) { 13 | try { 14 | Thread.sleep(1000); 15 | } catch (InterruptedException e) { 16 | System.out.println("Thread has been interrupted"); 17 | Thread.currentThread().interrupt(); 18 | } 19 | System.out.println("Count from thread 1 - " + i); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson4/Threads demo/target/classes/com/nabenik/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Threads demo/target/classes/com/nabenik/Main.class -------------------------------------------------------------------------------- /Lesson4/Threads demo/target/classes/com/nabenik/ThreadAltObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Threads demo/target/classes/com/nabenik/ThreadAltObject.class -------------------------------------------------------------------------------- /Lesson4/Threads demo/target/classes/com/nabenik/ThreadObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromasterandroid/java/67d4d148e728b7cbf691aeb9180d5ffba97b2d85/Lesson4/Threads demo/target/classes/com/nabenik/ThreadObject.class -------------------------------------------------------------------------------- /Lesson5/Introduction/EchoServer/EchoServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 3 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 6 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 7 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 8 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 9 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 10 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 11 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 12 | * SUCH DAMAGE.*/ 13 | 14 | import java.net.*; 15 | import java.io.*; 16 | 17 | public class EchoServer{ 18 | public static void main(String[] args) throws IOException { 19 | if(args.length != 1){ 20 | System.err.println("Usage: java EchoServer "); 21 | System.exit(1); 22 | } 23 | 24 | int portNumber = Integer.parseInt(args[0]); 25 | 26 | try{ 27 | ServerSocket serverSocket = new ServerSocket(Integer.parseInt(args[0])); 28 | Socket clientSocket = serverSocket.accept(); 29 | PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true); 30 | BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); 31 | }catch(IOException e){ 32 | System.out.println(" Exception caught when trying to listen on port " + portNumber + " or listening for a connection"); 33 | System.out.println(e.getMessage()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lesson5/Introduction/Echoclient/EchoClient.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | 4 | public class EchoClient{ 5 | public static void main(String[] args) { 6 | 7 | if(args.length != 2){ 8 | System.err.println("Usage: java EchoClient "); 9 | System.exit(1); 10 | } 11 | String hostName = args[0]; 12 | int portNumber = Integer.parseInt(args[1]); 13 | 14 | try{ 15 | Socket echoSocket = new Socket(hostName, portNumber); 16 | PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true); 17 | BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); 18 | BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); 19 | String userInput; 20 | while((userInput = stdIn.readLine())!= null){ 21 | out.println(userInput); 22 | System.out.println("echo: " + in.readLine()); 23 | } 24 | }catch(UnknownHostException e){ 25 | System.err.println("Don't know about host " + hostName); 26 | System.exit(1); 27 | }catch(IOException e){ 28 | System.out.println("Couldn't get I/O for the connection to " + hostName); 29 | System.exit(1); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lesson5/Introduction/URL Connetion Example/URLPost.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | 4 | public class URLPost { 5 | public static void main(String[] args) throws Exception { 6 | 7 | // Check the input arguments, has to be the url and a value to post 8 | if (args.length != 2) { 9 | System.err.println("Usage: java post " 10 | + "http://" 11 | + " name_to_post"); 12 | System.exit(1); 13 | } 14 | 15 | 16 | // Encode the value to post string to avoid problem with special characters. 17 | String stringToPost = URLEncoder.encode(args[1], "UTF-8"); 18 | 19 | // create the URL Object and open a connection 20 | URL url = new URL(args[0]); 21 | URLConnection connection = url.openConnection(); 22 | // Enable write capability on the url 23 | connection.setDoOutput(true); 24 | // get the connection outputstream, write to it and close it 25 | OutputStreamWriter out = new OutputStreamWriter( 26 | connection.getOutputStream()); 27 | 28 | //Write to de connection, the method write will do a http post to the url. 29 | out.write("name=" + stringToPost); 30 | out.close(); 31 | 32 | // Get the connection inputstream, 33 | BufferedReader in = new BufferedReader( 34 | new InputStreamReader( 35 | connection.getInputStream())); 36 | String welcomeMessage; 37 | // read the returned lines and print to standar output 38 | while ((welcomeMessage = in.readLine()) != null) { 39 | System.out.println(welcomeMessage); 40 | } 41 | in.close(); 42 | } 43 | } -------------------------------------------------------------------------------- /Lesson5/Introduction/Working with URLS/URLConnectionReader.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | public class URLConnectionReader { 5 | public static void main(String[] args) throws Exception { 6 | URL oracle = new URL("http://www.example.com/docs/resource1.html"); 7 | URLConnection yc = oracle.openConnection(); 8 | BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); 9 | String inputLine; 10 | while((inputLine = in.readLine()) != null) 11 | System.out.println(inputLine); 12 | in.close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson5/Introduction/Working with URLS/URLReader.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | public class URLReader { 5 | public static void main(String[] args) throws Exception { 6 | URL oracle = new URL("http://www.example.com/docs/resource1.html"); 7 | BufferedReader in = new BufferedReader( new InputStreamReader(oracle.openStream())); 8 | String inputLine; 9 | while((inputLine = in.readLine()) != null){ 10 | System.out.println(inputLine); 11 | } 12 | in.close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.androidcourse.yosef.clickscounter" 8 | minSdkVersion 23 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | jackOptions { 14 | enabled true 15 | } 16 | compileOptions{ 17 | sourceCompatibility JavaVersion.VERSION_1_8 18 | targetCompatibility JavaVersion.VERSION_1_8 19 | } 20 | } 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | compile fileTree(dir: 'libs', include: ['*.jar']) 31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 32 | exclude group: 'com.android.support', module: 'support-annotations' 33 | }) 34 | compile 'com.android.support:appcompat-v7:25.3.0' 35 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 36 | testCompile 'junit:junit:4.12' 37 | } 38 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\ivany\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/src/androidTest/java/com/androidcourse/yosef/clickscounter/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.androidcourse.yosef.clickscounter; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.androidcourse.yosef.clickscounter", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/src/main/java/com/androidcourse/yosef/clickscounter/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.androidcourse.yosef.clickscounter; 2 | 3 | import android.support.v4.widget.TextViewCompat; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.TextView; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | int count = 0; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | Button buttonReset = (Button) findViewById(R.id.button_reset); 19 | buttonReset.setOnClickListener(view1 -> { 20 | count = 0; 21 | display(0); 22 | 23 | }); 24 | } 25 | 26 | private void display(int number){ 27 | TextView quantityTextView = (TextView) findViewById(R.id.textView); 28 | quantityTextView.setText(""+number); 29 | } 30 | 31 | public void submitCount(View view){ 32 | count = count + 1; 33 | display(count); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Lesson5/Java 8 On Android/Demo Java 8 on Android/Creating my First App/ClicksCounter/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 26 | 27 |