• Post Reply Bookmark Topic Watch Topic
  • New Topic

Needing help with my char variable  RSS feed

 
Üzeyir Kilic
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.
 
Wayan Saryada
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.
 
Tim Cooke
Marshal
Posts: 4051
239
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?
 
Knute Snortum
Sheriff
Posts: 4287
127
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: 4051
239
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: 4051
239
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: 4287
127
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: 4287
127
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!