
That just creates a variable x that is a boolean variable without setting its value. We're also setting the variable equal to something, and here we're setting it to true. In this case the variable's name is x, and it's type is boolean. In Java, the type of variable has to go before the variable's name. This is how a boolean variable is created. I say special because in true and false are actually values that the language recognizes. If you want to avoid problems just don't use any symbols in your variable names (it's bad coding style anyway).Ī boolean is one of the special Java variables that stores either true or false. I won't go over all the symbols you cannot use because the list is extensive. Java won't allow this either because Java uses the closing parenthesis as a special symbol. Try naming your variable ")x" (again, without the quotes). Try naming your variable "if" (without the quotes). Since Java uses these words for specific purposes, you cannot name your variables as those keywords. Java has certain words that are used in the language. Java variables cannot be a keyword already.Java variables cannot start with a number or special symbol.In general, you can name your variables whatever you want, as long as they follow these simple guidelines: Of the list above, we'll go into detail with boolean, char, double, and int.īefore we begin looking at the types, there's some rules we have to follow when picking variable names. The only more complicated type you've dealt with so far is String, so I'll discuss those as well. There are other types of Java variables, but those are more complicated to deal with. Java specifically has these variables as primitive types (don't worry about what a primitive type means): Java variables work no different from regular math variables. Now X is equal to Hello world! A pretty simple concept, right? X right now equals 4 because that's how I have it set. There, now if I say what is the value of X, you would have to tell me 4.

X holds a value, but I haven't told you what it is yet. For example, lets say you have a variable called X.


What if you want to output numbers? What if you'd like to be able to perform simple calculations? Obviously there's no sense in having a program that does not perform any useful work for you, so we need to introduce a new concept: variables.Ī variable holds a value that's its only purpose. While this is great, we'd like to be able to do much more with Java. This means that your programs can output whatever words, phrases, and sentences you'd like.
#SYMBOL FOR DOES NOT EQUAL IN JAVA HOW TO#
If you've been following the tutorials then you have learned how to output strings onto the screen.
