Hello, World
Hello World Example in Java
Here is a simple "Hello, World!" program in Java:
Instructions to Run the Program
Install Java Development Kit (JDK):
Download and install the JDK from the official Oracle website or use a package manager like
brewon macOS:brew install openjdk
Set Up Your Environment:
Ensure that the
JAVA_HOMEenvironment variable is set correctly. You can add the following line to your.bash_profile,.zshrc, or equivalent:export JAVA_HOME=$(/usr/libexec/java_home) export PATH=$JAVA_HOME/bin:$PATH
Create the Java File:
Create a new file named
HelloWorld.javaand paste the above code into it.
Compile the Java Program:
Open a terminal and navigate to the directory where
HelloWorld.javais located.Compile the program using the
javaccommand:javac HelloWorld.java
Run the Compiled Program:
After compilation, a file named
HelloWorld.classwill be generated in the same directory.Run the program using the
javacommand:java HelloWorld
You should see the output: