Hello and welcome to With Ninja 😃
We're thrilled to have you here and hope you enjoy reading our content. Our blog is dedicated to first java program and explanations, and we're passionate about sharing our knowledge and insights with you.
If you ever have any questions or comments, please don't hesitate to reach out to us. We love hearing from our readers and value your feedback
Here is an example of a simple Java program that prints "Hello, World!" to the console:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
The "main" method takes an array of strings as an argument named "args". This argument is not used in this program, but it can be used to pass command-line arguments to the program.
Inside the "main" method, the "System.out.println" statement prints the string "Hello, World!" to the console. The "println" method adds a new line after the string, so the output appears on a separate line.
To run this program, you need to compile it first. Here are the steps to compile and run the program:
1. Save the code in a file named "HelloWorld.java". Make sure to use the same class name as the filename.
2. Open a command prompt or terminal window and navigate to the directory where the file is saved.
3. Type the following command to compile the program:
javac HelloWorld.java
This will generate a file named "HelloWorld.class" in the same directory.
4. Type the following command to run the program:
java HelloWorld
This will execute the program and print "Hello, World!" to the console.
That's it! You have successfully written and executed your first Java program.
Best regards,
With Ninja
0 Comments