Java: Hello World! + About Eclipse and Java

In this tutorial I will show you how to print out “Hello World!” in the console. This is one of the first things you have to do when you want to start coding. This is the file I will start with.


package net.tutorial.src;

public class Tutorial 
{

}


Java is an object orientated programing language. This means that you use Objects of certains things to do things with them. When you create a program with it you will have variables which are for example numbers, letters or words. The complete list of variables you can use will be explained in a later tutorial. Another thing you will find in Java are methods. Methods can be called groups of code. Methods are placed inside of a Class file, because they have to be saved somewhere on your pc under a certain name.
The things you are writing in Eclipse are actually .java files and not .class files. This is because .java files are written in understandable code with words etc. .class files aren’t. They are made in such a way that they are much faster to use for a pc, but you can’t read them just like that. When you try to run your program in Eclipse by clicking the green arrow on the top Eclipse will compile your files which means that it changes .java into .class files. Then it runs the Application from the command prompt, but it’s all done in a easy to use Gui.
Java needs a place to start reading the code in an Application. This place is the main method. It looks like this.


public static void main(String[] args)
{

}


So when you start a Java application Java starts reading the code from here. It will do it once when you click start. How you can make the same code run several times will be something for a later tutorial. Because Java starts reading here every single program you will ever make will need one of these methods.
In here you can acces pretty much everything from Java. There are a lot of things you can do from here. For this tutorial we will do nothing more than print one simple line of text to the console. If you read through later tutorials you can also create windows, buttons, images and a lot more.
To print a line of code to the console you will need this line of code.


package net.tutorial.src;

public class Tutorial 
{
public static void main(String[] args)
{
System.out.println(“Hello World!”);
}
}


This code will write out: Hello World! to the console. Now click the green arrow on the top left right next to the bug icon. When you do that it will print out that line.
You can see that it works by looking at the bottom of the Eclipse window. There should be 4 tabs on there. Before you click the green arrow it is on the Problems tab. This will show you any mistakes in your Java code. After you have clicked the green arrow it will switch to the Console. There it will show you what the program does. If your game crashes it will also show the Print Stack Trace on there which is a pretty easy to read error log. In there you can see where and why it crashes, but also that is for a later tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">