Download presentation
Presentation is loading. Please wait.
Published byEugene Gilbert Modified over 8 years ago
1
Hashmap, date, exception Android Club 2015
2
Agenda Hashmap Date Exception handling
3
HashMap Unordered list Based on key-value
4
HashMap: example HashMap countryCodes = new HashMap (); countryCodes.put("UZ", "Uzbekistan"); countryCodes.put("JP", "Japan"); countryCodes.put("US", "United States"); System.out.println(countryCodes.get("UZ" ));
5
HashMap: practice Create HashMap: elements Key: String Value: String Add values: H – Hydron O – Oxygen N – Nitrogen Print Oxygen
6
HashMap: practice 2 Create Hashmap: httpCodes Key: int Value: String 404 – Not found 403 – Forbidden 400 – Bad request Print “Not found”
7
HashMap: practice 3 Create HashMap: capitals Key: String Value: String Uzbekistan – Tashkent Japan – Tokyo US – Washington Print Japan’s capital city
8
Date Date d = new Date(); System.out.println(d);
9
SimpleDateFormat: date Date d = new Date(); SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(sdfDate.format(d));
10
Documentation http://docs.oracle.com/javase/8/docs/api/ja va/text/SimpleDateFormat.htmlhttp://docs.oracle.com/javase/8/docs/api/ja va/text/SimpleDateFormat.html
11
SimpleDateFormat: time SimpleDateFormat sdfTime = new SimpleDateFormat("hh:mm:ss"); System.out.println("Time:"+sdfTime.forma t(d));
12
SimpleDateFormat: practice Show: AM or PM
13
SimpleDateFormat: practice2 Show hour in 0-23 format: PM 07:35:45 -> 19:35:45
14
SimpleDateFormat: practice3 Create new SimpleDateFormat: sdfYearWeek Week in year: XX Create new SimpleDateFormat: sdfMonthWeek Week in month: XX
15
SimpleDateFormat: practice4 Show weekday in number: 1 Show weekday in text: Monday
16
Error Compile time error Run time error
17
Compile time error String name = "Joe"
18
Compile time error: practice Create String: without any value Print String
19
How to handle: compile Fix it!
20
Run time error String[] names = {"Joe"}; System.out.println(names[1]);
21
Run time error: practice Create char array: abc Print index 5 value
22
Try-catch try { String[] names = {"Joe"}; System.out.println(names[1]); } catch (Exception e) { e.printStackTrace(); }
23
Try-catch block: practice int x = 5; int y = 0; System.out.println(x/y); System.out.println(x+y);
24
Try-catch: practice2 String[] names = {"Joe"}; System.out.println(names[-1]);
25
Debugger bug Debug Debugging Debugger
26
Debugger: example int sum = 0; for (int i = 0; i < 10; i++) { int square = i^2; sum+=square; } System.out.println(sum);
27
Debugger: practice Create new class Create main method Calculate sum of numbers from 1 to 10 inclusive Check every step using debugger
28
Questions? Any questions!
29
Review 8-4 Hashmap 6-4 Date Chapter 7 – Exception handling
30
Thank you! Thank you for your attention!
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.