Intro to Java: "Hello World" Program

Java programming can be complicated when undergoing big projects, but it can also be as simple as telling your computer to print out one sentence. In this post, I will show you how to create a Class and print out the phrase "Hello World."

First things first, you need to install Eclipse Neon onto your computer. This allows you to write and execute your code with feedback about errors. You can use this link to download for free: https://www.eclipse.org/downloads/?.

Now that you have the Eclipse program on your computer, click "File" in the upper left hand corner for your computer screen, select "New" on the drop down bar, and then select "Class". 

 

A new tab will then pop up. You need to name your Class. Remember that your Class name should begin with a capital letter, and each new word should also be capitalized. No spaces are allowed in between words. You can name your Class anything you would like, however it is best to name it something that reflects what your code will be about. I named my Class "HelloWorldDemo". Check the boxes that say "public static void main(String[] args)" and "inherited abstract methods" if they are not already selected. The modifier type is public. Press "Finish" when you are done.


In order to print out a sentence you must use the Java syntax for a String. The syntax to print a string is: System.out.println(""); . Write out the sentence that you would like to print inside the quotation marks. When the code runs the only thing that you will see is what is inside of the quotation marks (the syntax will not appear). You must remember that Java is case sensitive, so pay attention to which words are capitalized! Second, EVERY SINGLE LINE OF CODE IN JAVA MUST END WITH A SEMICOLON. It is so important to remember this rule because otherwise your code will not run. 


Last step: When you are finished writing out the code that you want to run, select the green circle in the upper left hand corner of the Eclipse program. A "Save and Launch" pop up will appear, select "OK".



An "Error in Workplace" popup will appear, press "Proceed". 


Your code should run properly if there are no errors! Your executed code should look like this:  

If however, you code does not execute properly, and an error message appears, go back and try to debug (scan code for errors) and press run again.




Comments

Popular Posts