Using Scripts in CMD

A Hello, World! is a simple program that outputs Hello, World! on the screen. Since it's a very simple program, it's often used to introduce a new programming language to a newbie. Let's explore how Java Hello, World! program works.

If you want to run this program on your computer, make sure that Java is properly installed. Also, you need an IDE (or a text editor) to write and edit Java code. Any text editor may be used for writing Java programs. In Windows Notepad can do well. However, most of the developers use a certain advanced text application called Notepad++. Visit https://notepad-plus-plus.org/downloads/ for latest version of Notepad++. The steps for writing and executing Hello World! Java program.

  1. Open text application (See that it must be a simple Notepad like program. Never ever use MSWord type of complex applications.)
  2. Put your code inside a new file (File -> New in Notepad++)
  3. Open CMD in Windows; compile
  4. Use the class to execute the program

The code inside the Notepad++ for Hello World! application can be as below.


\begin{lstlisting}
// Your First Program
\par
class HelloWorld {
public static ...
...(String[] args) {
System.out.println(''Hello, World!'');
}
}
\end{lstlisting}

If you have copied the exact code, you need to save the file name as HelloWorld.java. It's because the name of the class and filename should match in Java.

Go to the terminal use the following command


\begin{lstlisting}
javac HelloWorld.java
java HelloWorld
\end{lstlisting}

The command $\lstinline{java HelloWorld}$ should be able to produce the output "Hello, World!" inside CMD in Windows. This is world which is there in the listing 2.1.



Subsections