Right, so you're seeing it in your IDE. Eclipse, or IntelliJ, or some other.

Like I said, are you sure it's an error? I propose that it's just your IDE giving you a suggestion. I have run your code using just a terminal and the javac command with no error or warning.

It is recommended that when starting out with java programming that you do not jump straight in to using and IDE and keep it simple by using the command line tools. That way you really learn what errors and messages are coming from the compiler and what messages are just IDE sugar. Don't get me wrong, IDE's are a great tool and are hugely useful but it's extremely important to understand what the IDE is doing for you first.

At least in Eclipse, it's just a warning. It's telling you you're not using a local variable, which usually a mistake is spelling. It's not a compiler error. To prove this, you can compiler your file at the command line:

All things are lawful, but not all things are profitable.

Üzeyir Kilic

Greenhorn

Posts: 6

posted 4 months ago

Tim Cooke wrote:Right, so you're seeing it in your IDE. Eclipse, or IntelliJ, or some other.

Like I said, are you sure it's an error? I propose that it's just your IDE giving you a suggestion. I have run your code using just a terminal and the javac command with no error or warning.

It is recommended that when starting out with java programming that you do not jump straight in to using and IDE and keep it simple by using the command line tools. That way you really learn what errors and messages are coming from the compiler and what messages are just IDE sugar. Don't get me wrong, IDE's are a great tool and are hugely useful but it's extremely important to understand what the IDE is doing for you first.

Does that all make sense?

So when you run it, is everything running correctly? Did you copy/paste my whole class? I´m curious. I can´t really remember what I did with the IDE. I´m not a student anymore or taking any class. I do this on my freetime because i´m planing to make bigger projects one day. So I guess I don´t have the structure of how to attempt things.

Even with people like me, who don't think it's a bad idea to learn an IDE as you learn Java, I still believe that knowing how to run from the command line is essential. All you need is a JDK and a text editter (like Notepad++ on windows or vim on Linux).

Knute Snortum wrote:Even with people like me, who don't think it's a bad idea to learn an IDE as you learn Java, I still believe that knowing how to run from the command line is essential. All you need is a JDK and a text editter (like Notepad++ on windows or vim on Linux).

Knute Snortum wrote:All you need is a JDK and a text editter (like Notepad++ on windows or vim on Linux).

I have to agree with Knute on this. When you're beginning to learn programming an IDE like Eclipse can be a little "intimidating". I use the wordintimidating carefully, because I don't want to make it sound like Eclipse is some kind of "bad guy" here, designed to overwhelm you with coloured, underlined code in your project, with messages that can confuse you. But when starting out, enough cannot be said about building a solid foundation of programming concepts by using a simple editor like Notepad++. It strips out all the intuitiveness you get from IDE tools like Eclipse, and makes you focus on things like code syntax, logic, and so on. Once you have a good grasp of the fundamentals, then progress to an IDE like Eclipse. Then you're likely in a position to understand situations that come up like this one, where the IDE is simply pointing out to you that your declared and initialized variable Albert is not being used any where in your code. A warning like that, although not considered an error, can serve a bigger purpose when you're working with a lot more code and you inadvertently declare a variable that is needed, but which you neglect to actually use in your code.

There are other concerns with your code, but for the purposes of this post I'll stick to the specific warning you asked about.

The warning would disappear if you were to do something like this:

Now you're using the variable Alfred to show the value stored in that variable.