• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Needing help with my char variable  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i´m new to programing and i´m stuck here.

public class Executioners {
/*
*
*/
public static void main(String[] args) {
int my_variable = 6;
short my_short = 6;
char Alfred = 'a';

   
// TODO Auto-generated method stub
System.out.println(my_variable);
}

}


How do I give the variable "Alfred" a value. It shows me the error "The value of the local variable "Alfred" is not used.
 
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At what process did you get the error message? Your code looks quite good to me. The declaration and initialization of the Alfred variable is fine.
 
Marshal
Posts: 4465
284
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it's an actual error from the compiler? And not just a recommendation / suggestion from your IDE?
 
Sheriff
Posts: 5130
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A note on your post: If you UseCodeTags (that's a link) you won't lose the nice formatting of your code:
Looks better, huh?
 
Üzeyir Kilic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Are you sure it's an actual error from the compiler? And not just a recommendation / suggestion from your IDE?



It´s an error. "The value of the local variable alfred is not used"
 
Üzeyir Kilic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:A note on your post: If you UseCodeTags (that's a link) you won't lose the nice formatting of your code:
Looks better, huh?



Thanks. It was my first post btw. I got that suggested but didn´t want to mess around too much
 
Tim Cooke
Marshal
Posts: 4465
284
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where exactly do you see that error?
 
Üzeyir Kilic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Where exactly do you see that error?



short my_short = 6;
char Alfred = 'a';

"my_short" and "Alfred" are yellow underlined
 
Tim Cooke
Marshal
Posts: 4465
284
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Knute Snortum
Sheriff
Posts: 5130
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Üzeyir Kilic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Knute Snortum
Sheriff
Posts: 5130
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

Here is a wiki page that will get you started.
 
Üzeyir Kilic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Here is a wiki page that will get you started.



I´m already learning the IDE. I downloaded Eclipse since it´s the most popular and am programing and trying out Java on it.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables work its just that you aren't using all of them.
 
Rancher
Posts: 320
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 word intimidating 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.

Hope this helps. Cheers.
 
Marshal
Posts: 6015
415
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Randy Maddocks wrote:Hope this helps. Cheers.


That's indeed helpful. I just assigned skull, just joking, cow on me, great post
 
Randy Maddocks
Rancher
Posts: 320
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Liutauras, very much appreciated!   
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works just fine, that is the right way to make a char variable.



Result:
a
 
Knute Snortum
Sheriff
Posts: 5130
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

cris ortiz wrote:The variables work its just that you aren't using all of them.


This has already been discussed.  Be sure you are adding something new to the thread when you post.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!