The first program you will make in Java, gives the output HELLOWORLD
or as you should say in the programming language: prints, the words “Hello World”.
The program HelloWorld, is traditionally used to introduce new programmers to a programming language. Because at this moment you haven’t had any theory. It will be really hard to know what you’re doing. Therefore, I explain it first by creating HelloWorld in the easy way. Later on, we will build the program again, and then you should you know what is going on.
in java
1.
start, by copying the structure.
Change the:
Package Name | |
Class Name (on 2 places)
|
2.
For now we are only going to write in the start method:
In the start method we are going to say:
Getting output could be done in different ways. Most common for this program, is to use the CONSOLE.
3.
In Java it is not possible to run a single line of code without using any structure. Therefore, we have to combine the:
extra
System.out.println(“..”) is allowed in the Java, but when you are writing bigger programs it is easier and shorter to only use: out.println(” .. “). Therefore,
- Add this line of code in the start method:
2. You will get an error:
3. and dubbel-click on Import ‘PrintStream’ (java.io); eclipse automatically adds the code on the right place:
Now, your code looks like this:
4. Press run
BACK to the theory
because you created a programming without knowing what you were actually doing we first gonna learn some theory!