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.

helloworld java

This should work in the way, that you press run and the computer says HelloWorld

in java

1.

start, by copying the structure.
Change the:

Package Name

package HelloWorld;
package name java
Class Name (on 2 places)

class HelloWorld {

 

 

 

 

new HelloWorld().start();

 

 

  1.  herechange class java
  2. and herechange class java

STRUCTURE:

You have changed line 1, 3 and 9
package HelloWorld;

class HelloWorld {

	void start(){
	}
	
	public static void main(String[] args) {
		new HelloWorld().start();
	}
}

2.

For now we are only going to write in the start method:

 start method java  java file

 

In the start method we are going to say:

start method java

Getting output could be done in different ways. Most common for this program, is to use the CONSOLE.

This is the code to print hello world
System.out.println("Hello World")

3.

In Java it is not possible to run a single line of code without using any structure. Therefore, we have to combine the:

package P;

public class HelloWorld {

	void start() {
		System.out.println("HELLOWORLD");
	}
	
	public static void main (String [] args) {
		new HelloWorld().start();
	}

}

 

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,

  1. Add this line of code in the start method:
PrintStream out = new PrintStream(System.out);

2. You will get an error:

error PrintStream javaJust click on it:

error printstream java3. and dubbel-click on Import ‘PrintStream’ (java.io); eclipse automatically adds the code on the right place:

import java.io.PrintStream;

Now, your code looks like this:

Hello World Code
package HelloWorld;

import java.io.PrintStream;

class HelloWorld {

	void start() {
		PrintStream out = new PrintStream(System.out);
		out.printf("Hello World");
	}

	public static void main(String[] args) {
		new HelloWorld().start();
	}
}

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!

!CLICK HERE!