The first program we will make in java/eclipse, give the output, or as you should say in the programming language: prints, the words “Hello World”. This is traditionally used to introduce new programmers to a programming language.
1. To start, we use the example model. For this “program”, we will name the package: HelloWorld. And the class also: HelloWorld, because this is the main (and only) class in the package.
2. The program is the print the words “Hello World”. We will do this in the method “void start”. Java has a default output stream, which puts everything to the console. We could print something like the following:
This is allowed in the Java coding language, but when you are writing bigger programs it is easier and shorter to only use: out.printf(” .. “).
To use this option we have to adjust some things. Adjustments:
- We have to import PrintStream, this is just a built-in class in Java.
2. We have to create a class variable; this is a function what is available for the whole class.
We have now changed the default word “System” to the word “out”.
For a more advanced version of Hello World click here.