Certain PCs may come pre-installed with Java.
To determine if Java is installed on your Windows PC, you can either search for “Java” in the start bar or enter the following command in Command Prompt (cmd.exe):
C:\Users\Your Name>java -version |
Upon successful installation of Java, you’ll encounter a message similar to the following (content may vary based on the version):
|
In the event that Java is not installed on your computer, you can obtain it at no cost by visiting oracle.com.
Please note: In this tutorial, we’ll be writing Java code using a text editor. Nonetheless, you can also utilize Integrated Development Environments like IntelliJ IDEA, NetBeans, or Eclipse, especially beneficial for handling larger sets of Java files.
For installing Java on Windows:
In Java, each application initiates with a class name that must correspond to the filename.
Let’s initiate our inaugural Java file, named Main.java, which can be accomplished using any text editor, such as Notepad.
The file should feature a “Hello World” message, scripted with the following code:
Main.java
|
If the code above seems complex, don’t fret – we’ll delve into it thoroughly in subsequent chapters. For now, concentrate on mastering how to execute the provided code.
Save the provided code in Notepad as “Main.java”. Next, launch Command Prompt (cmd.exe), navigate to the directory where you saved your file, and execute the command “javac Main.java”:
C:\Users\Your Name>javac Main.java |
Compiling your code with this command will prompt the Command Prompt to proceed to the next line if there are no errors detected. Afterward, input “java Main” to execute the file.
C:\Users\Your Name>java Main |
Upon successful execution, the output should display:
|
Congrats! You’ve successfully written and executed your inaugural Java program.