Question on array.Length

I have an array[4]. Then the subscripts are number 0, 1, 2, 3. Does array.Length return 4 or 3. I am thinking 4 but I want to make sure.

java.secure(?).SecureRandom.java.security.SecureRandom
It's more straightforward and has better statistical properties.While I agree, with the straightforward,
but statistical I would of thought they'd
be even.It's better for several reasons:
1) nextInt is faster. It uses (on average) 1-1/3 calls to next(int), whereas nextDouble() (what Math.random() uses) always uses two. This also means nextInt will use up the generator's period more slowly.
2) It's statistically better. Although the odds of you noticing that some numbers are favored (slightly) over the "noise" of the prng's own bias are negligible.
3) It's nicer to use nextInt. It uses OO (instead of the relatively global function call to Math.random()), it doesn't compete with other parts of the Application for using up some of the prng's period, it allows the substitution of other (better or worse) algorithms with fewer changes, and it looks better.
~Cheers

Similar Messages

  • Quick array length question...

    for this part of my code i'm trying to determine the components needed to find the average of my array. I can't seem to find a way to determine the length of my array (how many components it consists of). Every time I keep getting the dereferencing error....I know it's something simple but I just can't seem to get it right. Please help!
    int total = 0, mean = 0, length = 0;
    for(int j=0; j<i; j++)
    total = total + array[j];
    System.out.print(array[j]+" ");
    System.out.print(total);

    Hi Cher,
    This length attribute if any array object will give you the number of components I mean number of elements in that array.
    array.length; rather than array.length();
    This may be helpfull.
    int total = 0, mean = 0, length = 0;
    for(int j=0; j<array.length; j++)
    total = total + array[j];
    System.out.print(array[j]+" ");
    System.out.print(total);>
    Aski

  • A question about arrays (brace yourself this is a long post)

    I am working on an assignment that is about generating a random rabbit race by using arrays:
    Rabbit Race
    Write a program to simulate a race between 4 rabbits (numbered 0 to 3). Initially, all contestants are at the start of the race track (position 0) and must race on a 20 meter track (positions numbered 0 to 19). Each participant has its own technique; some run fast, but are sometimes lazy; while others run slowly but steadily. All rabbits make 1 movement one after the other and the one who arrives at the end of the track before the others, wins the race. Here are the rabbit?s strategies :
    At each turn, rabbit 0:
    - sleeps (so does not run), 50% of the time;
    - runs 4 meters, 30% of the time;
    - runs 3 meters, 20% of the time.
    At every turn, rabbit 1 runs 2 meters.
    At each turn, rabbit 2:
    - sleeps, 30% of the time;
    - runs 3 meters, 70% of the time.
    At each turn, rabbit 3:
    - runs 1 meter, 80% of the time;
    - runs 10 meters, 20% of the time.
    The difficulty in the race is that the track has little slippery hills. So after each movement, rabbits can slide down a hill bringing them either closer to the finishing line, or closer to the starting line. How much they slide and in what direction depends on the slope of the hill at their current position, and how many meters they ran during this turn. Each position (or meter) of the hill has a slope represented by an integer between -3 and +2. If the slope is :
    - zero : then, there is no hill at this position and rabbits that reach this position stay there.
    - a negative integer : then, there is a declining side of a hill at this position, and all rabbits reaching this position will slide down
    to a new position that is closer to the finishing line. The new position will be the current position minus the slope times the number of meters the rabbit ran.
    For example, assume a rabbit was in position 10, then ran 5 meters to position 15. If the slope at position 15 is -2, then the new position of the rabbit will be 15 - (-2 x 5) = 25.
    - a positive integer : then, there is a rising side of hill at that position, and all rabbits reaching this position will slide down to a new position that is closer to the starting line. The new position will be the current position minus the slope times the number of meters the rabbit ran.
    For example, assume a rabbit was in position 10, then ran 5 meters to position 15. If the slope at position 15 is +1, then the new position of the rabbit will be 15 - (+1 x 5) = 10.
    Notes on the race:
    - Rabbits have 40 turns to reach the finish line. If after 40 turns no one has managed to reach position 19 (or beyond), then the race is cancelled and no winner is declared.
    - A rabbit?s position can never go below 0. If, after calculating a rabbit?s position, you arrive at a negative position (ex. position -3), then consider that it is at position 0.
    - Consider that any position outside the track (ex. position 0 or position 20) has a slope of 0.
    - If a rabbit reaches position 19 (or goes beyond it), it does not immediately win the race. If any other rabbit reaches position 19 (or beyond) during the same turn, then there is a tie.
    - If at the same turn, one rabbit reaches position 19, and another reaches a position higher than 19, the second rabbit does not win the race because it went further than the first. They both win.
    Ok I know this is long and boring to read but I already completed the majority of the assignment here is my code:
    public class Assignment_3 {
        public static void main (String args[])
             int[] position = new int[20];
             int[] slope = new int[20];
             int[] moveRabbit = new int[4];
                   moveRabbit[1] = 2;
             int[] currentPosition = new int[4];
             int currentPositionandSlope = 0;
             for (int i=0;i<position.length;i++)
             {     position=i;
              System.out.print(position[i] + " ");
         System.out.println();
         for (int i=0;i<(position.length-5);i++)
         {     slope[i]=(int) (-3 + Math.random()*5);
         for (int i=0;i<position.length;i++)
              System.out.print(slope[i] + " ");
         System.out.println();
         for (int turn=1;turn<=40;turn++)
              int randomNb0 = (int) (Math.random () * 100);
    int randomNb2 = (int) (Math.random () * 100);
    int randomNb3 = (int) (Math.random () * 100);
              if (randomNb0<=50)
                   moveRabbit[0] = 0;
              else if (randomNb<=30)
                   moveRabbit[0] = 4;
              else
              moveRabbit[0] = 3;
              if (randomNb2<=30)
                   moveRabbit[2] = 0;
              else
              moveRabbit[2] = 3;
              if (randomNb3<=80)
                   moveRabbit[3] = 1;
                   else
              moveRabbit[3] = 10;
    for (int j=0;j<=3;j++)           
    System.out.println ("Rabbit" + j + " is at position " + position[currentPosition[j]]);
    if (slope[currentPosition[j]+moveRabbit[i]] < 0)
         currentPositionandSlope = position[currentPosition[j]+moveRabbit[j]] - (slope[currentPosition[j]+moveRabbit[j]] * moveRabbit[j]);
    else if (slope[currentPosition[j]+moveRabbit[i]] > 0)
         currentPositionandSlope = position[currentPosition[j]+moveRabbit[j]] - (slope[currentPosition[j]+moveRabbit[j]] * moveRabbit[j]);
    else
         currentPositionandSlope = (currentPosition[j]+moveRabbit[j]);
    System.out.println ("it will move by " + moveRabbit[j] + ", but at position " + (position[currentPosition[j]] + moveRabbit[j]) + " there is a slope of " + slope[currentPosition[j] + moveRabbit[j]]);
    System.out.println ("so it will slip by " + (position[currentPositionandSlope] - moveRabbit[j]) + " positions, and end up at position " + position[currentPositionandSlope]);
    currentPosition[j] += currentPositionandSlope;
    *Ok basically my question is that in the assignment there is an example output where the rabbit is at position 21 but the array is only 20 in length and my program crashes if i go beyond the array length.*
    The example output is here:
    Welcome to the 4 rabbit race:
    position: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    slopes: 0 0 1 -2 1 0 -1 -1 1 -2 1 0 -1 -1 1 0 0 0 0 0
    TURN #1
    rabbit 0 is at position 0
    it will move by 3, but at position 3 there is a slope of -2
    so it will slip by 6 positions, and end up at position 9
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 0
    it will move by 3, but at position 3 there is a slope of -2
    so it will slip by 6 positions, and end up at position 9
    rabbit 3 is at position 0
    it will move by 1, but at position 1 there is a slope of 0
    so it will slip by 0 positions, and end up at position 1
    TURN #2
    rabbit 0 is at position 9
    it will move by 0, but at position 9 there is a slope of -2
    so it will slip by 0 positions, and end up at position 9
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 9
    it will move by 3, but at position 12 there is a slope of -1
    so it will slip by 3 positions, and end up at position 15
    rabbit 3 is at position 1
    it will move by 1, but at position 2 there is a slope of 1
    so it will slip by -1 positions, and end up at position 1
    TURN #3
    rabbit 0 is at position 9
    it will move by 3, but at position 12 there is a slope of -1
    so it will slip by 3 positions, and end up at position 15
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 15
    it will move by 3, but at position 18 there is a slope of 0
    so it will slip by 0 positions, and end up at position 18
    rabbit 3 is at position 1
    3
    it will move by 10, but at position 11 there is a slope of 0
    so it will slip by 0 positions, and end up at position 11
    TURN #4
    rabbit 0 is at position 15
    it will move by 0, but at position 15 there is a slope of 0
    so it will slip by 0 positions, and end up at position 15
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    *rabbit 2 is at position 18*
    *it will move by 3, but at position 21 there is a slope of 0*
    *so it will slip by 0 positions, and end up at position 21*
    *We have a potential winner...*
    rabbit 3 is at position 11
    it will move by 1, but at position 12 there is a slope of -1
    so it will slip by 1 positions, and end up at position 13
    So yeah :) that's basically my question (all this text for a simple question like that lol)
    If you've managed to get to the end of my post then any guidance on my code would be appreciated too :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I'm not going to read that long post. As suggested, produce an SSCCE
    and paste in the exact, complete error message, and indicate clearly which line causes it.
    I did notice this though:
    Ok basically my question is that in the assignment there is an example output where the rabbit
    is at position 21 but the array is only 20 in length and my program crashes if i go beyond the array length.Either you're misunderstanding something, or the assignment has a typo. If you have an array of length 20, then the indices are 0..19.
    Maybe the instructor is calling index 0 position 1--separating Java's array impelementation details from
    colloquial 1-based counting, so that the rabbit starts at "position 1" (index 0) goes through "position 20"
    (index 19), and when he's done, he's "at postion 21"--i.e., past the finish line, off the end of the course, etc.
    This won't correspond to any index in the array, but can still be considered a logical position in the race. "Oh, he's
    at position 21. He's done. There's nothing more to do with the array, as it has no slot corresponding to
    this 'done' position."
    That's pure speculation on my part. You'll have to ask your instructor or figure out for yourself what's going on.

  • This and super keywords, array.length attribute

    'this' and 'super' keywords and array.length attribute are declared in which java class?
    and also during running of a java program how they are initialized and how they work?

    'this' and 'super' keywords and array.length attribute are declared in which java class?They are not declared in any Java class, any more than the keywords 'class', 'interface', 'for', 'while', etc., are. They are defined in the grammar of the Java language, in the Java Language Specification.
    and also during running of a java program how they are initialized and how they work?That's much too large a question for a forum. Try reading the Java Tutorial.

  • Maximum possible ARRAY LENGTH ?!?!

    Hello All
    How can I know (before allocating memory) what is the maximum possible array length. Does it depend on the JVM version or OS or something else ???
    Please help !

    Thanx All !!!
    I've moved to more "memory saving" algorithm, so there is no problem now :-))
    But another 2 questions has poped up: I'm using a Vector object in a pretty long loop (millions of iterations) and once in a while accumulating some data (Long and Double objects) by adding them to the Vector.
    1. What can be the maximum possible vector length ?
    2. What's faster: using a Vector object or using a regular "long or double" array that should be reallocated as:
    double[] arr = new double[****];
    for(long i=0; i<Long.MAX_VALUE; i++)
        // add new elem
        double[] tmp = new double[arr.length+1];
        System.arraycopy(arr, 0, tmp, 0, arr.length);
        tmp[tmp.length] = newElem;
        arr = tmp;  
    }

  • Question about arrays

    I have a question regarding arrays. I have a contact class and two classes that extend from it a SchoolContact class and FamilyContact class. Right now as my code is I have three diffrernt arrays to hold all the info. Is there a way to store all this info into one array and print out only the School contacts at one time if the user enters that option or print out all the options at one time if the user selects that? my code is below
    //The imports below are for I/O
    import java.util.*;
    import java.io.*;
    // Declare a public class
    public class CodeExample {
         public static void main(String[] args) {
              // Create scanner
              Scanner sc = new Scanner(System.in);
              //Declare array to hold school contact
              SchoolContact[] schoolContactInfo = new SchoolContact[10];
              FamilyContact[] familyContactInfo = new FamilyContact[10];
              Contact [] contactInfo = new Contact [10];
              // Declare variables
              int menuOption, creditHours, area, prefix, suffix, studentId, studentContactsSoFar = 0, familyContactsSoFar = 0, contactsSoFar = 0;
              double gpa;
              char studentData, familyRelationOption;
              String menuOption2, menuOption3;
              // Get menu to display
              do {
                   System.out.println("-----MENU-----");
                   System.out.println("1) Enter a Student Contact");
                   System.out.println("2) Enter a Family Contact");
                   System.out.println("3) Enter a Contact");
                   System.out.println("4) Display Student Contacts");
                   System.out.println("5) Display Family Contacts");
                   System.out.println("6) Display Contacts");
                   System.out.println("7) Display All Contacts");
                   System.out.println("8) Quit");
                   System.out.println("Selection:");
                   menuOption = sc.nextInt();
                   SchoolContact schoolContact = new SchoolContact();
                   FamilyContact familyContact = new FamilyContact();
                   Contact contact = new Contact();
                   // Implement switch statement to
                   switch (menuOption) {
                   // If user enters 1 to create contact this will be displayed to user
                   case 1:
                        System.out.println("Enter The First Name of The Student");
                        schoolContact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Student");
                        schoolContact.setLastName(sc.next());
                        System.out.println("Enter the Student ID of this person: 900");
                        schoolContact.setStudentId(Integer.parseInt("900" + sc.next()));
                        System.out.println("G)Enter The GPA For This Student");
                        System.out.println("H)Enter The Number Of Completed Credit Hours");
                        menuOption2 = sc.next().toUpperCase();
                        studentData = menuOption2.charAt(0);
                        // Prompts the user for the next choice
                        if (studentData == 'G') {
                             System.out.println("GPA: ");
                             gpa = sc.nextDouble();
                             //create the Data object
                             Data data = new Data();
                             data.setStudentGPA(gpa);
                             //add it to the contact
                             schoolContact.setData(data);
                             else if (studentData == 'H') {
                                  System.out.println("Hours: ");
                                  creditHours = sc.nextInt();
                                  //create the Data object
                                  Data data = new Data();
                                  data.setStudentCreditHours(creditHours);
                                  //add it to the schoolcontact
                                  schoolContact.setData(data);
                                  else {
                                       System.out.println("Invalid Entry");
                        System.out.println("Enter The Phone Number of This Student");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number studentPhone = new Phone_Number(area, prefix,     suffix);
                        //add it to the Schoolcontact
                        schoolContact.setPhone(studentPhone);
                        //store info in an array
                        schoolContactInfo[ studentContactsSoFar ] = schoolContact;
                        //increase the counter to point to the next free location (if any)
                        studentContactsSoFar++;
                        break;
                   case 2:
                        System.out.println("Enter the First Name of The Contact");
                        familyContact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Student");
                        familyContact.setLastName(sc.next());
                        System.out.println("Enter The Relationship of This Contact");
                        System.out.println("A) SISTER");
                        System.out.println("B) BROTHER");
                        System.out.println("C) MOTHER");
                        System.out.println("D) FATHER");
                        System.out.println("E) OTHER");
                        menuOption3 = sc.next();
                        familyRelationOption = menuOption3.charAt(0);
                        if (familyRelationOption == 'A') {
                             System.out.println("Relationship: SISTER ");
                             familyContact.setRelationType(FamilyContact.RelationType.SISTER);
                             else if (familyRelationOption == 'B') {
                             System.out.println("Relationship: BROTHER ");
                             familyContact.setRelationType(FamilyContact.RelationType.BROTHER);
                                  else if (familyRelationOption == 'C') {
                                       System.out.println("Relationship: MOTHER ");
                                       familyContact.setRelationType(FamilyContact.RelationType.MOTHER);
                                       else if (familyRelationOption == 'D') {
                                            System.out.println("Relationship: FATHER ");
                                            familyContact.setRelationType(FamilyContact.RelationType.FATHER);
                                            else if (familyRelationOption == 'E') {
                                                 System.out.println("Relationship: OTHER ");
                                                 familyContact.setRelationType(FamilyContact.RelationType.OTHER);
                        System.out.println("Enter The Phone Number of This Contact");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number familyContactNumber = new Phone_Number(area, prefix,     suffix);
                        //add it to the familyContact
                        familyContact.setPhone(familyContactNumber);
                        //store info in an array
                        familyContactInfo[ familyContactsSoFar ] = familyContact;
                        //increase the counter to point to the next free location (if any)
                        familyContactsSoFar++;
                        break;
                   case 3:
                        System.out.println("Enter The First Name of The Contact");
                        contact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Contact");
                        contact.setLastName(sc.next());
                        System.out.println("Enter The Phone Number of This Contact");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number contactNumber = new Phone_Number(area, prefix,     suffix);
                        //add it to the contact
                        contact.setPhone(contactNumber);
                        //store info in an array
                        contactInfo[ contactsSoFar ] = contact;
                        //increase the counter to point to the next free location (if any)
                        contactsSoFar++;
                        break;
                   case 4:
                        System.out.println("-----Student Contacts-----");
                        //print each stored contact
                        for( int i = 0 ; i < studentContactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + schoolContactInfo.toString() + "\n");
                        break;
                   case 5:
                        System.out.println("-----Family Contacts-----");
                        //prints each stored contact
                        for( int i = 0 ; i < familyContactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + familyContactInfo[i].toString() + "\n");
                        break;
                   case 6:
                        System.out.println("-----Contacts-----");
                        //prints each stored contact
                        for( int i = 0 ; i < contactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
                        break;
                   case 7:
                        System.out.println("Calling Case 7");
                        for( int i = 0 ; i < contactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
                        break;
                   case 8:
                        System.out.println("Program Ended");
                        break;
              } while (menuOption != 8);

    how would I go in printing the contacts from one array, then the next array and so on?
    case 7:
        System.out.println("Calling Case 7");
        for( int i = 0 ; i < studentContactsSoFar ; i++ ) {
            System.out.println( (i+1) + ". " + schoolContactInfo.toString() + "\n");
    for( int i = 0 ; i < familyContactsSoFar ; i++ ) {
    System.out.println( (i+1) + ". " + familyContactInfo[i].toString() + "\n");
    for( int i = 0 ; i < contactsSoFar ; i++ ) {
    System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
    break;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Why arrays length is defined to be a field not a method in Java?

    Why arrays length is defined to be a field not a method in Java?

    TRANSLATE result USING R.
    This statement replaces all characters in field result according to the substitution rule stored in field string R .  R contains pairs of letters, where the first letter of each pair is replaced by the second letter.
    in your case TRANSLATE result USING '#'.
    menas '#' and  ' ' space are 2 pair of characters.. and # is replaced by ' ' (space).
    for better understanding..
    Example:
    DATA: T(10) VALUE 'AbCdEfGhIj',
    STRING LIKE T,
    RULE(20) VALUE 'AxbXCydYEzfZ'.
    STRING = T.
    TRANSLATE STRING USING RULE.
    WRITE / STRING.
    Output:
    xXyYzZGhIj
    Hope this helps..

  • How to set array length correctly in this case

      class RunJavaCode implements ActionListener{
        public void actionPerformed(ActionEvent e){
          try{
            Process proc=Runtime.getRuntime().exec("java javaapp");
            InputStream input=proc.getInputStream();
            byte[] b=new byte[3000];
            input.read(b);              
            String javaReport=new String(b);
            input.close();
            outputText.setText(javaReport);
          }catch(IOException ioex){System.out.println("IOException is "+ioex);}
      }how to set this array(byte[] b) length correctly? I mean this array length should not only save memory,but also enough to use('enough to use' mean that read outputed info from console to this byte array never overflow)

    Hi,
    you cannot know in advance, how many bytes will be read. But the read-method returns the number of bytes actually read and this is important!
    So at least you have to write:        int r = input.read(b);
            String javaReport=new String(b, 0, r); However, you still do not know, whether there is even more output available. You could however retrieve the data in a loop and append it e.g. to a StringBuffer, until EOF is encountered.

  • Maximum array length in javacard

    hi all
    i have a java class with 20 member variables.
    member variables are array of bytes. i doesn't allocate
    memory for this variables in class constructor,
    memory for this variables is dynamically allocated
    in my javacard applet (*runtime*).
    i defined an array of this class in my applet( in applet constructor):
    myclassArray = new myclass[MAX]
    for ( short i =0; i < MAX; i++ )
        myclassArray[i] = new myclass();myclass.java:
           class myclass {
                 byte[] membervariable1;
                  setVar1( byte[] input) {
                   membervariable1 = input;
            }if MAX >= 100 , i can't load applet on the card.
    (error :conditions of use not satisfied)
    why this problem occurs? my card is 32k and i doesn't allocate memory for myclass member variables in applet constructor;
    maybe an array of class in javacard has a maximum value in its length. am i right?
    thanks,
    siavash

    s.fallahdoost wrote:
    hi all
    i have a java class with 20 member variables.
    member variables are array of bytes. i doesn't allocate
    memory for this variables in class constructor,It doesn't look like it. If you look at the code snippet below, which is located in the constructor, you are allocating memory in the loop.
    memory for this variables is dynamically allocated
    in my javacard applet (*runtime*).Does not like it neither. If you look at your second code snippet, you're jusr re-referencing the pointer to another instance.
    i defined an array of this class in my applet( in applet constructor):
    myclassArray = new myclass[MAX]
    for ( short i =0; i < MAX; i++ )
    myclassArray[i] = new myclass();myclass.java:
    class myclass {
    byte[] membervariable1;
    setVar1( byte[] input) {
    membervariable1 = input;
    }if MAX >= 100 , i can't load applet on the card.
    (error :conditions of use not satisfied)Could be, since you're allocating memory in the constructor.
    why this problem occurs? my card is 32k and i doesn't allocate memory for myclass member variables in applet constructor;
    maybe an array of class in javacard has a maximum value in its length. am i right?The maximum array length is 32k.

  • Problems with getting array length

    I couldn't get array length in the java from the oracle.
    Here is my source.
    Can anybody answer me, I will really appriciate that.
    Thanks.
    public class Test_tb{
    public static double Test (oracle.sql.ARRAY args){
    double ret = 0;
    try {
    Double[] retArr = (Double[]) args.getArray();
    return retArr.length;
    } catch (Exception e){}
    return ret;
    }

    I've rewritten your code to include the display of any exception that might occur. Could you please run it and post any stack trace here? Thanks.
    public class Test_tb{
      public static double Test (oracle.sql.ARRAY args){
      double ret = 0;
      try {
        Double[] retArr = (Double[]) args.getArray();
        return retArr.length;
      } catch (Exception e){}
        e.printStackTrace();
        return ret;
    }

  • How to calc array length in Labwindows CVI ?

    How to calc array length in Labwindows CVI ? In labwiew,I can find function to calc array length,but in CVI ,I can not ,...

    Hello 让一切随风 
    char  *name ;                              
    int length = 0;
    int i = 0;
     name = malloc(256) ; 
    strcpy(name   , "National Instruments");
    while( name[i] ! = "\0")
      length ++;
    i++
    free(name);

  • Finding Array Length

    I was just wondering if i have an array
    double [][][] array = new double [1][2][3];array.length only gives 1, what function can i use to find the size of the other dimensions (2 and 3)? Thanks in advance for any help.

    I'll try and explain this a little better.
    Say array[0].length is 2, then that means that there is only
    array[0][0] and array[0][1].
    If array[0][0] is 4, then that means that there is only
    array[0][0][0], array[0][0][1], array[0][0][2], and array[0][0][3].
    The reason i did array[0][0].length and not array[0][1].length
    in my other post is because they would both return the same
    thing because of the way you declared the array.
    When you dodouble[][] array = new double[2][3];this is making it so that array[0].length is 3 and array[1].length is 3.
    But if you do this (shown in the previous post)
    double[][] aray = {
        { 2.4, 5.6, 6.4 },
        { 1.4 }
    }then array[0].length is 3, but array[1].length is 1.
    Hope this helps.

  • Trying to teach self Java-question with arrays

    I have a question with arrays. I have a simple inventory program that I am writing(very simple). I have declared and created my array. Is this the time I should build a new class outside of my main in order to hold my array? I am still trying to sort through classes and when to create them. My thought is that because it is a hierarchy I should have a new class. For example, Albums is at the top and then there are specific types of albums, like TributeAlbum, PremiereAlbum, etc. Do I need a class for each of these? When I create the class, do I use the same name as the array?
    More info, just in case: My original class is AlbumInventory. I have created an array to hold 25 TributeAlbums which has 4 instance variables.
    Question 2: Why can I not refer to an album variable like TributeAlbums[0].itemNumber?
    Thanks in advance for your input.
    Denise

    I have a question with arrays. Okay.
    I have a simple
    inventory program that I am writing(very simple). I
    have declared and created my array. Is this the time
    I should build a new class outside of my main in
    order to hold my array? In an OO language classes are usually a good idea.
    I am still trying to sort
    through classes and when to create them. My thought
    is that because it is a hierarchy I should have a new
    class.This sounds a bit confused. You should have a new class when it is appropriate to do so.
    For example, Albums is at the top and then
    there are specific types of albums, like
    TributeAlbum, PremiereAlbum, etc. Do I need a class
    for each of these? Not sure. Why is the type not an attribute of the Album class? This (attribute) seems at first glance to be the way to do it.
    When I create the class, do I use
    the same name as the array?
    ? I am going to say no but I'm not following what you are really asking here.
    More info, just in case: My original class is
    AlbumInventory. I have created an array to hold 25
    TributeAlbums which has 4 instance variables.
    Can you please post some of your actual formatted code? It would also be helpful to know what the attributes for an Album are as you have them.

  • Get Type ArrayElement  fails if array length is 0

    All:
    Get<Type>ArrayElement fails if the array length is 0 in 1.4. It seems to work fine in 1.5. I was "googling" and I found this link -- http://e-docs.bea.com/wljrockit/v315/relnotes/relnotes.htm. It mentions that this problem -- The JNI methods GetStringChars and Get<>ArrayElements threw OutOfMemoryError if called with a String or array of zero length -- was fixed in version 3.1.4. What is version 3.1.4 and how does this relate to JDK verions that I get out of java -version.
    I will appreciate any pointers.
    M.P. Ardhanareeswaran
    Oracle USA

    Drag and drop within a datagrid is rather an unusual thing to do.
    I would suggest your problem lies in choosing to do something which will cause complications.
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • Array.length Question

    Hello,
    I am trying to find out what class array's length attribute comes from and how array is able to use it.
    I have been studying the API but cannot find it or work it out.
    Thanks,
    Harold Clements

    Arrays are considered part of the language and are not listed in the API.
    But length appears to behave like a public field, mostly.
    Have you checked the language spec? It's available free online.

Maybe you are looking for

  • Access Denied - Failed to Open Document

    I've done a few hours of searching for a solution to my problem with no specific answer helping me. I recently upgraded 63 various reports from Crystal Reports version 8.5 to Crystal Reports 2011 (using a Windows 7 box). I realigned all of the report

  • How do I create a desktop shortcut to an application in IOS ?

    I have developped an application.I hope this application create a icon to desktop.when I touch the icon ,it will start the application.

  • Creating a table of contents in a pdf

    Hi all, I'm using the API to create a large pdf i.e a bundle of quotes. Since I'm using the FOPRocessor(InputStrreams[],Templates[]) to create the PDF, I was wondering if there is a way to create a table of contents using the Outlineprocessor or do I

  • Username and password for Windows doesn't work for Safari

    I just installed Safari 3.0.3 for windows under WindowsXP on local machine. But I have problem access local IIS. Here is what I did: 1. type http://localhost in Safari 2. I get a pop up login window says "To view this page, you need to log in to area

  • Log4j configuration problem

    Can anyone explain why every line in the log file is printed twice - this is my log4j configuration file. thanks... Liat <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <!-- ===================================