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:
class InitString
: Any Java program starts with a class, in this case the class name is InitStringpublic static void main(String[] args)
: main is the entry point for any Java program.String str
; : Declare a string variable. Here str is the variable name of type String.str
= "Welcome to Java Programming tutorial on oodlescoop.com"; : Initialize the str by assigning the value to variable using double quotes("").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