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
brew
on macOS:brew install openjdk
Set Up Your Environment:
Ensure that the
JAVA_HOME
environment 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.java
and paste the above code into it.
Compile the Java Program:
Open a terminal and navigate to the directory where
HelloWorld.java
is located.Compile the program using the
javac
command:javac HelloWorld.java
Run the Compiled Program:
After compilation, a file named
HelloWorld.class
will be generated in the same directory.Run the program using the
java
command:java HelloWorld
You should see the output: