Java Keywords and Expressions

A free video tutorial from Tim Buchalka
Java Python Android and C# Expert Developer - 912K+ students
4.6 instructor rating •
12 courses •
924,157 students
Lecture description
In this video we will learn about Java keywords as well as what makes up an expression. You will find out the keywords that Java has already reserved, how Java lets you know that these keywords are reserved, and you will get to know what a valid expression looks like. A Challenge is at the end of the video to assist your understand of these important concepts.
Learn more from the full course
Java Programming Masterclass for Software DevelopersLearn Java In This Course And Become a Computer Programmer. Obtain valuable Core Java Skills And Java Certification
80:09:25 of on-demand video • Updated April 2021
- Learn the core Java skills needed to apply for Java developer positions in just 14 hours.
- Be able to sit for and pass the Oracle Java Certificate exam if you choose.
- Be able to demonstrate your understanding of Java to future employers.
- Learn industry "best practices" in Java software development from a professional Java developer who has worked in the language for 18 years.
- Acquire essential java basics for transitioning to the Spring Framework, Java EE, Android development and more.
- Obtain proficiency in Java 8 and Java 11.
English
In this video we're going to talk more
about keywords, and also just elaborate a little bit on expressions, which we've
already covered to a degree previously. Firstly with the keywords. Now Java has actually got 50
reserved words that are used for keywords in your applications. And you have seen some of
those in operation already. For example on the screen you can see some
of the keywords that are showing in blue. IntelliJ will actually
highlight keywords in blue to show you that they actually are a keyword. So, what I'm going to do is just go to a
browser, and I'm gonna paste in this link. And the link will be in
the resources section of this video. And here is a list of Java keywords, and you can see in the Java programming
language a keyword is one of 53 reserved words that have a predefined meaning in the language and as we scroll down in the list you will see some of this you already use boolean is one double is another And also float but don't worry you don't need to memorize any of these because we are going to go through each and every one of this in the course but the thing is they are reserved and lets swing back to IntelliJ and I'm going to talk further about that And incidentally, if you pull this video, I've created a new
project called KeywordsAndExpressions. So anything in blue,
that's showing IntelliJ editor is confirming to you that
this is a reserved word. So for example, we can't go in here,
And create a variable called. So if we type int int=5; unexpected token. And that's because as far as IntelliJs
concerned, int is a reserved word. It's actually a data type. We could use int2, that would be
quite valid because that's only using part of the word, but
you can't use an exact word. So anytime you get into weird errors,
just make sure that you're not using a reserved keyword, and
you can refer back to that list. And some of the other keywords that you've
already seen that you can't use are false, you saw false before, we've used that
in a previous video, true, and null. But we'll be talking about those
as we progress through the course. So as I mentioned, by the time
you've finished with this course you will have gone through
all 50 of those keywords. We will have a good understanding
of what they actually are. Okay, now lets talk now about expressions. We have talked a little bit
in the past about those and you have seen some of those in operations,
but lets just expand that a little bit more just so we have a specific
understanding of what expressions are. I am just going to delete this and
make a bit more space. Expressions are essentially building
blocks of all Java programs. You'll be using expressions a lot,
and expressions are built with values, variables, and operators,
which you've seen previously. But also with method calls, which we'll be discussing in a future
set of videos later in the course. For example, if we wanted to
create an expression to convert miles into kilometers, you'd need to
know firstly that a mile was equal to- To 1.609344 kilometers. So if we wanted to figure out what a 100
miles were converted to kilometers, double kilometers equals
100 times 1.609344. So that would be a valid statement. For that line, the actual expression
is this component of the entire line. The data type does not form
part of an expression, but everything else on the line typically
forms or is part of the expression. So the expression component is variables,
values, and operators. All of those used in this case. We've got a variable kilometers. We've got values, like a 101.609344. And of course, operators,
equals, and multiplications. So that's an expression
this component of the line. By adding the datatype,
we're creating a valid java statement. The combination of that And also the semi
colon at the end of the line as well. Some more examples of expressions. We've got something like
if highscore equals 50. As we've done before. We're getting an error because
I haven't defined the variable. So I'll just define that. So, this component is the expression. Within the brackets as you can see there. So, the keyword for
if in the brackets, and the braces as well do not form part of
the expression as this component in here. And incidentally there's
another expression, and the expression is quite valid as well. With a literal value as it's
got there with the number 50. And finally, another valid expression. Is this component here. So the component within
the brackets is also an expression. And that's actually calling a method. And we'll be talking about methods in
a future section of the course as well. The main idea is just to get your head
around what components of the entire line is an expression from what
an expression actually is. Just a confirmation when
you're defining a variable the entire line minus
the semi colon at the end and the datatype is the expression,
so that's that component there. Or with the literal value that's the component there minus the data
type at the start and also the semi colon. If you've got a control statement, control
flow statement, and we'll be talking more about those also in future videos, the
component in brackets is the expression. And if you're using a method, and again,
methods, we're going to be covering later, but anything in the brackets, essentially,
that is also an expression as well. And now that you know that
I'm going to clear this off, the other that's off the screen. And my challenge for you is as follows. Have a look at the code that
you can see on the screen. Write down what components of the lines
I've entered there are expressions. And come back and check your results
after you've had a go at it. So, how did you get on? Did you figure it out? Let's go through and talk this through. So the components that are expressions,
firstly on the first line. The score equals a hundred
component is the expression. Remembering that a data type and also the semicolon to the end the line
are not part of the expression. In the second example,
the if score greater than 99. Well the part in brackets
is also an expression. So the if, the braces, and the brackets
do not form part of an expression. In the next case we’ll be
printing out to the console. The component that’s in between
the brackets in the double quotes is the expression. The final example here, score = 0 that
is also a valid expression as well. So that you figure all this out,
congratulations if you got them all. So that's expressions and
you'll be seeing expressions and keywords in use a lot
more in future videos. But speaking of future videos,
in the next video we're gonna be discussing statements which
we talks on briefly here. Also, what whitespace is and the use of
indenting, So, I'll see you on that video.