Results 1 to 14 of 14
  1. #1
    ajaykushwaha is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default How to undefine a Global Variable in JAVA?

    How to undefine a Global Variable in JAVA?

    what is the method used in java to undefine/unset a global variable in JAVA.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What you mean by Global variables? Can you explain little more what you are expecting on global variables?

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Easy. You don't have to because there are no "global variables" in Java.

  4. #4
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    ajaykushwaha may be referring to instance variables.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by matzahboy View Post
    ajaykushwaha may be referring to instance variables.
    Ya, I think so. Depends on his design there are two choices actually.

    Instance and Class members

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by matzahboy View Post
    ajaykushwaha may be referring to instance variables.
    To tell you the truth, it doesn't really matter what he meant, since he didn't ask it. Until he asks a question that actually makes sense it does no good to guess at what he meant.

  7. #7
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    To tell you the truth, it doesn't really matter what he meant, since he didn't ask it. Until he asks a question that actually makes sense it does no good to guess at what he meant.
    I disagree. He may be new and not know the technical term. When I was learning java for the first time in school, my teacher explained instance variables as global variables.

  8. #8
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Quote Originally Posted by matzahboy View Post
    I disagree. He may be new and not know the technical term. When I was learning java for the first time in school, my teacher explained instance variables as global variables.
    Same here I have been programming for 3 years and still use the term global variables. This is my first time seeing something like they don't exist.

  9. #9
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Global variables is a term that carries between languages. Almost every language has global variables, but not every language uses the term instance variables.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    To tell you the truth, it doesn't really matter what he meant, since he didn't ask it. Until he asks a question that actually makes sense it does no good to guess at what he meant.
    Lol, some people doesn't know exact technical terms. So they try to explain on what they know, they heard. What we should do is try to make some guesses and help him/her, isn't it? But if someone done it again and again, we have to think as you said. It's critical I think.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by matzahboy View Post
    Global variables is a term that carries between languages. Almost every language has global variables, but not every language uses the term instance variables.
    Yep, lots of people have this conflict from C/C++ to Java. In C/C++ we refer Global variables.

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    A global variable is a variable that can be referenced throughout the program with just it's designation, without a need for prepending the Class (or whatever might otherwise be used in other languages), as they exist in a "global" namespace. Java does not have those.

    Now maybe he means instance variables, maybe he means class variables, maybe he means "public static final variables", maybe he means something else. Until he clarifies what it is he means, we cannot help him. As "cruel" as that may sound, it is the truth. We can take "stabs in the dark" for years, and eventually touch on what he wants, but why? All he has to do is come back and say "I mean those variables that are defined by a line of code similar to the following: " and post an example. Then, he can not only be helped with his original question, he can also be instructed as to what they actually are.

  13. #13
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by matzahboy View Post
    my teacher explained instance variables as global variables.
    I can't imagine this. An instance variable, or a member variable of a class, say a Student class, is about as far away as you can get from a global variable. You have to have a Student object to begin to talk about it.

    Static variables in a class are nearly global when public. They are, of course, a really bad idea.

    As is the singleton pattern from the Gang of Four book.

  14. #14
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by fishtoprecords View Post
    I can't imagine this. An instance variable, or a member variable of a class, say a Student class, is about as far away as you can get from a global variable. You have to have a Student object to begin to talk about it.

    Static variables in a class are nearly global when public. They are, of course, a really bad idea.

    As is the singleton pattern from the Gang of Four book.
    Let's just say that I didn't have a good teacher. Almost all I know about java is from the textbook and learning on my own. I mostly didn't pay attention in that class, since the teacher couldn't teach well.

Similar Threads

  1. Would you like to publish your game global?
    By tridens in forum Reviews / Advertising
    Replies: 0
    Last Post: 08-18-2008, 09:42 AM
  2. Global constants
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 09:06 AM
  3. Declaring global variables
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 12:11 AM
  4. Replies: 1
    Last Post: 08-06-2007, 02:17 AM
  5. save global data in servlets
    By Marty in forum Java Servlet
    Replies: 1
    Last Post: 05-31-2007, 06:38 PM

Posting Permissions

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