Results 1 to 4 of 4

Thread: Static Arrays?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Question

    Does anyone know if there is anyway i can declare an
    array static so it holds it's value if i want to access
    it from out of it's scope?

    String filename
    byte[] fileholder;

    while ((character = fileinputstream.read(fileholder)) != -1){}
    for(int k = 0; k < fileholder.length; k++){
    String s = new String(fileholder);
    System.out.print(s);}

    // when the for loop executes nothing is printed becuase
    i think the byte[] file holder is being accessed out
    of it's scope. It's not that i need to print out the
    contents of fileholder, i just need a way to fill it up
    and be able to use it at a later time.








  2. #2
    Guest
    Placing the keyword "static" in the declaration will make that item "static", however, static means that all instances of a class will share this member's value(s).

    Strictly speaking, "Global Scope" is a kind of no-no in Java (or true OOP), but the keyword "public" may give you what you need.

    In fact, "public" in "public static void main(String[] args)" makes "main" callable by java.exe and "static" makes "main" callable without instantiating a "Test object" (instance of class Test).

    //GlobalStuff.java
    public class GlobalStuff{
    public static String filename;
    public static byte[] fileholder;
    }
    //Test.java
    public class Test{
    public static void main(String[] args){
    GlobalStuff.filename = new String("Hello");
    System.out.println(GlobalStuff.filename);
    GlobalStuff.filename = new String("Good Bye");
    System.out.println(GlobalStuff.filename);
    }
    }

    BTW, I'd like to get a copy of the problem statement for htmlparser. Your teacher may be nicely describing the required components for a web browser. Right now, my main issue is with wrap around text/hyper-links.

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Talking

    I wish my teacher presented a clear specification of exactly what he wants in terms of this project.
    I get what he whats but others in the class are kind of lost {{{laughing}}}. From what i get of what he is saying
    all he wants is somthing that reads in a text file and parses out the tags only. Im comming to the end of a 17 month computer programming course at a local tech school so this really isnt any high level stuff if you know what i mean. I would have preferred doing a web browser project
    myself but at this point i just want to finish this crappy course and split!

  4. #4
    Guest
    What exactly is meant by "parses out the tags only"? I saw some code where you were looking for "<", but are you concerned if it is a "<" within a tag but not a tag itself?

    Are you just printing out the tags in the file or are you going to do something with the tags?

    Will the output look like this:
    Found Tags:
    <HTML>
    <HEAD>
    <TITLE>
    </TITLE>
    <HEAD>
    <BODY ??? What if there are attributes?
    <IMG ???
    </BODY>
    </HTML>

    Or will it just look like this:
    Found Tags:
    HTML
    HEAD
    TITLE
    /TITLE
    HEAD
    BODY
    IMG
    /BODY
    /HTML

Posting Permissions

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



Click Here to Expand Forum to Full Width