Quantcast

Start with 7 free days of training.

Gain instant access to our entire IT training library, free for your first week.
Train anytime on your desktop, tablet, or mobile devices.

This Java video training course with Ben Finkel covers basic and advanced programming topics using the Java programming language. Java is a platform-independent programming language developed to ease both development time and code legibility. Topics covered in this course include: variables and scope, control flow, functions, object-oriented language features, unit testing, error handling, and web application serving....
This Java video training course with Ben Finkel covers basic and advanced programming topics using the Java programming language. Java is a platform-independent programming language developed to ease both development time and code legibility. Topics covered in this course include: variables and scope, control flow, functions, object-oriented language features, unit testing, error handling, and web application serving.

Whether you're new to programming or new to Java, this course has a lot to offer. Java is one of the most popular languages in the world and makes a great introductory programming language because of its ease-of-use and full-feature set. Experienced developers can get up to speed on one of the most popular languages in use today.

Recommended Experience
  • Basic familiarity with Windows, Linux, or Macintosh
Recommended Equipment
  • A desktop environment with an internet connection
Related Job Functions
  • Web developer
  • Software engineer
  • Programmer/analyst
Ben Finkel has been a CBT Nuggets trainer since 2014. His areas of expertise and certifications include Google Developer Expert, Google Certified Trainer, Microsoft ASP.NET (WebForms and MVC), Data Analysis and Design, Relational Database Architecture, MS SQL Server, Microsoft C#.NET, Javascript, jQuery, Microsoft Visual Basic .NET & 6.0, .NET Reporting Services, MS Access, and Python.
 show less
1. Introduction to Programming with Java (14 min)
2. Installing Java Development Tools (8 min)
3. Your First Java Program (12 min)
4. Java Programming Basics (14 min)
5. Java Variables (12 min)
6. Data Types and Operators (17 min)
7. Chars and Strings (13 min)
8. If, Then, Else (12 min)
9. Loops (12 min)
10. Arrays (15 min)
11. Introduction to Functions (12 min)
12. Parameters and Return Values (14 min)
13. Input and Output (11 min)
14. Error Handling (11 min)
15. Package Imports (8 min)
16. Writing a Complete Java Program (14 min)
17. Introduction to Object-Oriented Programming (11 min)
18. Classes (14 min)
19. Modifiers (10 min)
20. Inheritance (8 min)

Introduction to Programming with Java

00:00:00

Introduction to Programming with Java. Hey everyone. Ben Finkel here. In this Nugget, I'm going to give you a really brief, really fast introduction to programming. Specifically, with how we program with the Java programming language, a high-level programming language that gets parbaked, as I like to call it, into bytecode before it's executed on our target environment.

00:00:19

So I think we should start with the question, what is programming and why do we need programmers for computers? And at least my answer to that question is, computers are dumb. Now, I know what you're thinking. My computer is not dumb, Ben. My computer is super smart.

00:00:32

My computer can, I don't know, calculate pi out to 1,000 places in the time that it takes me to say the word pi. And, well, yeah. That's right. But that's not necessarily smart, that's just fast. After all, calculating pi is a relatively straightforward operation.

00:00:45

Most of us can learn how to do it and do it very easily. The computer can just do it a lot faster than you. And, more importantly, the computer doesn't know how to calculate pi or when to calculate pi until someone tells it to. Until someone writes a program or a set of instructions that tell the computer what to do.

00:01:04

We are the most important part of any computer because we are the brain of the computer. We are the one who comes up and tells the computer what to do. Without us, the computers have no idea what they do. They just sit there with all this limitless power.

00:01:16

Yeah, they can play amazing video games. Yeah, they can do your budget in a spreadsheet, or they can connect to the web, and download videos, and watch live stream TV. But none of that is possible without the programmer, or without someone to sit down and provide those instructions to the computer.

00:01:32

Now, I'm going to use this phrase, computers are dumb, throughout this Nugget because I think it's really, really important. And it informs a lot of what we do, and why we do what we do as programmers. For instance, computers are so dumb that they will actually do exactly what we tell them to do without fail.

00:01:49

They will walk right off a cliff if we tell them to. They will try to divide by zero, which, as we all know, is impossible. They will corrupt our memory. They will allow viruses in. Computers are very, very direct. They do not have any room for ambiguity.

00:02:02

They do not have any room for intuition. They do not have any room for anything other than a precise set of instructions that they will follow, without fail, until they run into fault or they complete the execution of those instructions. So to that end, computers are not programmed with natural languages.

00:02:19

We cannot tell a computer what to do with English, or Mandarin, or German, or whatever other language you might speak. Because natural languages, the languages that we've evolved in our own natural society, are full of ambiguity. They are full of idiomatic expressions, and metaphors, and all sorts of things that computers are just never going to be able to interpret and understand properly.

00:02:38

Instead, computers use something called machine language, and machine language looks a little bit something like this. This is numerical machine language code. And yeah, I don't know what that says either, believe me. This is pretty confusing stuff. Just a bunch of numbers.

00:02:51

There's a couple of letters in there. What's going on? I have no idea. Another variation of machine language, assembly code. You may have seen this. It's a little bit better, but it's still completely confusing. I, again, have no idea what this is telling the computer to do, but that's not important.

00:03:06

The computer knows. And, more importantly, this is very precise and very explicit. These instructions are not possible to be misinterpreted. They tell the computer exactly what to do, step by step, so that it can accomplish some goal. Now, why do we need to use this machine language, this machine code?

00:03:23

Well, again, because computers are dumb. They need very explicit instructions. And so machine code is good for a few different reasons. It's very precise and it's very efficient. Assembly code, or machine language, runs very, very fast. It executes very quickly because it is direct instructions for the CPU.

00:03:40

But it's got some problems. Obviously, it's not especially intuitive. You and I look at this code and we have no idea what it's doing unless we are very familiar with the machine language that we're talking about here. It's also very wordy, or very, long winded.

00:03:53

The assembly code that we're looking at up here probably does something very, very simple, even though it's eight or 10 lines long. Because of the minute specific nature of the instructions, it takes a lot of code to perform very, very simple tasks. And, of course, it's error prone because we don't understand completely what we're typing in.

00:04:11

There's a lot of typing that we have to do. It's easy to make a mistake. Now, maybe the most challenging part about machine code is that it is CPU, or architecture-specific. I'm going to talk about a lot as well. But, aspectively, that assembly code that we're looking at up there is only good on one particular architecture.

00:04:29

Whatever architecture it's built for, whatever CPU, whatever hardware it is designed to run on, that's the only hardware that is going to run on. So if you have some code, if you have a program that you would like to run on two different pieces of equipment, say both a computer and a tablet.

00:04:43

Well, you're going to have to write assembly code twice. Holy cow. Way too much work. That's not what we're learning to do here. We're learning to use the Java programming language. And Java belongs to a class of programming languages that we call high-level languages.

00:04:58

High-level languages, things like C and C , Python, C-sharp, and, yes, Java, are language that kind of bridge that gap between assembly code and the natural languages that we talk about. Typically English. High-level languages are going to reflect the English language a little bit more.

00:05:15

Here is an example of a Java program. This is a fully functional Java program. And if you don't know any Java, you might even be able to look at this and kind of determine what it's going to do. You're going to say, well, this says, "HelloWorld". And out here it says, system print Hello World.

00:05:33

You could accurately guess that this program is probably going to print out maybe to a printer or to the screen the text, "Hello World". And you would be absolutely correct. That's what it's going to do. So a high-level language, while not exactly being English, there's a lot going on here that is definitely not the English language, is in between assembly code and a natural language like English.

00:05:53

It's easier for us to understand. It is more intuitive and easier to maintain. So, as you write code in a high-level language and another developer another programmer has to come along and maintain it, or you six months later down the line have to come and fix a bug in it, you could look at that code and you can figure out what was going on.

00:06:11

What it's attempting to do, how it is supposed to work. It's not completely obfuscated by just the really detailed technical nature of it. Now, you do still need to learn it. And that's the point of this course. You can't just walk up and understand how to write Java code without spending a lot of time learning how to write Java.

00:06:31

But it is more intuitive. It is easier to maintain. It's a little bit less precise. And for that reason, you can see that we've got longer, wordier commands here. So instead of SEI or LDA that we see over in assembly code, we have public class. So we need to take some extra effort to make sure that we are precise about what is going on and what we want to happen with this code.

00:06:51

And it's less efficient. Although, in a particular way that I'm going to talk about now. Because the thing that has to happen here, and you may have sort of understood this while I was talking about it or it may come as a surprise to you, is that high-level languages are not instructions for your computer.

00:07:06

Your computer does not know how to understand or perform whatever you describe in a high-level language like Java. The high-level language has to get converted into machine language before it can be run. It has to go through a process that we call compiling.

00:07:21

So high-level languages, after they've been written, have to go through a process called compiling to get converted in machine code. And to paint out how much code you have, compiling can take a little bit of time. It can take a while. The analogy I like to use for compiling is that it's a lot like baking.

00:07:37

And the reason we have to go through this step, of course, don't forget, is because, yeah, computers are dumb. They can't understand even this very formal, structured, high-level language like Java, or C , or C directly. We still have to convert it into machine code.

00:07:51

And when you think about the process of baking, you start with, well, your raw ingredients. Your flour, sugar and eggs, right? You can't really eat those. Man, I guess you could, but no one needs to eat a spoonful of flour. You've got to kind of mix them all together, put them in the oven to bake for a little bit, and then put the finished product together as a cake, in this case that you can eat.

00:08:10

You can now consume it. Well, it's the same with your computer. The high-level language is like the raw ingredients here. That is your raw code. And, let's say, you're working in the C programming language. That a high-level language. You're going to sit down and you're going to write that code, those raw ingredients, right out into a .txt file.

00:08:28

Most code is just straight plain text. You could edit it in Notepad if you want. In fact, we're going to do that in the Nugget, Your First Java Program. Now, once you've written that code, that can't be consumed. It's not a cake, it's just raw ingredients.

00:08:39

It's got to be baked. It's got to go through the process of compiling. So after you write the code, that process of compiling happens, and it turns these .txt files into binary executables. Assembly code that can be run on a specific machine. Remember, assembly code is CPU-specific.

00:08:58

It is built for the specific architecture that it's going to run on. So that is the process I like to think of as baking, or compiling your code into a consumable product. Assembly code, a cake that you can eat, or a cake to your computer can eat, in this case.

00:09:13

Now, one big challenge that we have with this. and something the Java tries to address, and you may have thought of this as well, is that once you compile a program into assembly code, it's still CPU-specific. It's still platform or architecture-specific.

00:09:26

So say you've got some code that you want to run on both Windows, and Apple, and Linux. Got our little ninja penguin there. Well, you've got to go through this whole process every single time for every single one of these architectures. So if you have really good code, you may be able to start with just one single code base here.

00:09:43

You don't have to have multiple code. But then you've got to compile it to run on every target environment-- we call these target environments-- that you want it to run on. Because the executable that you produce, that you compile, for Linux is not going to run in Windows, and it's not going to run on Apple.

00:09:56

They each have to get their own version of the code compiled. This is inefficient from a developer's perspective. You've got to redo this whole process and it can be a time-consuming process. Every time you patch, or fix, or update your code, you've got to remember to do it on all of them.

00:10:11

And if you're not able to maintain one single code base for all three of those, you may have two, or three, or four different code bases just for your different target environments. This is a lot of work from the consumer perspective. From the person who's downloading and running your program.

00:10:24

Well, they've got to make sure that they get the right executable. If they're running on Windows, they got to find the list of executables wherever you have them, on your website or whatever. And they've got to make sure they clicked the right one for Windows.

00:10:33

Don't actually try to download and install the one for Linux. You get the idea. There's a lot of room for confusion. There's a lot of extra work. Now, back in the early 90's, a company called Sun Microsystems decided there was probably a better way to do this, and they invented the Java programming language.

00:10:49

And what makes Java different is that Java is what I like to call parbaked. If you ever bought parbaked rolls at the bakery, they're basically half baked rolls. They're kind of cooked, but not all the way. You bring them home and you finish cooking them in your own oven so that they're nice, and warm, and delicious right there for you.

00:11:05

And parbaking is pretty cool in baked goods because you get nice, fresh, warm baked goods right in your own home that you don't have to do all the work putting them together. It's amazing in computers because in computers it allows us to work with a single codebase and a single compile operation to target multiple different platforms.

00:11:23

In fact, any platform that we want. With Java, the programming process starts off the same. We have our base code in a Java file here at the beginning. That is our raw ingredients. And, again, it's still a .txt file. It's still just plain old text sitting on our system.

00:11:39

It's completely portable, we can write our code on any system we want. But then what we do is we go ahead and we compile it, at least sort of. Part of the way. We kind of mix it together if you think about your mixer in the baking analogy that I've been using.

00:11:51

In something called bytecode. This is a .class file in the world of Java. And bytecode is not machine code. It's not a high-level language, but it's not machine code either. It's something in between. And what's cool about bytecode is you then deliver that bytecode to the end user's computer, the end user's process, where it gets compiled and executed on the end user's machine.

00:12:13

In other words, you have one code base and one compile operation that can get delivered to multiple different platforms. And the reason that this works, the reason this can happen, is because all of the platforms that are going to run Java have to have a little executable of their own, the Java Runtime Environment or Java Virtual Machine, JVM, installed on them.

00:12:34

That JVM performs the compiling and the execution in real time when the user wants to run it. So the bytecode gets fed into the JVM, the JVM converts it on the fly, what we called just in time, into machine code for whatever program it's running on. So this means that you have to have this JVM available for the platform that you want to deliver to.

00:12:56

Now, thankfully, Java is super-duper popular and there are JVMs available for just about every platform you can imagine. All of your desktops, your laptops, your tablets, even your smart home connected devices, your washing machines and refrigerators that are connected to the internet now, they have Java virtual machine, so that they can execute Java code on them.

00:13:15

So it is incredibly widespread. There is a Java platform available for every device out there. So you can comfortably and confidently write Java code once, produce your bytecode once, and know that it will be able to run on whatever target device it needs to run on.

00:13:29

And, once again, why do we have to jump through all these hoops? That's right, because computers are dumb. Computers need very specific machine language low-level instructions. We as human beings need higher-level language. Something that's closer to a natural language in order to write those instructions clearly both for ourselves and for our other programmers that we're working with.

00:13:48

So, ultimately, programming boils down to this. Writing your program in plain text, compiling it, and then delivering the compile executables, or in our case compiled bytecode, to the target platform. All right, that concludes this Nugget, An Introduction to Programming with Java.

00:14:03

We covered a lot of material really, really fast. And if you didn't fully internalize it all, that's OK. You will over time as you work with the language. Just a couple of key takeaways. Programming is nothing more than providing a set of instructions to the computer so the computer knows what to do.

00:14:18

Programming with Java means using a high-level programming language. Something that's in between machine language and natural language, so that it's easy for us to understand and to write, but can still ultimately be compiled into something that the computer can understand and run.

00:14:31

And, lastly, Java uses something called the Java Virtual Machine, JVM, in order to turn the parbaked code, the bytecode, into an executable that a machine can run. I hope this has been informative for you and I'd like to thank you for viewing.

Installing Java Development Tools

Your First Java Program

Java Programming Basics

Java Variables

Data Types and Operators

Chars and Strings

If, Then, Else

Loops

Arrays

Introduction to Functions

Parameters and Return Values

Input and Output

Error Handling

Package Imports

Writing a Complete Java Program

Introduction to Object-Oriented Programming

Classes

Modifiers

Inheritance

Please help us improve by sharing your feedback on training courses and videos. For customer service questions, please contact our support team. The views expressed in comments reflect those of the author and not of CBT Nuggets. We reserve the right to remove comments that do not adhere to our community standards.

comments powered by Disqus
Entry 4 hrs 20 videos

COURSE RATING

Training Features


Practice Exams
These practice tests help you review your knowledge and prepare you for exams.

Virtual Lab
Use a virtual environment to reinforce what you are learning and get hands-on experience.

Offline Training
Our iOS and Android mobile apps offer the ability to download videos and train anytime, anywhere offline.

Accountability Coaching
Develop and maintain a study plan with one-to-one assistance from coaches.

Supplemental Files
Files/materials that supplement the video training.

Speed Control
Play videos at a faster or slower pace.

Bookmarks
Included in this course
Pick up where you left off watching a video.

Notes
Included in this course
Jot down information to refer back to at a later time.

Closed Captions
Follow what the trainers are saying with ease.
Ben Finkel
Nugget trainer since 2014