In this exercise, we will try to write our first simple program. The program name is "HelloWorld.java".
Double click the icon to launch the IDE.
You will get the following window.
"eclipse-workspace" is a default workspace that you can use to keep all your Java programs. Workspace is a folder on your computer. You can create your own folder by typing your folder's name. In the following example, I use "TK1114-workspace". And then click on the "Launch" button.
Then, the Welcome window will appear.
Close the Welcome window and you will get the following display.
Before you can write your Java program, you need to create a Java project. I would suggest you to create a different Java project for different topics. For example, Lab1, Lab2, Lab3, etc. By doing so, it is easy for you to search the program.
Create a project by click on the "File" menu, and choose New->Java Project. (refer to the following screenshot).
Then, you will get the following display. On the Project Name, type your project name, i.e. Lab1. Always start with capital letter for project name and class name.
Make sure you untick the "Create module-info.java file" box, and then click the "Finish" button.
Then, you will get the following display.
Right-click on your project i.e Lab1, and choose New->Class.
Then, you will get the "Java Class" window as the following. Type your class name (program name) i.e. HelloWorld (one word begin with capital letter).
Tick the "public static void main(String[] args)", and click "Finish" button.
You will get the Java program template named "HelloWorld.java".
Add a statement:
System.out.println("Hello World");
Don't forget to put semi-colon ";" at the end of the statement. Every Java statement must end with semi-colon, otherwise, your program will get an error.
Click on "run" button available on the Toolbar (below the menu bar). To find the "run" button, just hover on top of each button. The pop-up tips will tell you which one is the "run" button.
On the "Console" window (at the bottom of the screen), you can see the output of your program if your program has no error.
In our HelloWorld.java program, suppose the output is:
Hello World
The following video will show how to write our "HelloWorld.java" program.
Refer to the HelloWorld.java program.
/* This is my first java program.
* This will print 'Hello World' as the output
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
public class HelloWorld
HelloWorld is a class name. For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.
Name of the program file should exactly match the class name.
When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).
/* This is my first java program.
* This will print 'Hello World' as the output
*/
This is a comment. Java supports single-line and multi-line comments very similar to c and c++. All characters available inside any comment are ignored by Java compiler.
public static void main(String args[])
In Java, this is called a method. Java program processing starts from the main() method which is a mandatory part of every Java program.
All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
System.out.println("Hello World");
The method System.out.println will print whatever in between " and ". So, in the above statement Hello World will be printed on the screen.
Write a program name "AmazingJourney.java". Suppose the output of the program is as follows:
This is my first Java Program
There is no error
and I feel excited