Results 1 to 2 of 2
  1. #1
    elizabeth is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default help with basic java code

    Can I this function better?
    Java Code:
    //Calculate Csum A = A XOR B
    byte CountCsum(String m) {
    byte[] inData = m.getBytes();
    byte csum=0;
    // Don't Count the first byte
    for(byte n=1;n<m.length();n++)
    csum ^= inData[n];
    
    return csum;
    }
    In C you normally sending a pointer to an array into the function but here I must convert the string to byte array
    an that takes time and memory.

    Are java sending a reference to the string or the entire string to the function??

  2. #2
    leonard is offline Member
    Join Date
    Jul 2007
    Posts
    43
    Rep Power
    0

    Default

    Java is pass-by-reference, so the argument to your method is a copy of the reference to the original String.

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 06:17 PM
  2. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 12:36 PM
  3. java code
    By sobhalr in forum New To Java
    Replies: 0
    Last Post: 12-28-2007, 10:25 AM
  4. Help with basic shapes in java
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 11:40 PM
  5. Help, basic shapes using java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 08:52 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
  •