fork download
  1. class StringTester
  2. {
  3.  
  4. public static void main ( String[] args )
  5. {
  6. String str1; // str1 is a variable that may refer to an object.
  7. // The object does not exist unit the "new" is executed.
  8. int len; // len is a primitive variable of type int
  9.  
  10. str1 = new String("Random Jottings"); // create an object of type String
  11.  
  12. len = str1.length(); // invoke the object's method length()
  13.  
  14. System.out.println("The string is " + len + " characters long");
  15. }
  16. }
  17.  
Success #stdin #stdout 0.09s 212416KB
stdin
Standard input is empty
stdout
The string is 15 characters long