Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Cool Variable Storage and Global Variables in Java

    hi
    i had two querys..so please answer me if u have time

    1. why a single value can be stored in a variable ? why cant we store two values ? i mean int a=5 means 5 is stored in a variable a...why cant we store 2 values..i want to know the exact reason.. ?

    2.Why global varaibles concept is not present in java ? Is there any security problem or referrential transparency problem ? if not how can we implement that functionality ?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default Re: Variable Storage and Global Variables in Java

    why cant we store two values
    That is true of many things. Either it has one value or another value. What things can you think of that can have more than one value?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Variable Storage and Global Variables in Java

    You can store 32 bit values in an int. And appoximately infinitely many in a BigDecimal (*).

    public class Global {static int answer = 42;}

    (*) nyah, nyah

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default Re: Variable Storage and Global Variables in Java

    You can have globally accessible variables as shown by pbrockway, but they're frowned upon as bad coding practice.
    Constants, no problem, but variables aren't generally a good idea.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Global variables
    By nikkka in forum New To Java
    Replies: 6
    Last Post: 03-16-2011, 09:10 AM
  2. 1 of 8 global variables not visible
    By Bobbo in forum New To Java
    Replies: 7
    Last Post: 12-02-2010, 05:07 AM
  3. global variables
    By blackstormattack in forum New To Java
    Replies: 1
    Last Post: 03-08-2009, 07:19 PM
  4. How to undefine a Global Variable in JAVA?
    By ajaykushwaha in forum New To Java
    Replies: 13
    Last Post: 11-19-2008, 10:53 PM
  5. Declaring global variables
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 12:11 AM

Posting Permissions

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