Java Program to initialize a string and print

In this program, lets create a class named InitString which initializes the string and prints on the console using a variable.

Program

public class InitString {
    public static void main(String[] args) {
        String str;
        str = "Welcome to Java Programming tutorial on oodlescoop.com";
        System.out.println(str);
    }
}

Let us understand the program by breaking into simple parts:

  1. class InitString: Any Java program starts with a class, in this case the class name is InitString
  2. public static void main(String[] args): main is the entry point for any Java program.
  3. String str; : Declare a string variable. Here str is the variable name of type String.
  4. str = "Welcome to Java Programming tutorial on oodlescoop.com"; : Initialize the str by assigning the value to variable using double quotes("").
  5. System.out.println(str);: System.out.println prints the value/text stored in the variable str.

Output

Welcome to Java Programming tutorial on oodlescoop.com