Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » questions about Java programming
Closed Thread
Old 09-05-2007, 04:54 PM   #1 (permalink)
 
Newb Techie

Join Date: Sep 2007

Posts: 1

fleahuncut is on a distinguished road

Default questions about Java programming

What is the difference between a constant and a variable? Aslo, in a program where is the constant and/or variable found?
fleahuncut is offline  
Old 09-05-2007, 06:46 PM   #2 (permalink)
void's Avatar
 
True Techie

Join Date: Oct 2005

Posts: 198

void

Default Re: questions about Java programming

A constant is a value that is set once at compile time and cannot change, whereas a variable can change whilst the program is running. There isn't a specific place to find constants and variables as they can be global to the program, local to a method or a member of a class.
void is offline  
Old 09-11-2007, 01:17 PM   #3 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: questions about Java programming

What void said, but in addition, with Java, constants will be tagged with the "final" keyword. Eg:

public static final String numberPattern = "0123456789";

Then with variables, they are (in some sense) everything without the "final" keyword. Eg:

private String hi = "hi";
Integer zero = new Integer( 0 );
protected JFrame frame = new JFrame( );
int counter = 0;

etc.
__________________
Vormund is offline  
Old 09-11-2007, 09:03 PM   #4 (permalink)
zmatt's Avatar
 
The Bulldog

Join Date: Mar 2006

Location: In an empty Ramen packet

Posts: 4,370

zmatt has a spectacular aura aboutzmatt has a spectacular aura about

Default Re: questions about Java programming

for a more simpler look a few common variables are

int (integer)
double (floating point aka anything with a decimal)
string (a sentence or group of characters)
char (one character)

all of these are made constant with the FINAL tag. sorta oxymoronic really. a constant variable..........
__________________


ポップ・タルトが大好きです。
<<<<<<<Rep is always welcome
Ultimate Guitar exercises/ Songs for technique
zmatt is offline  
Old 09-12-2007, 01:43 AM   #5 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: questions about Java programming

Quote:
Originally Posted by zmatt View Post
all of these are made constant with the FINAL tag. sorta oxymoronic really. a constant variable..........
Hmm, o'course it is, since that phrase should never be used. :happy: It could be a constant reference, pointer, value, number... but not a variable, as you pointed out!
__________________
Vormund is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lots of questions help.... pinoy3000 Building, Buying, or Upgrading High Performance PC Systems 4 09-01-2007 02:28 AM
Two questions before pulling the trigger... Portland Newb Building, Buying, or Upgrading High Performance PC Systems 12 08-16-2007 01:07 PM
New Hack Technique Exploits Common Programming Error Osiris Virus - Spyware Protection / Detection 0 07-23-2007 02:26 PM
Dangerous Java Flaw Threatens Virtually Everything Osiris Virus - Spyware Protection / Detection 1 07-13-2007 04:44 PM
Java Game Yek Programming Discussions 5 06-16-2007 04:29 AM