Java tutorial for beginners (2020): #1 (install, println, etc.)


Welcome back ladies and gentlemen to my one-of-a-kind Java tutorial series You can call me, bro And I’m here to help Just remember to believe in yourself and never give up because you can do so much more than what you think you’re capable of. If you’re ready, then let’s get started For the first part of this lesson we are going to be looking underneath the hood for how Java programs compile and execute feel free to fast forward to where we begin the install or Even where we’ll begin setting up a project if you want to skip this part, it’s entirely optional I’ll include timestamps in the description if you want to jump around so Programming languages tend to fall in a spectrum between high level and low level High level programming languages tend to use natural language elements that are recognizable by humans You can say high level languages have similarities to human vocal Airy and have more automation than low level languages The highest level language that we can see one day is us directly having a conversation with our computer to write software high level languages utilize more human vocabulary and feature more automation than lower-level languages and a few examples would be c-sharp Python, and of course Java a Low-level programming language is more easily understood by machines because it’s in a format that’s easier for them to process These languages more closely resemble a computer’s instruction set architecture than what it does compared to human. Speech low-level languages are not easily understood by humans because it’s sometimes Rarely or never contains familiar words and phrases that are easily Recognizable by humans a great example of a low-level language would be the assembly processing language High-level languages are advantageous because they are easier for us people to write code with and offer more automation But a disadvantage compared to low-level languages is less control entire processing power and vice versa With low-level languages these languages offer more control and use up less processing power But are more difficult for humans to interact and work with For the purpose of this tutorial series will be working with Java a high-level programming language and in Java we write source code It’s a format that we as humans can understand fairly easily and source code files and with the dot Java file extension What we can do with our source code is compile it which is a fancy term for Translate We can translate our human-like source code into code that can be read by a machine Imagine the compiler is a friend of yours. That’s Bilingual and they are translating what you tell them to a third party. The final product after compilation is called object Sometimes it’s referred to as machine code, but it’s basically the same thing It’s made up of binary ones and zeros that a computer can easily read in process While it is possible to write programs in object code it would be exceptionally more difficult for us to do so especially for new programmers That’s why we write our source code and then compile it into object code what J machine can easily read makes sense Right. However, we do have one problem. Our object code is not portable The object code is a binary format that is tied with a particular type of computer Meaning that if you have object code that was written with a Windows computer You can only run that object code on another Windows computer because it is machine specific Likewise if you have object code that was written with a Mac computer, then you can only run it on Mac computers This is important because software manufacturers would then need to compile and sell different versions of software With varying object code depending on what machine their source code was originally written with and this would be a lot of extra work So the developers of Java addressed this by introducing an intermediate level called byte code This level lies somewhere between source code and object code and it’s also somewhere between a high level language and a low level language when we compile our source code down to object code what we do instead is Translate it to this new byte code to make our byte code portable to different computer brands and varieties We can translate our byte code one additional time Into object code using a tool called a JVM and that’s an acronym for a java virtual machine It also might be referred to as a JRE at Java Runtime environment. It’s a small software tool that can translate a Dot class file extension into an object file that a specific machine can understand So I know I’ve given you a lot of information here. Don’t worry You don’t need to know the exact science for how all this works that will be outside the scope of this tutorial series It would be at least beneficial to have a general idea of how these processes work together but what you should know before we get started is that we are going to be focusing on writing source code for this tutorial series and what we are going to be doing is Downloading a few tools to make our lives easier that will take care of the rest of these processes for us So let’s open up a web browser and take a quick break For this part of the lesson. We’ll be setting up an IDE and a JDK an IDE is an acronym for integrated development Environment to summarize in one sentence. What an IDE is I would describe it a software that helps us write software it will give us an interface or a Text editor for us to see and work with our code the other item that we need The JDK is another acronym this stands for Java development kit It contains useful tools that will assist us It includes the compiler and the JVM that we were discussing before in the previous lesson along with a few other tools It might help to picture that JDK as a toolbox If you need an analogy today, I’ll be walking you through how to install the Eclipse IDE There are a few others out there such as NetBeans and IntelliJ IDEA if you prefer to use one of those that is perfectly acceptable They will function just the same. I’ll include a few links in the description if you prefer one of those so let’s get started Let’s begin by installing the JDK the Java development kit open up any web browser And then go to any search engine and type in Java JDK Download this is probably the easiest way to find it. Look for the Java SE downloads page Click this Oracle JDK download button Scroll down accept the license agreement and then depending on what operating system you’re running click the Corresponding download file for your Michigan. So since I’m running Windows, I’m going to download this dot exe file Alright and then open it when you’re done I’ll include the URL in the description So I already have the JDK installed on my Michigan just for the purpose of this demonstration I’ll reinstall it Click Next Next And you can close we now have the JDK successfully installed Next let’s install the Eclipse IDE, so open up any web browser again and type in this URL Eclipse.org slash downloads alternatively. You can just go to google and type in Eclipse download and it should be the first link Alright, so if you’re using windows for your operating system You can do the download 64-bit button. It’s that’s the easy install if you’re using Mac or Linux, you’ll have to go to download packages Scroll down to Eclipse IDE for Java developers and then select the download for whatever operating system you’re using since I’m using Windows I’ll walk you through the windows installs. So I’m going to hit back and go to the easy install Alright then download again Ok, so it’s currently downloading I’ll get back to you when that’s finished Alright so my download finished if you’re running Mac or Linux, you’ll probably have some sort of executable file So just be sure to look for that. I’m running Windows and this ended up in my downloads folder So if you’re missing this you could just look for it there When you’re brought to this window, I would recommend clicking Eclipse IDE for Java developers and install So here you can select the directory as a workspace, I’m just going to use the default All right, then eventually you’ll be brought to this home screen then we can begin a new project Now here are the steps to setup a new project in Eclipse. Go to the top toolbar then under new Go to Java project Come up with a project name. I’ll call this. Hello YouTube but you can name this whatever you want click finish Click create I might have to close out of this checkbox here Okay, so then when you’re on this screen go to your source folder, it’s labeled as SRC Then go back to the tool bar file new class and I’ll name this main and Click the public static void main string args checkbox. I’ll describe what that does in just a moment and then click finish Okay, so your screen should now look like mine For the next part of this lesson I would like to discuss the format for the new project in class that we created near the top of this program you can see this line that says public class main or Possibly public class something else depending on what you name to this class originally when we made this project This is called the class heading for now think of a class simply as a container for your programs code Will be working with classes in a future tutorial everything written within this set of curly braces is Contained within the main class or whatever else you’ve named your class Within the class heading we have this line called the main method how this main method works Is that when we execute our program? The computer looks for this main method and executes everything within it starting from the top and working its way down It’s important that all of these keywords match exactly as long as well With the main method having its own set of curly braces as we progress through more lessons We’ll slowly begin to understand what each of these keywords means and how they function Onde another thing so these two forward slashes Anything after that’s just a comment The program just ignores them. They don’t really do anything. So I’m actually going to take this out for this example So our program will not execute without this main method because it’s the first thing that our computer looks for when we run the program So just for an example, I’ll take this out I’ll copy at first though and Then we can run the program by hitting this green play button. It says run man, but same thing alright, so Down here. We’ll have a console window So all of our output is displayed here and it says we have an error because it could not define the main method because it’s missing and We need that for our program to run because it’s the first thing the computer looks for So let’s put it back in and if you are missing this you can just type this in and it should work Then let’s run the program okay, as you can see we get no errors, but Nothing happens yet, because we haven’t done anything so when I was studying at my university my textbook for my intro to programming course told me to think of the main method as Some sort of magical spell or incantation that we need to say before we can get our program to run I thought it was kind of a funny example, so I thought I would share it But yeah You do need each of these keywords to match exactly along with the main method having its own set of curly braces For this next part let’s display some text as output so to display text type in system with a capital S dot out dot print add a pair of parentheses With double quotes within and a semicolon at the end. I’ll take just a moment and Pause here if you need a moment to write this down So anything within these double quotes will be displayed as output to the console window when we run the program, so typically a Programmers first program is a HelloWorld program where they type in hello world and display it as output But at this channel, we like to be different so instead of typing HelloWorld I’m going to be making a reference to the 1989 arcade video game zero weighing and it’s poor translations So type in whatever you want here, but I’ll be typing in all your base are belong to us so once you have typed in whatever you want within the double quotes hit this green play button to run the program and As you can see whatever we typed within the double quotes was placed as output in the console window all your base are belong to us we Can add a second line too? So I’m going to copy this and Then just paste it right underneath and I’ll change the second line to you Have no chance to survive make your time Alright run the program. Okay, so we have one problem With our second line of text. It’s kind of combining both in the console window so there’s one way we can fix that and that’s changing the system dot out dot print portion of our statement to Print Ln which stands for print line and how that works is that when it reaches the end of your line of text it’s as if you’re hitting Enter to Start a new line. So let’s try and run the program now now that we changed the print to println for print line There much better now we have two different lines of text So I’d like to include a bonus round of how we can change the color scheme for the Eclipse IDE and the console window So this is the default white background with black text. If you want to change it go to the top toolbar window preferences General then appearance currently it’s set to light, but I think I’ll change it to dark apply Okay, apply and close Yeah, now we’re talking that’s much better and if you want to change the color scheme for the console go to window preferences scroll down to run debug Console and I’ll change the text color to like green Okay, so it reminds me of those old monochrome monitors It also reminds me of the computer consoles from the Bethesda Fallout series. I’ve always been a fan Ladies and gentlemen that will conclude this episode of Bro Code. You did great by making it to the end Keep up the good work if this video helped you out You can help me out by smashing that like button and leave a comment behind. Subscribe if you’d like to become a fellow, bro

Leave a Reply

Your email address will not be published. Required fields are marked *