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?

2 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.

2 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.