Object Oriented Java


In this series, Mark and Justin walk you through the hoops and hurdles of the Java syntax by providing examples and common mistakes and shortcuts you'll be faced with. By the end you'll have an understanding of all of the syntax as well as common Java tools. You will have built feature-filled programs to simplify your life and wrangle the challenges of junior programming jobs, so if you're ready to learn Java as a first or second programming language then join us!
Object Oriented Java Overview
During this episode, Mark and Justin get the Eclipse Integrated Development Environment(IDE) installed and setup. Additionally, they install the Java Development Kit(JDK) that is required for compiling and running Java programs.
Clock icon0h 24m
[MUSIC] Greetings everyone and welcome to another exciting episode of DevPro.TV. I'm your host Justin Dennison, and in today's episode, well we're getting started with Java, more specifically we've gotta get Java set up. And also we have to install an IDE, whatever that is. And here to help us on that adventure is Mr. Mark Davis. How you doing today Mark? Hey, doing well Justin, thanks for asking. That is that is good to hear. Now before we worry about getting everything installed. Why would we even care about Java? When I think of Java, I think of coffee. But from a programming standpoint, why do we care about Java? So I'm also a big fan of coffee, and I think we all are here. Every programmer loves coffee obviously. But yeah, Java is a language, it's still pretty popular. It's commonly in use around the world. Lots of companies still use it, as a primary language or secondary. Lots of the rankings still have it near the top, as far as how useful it is in the industry. So it is very useful, but how does it compare to other languages like, I don't know I'm not a big Python proponent. Why would I choose Java over Python for a project? So Java compiles first and Python uses run time interpretation. So generally Java is gonna be faster for your general use kind of stuff than Python is. So you said a phrase there Mark, run time interpretation, what is that? I know I use Python, I just think it's magic, I just use it. So how are those different? Can you give us a little bit more detail on that compilation from Java and runtime interpretation from Python stance? Yeah, so the difference between scripting languages and languages that you actually sort of compile into byte code for faster execution before you run them. So is that why we would care about Java? It's a little bit faster than Python and it's used wildly today. Anything else that we need to know about Java? Yeah, I just think it's got a lot of momentum and there's a lot of work that's already been done. There's a lot of good libraries out there for Java, and one of the fundamental axioms of programming is that you shouldn't repeat yourself, right? Don't repeat yourself, DRY and so yeah, it's good to draw on the work other people have done and use that to build your programs, as long as it's legal. [LAUGH] That's an important thing. As long as it's legal, remember that. We've said that here, so don't do anything crazy. Well you've got me convinced, I'm ready to get started. So how do I get started Mark? All right, well we're gonna go to these URLs. We're gonna download the Java Development Kit, and we're gonna download Eclipse here. So- So what is the Java Development Kit, while you're getting that up on the screen? So there's a Java Runtime Environment, which is sort of included as part of the JDK. But that's only if you want to execute Java programs. If you wanna actually have more than just the JVM and be able to compile them and all that good stuff, you've gonna need to download the JDK too. So the JDK is actually gonna, like I can write text and as long as its valid Java code. And then it becomes a Java program whereas the runtime is for Java programs that are already created. And I actually wanna run them on my computer, I've got that bulled down- Yeah. Appropriately, all right. I think it's a pretty good explanation. So yeah, I mean we've got it on with a JDK. So we can run Javac in our command line. Or use our IDE or whatever we're doing to comply any given code. So we can just go down here, and you're gonna look for the one for your OS. The latest version's pretty good,yYou just click here. Accept license agreement, and download whichever executable what you want. And while we're at it, we're also gonna get Eclipse for later. So you wanna go here to eclipse.org/downloads. The current version is Eclipse Neon, but Eclipse Axiom is actually coming out very soon, and 64-bit is the one that we're gonna get. So once we have those files, we're just gonna run the JDK installation. And you might have to do that as an administrator or give it the necessary permissions. So Mark, I noticed that you're doing this on a Windows. But these same steps, I mean very similarly hold true for Linux and Mac, is that correct? Yeah, I would say you generally wanna do the same thing. If there are any issues, you can reach out to me by email. It's markd315@gmail.com, or there's a lot of resources online doing a similar thing, where we could help you get it setup and installed. So Mark is the installation of the JDK is it something that takes a while or is it kinda just one of those flickers installation or is it kinda magic behind the scenes? What should we expect when we installing the JDK? I don't think the JDK will take as long as Eclipse will, but Eclipse sort of has a lot of like resources and stuff that it needs to install on the right directory on your computer. So it might take a little longer, we'll try and talk a little bit during the Eclipse installation. All right, so yeah, it's up on the computer now, we can just click Next. We're gonna wanna just install everything, I think. All of these features, development tools, source code, public jre, that way we just got everything we need. Well, that looks like it is taking a little longer than we would like. So let's use some TV magic to go ahead and speed that up. Yep, we've done that, all right. So coming back to our screen here. The progress bar finished, and we're just gonna install in the default directory, that'll work fine. And this one should not take as long. So compared to C++, I would like to mention that Java is not as dependent to pointers and stuff like that. There is a little more freedom with regard to just referencing objects directly. I think that that's another good advantage to mention over the competitor languages. What do you think, Justin? I've messed around with pointers before. Pointer arithmetic is where it really threw me off when I was in C land. Where I could not only increment the position of the pointer but also do position arithmetic and then modify a value. So you're telling me that Java just kinda abstracts all of that away. And well I can just reference an object by its variable name instead of actually getting low level access. Yeah. Now is there some of detriment to that as far as performance or are there other things that I need to consider since that is the case? I don't have low level kind of bit fiddling typeability. Yeah, I would say that there's definitely a tangible performance lost there. Depending on how you're accessing these variables. And so that's something we should take into account. Look at the needs of your project and figure our the best tool for the job. You've got a toolbox in front of you. You got a hammer, you got a saw, you kinda got to decide, which is the best one to approach this problem with? Well, that is something you definitely have to take into account, because I've been plagued by that premature optimization bug that I think a lot of people do. I have this unconscious bias to, let me see how fast I can make this go. And usually all it does is cause me a lot of headache, a lot of heartache, and well then I don't have anything that runs. So I'm a big proponent of make things happen now, instead of worrying about how fast it is. Now if it makes you feel any better, I have seen some, in very specific applications, Java is pretty fast, that JVM is pretty fast. And well I just said the word JVM, but the acronym Mark, I'm gonna have to ask you can you expound on what JVM is for us? Yeah, so the JVM refers to the Java Virtual Machine. And it's a virtual machine that runs on sort of all these different hardwares. And it makes it so that you can sort of run Java code on any different platform. You can just compile it once and run anywhere. And that's a really good feature of the Java language is that you have that capability. It's really strong, but it looks like that our JDK has successfully installed. So go ahead and close out of this, and let's get Eclipse running. Do the same thing, run as Administrator, and we're gonna wanna confirm that. So Mark, I know before the show you told me that Eclipse was gonna take a little bit while to run so we're kind of jumping ahead a little bit and getting that started up. While we talk about Eclipse and some other niceties. So, we're gonna let that get started so you can get started as well but then we'll probably veer off to some other fun times. All right. So yeah. Like Eclipse is, compared to the competition, I think Intelligia is another good IDE. There's a lot of good competition out there, but Eclipse is the one that's kind of been around the longest. There's sort of a lot of plugin support for it and a lot of different things it can do. So that's the one we're going to use. If you've got a different preference, I think you're entitled to that. People like doing different things in programing everyone has sort of their own little way of doing it. And yeah, go for it. So you have chosen Eclipse just because that's your personal preference. Yeah. And you kind of have an at homeness, right with Eclipse but I'm sure there's features that you will show us in due time that you feel that Eclipse is a great IDE, right? Yeah. Eclipse can fix a lot of your problems for you. You don't really have to compile for it to highlight the errors. You can do source generation for your gutters and and setter methods, which we'll talk about. I promise. And all the other stuff that you might need. It can do constructors. All that cool stuff. So ultimately it's a matter of preference, but Eclipse is mine so that's what we're gonna do and we're gonna have to click something here. So we want Eclipse IDE for Java developers. And you can create a start menu, enter your shortcut if you want. Let's do a shortcut. And then. Installation failed with error. Woah. This is always fun times. All right, so Eclipse. Let's just go to the desktop and dev pro. Let's try again. Well, seeing that there are sometimes errors is always a good thing, right? Because when things go without a hitch it just looks like magic and everybody goes well, I can't do that it is broke on my machine. A lot of times it's broken our machines as well, so just try something different and we'll see what happens. And this is the part that was gonna take a little bit longer, right, Mark? Yeah, I think so. So, could you highlight, well, you talked about why we should use Eclipse but could you give us a little more detail about why did you choose Eclipse as your primary IDE? Even for that can you talk about IDEs in general? Like, what is IDE? And make sure that we're all on the same page there. Yes, that's a really good question. I think we have been using that acronym without sort of clarifying but an IDE just stands for Integrated Development Environment and it's something that all programmers want to have access to. You want to pick one or the other. It sort of makes it a lot easier than typing into a text file and then changing the file extension and compiling it from the command line. Those are kind of some obscure steps that you might not want to do every time. And especially when you have a complicated build path, it gets really hairy really fast. So, yeah. Eclipse is a great tool to help you manage all that nonsense that you don't wanna have to do every time you write a program. So I have heard that the some programmers are, unless you use Notepad, plain Notepad and write down your Java files and you compile everything from the command line then you're not a real programmer. What are your thoughts on that? I mean I think every industry is going to have their puritans but I think if you've got resources in front of you that can make your job easier then you should use them. And going back to the old principle don't repeat yourself. It's sort of the same kind of vibe. Yeah understandable. It looks like we have something that we need to accept, right. Yeah, so these are the terms of service. Yeah. Good stuff. So we can just click accept here. And we should always definitely read this. Always read them, yeah. Always read those but just for the sake of time, we are being expeditious about this. Now, Mark while this is installing, I want to double back a little bit. We talk very high level about Java but could you illuminate some of the really strong points of the Java language? What are we going to learn that are gonna make us more productive? Or what is available to us? Do we have to write everything from scratch? Cuz you've been talking about don't repeat yourself. Build on the work of others. Is that something that Java is, is that in the Java ecosystem so to speak? Yeah, so as I alluded to, Java has a lot of cool inbuilt libraries. There's a math library. There's stuff for file IO and there's also things other people have done. There's j-unit which is going to help us with unit testing. That's something that I think is important to impart upon young programmers is to make sure your code works and meets the specifications that it has to. Yeah, so we're going to cover that too. Now Mark, some of our viewers may not know what unit testing is. Could you just give us a brief rundown about what is unit testing? Yeah. So the general idea is you write a test, either before or after you write your code and you run the test and if your code passes the test, then you can move on to the next development requirement, if you will. And if it doesn't, you know that your code is faulty in some way and you know what your code is doing wrong because of what it's returning. So it allows you to diagnosis your problems a lot easier and it allows you to make sure that your code is ready for production and it's not going to be dangerous out there. Dangerous? You made me scared Mark. I'm already terrified but you said something very interesting there that I've heard kind of back and forth. Right. Your tests before or after. I've heard real staunch you should always write tests first and then write your code, but you said you could write it after. What are your thoughts? Could you give us an idea of why you said it's okay to write tests- Yeah. Afterwards? I think it's generally okay to write tests afterwards but if you want the tests to drive the way you write your code and to meet very specific requirements It's best to write them beforehand and so that's a principle called test-driven development. Some people adhere very strictly to it. I think it's important as a concept that you use unit tests and that you make sure all the other parts of your code are working properly but if you program better without writing them first then by all means, I don't really think it's necessary. I do think some people go a little bit too crazy. I've seen people write unit tests for getter and setter methods which are really just one line of code and I think that's a little bit overboard. There's a good balance there that we should, you're going to help us keep in mind as we learn more about that. Mark, it does look like we do have a launch button and I always like launching, right? [SOUND] Yeah, take off. Take it through us. All right. Take us through it. [SOUND] So Eclipse is coming up here. Eclipse Neon 3. That's the current version. Eclipse Oxygen's coming out real soon, I think. I'm not sure when in June but it's definitely coming out in June so stay posted for that. All right, so if you're watching this at a different time and you have well, Eclipse Oxygen or Eclipse Flooring or Eclipse Chlorine, who knows? Well just know that this is going to be very similar to what you're doing. Just the names are gonna be different. So we have this menu here, Mark. Can you take us through what we're actually doing here? Yes, this is the workspace. This is just where all your code is located for any given project. Some people use a different workspace for every project. You don't really have to. I think I'm gonna create a new one here for our ITPro stuff. And, devpro/workspace, cool. We'll do that and we're also gonna check use this as the default and do not ask again. You don't necessarily have to do that. If you've got multiple workspaces, again, some people like to do it this way instead. Then yeah, you can do that as well, not check it as the default and just pick your workspace every time. If you've sorta got different things that you program for, maybe you program for open source your free time but you also have a job you do this for, you might want to have two workspaces. A home and a work one. That's something I've done in the past and I think it works well. All right so then that's creating the workspace and then this is the startup time always like this for eclipse? Is there always like a startup overhead? I know for some of the other IDE's that I've played with the startup overhead, it's really bad the first time. There's still a little bit the next time, but it gets a little bit less. Is that the story for eclipse? I would say so, yeah. You've gotta create some directories for the work spaces and all that. But mostly this will probably run faster on your machine. My computer's pretty terrible. [LAUGH] Self deprecating computer humor. I love it, I love it. So we're just waiting for this to start up so to speak. I do love that graphic though and there we go. Mm-hm. So, you sorta get this nice intro screen here. We don't really need to go over all that because we're going to be creating a hello world type application ourselves anyway. We can create a new Java project here, but that's not the way we're going to be doing it in the future. Let's just go up here, File, New, Java Project and we are going to use mostly the default options here. It's gonna to take a second here. Let's call this DevProHelloWorld. The convention for program names and class names is to capitalize the first letter of every word. And so then you'll get this package explorer. I clicked something without explaining it, sorry. This is a maximization thing for when you're looking through your file system for your Java projects. We have this cool new project folder here. And it's got a source folder. And we've gotta create our first class now, so we're gonna go to New and we're gonna do Class. And this is sort of the fundamental building block of Java, you're gonna have a lot of these classes and they're sort of gonna interact with each other. They're gonna represent sort of an abstract type of object, but that's sort of a more complicated topic for now. All we have to really do is write a class with a main method and we're going to get to that in a second. Do we still have time? I think we're good. I think I see where you're going and I think we can make it through in this episode. So we can also create a package here, what should we call it? Awesome sauce. Awesome sauce. I think that's great. Alright so, we're going to have to put that package declaration at the head of every class that we write that's inside this package. But that's fine. And we'll just, every class we write for now will just be Awesome Sauce. I love it, that's great. And this can be DevProTester, or something. And we don't really need that. We actually don't want to create an e-method stub so that way we can write it from scratch and show you. Alright, so this is just building out that file. Seems like a lot of work just to have that file, well, generated for us. What is actually going on behind the scenes? Is it making sure that everything is kind of pointing to the right places? Or is there any type of magic? Or is there just a helper that helps things get more complex? I think it helps you keep all of the compilation stuff in check. So it knows where the main class is for the projects are and stuff like that. And yeah, so here if you can see in the code. We've got package Awesome Sauce. That's the package we declared. And we got a public class DevProTester. Which is what we chose to name our class. All right Mark so, I know you're getting, you're getting excited, I can tell. But one quick thing. I tend to use a very large font. Whenever I'm programming, just to help with eye strain. And, I just wanna make sure everybody can see. Could we make that font just a little bit bigger? Well, so everybody can see it in all its glory. Yeah, I think that's really important to do, because programming should be accessible. Everyone, we might have people who have bad eyes that need to do this, and so we're gonna go and do that. We're going to go up to Window, and Preferences. And this is where you're going to change most of your settings for eclipse anyway. We can look up here. You've got all these different tabs. Kind of confusing, but we're just going to go with General, and Appearance, Colors and Fonts. And, we're going to look for our basic font here, Text Font, Edit. And it's gonna come up. And we're gonna blow up the size. What size do you think we should use? Let's try probably 18, 20, somewhere around in there. Just because that's a font size that I use and it tends to work fairly well. Okay. Whatever works, so I'll apply that, and look at that, code looks nice and big. That's beautiful. We can see everything on the screen, good stuff. All right, now I'm ready for this first program. Take it away, Mark, let's see what's involved. So we're gonna type public static void main, and your gonna do a parenthesis here, (String[] args), and that's gonna be really confusing and we can't really explain it right now cause there's a lot of words in there that are sort of a higher level. So just sort of think of it as casting a spell. You do it whenever you're writing an entry point to a program and this sort of where the program knows that it needs to start. And you've got this, it's called the main method, we can go ahead and get that out there. But this first line of the main method is where your program is gonna have it's entry point, that's where it starts. And so, this main method has to be inside of the class, and inside of a file, right? So, in this case we've got it in a package. Some of you, if you didn't create a package, you might have like a default package. And then you won't have this package declaration here. But we made ours in a package just to help keep everything for our projects nice and organized. And so now we can type System.out. Also you can see I've got all these code recommendations coming up here. It's a great feature of eclipse, sort of autocompletes lots of your stuff. I'm probably just going to type most of the things out completely so we're all on the same page. And we're gonna do println and we have to end every statement in eclipse and Java with a semicolon. And we're going to do a string here which is a concept we'll explain more later. We're just going to put "Hello World!" Now could we shrink down that task list on the side just to see all of that in it's glory at the same time. So we can sort of just click X's on these things that way we'll have a lot more space to work with here as our lines get longer. Well, Mark, is there any way we can make that task list go away, cuz I wanna see all of that program in its glory. Yeah, that's a good question. So, since we sorta blew up our font size, now we've got this problem where some of this text is getting covered up by this task list and outline. We don't really need any of that stuff, so we can just click X's on that. Get it all out of the way. Whatever you've got there, just get rid of it for now. It's not that important. What we really need is this Package Explorer which we can also shrink down. If you sorta grab onto this little thing, you can drag it and make it a little smaller so it doesn't take up as much space when we're typing our code in our main editor. Cuz that's what's really important right now. And you know you can click Control S here, and you'll notice there was an asterisk there went away. So it just means that we've saved our code. And now we can go ahead and sort of compile it. And we're gonna do Run As Java Application. Generally, you can just click this green button and if you've done it before it'll work fine. But as you can see down here in our console, this is where your console is going to appear down here on the bottom. This is sort of the output for whatever programs you run whenever you do System.out.println you're gonna get text down here in your console. And you can also, later on we'll go for sort of more I/O stuff and we'll talk about how you can type stuff into this console as well, and make your programs more interactive. Well, Mark, this has been a wonderful ride. Just as a quick review, we installed the JDK, we installed eclipse, and we actually wrote our first Java program and ran it. We had a lot packed into this episode, but it does look like we are out of time for this episode. But please join us back as we continue our Java adventure. Signing out for Dev Pro TV, I've been your host Justin Denison. I am Mark Davis. Thanks for watching. We will see you next time. [SOUND]

Learning Style

On Demand

Length of course

13h 32m
33 Episodes

Here are the topics we'll cover

  • Object Oriented Java
    Learning Options

    Options for this course

    Train your team
    Stay ahead of the curve and future-proof your business with training programs designed for you.
    Channel & Reseller
    Transform your experience and integrate with our unique evolving library of Audit, Cybersecurity, and Information Technology courses.
    Individual learners
    Learn at your own pace and get your certification training.