Ways to Write Your First Program in Java. We will first create a program that prints . Hello. World is your class name and you will need your class name to be the same name as your file. The main method public static void main(String. This main method will have the same method declaration in every Java program. Your final Hello World program should look like the following. Hello. World . Navigate to the folder where you saved Hello.
World. java and type in javac Hello. World. java. This tells the Java compiler that you want to compile Hello. World. java. If there are errors, the compiler will tell you what you did wrong. Otherwise, you shouldn't see any messages from the compiler.
If you look at the directory where you have Hello. World. java now, you should see Hello.
World. class. This the the file that Java will use to run your program. Finally, we get to run our program!
In command prompt or terminal, type in java Hello. World. This tells Java that you want to run the class Hello.