FAQ: Learn Java: Variables - Static Checking

This community-built FAQ covers the “Static Checking” exercise from the lesson “Learn Java: Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Static Checking

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

Why does a string variable require an upper case “S”, when other variable types begin with a lower case letter?

That was actually briefly evoked on the exercise that starts using String variables.

The types we had been using so far, int, double, char and so on, were the so-called primitive types.

String was referred to as somewhat different, as Strings are objects.

When gaining experience in Java the difference between these two becomes absolute and obvious, but so far all we should try to get is that they are different.

(Though, String and the others we’ve seen so far, should feel very different for one reason. Primitives like int or double or so, are atomic. Scalar. They contain one thing that is its own thing. int contains one number, double also contains one number though it can be decimal, char contains one character, boolean contains one true or false. But String is a sequence of stuff, a sequence of characters. It is a compound of stuff that are separate from one another, not atomic. It should feel different.)

The primitive types, are the ones that Java allows, and no more than that. There are 8 of them and that’s it. They are named as Java decided would be their names, int, double, char and so on. All entirely lowercase. They are actually keywords of the Java language, and all keywords are entirely lowercase (at least up to Java 12. Could change later).

Object types, well Java provides some of them that we can use, such as String, but anyone can create new Object types. That’s actually what we do every time we write

class SomeName { /* stuff here */ }

Because anyone can make more of these, it is preferable that some naming conventions are respected. One of these conventions is that these type names start with an uppercase letter.

Java follows that convention with the classes it provides, as can be seen with String, which starts with a capital S.

1 Like

I used a “Clear” command to erase the compilation error message associated with the first question in the exercise to gain typing space, but to my amazement, the 2nd exercise ticked a green mark indicating that the compilation has been run successfully without errors while in actual fact, I have done no compiling yet. can I get an explanation to this?

The text in this excercise says that “The program will not compile if the declared type of the variable does not match the type of the assigned value”.

However, in line 5 the variable isn’t the correct type as it says

int genre = ‘C’

instead of char but it is possbile to compile the file with this mistake. Why is it so?

1 Like