Author: Vrund Patel
The first thing you do in any programming language is print out Hello, World!. So we are going to follow those conventions. Let’s get started:
Next go to File –> New –> Class –> Enter the name of the class, example: HelloWorld. You should see a basic class created by Eclipse.
public class HelloWorld {
}
Next we will write the main method that will execute the program. So, we will type in the main method between the curly braces of the HelloWorld class.
public class HelloWorld {
public static void main(String [] args) {
}
}
Next we will add some comments to our code so that when we come back to this program we know what it does. Comments are for humans and the computer ignores the comments. In Java, there are multiple ways to do comment.
// By using two slashes you can create a line comment.
/* This is a
* multi - line comment
*/
Next we will print out the text to our console. In Java, we can print anything to the screen using the System.out.println(); method. Let’s take a look in the program that we created.
public class HelloWorld {
/* This program prints out
* Hello,World to the console.
*/
public static void main(String[] args) {
//To print out text to the screen you need to put the text between quotation marks.
System.out.println("Hello,World!");
}
}
After that, we need to compile the program. Java will not run if there is an error. There are three types of error in Java. They are as follows:
Happy Coding!