

// Illustration of the byte type and String class in Java.  Unlike in C,
// the String class in Java is more than just an array of characters, in
// two senses:  First, each character is stored in 2 bytes, not just 1,
// in order to accommodate non-ASCII, i.e. non-English, characters.  (If
// the characters are English, then the ASCII code is placed in the
// first byte of each 2-byte pair.) Second, String is a class, and thus
// has variables (e.g. string length) and methods associated with it.

// In addition to illustrating the difference between byte[] and String,
// the code here shows how to convert between the two.

public class BytesNStrings 

{
   public static void main (String[] Args)
	
   {  String S;  
      byte[] B;  // remember, this just gives B's type; no storage 
                 // allocated yet

      S = "abc"; 
      System.out.println(S);
      B = S.getBytes();
      // now print out the bytes (as int's, i.e. their ASCII codes)
      System.out.println(B[0]+" "+B[1]+" "+B[2]);
      B[0]++;  // change 'a' to 'b'
      S = new String(B);  // call constructor of String class
      System.out.println(S);
   }
}


