3.3.6. String Literals

A string literal is a sequence of characters which must be enclosed in double quotes and must occur on a single line. All string literals are objects of the class String.

			package javatutorial;

			/**
			 * Example usage of String literals
			 * 
			 * @author f5java.com 
			 */
			public class StringLiterals {

				public static void main(String[] args) {
					
					// Printing the String literals
					System.out.println("this is an example of String literal");
					System.out.println("Escape sequence can be used \t did you see the extra space");
					System.out.println("Escape sequence can be used \n did you see I am in new line");
					
					// Escaping \ in the String : Imp- you will run across this scenario pretty often in java development
					System.out.println("I have to escape the \" like this!");
					
					System.out.println("Special charaters and symbols can be used in string like"
							+ "! ~ ' @ % & 1 2 84 many more ");
					
				}

			}