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?

3 Likes

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.

3 Likes

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

public class Mess {
public static void main(String args) {
String title = “Shrek”;
double runtime = 1.58;
int number = 2;
boolean good = true;
char type = ‘A’;
}
}
What is wrong?

Exactly Why do you do it so hard for us? It s confusing.

I don’t understand this at all. Again, what is it asking me to change? Why is it so hard to learn a simple ;language?

public class Mess {
public static void main(String args) {
String year = 2001;
double title = “Shrek”;
int genre = ‘C’;
boolean runtime = 1.58;
char isPG = true;
}
}

There is a mismatch between how the variables (year, title, genre, runtime, isPG) have been declared AND the values assigned to them. For example, year has been declared as a String but it has been assigned an integer value 2001. If you change the statement from String year = 2001; to int year = 2001; this will fix the mismatch. Similarly, go through all the statements and fix the declared type so that there is no mismatch. “Shrek” is a string but it has been assigned to title which is of type double. If we edit statement to String title = "Shrek"; this will fix the statement. Do the same for the rest of the statements.

Thank you for the reply. I’m really lost, Is there a mistake in the tutorial files i need to fix before trying the exercise? I know there were some issues like that with another bootcamp I tried. As far as what you suggested…I keep reading this over and over but i can’t figure it out, the changes… double, string, statement? Do I need to learn another language before learning javaScript?

I’m starting the lesson over. I wish I could share exactly what it is but I’m not even sure what’s confusing, like literally everything in the lessons makes no sense at all. I don’t know why this is so hard for me. I always had problems remembering weird concepts like this in school too.

I don’t think this is realistic, programming is for smart people but i’m a dropout. I don’t even know what to ask about? I don’t understand a single thing in the tutorials. it says:

Use string concatenation to concatenate a string with a space ' ' between the two other words: Use the + operator to join three separate strings:

console.log(‘string1’ + ’ ’ + ‘string2’)

concatenation? I only see string1 and string2

How do i figure out what this means? I’m not a math person at all. I still don’t even know what JavaScript does actually, I keep reading about it but it doesn’t make sense.

I’m confused about the first part. I put in javac Mess.java into the terminal on the right, but it says it’s wrong. IDK what to do next or what the solution is.

After you type in javac Mess.java in the terminal, do you see the green check mark next to Step 1 of the instructions?
If you do see the check mark, then you should ignore the errors and proceed to Step 2. The errors are expected behavior, because there are mistakes in the file which have to be fixed in Step 2. Once you have successfully fixed the errors, you should see there are no more warnings after compilation.

No, I don’t see a green check mark. It has a red x next to it, and it says I haven’t put it in the terminal, even though I have. I’ve checked that I’ve proper spelling and punctuation, since it seems to case sensitive, but nothing seems to be working

All I can suggest is to reset the exercise via the reset button next to ‘Run’. If that doesn’t fix the issue, then I don’t have any idea.
I just reset the exercise and tried completing the exercise again. It worked fine for me. After I typed javac Mess.java in the terminal and pressed enter, 4 errors were shown in compiling but a green check mark appeared next to Step 1. After I fixed the errors and hit the Run button, I was able to complete Step 2. In Step 3, I compiled the file through the terminal. If the reset doesn’t work for you, I don’t know what is going wrong.

it’s telling me cannot find symbol
string title = “Shrek”;

Instead of string title = "Shrek", use String title = "Shrek"
At the beginning of this thread, you can see a reply from ajax about why Java requires the S in String to be capitalized.

1 Like

During Static checking, why ( int genre = ‘C’; ) statement haven’t been seen as an error?

1 Like

Haven’t looked at it too closely, but I think it has to do with implicit type casting. The char type can be implicitly converted by the compiler to an int equivalent, so no error is raised.
Have a look at the first paragraph in this page titled Java char to int – implicit type casting
You may also want to have a look at this table to see the integer equivalents of characters. A stackoverflow thread on the same subject.
Based on the above, I think int genre = 'C' would result in the character 'C' being implicitly cast into its integer equivalent 67.

1 Like