Ghislain_Mike

OOP Thursday

Dec 5th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. /*
  2. write a java program that stores names of 3
  3. students (alice, bob, james) in an array and
  4. display them
  5.     - use list
  6.     - use Set
  7. ------------------------------------------------------------------
  8. create an array list polymorphically
  9.  
  10. Before java 5
  11. List names = new ArrayList(); // no specific data type
  12.  
  13. // Using Generics
  14. List<Integer> names = new ArrayList<Integer>();
  15.  
  16. /* Wrapper classes : allows you to use primitive types as objects
  17.     - int = Integer
  18.     - float = Float
  19.     - String = String
  20. -----------------------------------------------------------------
  21.  
  22. Difference between sets and lists
  23.     - sets do not preserve the order of elements
  24.         - no duplicates
  25.     - lists is the opposite of sets
  26.  
  27. -----------------------------------------------------------------
  28.  
  29. Maps store elements as pairs (key => value), unique pairs
  30. e.g: Create a map to store countries and their capitals
  31.  
  32. rwanda => kigali
  33. kenya => nairobi
  34.  
  35. ------------------------------------------------------------------
  36.  
  37. ORM : object relational mapping
  38.     technology that allows you to map classes to database tables
  39.  
  40. public class BankAccount {}                 java
  41. create table bank_account();                sql
  42.  
  43. ------------------------------------------------------------------
  44.  
  45. MINECOFIN / IFMIS
  46.     - Business Analyst : analysis, design
  47.     - Developer : java, coding
  48.  
  49.     - System Admins : linux
  50.         - System Administration
  51.         - Bash Programming, task automation
  52.         - Network Administration
  53.  
  54.     - Database Admins : postgresql, oracle
  55.         - performance tuning (index, partitioning, replica)
  56.  
  57.     - Support Team
  58.  
  59. */
  60.  
  61. import java.util.Set;
  62. import java.util.HashSet;
  63. import java.util.ArrayList;
  64. import java.util.List;
  65. import java.util.Collections;
  66. import java.util.Map;
  67. import java.util.HashMap;
  68.  
  69. public class MyClass {
  70.     public static void main(String ... args) {
  71.         String[] names1 = new String[3];
  72.         List<String> names2 = new ArrayList<>();
  73.         Set<String> names3 = new HashSet<>();
  74.         Map<String, String> countries = new HashMap<>(); // jdk 8
  75.  
  76.         names1[0] = "alice";
  77.         names1[1] = "bob";
  78.         names1[2] = "james";
  79.  
  80.         names2.add("alice");
  81.         names2.add("bob");
  82.         names2.add("james");
  83.  
  84.         names3.add("alice");
  85.         names3.add("bob");
  86.         names3.add("james");
  87.  
  88.         countries.put("rwanda", "kigali"); // entries
  89.         countries.put("kenya", "nairobi");
  90.         countries.put("congo", "kinshasa");
  91.  
  92.         Collections.sort(names2);
  93.  
  94.         for (String name: names) {
  95.             System.out.println(name);
  96.         }
  97.  
  98.         System.out.println(countries.get("rwanda"));
  99.  
  100.         Set<String> keys = countries.keySet();
  101.         System.out.println(keys);
  102.  
  103.         System.out.println("Country\tCapital");
  104.  
  105.         for (String key : keys) {
  106.             System.out.println(key);
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment