Tuesday, April 06, 2021

Java for Beginner #2: Make the first program

 

Once you installed JDK and IDE, let's make your first program.


(The screenshots are from Eclipse IDE but basic structure is the same in IntelliJ and Netbeans)


1. Click "File" from the top menu and select "Java Project".




2. Enter a project name (whatever name you want) and click "Finish".

















 

3. It asks if you want to create module-info.java, so choose "Don't Create"











  





4. Now, right click on the newly created project folder which is at the left of the screen and select "New" then "Class"


























5. Choose a name for the class (whatever name you want). I named "MyClass" here.



























6. Check "public static void main(String[] args)" then click "Finish".

















7. Now you see a screen like this:














This is the basic structure of Java program. You can see the class name that you chose (MyClass) is used.



8. Type: System.out.println("Hello"); 

like the picture below:















9. Press the Run button in the top menu.













10. See the "Console" window at the bottom of the screen.








"Hello" is displayed in the console window.


System.out.println(""); is a Java command to display text in the console window.


You can change the text between " " to whatever text you want.


Let's change the text to "This is my first program."

like the picture below:













And press the "Run" button again.



Then you can see the text in the console has been changed.









Congratulations! You've made your first program!


 

No comments:

Post a Comment