Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

JavaDeveloper.co.in network has launched a dedicated site just for Java Examples. You can now learn java language by examples.

Please visit Java Examples to get started !

/*

Java String example.

This Java String example describes how Java String object is created and used.

*/

public class JavaStringExample{

public static void main(String args[]){

/*

String in java represents the character sequence.

*/

/* creates new empty string */

String str1 = new String("");

/* creates new string object whose content would be Hello World */

String str2 = new String("Hello world");

/* creates new string object whose content would be Hello World */

String str3 = "Hello Wolrd";

/*

IMPORTANT : Difference between above given two approaches is, string object created using new operator will always return new string ojbect.

While the other may return the reference of already created string ojbect with same content , if any.

*/

System.out.println( str1.length());

}

}

/*

OUTPUT of the above given Java String Example would be :

*/

For more java examples please visit Java Examples

Home Java SCJP SCWCD Servlet Site map