It is customary for all programmers to create a Hello World program as their first program. We shall honor this tradition and make our very own!
Step 1: Open up your Integrated Development Environment (I will be using JGrasp.)
Step 2: Lets create a class to hold our program! To do this, lets write the following:
Step 3: We can now save our program. It is important to have our file name the same as our class. In this case, since our class is “HelloWorld”, we will also save our file name as “HelloWorld.”
*Note: it is not mandatory, but it is a good practice for future programing projects.
Step 4: Now that we have established our class, we are going to add our main method into the class:
(Don’t worry, we will explain exactly what that means in later lessons.)
Step 5: Now between the brackets of our main method we are going to add our printing method and what we want printed inside of it:
Step 6: Compile and run your code and you should see “Hello World!” in the Run I/O console at the bottom of the screen.
Congrats!!!! You have made your first Java program!!!
Notice how when you compiled the program, the indentation changed? This is an important feature and helps you understand the structure of a program more easily.
Now, lets go over some key points:
What is an IDE?
IDE stands for Integrated Development Environment. It is used for creating, compiling, and finally running your code.
Why should our file name match the class name?
Although it isn’t technically necessary now, in the future we will be creating programs with multiple classes. In order to reference these classes, we will want to have our names matching.
Does capitalization matter?
I have no idea what I just did, should I be worried?
Don’t worry. In the next lesson we will go over what we just wrote.