1 00:00:00,960 --> 00:00:04,510 Okay, so now that we have our dependencies defined and 2 00:00:04,510 --> 00:00:08,540 we've run the Gradle command to download them, it's actually really simple to use. 3 00:00:08,540 --> 00:00:11,030 You just import it to a file and use it. 4 00:00:11,030 --> 00:00:14,270 What might not have been clear is that as long as you've checked in your 5 00:00:14,270 --> 00:00:19,030 Build Script using Git or another version control tool, Anyone who has a copy 6 00:00:19,030 --> 00:00:22,360 of your source code can now run the Build command on their computer and 7 00:00:22,360 --> 00:00:25,830 get the same version dependency that you specified. 8 00:00:25,830 --> 00:00:26,900 Pretty cool, right? 9 00:00:26,900 --> 00:00:28,380 No need to check in the JAR files, 10 00:00:28,380 --> 00:00:30,630 because they can get installed the same way that we did. 11 00:00:31,810 --> 00:00:35,980 So this opens up a whole new world of APIs to us, right? 12 00:00:35,980 --> 00:00:38,570 Let's first go play with our new library, and then poke around and 13 00:00:38,570 --> 00:00:39,540 see what else is out there. 14 00:00:41,570 --> 00:00:46,160 Okay, so let's make a new class in our source main Java directory here, 15 00:00:46,160 --> 00:00:49,863 let's make a new class, and let's call it, main right? 16 00:00:49,863 --> 00:00:54,570 We'll make the first file just to play around, so 17 00:00:54,570 --> 00:00:59,856 we'll call it com.team treehouse.reviews.Main. 18 00:00:59,856 --> 00:01:03,410 And then we'll click okay. 19 00:01:03,410 --> 00:01:06,200 I have set up some version control here, so I'm just gonna go ahead and 20 00:01:06,200 --> 00:01:07,880 automatically check that in. 21 00:01:07,880 --> 00:01:10,552 Okay so, here's our Main class here and 22 00:01:10,552 --> 00:01:13,628 let's just write up a quick prove of concept. 23 00:01:13,628 --> 00:01:18,712 Let's imagine that our app allowed reviews of different code snippets. 24 00:01:18,712 --> 00:01:23,802 So what we want here is we wanna provide a way to export the data, those reviews, and 25 00:01:23,802 --> 00:01:28,670 then later import it into a spreadsheet to make further graphs and things. 26 00:01:28,670 --> 00:01:30,730 So this is actually a pretty common request, and 27 00:01:30,730 --> 00:01:33,270 the good news is we really don't have to do that much, right? 28 00:01:33,270 --> 00:01:34,990 Cuz we already have this library. 29 00:01:34,990 --> 00:01:36,900 So let's do this, let's just go ahead and 30 00:01:36,900 --> 00:01:42,170 let's start out with our public static void main method. 31 00:01:42,170 --> 00:01:46,440 And let's just start talking about the CSVPrinter object. 32 00:01:46,440 --> 00:01:48,540 So the way that you do that is you just start typing, right? 33 00:01:48,540 --> 00:01:52,920 So CSVPrinter, oh there it is, that's what we want, CSV Printer, okay? 34 00:01:54,580 --> 00:01:58,540 And we'll call that a printer, and we'll make a new one of them, 35 00:01:58,540 --> 00:02:03,350 and I'm not exactly sure what that is, but let's just see what it comes back with, so 36 00:02:03,350 --> 00:02:05,620 it says it needs an appendable called out. 37 00:02:05,620 --> 00:02:07,250 So this is just a proof of concept but 38 00:02:07,250 --> 00:02:10,760 I happen to know that the system.app where we normally print the console. 39 00:02:10,760 --> 00:02:14,963 That implements the appendable interface, so let's do that, so 40 00:02:14,963 --> 00:02:19,691 system.out is the first parameter here and the next thing I was looking for 41 00:02:19,691 --> 00:02:21,130 was a format, right? 42 00:02:21,130 --> 00:02:24,290 So it's a CSV format and we'll make it excel format, 43 00:02:24,290 --> 00:02:26,320 cuz that's what they're gonna be looking at here. 44 00:02:27,450 --> 00:02:29,310 Right, so we got a little red mark here, let's see why. 45 00:02:31,090 --> 00:02:33,460 Let's surround that with a try and a catch. 46 00:02:33,460 --> 00:02:36,800 We'll just leave that as the default here, this is again just a quick little mock up. 47 00:02:37,820 --> 00:02:40,296 Okay so let's add, let's write this stuff out. 48 00:02:40,296 --> 00:02:46,795 So I'm gonna type printer.printRecord, I saw that that was available, right? 49 00:02:46,795 --> 00:02:49,310 I saw that was available when I was looking at the documentation. 50 00:02:49,310 --> 00:02:52,600 But I don't remember exactly how to use it, so now I could press F1, and 51 00:02:52,600 --> 00:02:56,560 look at that, all the help is here because it's in the Java doc. 52 00:02:56,560 --> 00:02:59,080 Okay, so we just, we put in the different values that we want, and 53 00:02:59,080 --> 00:03:01,940 it takes in an endless amount of objects. 54 00:03:01,940 --> 00:03:04,619 So it'll print, oh that's cool, so I can print out, 55 00:03:04,619 --> 00:03:06,379 not only can I print out the string. 56 00:03:06,379 --> 00:03:11,080 So let's say that we had, we'll just make a couple of fake reviews here. 57 00:03:11,080 --> 00:03:14,838 So I totally thought that that code was five and I said that, I love it, 58 00:03:14,838 --> 00:03:16,254 five out of five, right? 59 00:03:16,254 --> 00:03:20,316 And then let's do another one and 60 00:03:20,316 --> 00:03:25,105 we'll do printRecord, and we'll say 61 00:03:25,105 --> 00:03:30,341 that Chris, our other Java teacher here. 62 00:03:30,341 --> 00:03:32,630 If you haven't seen his stuff yet, it's great. 63 00:03:32,630 --> 00:03:38,420 He gave it a 4 though, and he says pretty good. 64 00:03:38,420 --> 00:03:45,004 Would be better with an annotation or two. 65 00:03:45,004 --> 00:03:48,600 I noticed he used a comma in his review, and that's kind of the edge case that we 66 00:03:48,600 --> 00:03:51,125 were talking about, that was a problem before right? 67 00:03:52,805 --> 00:03:56,857 So, the other thing that's kind of cool that I also wanted to show you real quick, 68 00:03:56,857 --> 00:03:59,470 is that you can also navigate to the source, right? 69 00:03:59,470 --> 00:04:01,780 So if I Cmd+B that or Ctrl+B. 70 00:04:01,780 --> 00:04:02,650 I can actually look and 71 00:04:02,650 --> 00:04:06,942 see how the codes happening because it's an open source, pretty crazy right? 72 00:04:06,942 --> 00:04:07,500 All right, so 73 00:04:07,500 --> 00:04:11,150 we're back here, we're in our file, it automatically gets those imports for me. 74 00:04:11,150 --> 00:04:13,340 I don't know if you saw that pop up. 75 00:04:13,340 --> 00:04:17,007 So I think if we scroll down here and 76 00:04:17,007 --> 00:04:23,087 we run it we should be all good, let's see what happens. 77 00:04:23,087 --> 00:04:25,796 We'll say run, we'll run main. 78 00:04:30,754 --> 00:04:35,510 I forgot a semicolon, there we go. 79 00:04:35,510 --> 00:04:36,390 Now let's go ahead and run that. 80 00:04:37,770 --> 00:04:41,910 Here we go, see, it's comma separated and notice that when the comma happens, 81 00:04:41,910 --> 00:04:42,710 it put it in quotes. 82 00:04:42,710 --> 00:04:46,520 This is how Excel format allows you to have the separator inside the text, but 83 00:04:46,520 --> 00:04:48,090 this did it for us. 84 00:04:48,090 --> 00:04:51,030 Note how it knew about strings and numbers, 85 00:04:51,030 --> 00:04:52,500 that we didn't have to think about any of that. 86 00:04:52,500 --> 00:04:54,150 It just did it all for us. 87 00:04:54,150 --> 00:04:56,550 Just a few lines of code, right? 88 00:04:56,550 --> 00:04:59,680 This is just the beginning of your open source adventures. 89 00:04:59,680 --> 00:05:03,150 So this example that I kinda walked you through works pretty well if you know 90 00:05:03,150 --> 00:05:04,680 exactly what you're looking for. 91 00:05:04,680 --> 00:05:07,510 And I kinda did, right, I showed you this library. 92 00:05:07,510 --> 00:05:09,940 But what if we're looking for something less specific. 93 00:05:09,940 --> 00:05:13,760 For example, let's think about adding some more cool features to our project. 94 00:05:13,760 --> 00:05:16,190 I think it would be great if we could go to any website and 95 00:05:16,190 --> 00:05:17,380 pull information from it. 96 00:05:17,380 --> 00:05:18,930 Like with these code snippets that are there. 97 00:05:18,930 --> 00:05:22,230 Let's go to a website, pull that code snippet down if it didn't have API. 98 00:05:22,230 --> 00:05:24,260 So now I could probably write this myself right? 99 00:05:24,260 --> 00:05:28,120 I understand how HTML tags work and everything like that. 100 00:05:28,120 --> 00:05:30,698 But first, I think we should check if something else is out there 101 00:05:30,698 --> 00:05:32,010 that does this. 102 00:05:32,010 --> 00:05:33,720 So, what I would do is I would search and 103 00:05:33,720 --> 00:05:36,430 say how do you do this and then I come across some technology. 104 00:05:36,430 --> 00:05:40,760 Now it might not be specifically in my language, and, so it says, oh, 105 00:05:40,760 --> 00:05:45,140 it sounds like you are talking about an HTML parser or something along those line. 106 00:05:45,140 --> 00:05:47,100 So that is what I want, so 107 00:05:47,100 --> 00:05:50,150 now logically you'd think that I can just go search Maven for that right? 108 00:05:50,150 --> 00:05:54,810 So let's try that, let's go over here, this is search.maven.org. 109 00:05:54,810 --> 00:05:57,550 So I'm going to search for html parser. 110 00:05:59,250 --> 00:06:01,194 That comes back with something. 111 00:06:01,194 --> 00:06:04,884 Oh, it says it hasn't been updated since 2010, 112 00:06:04,884 --> 00:06:08,087 the last html parser written was in 2010. 113 00:06:08,087 --> 00:06:11,660 Not true, this search is a little bit off. 114 00:06:11,660 --> 00:06:16,510 Now, your other favorite java teacher, Chris, wanted to make sure 115 00:06:16,510 --> 00:06:19,800 that I shared his technique with how he does things like this. 116 00:06:19,800 --> 00:06:25,086 So what Chris does is he goes to Google and he searches just for Maven. 117 00:06:25,086 --> 00:06:26,740 And then what are you searching for? 118 00:06:26,740 --> 00:06:29,110 So, html parsers, so he does that. 119 00:06:29,110 --> 00:06:32,505 And you'll see that there's this great thing here called www.mvmrepository.com. 120 00:06:32,505 --> 00:06:36,330 Now mvm is the word for Maven shortcut, that's kind of how it goes. 121 00:06:36,330 --> 00:06:41,500 This is a little open source website that indexes the Maven site. 122 00:06:41,500 --> 00:06:44,840 So here is one, htmlparser.jar. 123 00:06:44,840 --> 00:06:48,030 We could take a look at it if we wanted to, and 124 00:06:48,030 --> 00:06:53,380 see that it was created on 2011, that's okay. 125 00:06:53,380 --> 00:06:55,940 Let's go ahead and let's search this site, this site looks pretty good. 126 00:06:55,940 --> 00:06:57,610 It may have it in repositories, so HTML parser. 127 00:06:57,610 --> 00:07:01,560 Oh here's one called Jsoup and it shows you how many people are using it, 335. 128 00:07:01,560 --> 00:07:03,470 So that looks pretty nice. 129 00:07:03,470 --> 00:07:06,930 So open this up, and here, oh, August 2015, that's great. 130 00:07:06,930 --> 00:07:09,380 It's been updated recently, I think we should use this one. 131 00:07:09,380 --> 00:07:10,640 Let's use J suit. 132 00:07:10,640 --> 00:07:12,337 So I'd use Jsoup, and that's how right? 133 00:07:12,337 --> 00:07:14,748 I'd just come over back to our dependencies and 134 00:07:14,748 --> 00:07:16,504 I'd pop it in our deps right here. 135 00:07:16,504 --> 00:07:18,920 Deps is the cool way to say dependencies. 136 00:07:18,920 --> 00:07:23,910 Also remember that the majority of active open source project code is actually now 137 00:07:23,910 --> 00:07:26,962 on GitHub and GitHub uses a thing for stars right? 138 00:07:26,962 --> 00:07:29,768 So you can come in and you can search for language colon Java or 139 00:07:29,768 --> 00:07:32,470 whatever they're over here on the side too. 140 00:07:32,470 --> 00:07:35,480 And if you sort by most stars, you'll see the most popular. 141 00:07:35,480 --> 00:07:38,380 And you can cruise around here and see what's out, and see what you find and 142 00:07:38,380 --> 00:07:40,290 share it in the community with us. 143 00:07:40,290 --> 00:07:44,330 And also, don't forget that when you see these, you can contribute. 144 00:07:44,330 --> 00:07:46,340 If you see a spelling error, fix it. 145 00:07:46,340 --> 00:07:47,570 You can do that. 146 00:07:47,570 --> 00:07:48,470 That's a different lesson, though.