Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to make an array a global static variable

  1. #1
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default How to make an array a global static variable

    I have an issue where I need an array as a global variable. If someone could tell me if that is possible and/or how to do that then that would be great. (insert meme here XD).


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to make an array a global static variable

    There is no such thing as a global variable in Java.

    The closest parallel is to create a public static member of a class, then every class which wants to use that "global" would reference it from the given class.

    public class MyGlobals
    {
        public static int[] data = new int[]{1,2,3};
    }

    An alternative is to employ the singleton idiom.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    lil_misfitss (August 15th, 2013)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to make an array a global static variable

    If you explain WHAT you're trying to do - a code example would be great - someone here can explain HOW to do it. The solution won't include the approach you've suggested.

  5. #4
    Junior Member
    Join Date
    Aug 2013
    Location
    ferozepur(India)
    Posts
    1
    My Mood
    Hungover
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How to make an array a global static variable

    you make a global type array just as like you instantiate a array. But one thing remind it, that array elements are always get a default value irrespective of the position of a array.

  6. The Following User Says Thank You to Rahul bansal For This Useful Post:

    lil_misfitss (August 15th, 2013)

  7. #5
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: How to make an array a global static variable

    Thank you all for the help! Especially Rahul Bansal and helloworld922. My professor called the example helloworld922 gave, global variables. Sorry for the misuse of the term.

Similar Threads

  1. topic related to static final variable and static block !!!!
    By Arnab Kundu in forum Java Theory & Questions
    Replies: 4
    Last Post: July 19th, 2013, 09:06 AM
  2. topic related to static final variable and static block !!!!
    By Arnab Kundu in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 18th, 2013, 12:12 PM
  3. [SOLVED] Problem while getting a number from another thread
    By Koren3 in forum Threads
    Replies: 4
    Last Post: April 7th, 2009, 01:42 PM