In a Windows-based operating system, if the environment variables are not correct, you might get an error when running javac. Refer the installation article How to Install the Java Software Development Kit for more details about JDK installation to avoid this error.

Let’s look at the components of this line: System tells the system to do something. out tells the system that we are going to do some output stuff. println stands for “print line,” so we are telling the system to print a line in the output. The parentheses around (“Hello World. “) means that the method System. out. println() takes in a parameter, which, in this case, is the String “Hello World. " Note that there are some rules in Java that we have to adhere to: You must always add a semicolon at the end of every line. Java is case sensitive, so you must write method names, variable names, and class names in the correct case or you will get an error. Blocks of code specific to a certain method or loop are encased between curly brackets.

This tells our program that we want to use the Scanner object which exists in the package java. util. If we wanted to have access to every object in the java. util package, we simply write import java. util. *; at the beginning of our code.

userInputScanner is the name of the Scanner object that we just instantiated. Note that the name is written in camel case; this is the convention for naming variables in Java. We use the new operator to create a new instance of an object. So, in this instance, we created a new instance of the Scanner object by writing new Scanner(System. in). The Scanner object takes in a parameter that tells the object what to scan. In this case, we put in System. in as a parameter. System. in tells the program to scan the input from the system, which is the input that the user will type into the program.

In Java, the convention for using an object’s method is objectName. methodName(parameters). In userInputScanner. nextLine(), we are calling our Scanner object by the name we just gave it and then we are calling its method nextLine() which does not take in any parameters. Note that we are storing the next line in another object: the String object. We have named our String object userInputName

The way we chained up “Hello “, the user’s name, and “!” by writing “Hello " + userInputName + “!” is called String concatenation. What’s happening here is that we have three strings: “Hello “, userInputName, and “!”. Strings in Java are immutable, which means that they cannot be changed. So when we are concatenating these three strings, we are essentially created a new string that contains the greeting. Then we take this new string and feed it as a parameter to System. out. println.