Results 1 to 3 of 3

Thread: Variable Naming

  1. #1
    67726e is offline Member
    Join Date
    Mar 2010
    Hilton Head, SC
    Rep Power

    Default Variable Naming

    I have found no equivocal in any programming language I have used or come across and what I am currently wondering is if you can take a variable value (of a string) and use that value to create a new variable.


    My username is 67726e, and I have a login form for a chat program. I have any user enter a username during their chat session. Would there be a way to take the username used during the 'login' and use that as a string variable name.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    This is not really the Java "way". If you want to associate an object with a String, then use a Map such as a HashMap. What's important here is more the object and not the variable, and objects don't have names. In fact many objects may be unassociated with any simple variable (anonymous objects, for instance), and in fact even if you create a variable, name it 67726e, what's to prevent you from later having it reference another user named "Fred"? What you are trying to do though is to associate an object with a String, and Maps are tailor made to do this and worth investigating.
    Last edited by Fubarable; 03-30-2010 at 02:14 AM.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Rep Power


    And, as an aside, you can't have a variable starting with a number in Java anyway...:)

Similar Threads

  1. Naming Arrays
    By cs1h in forum New To Java
    Replies: 5
    Last Post: 01-05-2009, 05:17 AM
  2. Naming a class instance with a variable
    By pikalex88 in forum New To Java
    Replies: 3
    Last Post: 09-30-2008, 06:27 PM
  3. Naming a Class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 12:21 PM
  4. RMI naming problem
    By Robbinz in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 12:32 AM
  5. Naming conventions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts